Collapseable Properties Functionality (#534)

* all done

* oop

* two quick tweaks
This commit is contained in:
Rapandrasmus
2023-08-16 13:00:27 +02:00
committed by GitHub
parent fa0c053b1c
commit a9b7113b2c
9 changed files with 166 additions and 15 deletions

View File

@ -94,14 +94,31 @@ namespace HeavenStudio.Editor
DestroyParams();
Dictionary<string, GameObject> ePrefabs = new();
for (int i = 0; i < action.parameters.Count; i++)
{
object param = action.parameters[i].parameter;
string caption = action.parameters[i].propertyCaption;
string propertyName = action.parameters[i].propertyName;
string tooltip = action.parameters[i].tooltip;
ePrefabs.Add(propertyName, AddParam(propertyName, param, caption, tooltip));
}
AddParam(propertyName, param, caption, tooltip);
foreach (var p in action.parameters)
{
if (p.collapseParams == null) return;
EventPropertyPrefab input = ePrefabs[p.propertyName].GetComponent<EventPropertyPrefab>();
foreach (var c in p.collapseParams)
{
List<GameObject> collapseables = new();
foreach (var s in c.collapseables)
{
collapseables.Add(ePrefabs[s]);
}
input.propertyCollapses.Add(new EventPropertyPrefab.PropertyCollapse(collapseables, c.CollapseOn));
}
input.SetCollapses(p.parameter);
}
active = true;
@ -112,7 +129,7 @@ namespace HeavenStudio.Editor
}
}
private void AddParam(string propertyName, object type, string caption, string tooltip = "")
private GameObject AddParam(string propertyName, object type, string caption, string tooltip = "")
{
GameObject prefab = IntegerP;
GameObject input;
@ -164,8 +181,9 @@ namespace HeavenStudio.Editor
else
{
Debug.LogError("Can't make property interface of type: " + type.GetType());
return;
return null;
}
return input;
}
private GameObject InitPrefab(GameObject prefab, string tooltip = "")

View File

@ -16,8 +16,10 @@ namespace HeavenStudio.Editor
public TMP_Text caption;
public EventParameterManager parameterManager;
public string propertyName;
public List<PropertyCollapse> propertyCollapses = new List<PropertyCollapse>();
public void SetProperties(string propertyName, object type, string caption) {}
public virtual void SetCollapses(object type) { }
public void InitProperties(string propertyName, string caption)
{
@ -25,5 +27,28 @@ namespace HeavenStudio.Editor
this.propertyName = propertyName;
this.caption.text = caption;
}
public void UpdateCollapse(object type)
{
foreach (var p in propertyCollapses)
{
foreach (var c in p.collapseables)
{
c.SetActive(p.collapseOn(type) && gameObject.activeSelf);
}
}
}
public class PropertyCollapse
{
public List<GameObject> collapseables;
public Func<object, bool> collapseOn;
public PropertyCollapse(List<GameObject> collapseables, Func<object, bool> collapseOn)
{
this.collapseables = collapseables;
this.collapseOn = collapseOn;
}
}
}
}

View File

@ -30,6 +30,14 @@ namespace HeavenStudio.Editor
);
}
public override void SetCollapses(object type)
{
toggle.onValueChanged.AddListener(
_ => UpdateCollapse(toggle.isOn)
);
UpdateCollapse(toggle.isOn);
}
private void Update()
{
}

View File

@ -43,6 +43,12 @@ namespace HeavenStudio.Editor
ColorTable.gameObject.SetActive(false);
}
public override void SetCollapses(object type)
{
colorPreview.colorPicker.onColorChanged += _ => UpdateCollapse(colorPreview.colorPicker.color);
UpdateCollapse(colorPreview.colorPicker.color);
}
private void Update()
{
if (colorTableActive)

View File

@ -17,13 +17,14 @@ namespace HeavenStudio.Editor
[Header("Dropdown")]
[Space(10)]
public TMP_Dropdown dropdown;
private Array enumVals;
new public void SetProperties(string propertyName, object type, string caption)
{
InitProperties(propertyName, caption);
var enumType = type.GetType();
var enumVals = Enum.GetValues(enumType);
enumVals = Enum.GetValues(enumType);
var enumNames = Enum.GetNames(enumType).ToList();
// Can we assume non-holey enum?
@ -42,6 +43,12 @@ namespace HeavenStudio.Editor
);
}
public override void SetCollapses(object type)
{
dropdown.onValueChanged.AddListener(_ => UpdateCollapse((int)enumVals.GetValue(dropdown.value)));
UpdateCollapse((int)enumVals.GetValue(dropdown.value));
}
private void Update()
{
}

View File

@ -94,6 +94,56 @@ namespace HeavenStudio.Editor
}
}
public override void SetCollapses(object type)
{
switch (type)
{
case EntityTypes.Integer integer:
slider.onValueChanged.AddListener(
_ =>
{
UpdateCollapse((int)slider.value);
}
);
inputField.onEndEdit.AddListener(
_ =>
{
UpdateCollapse((int)slider.value);
}
);
UpdateCollapse((int)slider.value);
break;
case EntityTypes.Float fl:
slider.onValueChanged.AddListener(
_ =>
{
var newValue = (float)Math.Round(slider.value, 4);
UpdateCollapse(newValue);
}
);
var newValue = (float)Math.Round(slider.value, 4);
UpdateCollapse(newValue);
inputField.onEndEdit.AddListener(
_ =>
{
UpdateCollapse(slider.value);
}
);
break;
default:
throw new ArgumentOutOfRangeException(
nameof(type), type, "I don't know how to make a property of this type!"
);
}
}
private void Update()
{
}

View File

@ -42,6 +42,16 @@ namespace HeavenStudio.Editor
);
}
public override void SetCollapses(object type)
{
inputFieldString.onValueChanged.AddListener(
_ =>
{
UpdateCollapse(inputFieldString.text);
});
UpdateCollapse(inputFieldString.text);
}
private void Update()
{
}