Reset Event Property Value + Right Click Dropdown API + Confirm Quit (#563)

* * in name when changing value

* Popup UI and quit basics

* Quit button finalized, i think

* fix

* fixed

* right click dropdown prefab

* tryna getit to work

* woohoo it works

* value reset support for text areas

* Color reset support

* Enums and numbers supported

* catchy tune fix
This commit is contained in:
Rapandrasmus
2023-10-14 03:43:44 +02:00
committed by GitHub
parent 0d35d4325e
commit 8903ffec60
17 changed files with 2019 additions and 87 deletions

View File

@ -105,11 +105,8 @@ namespace HeavenStudio.Editor
ePrefabs.Add(propertyName, AddParam(propertyName, param, caption, tooltip));
}
Debug.Log(action.parameters);
foreach (var p in action.parameters)
{
Debug.Log(p.collapseParams);
if (p.collapseParams == null || p.collapseParams.Count == 0) continue;
EventPropertyPrefab input = ePrefabs[p.propertyName].GetComponent<EventPropertyPrefab>();
foreach (var c in p.collapseParams)

View File

@ -14,6 +14,7 @@ namespace HeavenStudio.Editor
public class EventPropertyPrefab : MonoBehaviour
{
public TMP_Text caption;
protected string _captionText;
public EventParameterManager parameterManager;
public string propertyName;
public List<PropertyCollapse> propertyCollapses = new List<PropertyCollapse>();
@ -25,7 +26,10 @@ namespace HeavenStudio.Editor
{
this.parameterManager = EventParameterManager.instance;
this.propertyName = propertyName;
this.caption.text = caption;
_captionText = caption;
this.caption.text = _captionText;
}
public void UpdateCollapse(object type)
@ -34,7 +38,7 @@ namespace HeavenStudio.Editor
{
foreach (var c in p.collapseables)
{
c.SetActive(p.collapseOn(type) && gameObject.activeSelf);
if (c != null) c.SetActive(p.collapseOn(type) && gameObject.activeSelf);
}
}
}

View File

@ -18,18 +18,36 @@ namespace HeavenStudio.Editor
[Space(10)]
public Toggle toggle;
private bool _defaultValue;
new public void SetProperties(string propertyName, object type, string caption)
{
InitProperties(propertyName, caption);
// ' (bool)type ' always results in false
_defaultValue = (bool)type;
toggle.isOn = Convert.ToBoolean(parameterManager.entity[propertyName]);
toggle.onValueChanged.AddListener(
_ => parameterManager.entity[propertyName] = toggle.isOn
_ =>
{
parameterManager.entity[propertyName] = toggle.isOn;
if (toggle.isOn != _defaultValue)
{
this.caption.text = _captionText + "*";
}
else
{
this.caption.text = _captionText;
}
}
);
}
public void ResetValue()
{
toggle.isOn = _defaultValue;
}
public override void SetCollapses(object type)
{
toggle.onValueChanged.AddListener(
@ -37,9 +55,5 @@ namespace HeavenStudio.Editor
);
UpdateCollapse(toggle.isOn);
}
private void Update()
{
}
}
}

View File

