Delete dead generic popup inspector shell
This commit is contained in:
parent
24aa842261
commit
6de0141b33
19 changed files with 448 additions and 5638 deletions
|
|
@ -1,88 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UniRx;
|
||||
|
||||
public class DropdownMenu : MonoBehaviour
|
||||
{
|
||||
public Canvas Canvas;
|
||||
public ClickCatcher CancelClickCatcher;
|
||||
public PropertyButton OptionPrefab;
|
||||
|
||||
public RectTransform ContentRoot;
|
||||
|
||||
public float OptionHeight;
|
||||
public float PaddingHeight;
|
||||
|
||||
private List<GameObject> _options = new List<GameObject>();
|
||||
private IDisposable _backgroundClickSubscription;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (CancelClickCatcher != null)
|
||||
_backgroundClickSubscription = CancelClickCatcher.OnClick.Subscribe(data =>
|
||||
{
|
||||
End();
|
||||
});
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_backgroundClickSubscription?.Dispose();
|
||||
_backgroundClickSubscription = null;
|
||||
}
|
||||
|
||||
private void End()
|
||||
{
|
||||
CancelClickCatcher.gameObject.SetActive(false);
|
||||
gameObject.SetActive(false);
|
||||
ActionGameManager.Instance?.Input.Global.Enable();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
// Destroy previous options
|
||||
foreach(var option in _options)
|
||||
Destroy(option);
|
||||
_options.Clear();
|
||||
}
|
||||
|
||||
public void AddOption(string text, Action action, bool selected = false, bool enabled = true)
|
||||
{
|
||||
var optionButton = Instantiate(OptionPrefab, ContentRoot);
|
||||
optionButton.Label.text = text;
|
||||
optionButton.Button.onClick.AddListener(() =>
|
||||
{
|
||||
action();
|
||||
End();
|
||||
});
|
||||
optionButton.Button.interactable = enabled;
|
||||
//optionButton.Button..CurrentState = !enabled ? FlatButtonState.Disabled : selected ? FlatButtonState.Selected : FlatButtonState.Unselected;
|
||||
_options.Add(optionButton.gameObject);
|
||||
}
|
||||
|
||||
public void Show(RectTransform parent)
|
||||
{
|
||||
var rect = transform as RectTransform;
|
||||
var pivot = rect.pivot;
|
||||
pivot.x = 0;
|
||||
var scaleFactor = Canvas.scaleFactor;
|
||||
var corners = new Vector3[4];
|
||||
parent.GetWorldCorners(corners);
|
||||
var pivotTop = corners[0].y > (PaddingHeight + _options.Count * OptionHeight) * scaleFactor;
|
||||
pivot.y = pivotTop ? 1 : 0;
|
||||
rect.pivot = pivot;
|
||||
rect.sizeDelta = parent.sizeDelta;
|
||||
rect.position = pivotTop ? corners[0] : corners[1];
|
||||
CancelClickCatcher.gameObject.SetActive(true);
|
||||
ActionGameManager.Instance?.Input.Global.Disable();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 848ae49aff071f5458dcc0322b8b84eb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PropertiesList : PropertiesPanel
|
||||
{
|
||||
public Image FoldoutIcon;
|
||||
public float FoldoutRotationDamping;
|
||||
public Button Button;
|
||||
public VerticalLayoutGroup LayoutGroup;
|
||||
public int FoldedPadding = -8;
|
||||
public int ExpandedPadding = 8;
|
||||
public event Action<bool> OnExpand;
|
||||
|
||||
private bool _expanded = false;
|
||||
private float _targetFoldoutRotation = 0;
|
||||
private float _foldoutRotation = 0;
|
||||
|
||||
public bool Expanded => _expanded;
|
||||
|
||||
public new void Awake()
|
||||
{
|
||||
Button.onClick.AddListener(ToggleExpand);
|
||||
OnPropertyAdded += go => go.SetActive(_expanded);
|
||||
//SetExpanded(true, true);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
RefreshValues();
|
||||
_foldoutRotation =
|
||||
Mathf.Lerp(_foldoutRotation, _targetFoldoutRotation, FoldoutRotationDamping * Time.deltaTime);
|
||||
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
|
||||
}
|
||||
|
||||
public void ToggleExpand() => SetExpanded(!_expanded, false);
|
||||
|
||||
public void SetExpanded(bool expanded, bool force)
|
||||
{
|
||||
_expanded = expanded;
|
||||
var padding = LayoutGroup.padding;
|
||||
padding = new RectOffset(padding.left, padding.right, padding.top, _expanded ? ExpandedPadding : FoldedPadding);
|
||||
LayoutGroup.padding = padding;
|
||||
foreach (var property in Properties) property.SetActive(_expanded);
|
||||
_targetFoldoutRotation = _expanded ? -90 : 0;
|
||||
if (force)
|
||||
{
|
||||
_foldoutRotation = _targetFoldoutRotation;
|
||||
FoldoutIcon.transform.localRotation = Quaternion.Euler(0,0, _foldoutRotation);
|
||||
}
|
||||
OnExpand?.Invoke(_expanded);
|
||||
}
|
||||
|
||||
// public override PropertyLabel AddProperty(string name, Func<string> read = null, Action<PointerEventData> onClick = null, bool radio = false)
|
||||
// {
|
||||
// var prop = base.AddProperty(name, read, onClick, radio);
|
||||
// prop.gameObject.SetActive(false);
|
||||
// return prop;
|
||||
// }
|
||||
//
|
||||
// public override PropertiesList AddList(string name)
|
||||
// {
|
||||
// var list = base.AddList(name);
|
||||
// list.gameObject.SetActive(false);
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
// public override RectTransform AddSection(string name)
|
||||
// {
|
||||
// var section = base.AddSection(name);
|
||||
// section.gameObject.SetActive(false);
|
||||
// return section;
|
||||
// }
|
||||
//
|
||||
// public override PropertyButton AddButton(string name, Action<PointerEventData> onClick)
|
||||
// {
|
||||
// var button = base.AddButton(name, onClick);
|
||||
// button.gameObject.SetActive(false);
|
||||
// return button;
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2544c9c8b6358c54ea58c5fb33bb48b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,631 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public class PropertiesPanel : MonoBehaviour
|
||||
{
|
||||
public RectTransform Spacer;
|
||||
public DropdownMenu Dropdown;
|
||||
public TextMeshProUGUI Title;
|
||||
public RectTransform Section;
|
||||
public PropertiesList List;
|
||||
public Property Property;
|
||||
public PropertyLabel PropertyLabel;
|
||||
public AttributeProperty Attribute;
|
||||
public InputField InputField;
|
||||
public RangedFloatField RangedFloatField;
|
||||
public RangedFloatField ProgressField;
|
||||
public EnumField EnumField;
|
||||
public BoolField BoolField;
|
||||
public PropertyButton PropertyButton;
|
||||
public ButtonField ButtonField;
|
||||
public IncrementField IncrementField;
|
||||
public StatSheet StatSheet;
|
||||
public CurveField CurveField;
|
||||
public RectTransform Content;
|
||||
|
||||
[HideInInspector] public ActionGameManager GameManager;
|
||||
|
||||
protected List<GameObject> Properties = new List<GameObject>();
|
||||
protected event Action RefreshPropertyValues;
|
||||
protected bool RadioSelection = false;
|
||||
|
||||
protected event Action<GameObject> OnPropertyAdded;
|
||||
protected Action OnPropertiesChanged;
|
||||
|
||||
public int Children => Properties.Count;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
OnPropertyAdded += go => go.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
RefreshValues();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
// private void OnDisable()
|
||||
// {
|
||||
// RemoveListener();
|
||||
// }
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
//RemoveListener();
|
||||
foreach(var property in Properties)
|
||||
Destroy(property);
|
||||
Title.text = "Properties";
|
||||
Properties.Clear();
|
||||
RefreshPropertyValues = null;
|
||||
RadioSelection = false;
|
||||
}
|
||||
|
||||
public RectTransform AddSpacer()
|
||||
{
|
||||
var spacer = Instantiate(Spacer, Content ?? transform);
|
||||
Properties.Add(spacer.gameObject);
|
||||
OnPropertyAdded?.Invoke(spacer.gameObject);
|
||||
return spacer;
|
||||
}
|
||||
|
||||
public RectTransform AddSection(string name)
|
||||
{
|
||||
var section = Instantiate(Section, Content ?? transform);
|
||||
section.GetComponentInChildren<TextMeshProUGUI>().text = name;
|
||||
Properties.Add(section.gameObject);
|
||||
OnPropertyAdded?.Invoke(section.gameObject);
|
||||
return section;
|
||||
}
|
||||
|
||||
public Property AddProperty(Func<string> read)
|
||||
{
|
||||
if (read == null) throw new ArgumentException("Attempted to add property with null read function!");
|
||||
|
||||
var property = Instantiate(Property, Content ?? transform);
|
||||
property.Label.text = read();
|
||||
|
||||
RefreshPropertyValues += () => property.Label.text = read();
|
||||
Properties.Add(property.gameObject);
|
||||
OnPropertyAdded?.Invoke(property.gameObject);
|
||||
return property;
|
||||
}
|
||||
|
||||
public Property AddProperty(string name, Func<string> read = null)
|
||||
{
|
||||
Property property;
|
||||
if(read != null)
|
||||
property = Instantiate(PropertyLabel, Content ?? transform);
|
||||
else
|
||||
property = Instantiate(Property, Content ?? transform);
|
||||
property.Label.text = name;
|
||||
|
||||
if (read != null)
|
||||
RefreshPropertyValues += () => ((PropertyLabel) property).Value.text = read.Invoke();
|
||||
Properties.Add(property.gameObject);
|
||||
OnPropertyAdded?.Invoke(property.gameObject);
|
||||
return property;
|
||||
}
|
||||
|
||||
public StatSheet AddStatSheet()
|
||||
{
|
||||
var sheet = Instantiate(StatSheet, Content ?? transform);
|
||||
Properties.Add(sheet.gameObject);
|
||||
OnPropertyAdded?.Invoke(sheet.gameObject);
|
||||
RefreshPropertyValues += () => sheet.RefreshValues();
|
||||
return sheet;
|
||||
}
|
||||
|
||||
public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
|
||||
{
|
||||
var list = Instantiate(List, Content ?? transform);
|
||||
list.GameManager = GameManager;
|
||||
list.Dropdown = Dropdown;
|
||||
list.Title.text = name;
|
||||
// foreach (var element in elements)
|
||||
// {
|
||||
// var item = Instantiate(PropertyPrefab, list);
|
||||
// item.Name.text = element.Item1;
|
||||
// item.Value.text = element.Item2();
|
||||
// item.ValueFunction = element.Item2;
|
||||
// Properties.Add(item.gameObject);
|
||||
// }
|
||||
//RefreshPropertyValues += () => list.RefreshValues();
|
||||
Properties.Add(list.gameObject);
|
||||
OnPropertyAdded?.Invoke(list.gameObject);
|
||||
return list;
|
||||
}
|
||||
|
||||
public CurveField AddCurveField()
|
||||
{
|
||||
var curveInstance = Instantiate(CurveField, Content ?? transform);
|
||||
Properties.Add(curveInstance.gameObject);
|
||||
return curveInstance;
|
||||
}
|
||||
|
||||
public virtual PropertyButton AddButton(string name, Action onClick)
|
||||
{
|
||||
var button = Instantiate(PropertyButton, Content ?? transform);
|
||||
button.Label.text = name;
|
||||
button.Button.interactable = onClick != null;
|
||||
button.Button.onClick.AddListener(() => onClick());
|
||||
Properties.Add(button.gameObject);
|
||||
OnPropertyAdded?.Invoke(button.gameObject);
|
||||
return button;
|
||||
}
|
||||
|
||||
public void AddButton(string name, string label, Action onClick)
|
||||
{
|
||||
var button = Instantiate(ButtonField, Content ?? transform);
|
||||
button.Label.text = name;
|
||||
button.ButtonLabel.text = label;
|
||||
button.Button.interactable = onClick != null;
|
||||
button.Button.onClick.AddListener(() => onClick());
|
||||
Properties.Add(button.gameObject);
|
||||
OnPropertyAdded?.Invoke(button.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<string> read, Action<string> write)
|
||||
{
|
||||
var field = Instantiate(InputField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.Standard;
|
||||
field.Field.onValueChanged.AddListener(val => write(val));
|
||||
// field.Field.text = read();
|
||||
RefreshPropertyValues += () =>
|
||||
{
|
||||
var s = read();
|
||||
if (field.Field.text != s)
|
||||
{
|
||||
field.Field.text = s;
|
||||
field.gameObject.SetActive(false);
|
||||
Observable.NextFrame().Subscribe(_ =>
|
||||
{
|
||||
if(field != null)
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
});
|
||||
}
|
||||
};
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<float> read, Action<float> write)
|
||||
{
|
||||
var field = Instantiate(InputField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.DecimalNumber;
|
||||
field.Field.onValueChanged.AddListener(val => write(float.Parse(val)));
|
||||
RefreshPropertyValues += () =>
|
||||
{
|
||||
var s = read().ToString(CultureInfo.InvariantCulture);
|
||||
if (field.Field.text != s)
|
||||
{
|
||||
field.Field.text = s;
|
||||
field.gameObject.SetActive(false);
|
||||
Observable.NextFrame().Subscribe(_ => OnPropertyAdded?.Invoke(field.gameObject));
|
||||
}
|
||||
};
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<int> read, Action<int> write)
|
||||
{
|
||||
var field = Instantiate(InputField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Field.contentType = TMP_InputField.ContentType.IntegerNumber;
|
||||
field.Field.onValueChanged.AddListener(val => write(int.Parse(val)));
|
||||
RefreshPropertyValues += () =>
|
||||
{
|
||||
var s = read().ToString(CultureInfo.InvariantCulture);
|
||||
if (field.Field.text != s)
|
||||
{
|
||||
field.Field.text = s;
|
||||
field.gameObject.SetActive(false);
|
||||
Observable.NextFrame().Subscribe(_ => OnPropertyAdded?.Invoke(field.gameObject));
|
||||
}
|
||||
};
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddIncrementField(string name, Func<int> read, Action<int> write, Func<int> min, Func<int> max)
|
||||
{
|
||||
var field = Instantiate(IncrementField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Increment.onClick.AddListener(() => write(read() + 1));
|
||||
field.Decrement.onClick.AddListener(() => write(read() - 1));
|
||||
RefreshPropertyValues += () =>
|
||||
{
|
||||
var val = read();
|
||||
var minval = min();
|
||||
var maxval = max();
|
||||
if (val < minval || val > maxval)
|
||||
write(val = clamp(val, minval, maxval));
|
||||
field.Value.text = val.ToString(CultureInfo.InvariantCulture);
|
||||
field.Increment.interactable = val == maxval;
|
||||
field.Decrement.interactable = val == minval;
|
||||
};
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<float> read, Action<float> write, float min, float max)
|
||||
{
|
||||
var field = Instantiate(RangedFloatField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Slider.wholeNumbers = false;
|
||||
field.Slider.minValue = min;
|
||||
field.Slider.maxValue = max;
|
||||
field.Slider.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Slider.value = read();
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddProgressField(string name, Func<float> read)
|
||||
{
|
||||
var field = Instantiate(ProgressField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Slider.wholeNumbers = false;
|
||||
field.Slider.minValue = 0;
|
||||
field.Slider.maxValue = 1;
|
||||
//field.Slider.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Slider.value = read();
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<int> read, Action<int> write, int min, int max)
|
||||
{
|
||||
var field = Instantiate(RangedFloatField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Slider.wholeNumbers = true;
|
||||
field.Slider.minValue = min;
|
||||
field.Slider.maxValue = max;
|
||||
field.Slider.onValueChanged.AddListener(val => write(Mathf.RoundToInt(val)));
|
||||
RefreshPropertyValues += () => field.Slider.value = read();
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<bool> read, Action<bool> write)
|
||||
{
|
||||
var field = Instantiate(BoolField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Toggle.onValueChanged.AddListener(val => write(val));
|
||||
RefreshPropertyValues += () => field.Toggle.isOn = read();
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
public void AddField(string name, Func<int> read, Action<int> write, string[] enumOptions)
|
||||
{
|
||||
var field = Instantiate(EnumField, Content ?? transform);
|
||||
field.Label.text = name;
|
||||
field.Dropdown.onClick.AddListener(() =>
|
||||
{
|
||||
var selected = read();
|
||||
Dropdown.gameObject.SetActive(true);
|
||||
Dropdown.Clear();
|
||||
for (int i = 0; i < enumOptions.Length; i++)
|
||||
{
|
||||
var index = i;
|
||||
Dropdown.AddOption(enumOptions[i], () => write(index), index == selected);
|
||||
}
|
||||
|
||||
Dropdown.Show((RectTransform) field.Dropdown.transform);
|
||||
});
|
||||
RefreshPropertyValues += () => field.DropdownLabel.text = enumOptions[read()];
|
||||
Properties.Add(field.gameObject);
|
||||
OnPropertyAdded?.Invoke(field.gameObject);
|
||||
}
|
||||
|
||||
private void AddItemProperties(ItemInstance item)
|
||||
{
|
||||
var typedItem = FindTypedPropertyItem(item);
|
||||
|
||||
AddProperty(typedItem?.Description ?? "No typed item description is available.");
|
||||
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
AddProperty("Quantity", () => simpleCommodity.Quantity.ToString());
|
||||
|
||||
var sheet = AddStatSheet();
|
||||
var manufacturer = typedItem != null ? ActionGameManager.RuntimeCatalog?.GetManufacturer(typedItem) : null;
|
||||
sheet.AddStat("Manufacturer", () => manufacturer?.Name ?? "GameCult");
|
||||
sheet.AddStat("Mass", () => ActionGameManager.RuntimePlayerSettings.Format(GetTypedMass(item, typedItem)));
|
||||
|
||||
//AddProperty("Thermal Mass", () => Context.GetThermalMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
|
||||
}
|
||||
|
||||
private float GetTypedMass(ItemInstance item, AetheriaRuntimeCatalogItem typedItem)
|
||||
{
|
||||
if (typedItem == null)
|
||||
return 0f;
|
||||
|
||||
return item is SimpleCommodity simpleCommodity
|
||||
? (float)typedItem.Mass * simpleCommodity.Quantity
|
||||
: (float)typedItem.Mass;
|
||||
}
|
||||
|
||||
private float GetMaxDurability(ItemInstance item)
|
||||
{
|
||||
var typedItem = FindTypedPropertyItem(item);
|
||||
if (typedItem != null && typedItem.Durability > 0)
|
||||
return (float)typedItem.Durability;
|
||||
|
||||
return item is EquippableItem equippable ? Math.Max(equippable.Durability, 1f) : 1f;
|
||||
}
|
||||
|
||||
private static (float minimum, float maximum) GetThermalRange(AetheriaRuntimeCatalogItem typedItem)
|
||||
{
|
||||
if (typedItem != null && typedItem.MaximumTemperature > typedItem.MinimumTemperature)
|
||||
return ((float)typedItem.MinimumTemperature, (float)typedItem.MaximumTemperature);
|
||||
|
||||
return (0f, 1f);
|
||||
}
|
||||
|
||||
private static BezierCurve GetThermalPerformanceCurve(AetheriaRuntimeCatalogItem typedItem)
|
||||
{
|
||||
if (typedItem?.ThermalPerformanceCurveKeys != null && typedItem.ThermalPerformanceCurveKeys.Count > 0)
|
||||
{
|
||||
return new BezierCurve
|
||||
{
|
||||
Keys = typedItem.ThermalPerformanceCurveKeys
|
||||
.Select(key => new float4(
|
||||
(float)key.Time,
|
||||
(float)key.Value,
|
||||
(float)key.InTangent,
|
||||
(float)key.OutTangent))
|
||||
.ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
return new BezierCurve
|
||||
{
|
||||
Keys = new[]
|
||||
{
|
||||
new float4(0f, 1f, 0f, 0f),
|
||||
new float4(1f, 1f, 0f, 0f)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCatalogItem FindTypedPropertyItem(ItemInstance item)
|
||||
{
|
||||
return ActionGameManager.RuntimeCatalog?.FindItem(item?.ItemKey ?? "");
|
||||
}
|
||||
|
||||
private void AddEquippableItemProperties(EquippableItem item, Func<PerformanceStat, float> statValueFunction)
|
||||
{
|
||||
if (item.Durability < .01f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AddTypedBehaviorProperties(FindTypedPropertyItem(item), statValueFunction);
|
||||
}
|
||||
|
||||
private void AddTypedBehaviorProperties(AetheriaRuntimeCatalogItem typedItem, Func<PerformanceStat, float> statValueFunction)
|
||||
{
|
||||
var sheet = AddStatSheet();
|
||||
foreach (var behavior in typedItem?.BehaviorPayloads ?? Array.Empty<AetheriaRuntimeBehaviorPayload>())
|
||||
{
|
||||
if (string.Equals(behavior.Kind, AetheriaRuntimeBehaviorKinds.StatModifier, StringComparison.Ordinal))
|
||||
{
|
||||
var statReference = ReadTypedStatReference(FindTypedBehaviorField(behavior, 1)?.Value);
|
||||
var modifier = ReadTypedPerformanceStat(FindTypedBehaviorField(behavior, 2)?.Value);
|
||||
var modifierType = ReadTypedEnum(FindTypedBehaviorField(behavior, 3)?.Value, StatModifierType.Constant);
|
||||
sheet.AddStat($"{statReference.target.SplitCamelCase()}:{statReference.stat.SplitCamelCase()}",
|
||||
() => $"{(modifierType == StatModifierType.Constant ? "+" : "x")}{ActionGameManager.RuntimePlayerSettings.Format(statValueFunction(modifier))}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var metadata = AetheriaRuntimeBehaviorMetadataCatalog.Get(behavior.Kind);
|
||||
if (metadata == null) continue;
|
||||
foreach (var field in metadata.DisplayFields)
|
||||
{
|
||||
var payloadField = FindTypedBehaviorField(behavior, field.Key);
|
||||
if (field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.Number)
|
||||
{
|
||||
var value = (float)(payloadField?.Value.NumberValue ?? 0);
|
||||
sheet.AddStat(field.Name.SplitCamelCase(), () => $"{ActionGameManager.RuntimePlayerSettings.Format(value)}");
|
||||
}
|
||||
else if (field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.Temperature)
|
||||
{
|
||||
var value = (float)(payloadField?.Value.NumberValue ?? 0);
|
||||
sheet.AddStat(field.Name.SplitCamelCase(), () => $"{ActionGameManager.RuntimePlayerSettings.FormatTemperature(value)}");
|
||||
}
|
||||
else if (field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.Integer)
|
||||
{
|
||||
var value = (int)(payloadField?.Value.NumberValue ?? 0);
|
||||
sheet.AddStat(field.Name.SplitCamelCase(), () => $"{value}");
|
||||
}
|
||||
else if (field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.PerformanceStat)
|
||||
{
|
||||
var stat = ReadTypedPerformanceStat(payloadField?.Value);
|
||||
sheet.AddStat(field.Name.SplitCamelCase(), () => $"{ActionGameManager.RuntimePlayerSettings.Format(statValueFunction(stat))}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var weaponPayload = typedItem?.BehaviorPayloads.FirstOrDefault(payload => AetheriaRuntimeBehaviorKinds.IsWeapon(payload.Kind));
|
||||
if (weaponPayload != null)
|
||||
{
|
||||
var damageCurve = ReadTypedBezierCurve(FindTypedBehaviorField(weaponPayload, 7)?.Value);
|
||||
var minRange = ReadTypedPerformanceStat(FindTypedBehaviorField(weaponPayload, 5)?.Value);
|
||||
var rangeStat = ReadTypedPerformanceStat(FindTypedBehaviorField(weaponPayload, 6)?.Value);
|
||||
var range = AddCurveField();
|
||||
range.Show("Damage Range", damageCurve, t => ActionGameManager.RuntimePlayerSettings.Format(lerp(statValueFunction(minRange), statValueFunction(rangeStat), t)));
|
||||
}
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorField FindTypedBehaviorField(AetheriaRuntimeBehaviorPayload behavior, int? key)
|
||||
{
|
||||
return key == null
|
||||
? null
|
||||
: behavior.Fields.FirstOrDefault(field => field.Key == key.Value);
|
||||
}
|
||||
|
||||
private static PerformanceStat ReadTypedPerformanceStat(AetheriaRuntimeBehaviorValue value)
|
||||
{
|
||||
return new PerformanceStat
|
||||
{
|
||||
Min = ReadTypedChildNumber(value, 0),
|
||||
Max = ReadTypedChildNumber(value, 1),
|
||||
HeatExponentMultiplier = ReadTypedChildNumber(value, 2),
|
||||
DurabilityExponentMultiplier = ReadTypedChildNumber(value, 3),
|
||||
QualityExponent = ReadTypedChildNumber(value, 4)
|
||||
};
|
||||
}
|
||||
|
||||
private static (string target, string stat) ReadTypedStatReference(AetheriaRuntimeBehaviorValue value)
|
||||
{
|
||||
return (
|
||||
ReadTypedChildString(value, 1),
|
||||
ReadTypedChildString(value, 2));
|
||||
}
|
||||
|
||||
private static BezierCurve ReadTypedBezierCurve(AetheriaRuntimeBehaviorValue value)
|
||||
{
|
||||
var keysValue = value != null && value.Children.Count > 0 ? value.Children[0] : null;
|
||||
var keys = keysValue?.Children
|
||||
.Select(ReadTypedFloat4)
|
||||
.ToArray();
|
||||
|
||||
return new BezierCurve
|
||||
{
|
||||
Keys = keys != null && keys.Length > 0
|
||||
? keys
|
||||
: new[] { new float4(0f, 1f, 0f, 0f), new float4(1f, 1f, 0f, 0f) }
|
||||
};
|
||||
}
|
||||
|
||||
private static float4 ReadTypedFloat4(AetheriaRuntimeBehaviorValue value)
|
||||
{
|
||||
return new float4(
|
||||
ReadTypedChildNumber(value, 0),
|
||||
ReadTypedChildNumber(value, 1),
|
||||
ReadTypedChildNumber(value, 2),
|
||||
ReadTypedChildNumber(value, 3));
|
||||
}
|
||||
|
||||
private static float ReadTypedChildNumber(AetheriaRuntimeBehaviorValue value, int index)
|
||||
{
|
||||
return value != null && value.Children.Count > index
|
||||
? (float)value.Children[index].NumberValue
|
||||
: 0f;
|
||||
}
|
||||
|
||||
private static string ReadTypedChildString(AetheriaRuntimeBehaviorValue value, int index)
|
||||
{
|
||||
return value != null && value.Children.Count > index
|
||||
? value.Children[index].StringValue ?? ""
|
||||
: "";
|
||||
}
|
||||
|
||||
private static T ReadTypedEnum<T>(AetheriaRuntimeBehaviorValue value, T fallback) where T : struct
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value?.StringValue) && Enum.TryParse(value.StringValue, true, out T parsed))
|
||||
{
|
||||
return parsed;
|
||||
}
|
||||
|
||||
return value != null && Enum.IsDefined(typeof(T), (int)value.NumberValue)
|
||||
? (T)Enum.ToObject(typeof(T), (int)value.NumberValue)
|
||||
: fallback;
|
||||
}
|
||||
|
||||
private string GetTitle(EquippableItem item)
|
||||
{
|
||||
var typedItem = FindTypedPropertyItem(item);
|
||||
var (tier, upgrades) = GameManager.ItemManager.GetTier(item);
|
||||
var name = typedItem?.Name ?? "Unknown Item";
|
||||
return
|
||||
$"<color=#{ColorUtility.ToHtmlStringRGB(tier.Color.ToColor())}>{name}</color><smallcaps><size=60%> ({tier.Name}{new string('+', upgrades)})";
|
||||
}
|
||||
|
||||
public void Inspect(ItemInstance item)
|
||||
{
|
||||
Clear();
|
||||
|
||||
AddItemProperties(item);
|
||||
|
||||
if (item is EquippableItem gear)
|
||||
{
|
||||
Title.text = GetTitle(gear);
|
||||
AddSpacer();
|
||||
var typedItem = FindTypedPropertyItem(gear);
|
||||
var thermalRange = GetThermalRange(typedItem);
|
||||
var thermalCurve = GetThermalPerformanceCurve(typedItem);
|
||||
var statusSheet = AddStatSheet();
|
||||
statusSheet.AddStat("Durability", () => $"{(int)(gear.Durability / GetMaxDurability(gear) * 100)}%");
|
||||
var heatCurve = AddCurveField();
|
||||
heatCurve.Show(
|
||||
"Thermal Performance",
|
||||
thermalCurve,
|
||||
t => ActionGameManager.RuntimePlayerSettings.FormatTemperature(lerp(thermalRange.minimum, thermalRange.maximum, t)),
|
||||
true);
|
||||
AddEquippableItemProperties(gear, stat => GameManager.ItemManager.Evaluate(stat, gear));
|
||||
}
|
||||
|
||||
RefreshValues();
|
||||
}
|
||||
|
||||
public void Inspect(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
Clear();
|
||||
if (item == null)
|
||||
{
|
||||
RefreshValues();
|
||||
return;
|
||||
}
|
||||
|
||||
Title.text = item.Name;
|
||||
AddProperty(item.Description).Label.fontStyle = FontStyles.Normal;
|
||||
|
||||
var sheet = AddStatSheet();
|
||||
var manufacturer = ActionGameManager.RuntimeCatalog?.GetManufacturer(item);
|
||||
sheet.AddStat("Manufacturer", () => manufacturer?.Name ?? "GameCult");
|
||||
sheet.AddStat("Mass", () => ActionGameManager.RuntimePlayerSettings.Format((float)item.Mass));
|
||||
sheet.AddStat("Price", () => item.Price.ToString("N0"));
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(item.HardpointType))
|
||||
{
|
||||
sheet.AddStat("Durability", () => ActionGameManager.RuntimePlayerSettings.Format((float)item.Durability));
|
||||
var thermalRange = GetThermalRange(item);
|
||||
var heatCurve = AddCurveField();
|
||||
heatCurve.Show(
|
||||
"Thermal Performance",
|
||||
GetThermalPerformanceCurve(item),
|
||||
t => ActionGameManager.RuntimePlayerSettings.FormatTemperature(lerp(thermalRange.minimum, thermalRange.maximum, t)),
|
||||
true);
|
||||
AddTypedBehaviorProperties(item, stat => stat.Min);
|
||||
}
|
||||
|
||||
RefreshValues();
|
||||
}
|
||||
|
||||
public void RefreshValues()
|
||||
{
|
||||
RefreshPropertyValues?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8c2bf4a7080061d42a87046c37bf0c60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- Spacer: {instanceID: 0}
|
||||
- Dropdown: {instanceID: 0}
|
||||
- Title: {instanceID: 0}
|
||||
- Section: {instanceID: 0}
|
||||
- List: {instanceID: 0}
|
||||
- Property: {instanceID: 0}
|
||||
- PropertyLabel: {instanceID: 0}
|
||||
- Attribute: {instanceID: 0}
|
||||
- InputField: {instanceID: 0}
|
||||
- RangedFloatField: {instanceID: 0}
|
||||
- ProgressField: {instanceID: 0}
|
||||
- EnumField: {instanceID: 0}
|
||||
- BoolField: {instanceID: 0}
|
||||
- PropertyButton: {instanceID: 0}
|
||||
- ButtonField: {instanceID: 0}
|
||||
- IncrementField: {instanceID: 0}
|
||||
- StatSheet: {fileID: 3416329628306957711, guid: 4f75723ed178a084e813965e84825bd4,
|
||||
type: 3}
|
||||
- Content: {instanceID: 0}
|
||||
- SelectedChild: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue