From c2f37bb3a15606b09fe1ba7ee324bbc52dc8efc8 Mon Sep 17 00:00:00 2001 From: bd_ Date: Tue, 6 Aug 2024 20:43:32 -0700 Subject: [PATCH] ui: redesign MA parameters UI (#956) Closes: #860, #720 --- .../Inspector/Parameters/DefaultValueField.cs | 29 +- .../Parameters/ParameterConfigDrawer.cs | 303 +++++++++++++----- .../Parameters/ParameterConfigDrawer.uxml | 78 +++-- Editor/Inspector/Parameters/Parameters.uss | 178 +++++----- 4 files changed, 378 insertions(+), 210 deletions(-) diff --git a/Editor/Inspector/Parameters/DefaultValueField.cs b/Editor/Inspector/Parameters/DefaultValueField.cs index 7980cbdf..efa948f1 100644 --- a/Editor/Inspector/Parameters/DefaultValueField.cs +++ b/Editor/Inspector/Parameters/DefaultValueField.cs @@ -1,5 +1,4 @@ using System.Globalization; -using nadena.dev.modular_avatar.core; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; @@ -15,6 +14,7 @@ namespace nadena.dev.modular_avatar.core.editor private readonly TextField _visibleField; private readonly FloatField _defaultValueField; + private readonly DropdownField _boolField; private readonly Toggle _hasExplicitDefaultSetField; public DefaultValueField() @@ -22,6 +22,11 @@ namespace nadena.dev.modular_avatar.core.editor // Hidden binding elements _defaultValueField = new FloatField(); _hasExplicitDefaultSetField = new Toggle(); + _boolField = new DropdownField(); + + _boolField.choices.Add(""); + _boolField.choices.Add("True"); + _boolField.choices.Add("False"); _defaultValueField.RegisterValueChangedCallback( evt => UpdateVisibleField(evt.newValue, _hasExplicitDefaultSetField.value)); @@ -50,10 +55,22 @@ namespace nadena.dev.modular_avatar.core.editor _defaultValueField.SetEnabled(false); _hasExplicitDefaultSetField.style.width = 0; _hasExplicitDefaultSetField.SetEnabled(false); + + _boolField.RegisterValueChangedCallback(evt => + { + if (evt.newValue == "True") + _defaultValueField.value = 1; + else + _defaultValueField.value = 0; + + _hasExplicitDefaultSetField.value = evt.newValue != ""; + }); + style.flexDirection = FlexDirection.Row; Add(_visibleField); + Add(_boolField); Add(_defaultValueField); Add(_hasExplicitDefaultSetField); } @@ -73,6 +90,16 @@ namespace nadena.dev.modular_avatar.core.editor var str = hasExplicitValue ? value.ToString(CultureInfo.InvariantCulture) : ""; _visibleField.SetValueWithoutNotify(str); + + string boolStr; + if (!hasExplicitValue) + boolStr = ""; + else if (value > 0.5) + boolStr = "True"; + else + boolStr = "False"; + + _boolField.SetValueWithoutNotify(boolStr); } } } \ No newline at end of file diff --git a/Editor/Inspector/Parameters/ParameterConfigDrawer.cs b/Editor/Inspector/Parameters/ParameterConfigDrawer.cs index 7bc498d9..e4afd0de 100644 --- a/Editor/Inspector/Parameters/ParameterConfigDrawer.cs +++ b/Editor/Inspector/Parameters/ParameterConfigDrawer.cs @@ -2,8 +2,8 @@ using System; using UnityEditor; -using UnityEditor.UIElements; using UnityEngine.UIElements; +using Toggle = UnityEngine.UIElements.Toggle; namespace nadena.dev.modular_avatar.core.editor.Parameters { @@ -20,105 +20,230 @@ namespace nadena.dev.modular_avatar.core.editor.Parameters Localization.UI.Localize(root); root.styleSheets.Add(uss); - var foldout = root.Q(); - var foldoutLabel = foldout?.Q