@ -21,12 +21,26 @@ namespace HeavenStudio.Editor
public bool colorTableActive;
public ColorPreview colorPreview;
private Color _defaultColor;
new public void SetProperties(string propertyName, object type, string caption)
{
InitProperties(propertyName, caption);
colorPreview.colorPicker.onColorChanged += _ =>
colorPreview.colorPicker.onColorChanged += _ =>
{
parameterManager.entity[propertyName] = colorPreview.colorPicker.color;
if (colorPreview.colorPicker.color != _defaultColor)
{
this.caption.text = _captionText + "*";
}
else
{
this.caption.text = _captionText;
}
};
_defaultColor = (Color)type;
Color paramCol = parameterManager.entity[propertyName];
@ -43,6 +57,11 @@ namespace HeavenStudio.Editor
ColorTable.gameObject.SetActive(false);
}
public void ResetValue()
{
colorPreview.ChangeColor(_defaultColor);
}
public override void SetCollapses(object type)
{
colorPreview.colorPicker.onColorChanged += _ => UpdateCollapse(colorPreview.colorPicker.color);

View File

@ -9,6 +9,7 @@ using Starpelly;
using HeavenStudio.Util;
using HeavenStudio.Editor;
using HeavenStudio.Common;
namespace HeavenStudio.Editor
{
@ -16,9 +17,11 @@ namespace HeavenStudio.Editor
{
[Header("Dropdown")]
[Space(10)]
public TMP_Dropdown dropdown;
public LeftClickTMP_Dropdown dropdown;
private Array enumVals;
private int _defaultValue;
private bool openedDropdown = false;
new public void SetProperties(string propertyName, object type, string caption)
@ -28,6 +31,7 @@ namespace HeavenStudio.Editor
var enumType = type.GetType();
enumVals = Enum.GetValues(enumType);
var enumNames = Enum.GetNames(enumType).ToList();
_defaultValue = (int)type;
// Can we assume non-holey enum?
// If we can we can simplify to dropdown.value = (int) parameterManager.entity[propertyName]
@ -40,11 +44,26 @@ namespace HeavenStudio.Editor
dropdown.AddOptions(enumNames);
dropdown.value = selected;
dropdown.onValueChanged.AddListener(_ =>
parameterManager.entity[propertyName] = (int) enumVals.GetValue(dropdown.value)
dropdown.onValueChanged.AddListener(_ =>
{
parameterManager.entity[propertyName] = (int)enumVals.GetValue(dropdown.value);
if ((int)enumVals.GetValue(dropdown.value) != _defaultValue)
{
this.caption.text = _captionText + "*";
}
else
{
this.caption.text = _captionText;
}
}
);
}
public void ResetValue()
{
dropdown.value = _defaultValue;
}
public override void SetCollapses(object type)
{
dropdown.onValueChanged.AddListener(_ => UpdateCollapse((int)enumVals.GetValue(dropdown.value)));

View File

@ -9,6 +9,7 @@ using Starpelly;
using HeavenStudio.Util;
using HeavenStudio.Editor;
using static HeavenStudio.EntityTypes;
namespace HeavenStudio.Editor
{
@ -19,6 +20,8 @@ namespace HeavenStudio.Editor
public Slider slider;
public TMP_InputField inputField;
private float _defaultValue;
new public void SetProperties(string propertyName, object type, string caption)
{
InitProperties(propertyName, caption);
@ -28,6 +31,7 @@ namespace HeavenStudio.Editor
case EntityTypes.Integer integer:
slider.minValue = integer.min;
slider.maxValue = integer.max;
_defaultValue = integer.val;
slider.wholeNumbers = true;
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
@ -38,6 +42,14 @@ namespace HeavenStudio.Editor
{
inputField.text = slider.value.ToString();
parameterManager.entity[propertyName] = (int) slider.value;
if (slider.value != _defaultValue)
{
this.caption.text = _captionText + "*";
}
else
{
this.caption.text = _captionText;
}
}
);
@ -52,6 +64,14 @@ namespace HeavenStudio.Editor
slider.value = Convert.ToSingle(inputField.text);
parameterManager.entity[propertyName] = (int) slider.value;
Editor.instance.editingInputField = false;
if (slider.value != _defaultValue)
{
this.caption.text = _captionText + "*";
}
else
{
this.caption.text = _captionText;
}
}
);
break;
@ -59,6 +79,7 @@ namespace HeavenStudio.Editor
case EntityTypes.Float fl:
slider.minValue = fl.min;
slider.maxValue = fl.max;
_defaultValue = fl.val;
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
inputField.text = slider.value.ToString("G");
@ -69,6 +90,14 @@ namespace HeavenStudio.Editor
var newValue = (float) Math.Round(slider.value, 4);
inputField.text = newValue.ToString("G");
parameterManager.entity[propertyName] = newValue;
if (newValue != _defaultValue)
{
this.caption.text = _captionText + "*";
}
else
{
this.caption.text = _captionText;
}
}
);
@ -83,6 +112,14 @@ namespace HeavenStudio.Editor
slider.value = (float) Math.Round(Convert.ToSingle(inputField.text), 4);
parameterManager.entity[propertyName] = slider.value;
Editor.instance.editingInputField = false;
if (slider.value != _defaultValue)
{
this.caption.text = _captionText + "*";
}
else
{
this.caption.text = _captionText;
}
}
);
break;
@ -94,6 +131,11 @@ namespace HeavenStudio.Editor
}
}
public void ResetValue()
{
slider.value = _defaultValue;
}
public override void SetCollapses(object type)
{
switch (type)

View File

@ -9,6 +9,7 @@ using Starpelly;
using HeavenStudio.Util;
using HeavenStudio.Editor;
using UnityEngine.UIElements;
namespace HeavenStudio.Editor
{
@ -18,10 +19,14 @@ namespace HeavenStudio.Editor
[Space(10)]
public TMP_InputField inputFieldString;
private string _defaultValue;
new public void SetProperties(string propertyName, object type, string caption)
{
InitProperties(propertyName, caption);
_defaultValue = (string)type;
inputFieldString.text = (string) parameterManager.entity[propertyName];
inputFieldString.onSelect.AddListener(
@ -30,10 +35,19 @@ namespace HeavenStudio.Editor
);
inputFieldString.onValueChanged.AddListener(
_ =>
{;
{
parameterManager.entity[propertyName] = inputFieldString.text;
if (inputFieldString.text != _defaultValue)
{
this.caption.text = _captionText + "*";
}
else
{
this.caption.text = _captionText;
}
}
);
inputFieldString.onEndEdit.AddListener(
_ =>
{;
@ -42,6 +56,11 @@ namespace HeavenStudio.Editor
);
}
public void ResetValue()
{
inputFieldString.text = _defaultValue;
}
public override void SetCollapses(object type)
{
inputFieldString.onValueChanged.AddListener(