2020-02-27 18:51:07 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Linq;
|
2020-06-06 03:21:03 +01:00
|
|
|
|
using System.Reflection;
|
2020-02-27 18:51:07 +00:00
|
|
|
|
using TMPro;
|
2020-06-07 03:21:47 +01:00
|
|
|
|
using UniRx;
|
2020-02-27 18:51:07 +00:00
|
|
|
|
using UnityEngine;
|
2020-06-02 07:01:03 +01:00
|
|
|
|
using UnityEngine.EventSystems;
|
2020-06-07 03:21:47 +01:00
|
|
|
|
using UnityEngine.UI;
|
2020-06-08 01:01:33 +01:00
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
using static Unity.Mathematics.math;
|
2020-02-27 18:51:07 +00:00
|
|
|
|
|
|
|
|
|
|
public class PropertiesPanel : MonoBehaviour
|
|
|
|
|
|
{
|
2020-06-07 23:40:19 +01:00
|
|
|
|
public DropdownMenu Dropdown;
|
2020-06-01 03:11:04 +01:00
|
|
|
|
public TextMeshProUGUI Title;
|
|
|
|
|
|
public RectTransform SectionPrefab;
|
|
|
|
|
|
public PropertiesList ListPrefab;
|
2020-06-04 01:36:55 +01:00
|
|
|
|
public PropertyButton PropertyPrefab;
|
|
|
|
|
|
public PropertyLabel PropertyLabelPrefab;
|
2020-06-01 03:11:04 +01:00
|
|
|
|
public AttributeProperty AttributePrefab;
|
|
|
|
|
|
public InputField InputField;
|
|
|
|
|
|
public RangedFloatField RangedFloatField;
|
2020-06-02 07:01:03 +01:00
|
|
|
|
public RangedFloatField ProgressField;
|
2020-06-01 03:11:04 +01:00
|
|
|
|
public EnumField EnumField;
|
|
|
|
|
|
public BoolField BoolField;
|
2020-06-02 07:01:03 +01:00
|
|
|
|
public PropertyButton PropertyButton;
|
|
|
|
|
|
public ButtonField ButtonField;
|
2020-06-08 01:01:33 +01:00
|
|
|
|
public IncrementField IncrementField;
|
2020-06-06 03:21:03 +01:00
|
|
|
|
[HideInInspector] public FlatFlatButton SelectedChild;
|
2020-12-10 23:20:38 +00:00
|
|
|
|
[HideInInspector] public ItemManager Context;
|
2020-02-27 18:51:07 +00:00
|
|
|
|
|
2020-06-01 03:11:04 +01:00
|
|
|
|
protected List<GameObject> Properties = new List<GameObject>();
|
|
|
|
|
|
protected List<FlatFlatButton> Buttons = new List<FlatFlatButton>();
|
|
|
|
|
|
protected event Action RefreshPropertyValues;
|
2020-06-02 07:01:03 +01:00
|
|
|
|
protected bool RadioSelection = false;
|
2020-02-27 18:51:07 +00:00
|
|
|
|
|
2020-06-07 03:21:47 +01:00
|
|
|
|
protected event Action<GameObject> OnPropertyAdded;
|
2020-06-06 03:21:03 +01:00
|
|
|
|
protected Action OnPropertiesChanged;
|
2020-07-03 01:33:42 +01:00
|
|
|
|
|
|
|
|
|
|
public int Children => Properties.Count + Buttons.Count;
|
2020-06-07 22:26:22 +01:00
|
|
|
|
|
2020-07-03 01:33:42 +01:00
|
|
|
|
public void Awake()
|
2020-06-07 22:26:22 +01:00
|
|
|
|
{
|
|
|
|
|
|
OnPropertyAdded += go => go.SetActive(true);
|
|
|
|
|
|
}
|
2020-06-06 03:21:03 +01:00
|
|
|
|
|
2020-06-07 03:21:47 +01:00
|
|
|
|
public virtual void Update()
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
|
|
|
|
|
RefreshValues();
|
|
|
|
|
|
}
|
2020-02-27 18:51:07 +00:00
|
|
|
|
|
2020-06-06 03:21:03 +01:00
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-07 22:26:22 +01:00
|
|
|
|
// private void OnDisable()
|
|
|
|
|
|
// {
|
|
|
|
|
|
// RemoveListener();
|
|
|
|
|
|
// }
|
2020-06-06 03:21:03 +01:00
|
|
|
|
|
2020-06-01 03:11:04 +01:00
|
|
|
|
public void Clear()
|
|
|
|
|
|
{
|
2020-06-12 02:11:31 +01:00
|
|
|
|
//RemoveListener();
|
2020-06-01 03:11:04 +01:00
|
|
|
|
foreach(var property in Properties)
|
|
|
|
|
|
Destroy(property);
|
|
|
|
|
|
Properties.Clear();
|
|
|
|
|
|
Buttons.Clear();
|
|
|
|
|
|
SelectedChild = null;
|
|
|
|
|
|
RefreshPropertyValues = null;
|
2020-06-02 07:01:03 +01:00
|
|
|
|
RadioSelection = false;
|
2020-06-01 03:11:04 +01:00
|
|
|
|
}
|
2020-02-27 18:51:07 +00:00
|
|
|
|
|
2020-06-01 03:11:04 +01:00
|
|
|
|
public void Deselect()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SelectedChild != null)
|
|
|
|
|
|
SelectedChild.CurrentState = FlatButtonState.Unselected;
|
|
|
|
|
|
SelectedChild = null;
|
|
|
|
|
|
}
|
2020-02-27 18:51:07 +00:00
|
|
|
|
|
2020-06-04 01:36:55 +01:00
|
|
|
|
public RectTransform AddSection(string name)
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
|
|
|
|
|
var section = Instantiate(SectionPrefab, transform);
|
|
|
|
|
|
section.GetComponentInChildren<TextMeshProUGUI>().text = name;
|
|
|
|
|
|
Properties.Add(section.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(section.gameObject);
|
2020-06-01 03:11:04 +01:00
|
|
|
|
return section;
|
|
|
|
|
|
}
|
2020-02-27 18:51:07 +00:00
|
|
|
|
|
2020-06-05 04:16:33 +01:00
|
|
|
|
public PropertyButton AddProperty(string name, Func<string> read = null, Action<PointerEventData> onClick = null, bool radio = false)
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
2020-06-05 04:16:33 +01:00
|
|
|
|
PropertyButton property;
|
|
|
|
|
|
if(read != null)
|
|
|
|
|
|
property = Instantiate(PropertyLabelPrefab, transform);
|
|
|
|
|
|
else
|
|
|
|
|
|
property = Instantiate(PropertyPrefab, transform);
|
|
|
|
|
|
property.Label.text = name;
|
2020-06-02 07:01:03 +01:00
|
|
|
|
if (radio)
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
2020-06-02 07:01:03 +01:00
|
|
|
|
RadioSelection = true;
|
2020-06-01 03:11:04 +01:00
|
|
|
|
Buttons.Add(property.Button);
|
2020-06-02 07:01:03 +01:00
|
|
|
|
property.Button.OnClick += data =>
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
2020-06-02 07:01:03 +01:00
|
|
|
|
if (data.button == PointerEventData.InputButton.Left)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SelectedChild != null)
|
|
|
|
|
|
SelectedChild.CurrentState = FlatButtonState.Unselected;
|
|
|
|
|
|
SelectedChild = property.Button;
|
|
|
|
|
|
SelectedChild.CurrentState = FlatButtonState.Selected;
|
|
|
|
|
|
}
|
|
|
|
|
|
onClick?.Invoke(data);
|
2020-06-01 03:11:04 +01:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(onClick!=null) property.Button.OnClick += onClick;
|
2020-06-05 04:16:33 +01:00
|
|
|
|
|
|
|
|
|
|
if (read != null)
|
|
|
|
|
|
RefreshPropertyValues += () => ((PropertyLabel) property).Value.text = read.Invoke();
|
2020-06-01 03:11:04 +01:00
|
|
|
|
Properties.Add(property.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(property.gameObject);
|
2020-06-01 03:11:04 +01:00
|
|
|
|
return property;
|
|
|
|
|
|
}
|
2020-02-27 18:51:07 +00:00
|
|
|
|
|
2020-06-04 01:36:55 +01:00
|
|
|
|
public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
|
2020-06-01 03:11:04 +01:00
|
|
|
|
{
|
|
|
|
|
|
var list = Instantiate(ListPrefab, transform);
|
2020-06-06 03:21:03 +01:00
|
|
|
|
list.Context = Context;
|
2020-06-07 23:40:19 +01:00
|
|
|
|
list.Dropdown = Dropdown;
|
2020-06-01 03:11:04 +01:00
|
|
|
|
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);
|
|
|
|
|
|
// }
|
2020-06-06 03:21:03 +01:00
|
|
|
|
//RefreshPropertyValues += () => list.RefreshValues();
|
2020-06-01 03:11:04 +01:00
|
|
|
|
Properties.Add(list.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(list.gameObject);
|
2020-06-01 03:11:04 +01:00
|
|
|
|
return list;
|
|
|
|
|
|
}
|
2020-02-27 18:51:07 +00:00
|
|
|
|
|
2020-06-01 03:11:04 +01:00
|
|
|
|
public AttributeProperty AddPersonalityProperty(PersonalityAttribute attribute, Func<float> read)
|
|
|
|
|
|
{
|
|
|
|
|
|
var attributeInstance = Instantiate(AttributePrefab, transform);
|
|
|
|
|
|
attributeInstance.Title.text = attribute.Name;
|
|
|
|
|
|
attributeInstance.HighLabel.text = attribute.HighName;
|
|
|
|
|
|
attributeInstance.LowLabel.text = attribute.LowName;
|
|
|
|
|
|
RefreshPropertyValues += () => attributeInstance.Slider.value = read();
|
|
|
|
|
|
Properties.Add(attributeInstance.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(attributeInstance.gameObject);
|
2020-06-01 03:11:04 +01:00
|
|
|
|
return attributeInstance;
|
|
|
|
|
|
}
|
2020-06-02 07:01:03 +01:00
|
|
|
|
|
|
|
|
|
|
public virtual PropertyButton AddButton(string name, Action<PointerEventData> onClick)
|
|
|
|
|
|
{
|
|
|
|
|
|
var button = Instantiate(PropertyButton, transform);
|
|
|
|
|
|
button.Label.text = name;
|
|
|
|
|
|
button.Button.OnClick += onClick;
|
|
|
|
|
|
Properties.Add(button.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(button.gameObject);
|
2020-06-02 07:01:03 +01:00
|
|
|
|
return button;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddButton(string name, string label, Action<PointerEventData> onClick)
|
|
|
|
|
|
{
|
|
|
|
|
|
var button = Instantiate(ButtonField, transform);
|
|
|
|
|
|
button.Label.text = name;
|
|
|
|
|
|
button.ButtonLabel.text = label;
|
|
|
|
|
|
button.Button.OnClick += onClick;
|
|
|
|
|
|
Properties.Add(button.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(button.gameObject);
|
2020-06-02 07:01:03 +01:00
|
|
|
|
}
|
2020-06-01 03:11:04 +01:00
|
|
|
|
|
2020-06-02 07:01:03 +01:00
|
|
|
|
public void AddField(string name, Func<string> read, Action<string> write)
|
2020-02-27 18:51:07 +00:00
|
|
|
|
{
|
2020-06-01 03:11:04 +01:00
|
|
|
|
var field = Instantiate(InputField, transform);
|
|
|
|
|
|
field.Label.text = name;
|
|
|
|
|
|
field.Field.contentType = TMP_InputField.ContentType.Standard;
|
|
|
|
|
|
field.Field.onValueChanged.AddListener(val => write(val));
|
2020-06-07 22:26:22 +01:00
|
|
|
|
// field.Field.text = read();
|
2020-06-07 03:21:47 +01:00
|
|
|
|
RefreshPropertyValues += () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var s = read();
|
|
|
|
|
|
if (field.Field.text != s)
|
|
|
|
|
|
{
|
|
|
|
|
|
field.Field.text = s;
|
2020-06-07 22:26:22 +01:00
|
|
|
|
field.gameObject.SetActive(false);
|
2020-06-12 01:57:15 +01:00
|
|
|
|
Observable.NextFrame().Subscribe(_ =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if(field != null)
|
|
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
|
|
|
|
|
});
|
2020-06-07 03:21:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2020-06-01 03:11:04 +01:00
|
|
|
|
Properties.Add(field.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
2020-02-27 18:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-02 07:01:03 +01:00
|
|
|
|
public void AddField(string name, Func<float> read, Action<float> write)
|
2020-02-27 18:51:07 +00:00
|
|
|
|
{
|
2020-06-01 03:11:04 +01:00
|
|
|
|
var field = Instantiate(InputField, transform);
|
|
|
|
|
|
field.Label.text = name;
|
|
|
|
|
|
field.Field.contentType = TMP_InputField.ContentType.DecimalNumber;
|
|
|
|
|
|
field.Field.onValueChanged.AddListener(val => write(float.Parse(val)));
|
2020-06-10 02:45:10 +01:00
|
|
|
|
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));
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2020-06-01 03:11:04 +01:00
|
|
|
|
Properties.Add(field.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
2020-02-27 18:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-02 07:01:03 +01:00
|
|
|
|
public void AddField(string name, Func<int> read, Action<int> write)
|
2020-02-27 18:51:07 +00:00
|
|
|
|
{
|
2020-06-01 03:11:04 +01:00
|
|
|
|
var field = Instantiate(InputField, transform);
|
|
|
|
|
|
field.Label.text = name;
|
|
|
|
|
|
field.Field.contentType = TMP_InputField.ContentType.IntegerNumber;
|
|
|
|
|
|
field.Field.onValueChanged.AddListener(val => write(int.Parse(val)));
|
2020-06-10 02:45:10 +01:00
|
|
|
|
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));
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2020-06-01 03:11:04 +01:00
|
|
|
|
Properties.Add(field.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
2020-02-27 18:51:07 +00:00
|
|
|
|
}
|
2020-06-01 03:11:04 +01:00
|
|
|
|
|
2020-06-08 01:01:33 +01:00
|
|
|
|
public void AddIncrementField(string name, Func<int> read, Action<int> write, Func<int> min, Func<int> max)
|
|
|
|
|
|
{
|
|
|
|
|
|
var field = Instantiate(IncrementField, transform);
|
|
|
|
|
|
field.Label.text = name;
|
|
|
|
|
|
field.Increment.OnClick += data => write(read() + 1);
|
|
|
|
|
|
field.Decrement.OnClick += data => 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.CurrentState = val == maxval ? FlatButtonState.Disabled : FlatButtonState.Unselected;
|
|
|
|
|
|
field.Decrement.CurrentState = val == minval ? FlatButtonState.Disabled : FlatButtonState.Unselected;
|
|
|
|
|
|
};
|
|
|
|
|
|
Properties.Add(field.gameObject);
|
|
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-02 07:01:03 +01:00
|
|
|
|
public void AddField(string name, Func<float> read, Action<float> write, float min, float max)
|
2020-02-27 18:51:07 +00:00
|
|
|
|
{
|
2020-06-01 03:11:04 +01:00
|
|
|
|
var field = Instantiate(RangedFloatField, 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);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
2020-02-27 18:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-02 07:01:03 +01:00
|
|
|
|
public void AddProgressField(string name, Func<float> read)
|
|
|
|
|
|
{
|
|
|
|
|
|
var field = Instantiate(ProgressField, 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);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
2020-06-02 07:01:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddField(string name, Func<int> read, Action<int> write, int min, int max)
|
2020-02-27 18:51:07 +00:00
|
|
|
|
{
|
2020-06-01 03:11:04 +01:00
|
|
|
|
var field = Instantiate(RangedFloatField, 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);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
2020-02-27 18:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-02 07:01:03 +01:00
|
|
|
|
public void AddField(string name, Func<bool> read, Action<bool> write)
|
2020-02-27 18:51:07 +00:00
|
|
|
|
{
|
2020-06-01 03:11:04 +01:00
|
|
|
|
var field = Instantiate(BoolField, transform);
|
|
|
|
|
|
field.Label.text = name;
|
|
|
|
|
|
field.Toggle.onValueChanged.AddListener(val => write(val));
|
|
|
|
|
|
RefreshPropertyValues += () => field.Toggle.isOn = read();
|
|
|
|
|
|
Properties.Add(field.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
2020-02-27 18:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-02 07:01:03 +01:00
|
|
|
|
public void AddField(string name, Func<int> read, Action<int> write, string[] enumOptions)
|
2020-02-27 18:51:07 +00:00
|
|
|
|
{
|
2020-06-01 03:11:04 +01:00
|
|
|
|
var field = Instantiate(EnumField, transform);
|
|
|
|
|
|
field.Label.text = name;
|
2020-06-07 23:40:19 +01:00
|
|
|
|
field.Dropdown.OnClick += data =>
|
|
|
|
|
|
{
|
|
|
|
|
|
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.Dropdown.Label.text = enumOptions[read()];
|
2020-06-01 03:11:04 +01:00
|
|
|
|
Properties.Add(field.gameObject);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
OnPropertyAdded?.Invoke(field.gameObject);
|
2020-02-27 18:51:07 +00:00
|
|
|
|
}
|
2020-06-06 03:21:03 +01:00
|
|
|
|
|
|
|
|
|
|
public void Inspect(Entity entity)
|
|
|
|
|
|
{
|
|
|
|
|
|
Clear();
|
|
|
|
|
|
Title.text = entity.Name;
|
2020-12-10 23:20:38 +00:00
|
|
|
|
var hullData = Context.GetData(entity.Hull) as HullData;
|
2020-06-06 03:21:03 +01:00
|
|
|
|
AddSection(
|
|
|
|
|
|
hullData.HullType == HullType.Ship ? "Ship" :
|
|
|
|
|
|
hullData.HullType == HullType.Station ? "Station" :
|
|
|
|
|
|
"Platform");
|
|
|
|
|
|
//AddList(hullData.Name).Inspect(hull, entity);
|
|
|
|
|
|
//PropertiesPanel.AddProperty("Hull", () => $"{hullData.Name}");
|
2020-06-10 02:45:10 +01:00
|
|
|
|
AddEntityProperties(entity);
|
2020-07-03 01:33:42 +01:00
|
|
|
|
//cargoList.SetExpanded(false,true);
|
2020-06-06 03:21:03 +01:00
|
|
|
|
|
|
|
|
|
|
RefreshValues();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-10 02:45:10 +01:00
|
|
|
|
public void AddEntityProperties(Entity entity)
|
|
|
|
|
|
{
|
2020-06-11 02:55:11 +01:00
|
|
|
|
AddField("Name", () => entity.Name, name => entity.Name = name);
|
2020-12-10 23:20:38 +00:00
|
|
|
|
AddProperty("Mass", () => $"{entity.Mass.SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
|
|
|
|
|
|
// AddProperty("Temperature", () => $"{entity.Temperature:0}°K");
|
|
|
|
|
|
// AddProperty("Energy", () => $"{entity.Energy:0}/{entity.GetBehavior<Reactor>()?.Capacitance??0:0}");
|
2020-06-10 02:45:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddItemProperties(Entity entity, ItemInstance item)
|
2020-06-07 03:21:47 +01:00
|
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
|
var data = Context.ItemData.Get<ItemData>(item.Data);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
AddProperty("Type", () => data.Name);
|
|
|
|
|
|
AddProperty(data.Description).Label.fontStyle = FontStyles.Normal;
|
2020-12-10 23:20:38 +00:00
|
|
|
|
// if (item is CraftedItemInstance craftedItemInstance)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var sourceEntity = Context.ItemData.Get<Entity>(craftedItemInstance.SourceEntity);
|
|
|
|
|
|
// if (sourceEntity != null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var corporation = Context.ItemData.Get<Corporation>(sourceEntity.Corporation);
|
|
|
|
|
|
// AddProperty("Manufacturer", () => corporation.Name);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// AddProperty("Manufacturer", () => "GameCult");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2020-06-07 03:21:47 +01:00
|
|
|
|
if (item is SimpleCommodity simpleCommodity)
|
|
|
|
|
|
AddProperty("Quantity", () => simpleCommodity.Quantity.ToString());
|
2020-12-10 23:20:38 +00:00
|
|
|
|
AddProperty("Mass", () => Context.GetMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
|
|
|
|
|
|
AddProperty("Thermal Mass", () => Context.GetThermalMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
|
|
|
|
|
|
if (item is EquippableItem gear)
|
2020-06-07 03:21:47 +01:00
|
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
|
var gearData = Context.GetData(gear);
|
2020-06-07 03:21:47 +01:00
|
|
|
|
AddProperty("Durability", () =>
|
2020-12-10 23:20:38 +00:00
|
|
|
|
$"{gear.Durability.SignificantDigits(Context.GameplaySettings.SignificantDigits)}/{gearData.Durability.SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
|
2020-06-10 02:45:10 +01:00
|
|
|
|
foreach (var behavior in gearData.Behaviors)
|
2020-06-07 03:21:47 +01:00
|
|
|
|
{
|
2020-06-10 02:45:10 +01:00
|
|
|
|
var type = behavior.GetType();
|
|
|
|
|
|
if (type.GetCustomAttribute(typeof(RuntimeInspectable)) != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var field in type.GetFields().Where(f => f.GetCustomAttribute<RuntimeInspectable>() != null))
|
|
|
|
|
|
{
|
|
|
|
|
|
var fieldType = field.FieldType;
|
|
|
|
|
|
if (fieldType == typeof(float))
|
2020-12-10 23:20:38 +00:00
|
|
|
|
AddProperty(field.Name, () => $"{((float) field.GetValue(behavior)).SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
|
2020-06-10 02:45:10 +01:00
|
|
|
|
else if (fieldType == typeof(int))
|
|
|
|
|
|
AddProperty(field.Name, () => $"{(int) field.GetValue(behavior)}");
|
|
|
|
|
|
else if (fieldType == typeof(PerformanceStat))
|
|
|
|
|
|
{
|
|
|
|
|
|
var stat = (PerformanceStat) field.GetValue(behavior);
|
2020-12-10 23:20:38 +00:00
|
|
|
|
AddProperty(field.Name, () => $"{Context.Evaluate(stat, gear, entity).SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
|
2020-06-10 02:45:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-06-07 03:21:47 +01:00
|
|
|
|
}
|
2020-06-10 02:45:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public void Inspect(Entity entity, EquippedItem item)
|
2020-06-06 03:21:03 +01:00
|
|
|
|
{
|
2020-07-03 01:33:42 +01:00
|
|
|
|
if (this is PropertiesList list)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (list.Expanded)
|
|
|
|
|
|
InspectGearInternal();
|
|
|
|
|
|
else
|
|
|
|
|
|
list.OnExpand += b =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (b) InspectGearInternal();
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
InspectGearInternal();
|
2020-06-06 03:21:03 +01:00
|
|
|
|
|
|
|
|
|
|
void InspectGearInternal()
|
|
|
|
|
|
{
|
2020-06-07 22:26:22 +01:00
|
|
|
|
//Debug.Log($"Refreshing {hardpoint.Gear.Name} properties");
|
2020-06-06 03:21:03 +01:00
|
|
|
|
Clear();
|
2020-12-10 23:20:38 +00:00
|
|
|
|
if (item.EquippableItem != null)
|
2020-06-06 03:21:03 +01:00
|
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
|
AddItemProperties(entity, item.EquippableItem);
|
|
|
|
|
|
foreach (var behavior in item.Behaviors)
|
2020-06-10 02:45:10 +01:00
|
|
|
|
{
|
|
|
|
|
|
if(behavior is IPopulationAssignment populationAssignment)
|
|
|
|
|
|
AddIncrementField("Assigned Population",
|
|
|
|
|
|
() => populationAssignment.AssignedPopulation,
|
|
|
|
|
|
p => populationAssignment.AssignedPopulation = p,
|
|
|
|
|
|
() => 0, () => entity.Population - entity.AssignedPopulation + populationAssignment.AssignedPopulation);
|
|
|
|
|
|
if (behavior is Thermotoggle thermotoggle)
|
|
|
|
|
|
AddField("Target Temperature", () => thermotoggle.TargetTemperature, temp => thermotoggle.TargetTemperature = temp);
|
2020-12-10 23:20:38 +00:00
|
|
|
|
// if (behavior is Factory factory)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// AddField("Production Quality", () => factory.ProductionQuality, f => factory.ProductionQuality = f, 0, 1);
|
|
|
|
|
|
// var corporation = Context.ItemData.Get<Corporation>(entity.Corporation);
|
|
|
|
|
|
// var compatibleBlueprints = corporation.UnlockedBlueprints
|
|
|
|
|
|
// .Select(id => Context.ItemData.Get<BlueprintData>(id))
|
|
|
|
|
|
// .Where(bp => bp.FactoryItem == item.ItemData.ID).ToList();
|
|
|
|
|
|
// if (factory.RetoolingTime > 0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// AddProgressField("Retooling", () => (factory.ToolingTime - (float) factory.RetoolingTime) / factory.ToolingTime);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// AddField("Item",
|
|
|
|
|
|
// () => compatibleBlueprints.FindIndex(bp=>bp.ID== factory.Blueprint) + 1,
|
|
|
|
|
|
// i => factory.Blueprint = i == 0 ? Guid.Empty : compatibleBlueprints[i - 1].ID,
|
|
|
|
|
|
// new []{"None"}.Concat(compatibleBlueprints.Select(bp=>bp.Name)).ToArray());
|
|
|
|
|
|
// AddField("Active", () => factory.Active, active => factory.Active = active);
|
|
|
|
|
|
// if (factory.Blueprint != Guid.Empty)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (factory.Active && factory.ItemUnderConstruction != Guid.Empty)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// AddProgressField("Production", () =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (factory.ItemUnderConstruction == Guid.Empty) return 1;
|
|
|
|
|
|
// var itemInstance = Context.ItemData.Get<CraftedItemInstance>(factory.ItemUnderConstruction);
|
|
|
|
|
|
// var blueprintData = Context.ItemData.Get<BlueprintData>(itemInstance.Blueprint);
|
|
|
|
|
|
// return (blueprintData.ProductionTime - (float) entity.IncompleteCargo[factory.ItemUnderConstruction]) / blueprintData.ProductionTime;
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// //AddField("Product Name", () => factory.ItemName, name => factory.ItemName = name);
|
|
|
|
|
|
// AddField("Product Name", () => factory.ItemName, name => factory.ItemName = name);
|
|
|
|
|
|
// var ingredientsList = AddList("Ingredients Needed");
|
|
|
|
|
|
// var blueprintData = Context.ItemData.Get<BlueprintData>(factory.Blueprint);
|
|
|
|
|
|
// foreach (var ingredient in blueprintData.Ingredients)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var itemData = Context.ItemData.Get<ItemData>(ingredient.Key);
|
|
|
|
|
|
// ingredientsList.AddProperty(itemData.Name, () => ingredient.Value.ToString());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // ingredientsList.SetExpanded(false, true);
|
|
|
|
|
|
// ingredientsList.RefreshValues();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2020-06-10 02:45:10 +01:00
|
|
|
|
}
|
2020-06-06 03:21:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
RefreshValues();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-01 03:11:04 +01:00
|
|
|
|
// public void Inspect(object obj, bool inspectablesOnly = false, bool readWrite = false, bool topLevel = true)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if(topLevel)
|
|
|
|
|
|
// Clear();
|
|
|
|
|
|
//
|
|
|
|
|
|
// var fields = obj.GetType().GetFields();
|
|
|
|
|
|
// foreach (var field in fields)
|
|
|
|
|
|
// Inspect(obj, field, inspectablesOnly, readWrite);
|
|
|
|
|
|
//
|
|
|
|
|
|
// if(topLevel)
|
|
|
|
|
|
// foreach (var field in _propertyFields)
|
|
|
|
|
|
// field.transform.SetSiblingIndex(_propertyFields.IndexOf(field));
|
|
|
|
|
|
//
|
|
|
|
|
|
// RefreshValues();
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// public void Inspect(object obj, FieldInfo field, bool inspectablesOnly = false, bool readWrite = false)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var inspectable = field.GetCustomAttribute<InspectableFieldAttribute>();
|
|
|
|
|
|
// if (inspectable == null && inspectablesOnly) return;
|
|
|
|
|
|
// var type = field.FieldType;
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (type == typeof(float))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (readWrite)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var ranged = inspectable as RangedFloatInspectableAttribute;
|
|
|
|
|
|
// if (ranged != null)
|
|
|
|
|
|
// Inspect(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f),
|
|
|
|
|
|
// ranged.Min, ranged.Max);
|
|
|
|
|
|
// else
|
|
|
|
|
|
// Inspect(field.Name.SplitCamelCase(), () => (float) field.GetValue(obj), f => field.SetValue(obj, f));
|
|
|
|
|
|
// } else Inspect(field.Name.SplitCamelCase(), () => ((float) field.GetValue(obj)).ToString("0.##"));
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (type == typeof(int))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (readWrite)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// var ranged = inspectable as RangedIntInspectableAttribute;
|
|
|
|
|
|
// if (ranged != null)
|
|
|
|
|
|
// Inspect(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f),
|
|
|
|
|
|
// ranged.Min, ranged.Max);
|
|
|
|
|
|
// else
|
|
|
|
|
|
// Inspect(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), f => field.SetValue(obj, f));
|
|
|
|
|
|
// } else Inspect(field.Name.SplitCamelCase(), () => ((int) field.GetValue(obj)).ToString());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (type.IsEnum)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (readWrite)
|
|
|
|
|
|
// Inspect(field.Name.SplitCamelCase(), () => (int) field.GetValue(obj), i => field.SetValue(obj, i),
|
|
|
|
|
|
// Enum.GetNames(field.FieldType));
|
|
|
|
|
|
// else
|
|
|
|
|
|
// Inspect(field.Name.SplitCamelCase(), () => Enum.GetName(type, field.GetValue(obj)).SplitCamelCase());
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (type == typeof(string))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (readWrite)
|
|
|
|
|
|
// Inspect(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj), i => field.SetValue(obj, i));
|
|
|
|
|
|
// else
|
|
|
|
|
|
// Inspect(field.Name.SplitCamelCase(), () => (string) field.GetValue(obj));
|
|
|
|
|
|
// }
|
|
|
|
|
|
// //else if (field.FieldType == typeof(Color)) Inspect(field.Name, () => (Color) field.GetValue(obj), c => field.SetValue(obj, c));
|
|
|
|
|
|
// else if (field.FieldType == typeof(bool)) Inspect(field.Name, () => (bool) field.GetValue(obj), b => field.SetValue(obj, b));
|
|
|
|
|
|
// else if (type.GetCustomAttribute<InspectableFieldAttribute>() != null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if(!_propertyFields.Any() || !_propertyFields.Last().gameObject.name.ToUpper().Contains("DIVIDER"))
|
|
|
|
|
|
// _propertyFields.Add(Divider.Instantiate<Prototype>());
|
|
|
|
|
|
// Inspect(field.GetValue(obj), inspectablesOnly, readWrite, false);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// Debug.Log($"Field \"{field.Name}\" has unknown type {field.FieldType.Name}. No inspector was generated.");
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
2020-02-27 18:51:07 +00:00
|
|
|
|
public void RefreshValues()
|
|
|
|
|
|
{
|
2020-06-01 03:11:04 +01:00
|
|
|
|
RefreshPropertyValues?.Invoke();
|
2020-02-27 18:51:07 +00:00
|
|
|
|
}
|
2020-06-01 03:11:04 +01:00
|
|
|
|
}
|