Super Sexy Properties Panel

Properties panel now allows nested lists with foldouts, item selection and click callbacks
Properties Panel UI has a new look
Refactored lambdas in control module code into methods for readability
This commit is contained in:
hyperion51 2020-05-31 03:10:11 +01:00
commit 50a8059ed4
43 changed files with 894 additions and 916 deletions

View file

@ -8,60 +8,67 @@ public class ReadOnlyPropertiesPanel : MonoBehaviour
{
public TextMeshProUGUI Title;
public RectTransform SectionPrefab;
public RectTransform ListPrefab;
public RectTransform ListItemPrefab;
public PropertyLabel ListPropertyPrefab;
public PropertiesList ListPrefab;
public PropertyLabel PropertyPrefab;
public bool ChildRadioSelection;
private List<GameObject> _properties = new List<GameObject>();
protected List<GameObject> Properties = new List<GameObject>();
protected List<FlatFlatButton> Buttons = new List<FlatFlatButton>();
protected FlatFlatButton SelectedChild;
public void Clear()
{
foreach(var property in _properties)
foreach(var property in Properties)
Destroy(property);
Properties.Clear();
Buttons.Clear();
SelectedChild = null;
}
public void AddProperty(string name, Func<string> value)
public PropertyLabel AddProperty(string name, Func<string> value = null, Action onClick = null)
{
var property = Instantiate(PropertyPrefab, transform);
property.Name.text = name;
property.Value.text = value();
property.Value.text = value?.Invoke() ?? "";
property.ValueFunction = value;
_properties.Add(property.gameObject);
if (ChildRadioSelection)
{
Buttons.Add(property.Button);
property.Button.OnClick += () =>
{
if (SelectedChild != null)
SelectedChild.CurrentState = FlatButtonState.Unselected;
SelectedChild = property.Button;
SelectedChild.CurrentState = FlatButtonState.Selected;
onClick?.Invoke();
};
}
else if(onClick!=null) property.Button.OnClick += onClick;
Properties.Add(property.gameObject);
return property;
}
public void AddSection(string name)
public RectTransform AddSection(string name)
{
var section = Instantiate(SectionPrefab, transform);
section.GetComponentInChildren<TextMeshProUGUI>().text = name;
_properties.Add(section.gameObject);
Properties.Add(section.gameObject);
return section;
}
public void AddList(string name, IEnumerable<string> elements)
public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
{
var list = Instantiate(ListPrefab, transform);
list.GetComponentInChildren<TextMeshProUGUI>().text = name;
foreach (var element in elements)
{
var item = Instantiate(ListItemPrefab, list);
item.GetComponentInChildren<TextMeshProUGUI>().text = element;
_properties.Add(item.gameObject);
}
_properties.Add(list.gameObject);
}
public void AddList(string name, IEnumerable<(string, Func<string>)> elements)
{
var list = Instantiate(ListPrefab, transform);
list.GetComponentInChildren<TextMeshProUGUI>().text = name;
foreach (var element in elements)
{
var item = Instantiate(ListPropertyPrefab, list);
item.Name.text = element.Item1;
item.Value.text = element.Item2();
item.ValueFunction = element.Item2;
_properties.Add(item.gameObject);
}
_properties.Add(list.gameObject);
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);
// }
Properties.Add(list.gameObject);
return list;
}
}