From c5e787045a979363a3de8e3aa4a7a18ccd56a4a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AF=7E?= Date: Fri, 6 Sep 2024 15:01:09 +0200 Subject: [PATCH] review: - Rebased to 1.10.0-rc.4 because the inspector of SubMenu of source Expressions Menu were broken in the base commit this branch initially started with, which was preventing testing some aspects raised during review. - When this is being rendered as part of an SubMenu of source Expressions Menu, don't use any of the label logic, as menu items within such an Expressions Menu are not backed by any GameObject. - Rename _isTryingRichLabel to _useLabel. - Since switching to unlinked always overwrites the label field with the current ObjectName, and switching to linked always empties the label field, the state of _useLabel while the Inspector is open is implied by the value of the label field, or the previous state of the _useLabel field itself when the label field is being emptied out. - In addition, use the |= operator. - When the name is linked, and the user begins typing the "<" character, set the label field, and do not apply the name. This will automatically switch to linked mode as the inspector will be reevaluated a second time. - If the original object name already contains a "<" character (i.e. it comes from a previous version of Modular Avatar), there will be no automatic conversion happening as long as the object name still contains the "<" character. - Changed the localization keys to discard the rich text toggle aspect. - Not addressed: When multiple Menu Item components are selected, the behaviour of the inspector currently edits the GameObject name, with no link button, and no automatic conversion when typing "<", regardless of the contents of the label field. --- Editor/Inspector/Menu/MenuItemGUI.cs | 48 +++++++++++++++++++--------- Editor/Localization/en-US.json | 4 +-- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Editor/Inspector/Menu/MenuItemGUI.cs b/Editor/Inspector/Menu/MenuItemGUI.cs index a48a35de..8a9c427c 100644 --- a/Editor/Inspector/Menu/MenuItemGUI.cs +++ b/Editor/Inspector/Menu/MenuItemGUI.cs @@ -59,6 +59,8 @@ namespace nadena.dev.modular_avatar.core.editor internal class MenuItemCoreGUI { + private const string ImpliesRichText = "<"; + private static readonly ObjectIDGenerator IdGenerator = new ObjectIDGenerator(); private readonly GameObject _parameterReference; private readonly Action _redraw; @@ -99,7 +101,7 @@ namespace nadena.dev.modular_avatar.core.editor private readonly Dictionary _knownParameters = new(); private bool _parameterSourceNotDetermined; - private bool _isTryingRichLabel; + private bool _useLabel; public MenuItemCoreGUI(SerializedObject obj, Action redraw) { @@ -262,8 +264,8 @@ namespace nadena.dev.modular_avatar.core.editor EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); - var needsRichLabel = (!string.IsNullOrEmpty(_prop_label.stringValue) || _isTryingRichLabel); - if (!needsRichLabel) + + if (_parameterReference == null) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_name, G("menuitem.prop.name")); @@ -274,26 +276,42 @@ namespace nadena.dev.modular_avatar.core.editor } else { - EditorGUILayout.PropertyField(_prop_label, G("menuitem.prop.name")); - } - var linkIcon = EditorGUIUtility.IconContent(needsRichLabel ? "UnLinked" : "Linked").image; - var guiIcon = new GUIContent(linkIcon, S(needsRichLabel ? "menuitem.rich_text.toggle_off.tooltip" : "menuitem.rich_text.toggle_on.tooltip")); - if (GUILayout.Button(guiIcon, GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.Width(25))) - { - if (!needsRichLabel) + _useLabel |= !string.IsNullOrEmpty(_prop_label.stringValue); + + if (!_useLabel) { - _isTryingRichLabel = true; - _prop_label.stringValue = _name.stringValue; + EditorGUI.BeginChangeCheck(); + var previousName = _name.stringValue; + EditorGUILayout.PropertyField(_name, G("menuitem.prop.name")); + if (EditorGUI.EndChangeCheck()) + { + if (!previousName.Contains(ImpliesRichText) && _name.stringValue.Contains(ImpliesRichText)) + { + _prop_label.stringValue = _name.stringValue; + } + else + { + _name.serializedObject.ApplyModifiedProperties(); + } + } } else { - _isTryingRichLabel = false; - _prop_label.stringValue = ""; + EditorGUILayout.PropertyField(_prop_label, G("menuitem.prop.name")); + } + + var linkIcon = EditorGUIUtility.IconContent(_useLabel ? "UnLinked" : "Linked").image; + var guiIcon = new GUIContent(linkIcon, S(_useLabel ? "menuitem.label.gameobject_name.tooltip" : "menuitem.label.long_name.tooltip")); + if (GUILayout.Button(guiIcon, GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.Width(25))) + { + _prop_label.stringValue = !_useLabel ? _name.stringValue : ""; + _useLabel = !_useLabel; } } + EditorGUILayout.EndHorizontal(); - if (needsRichLabel && _prop_label.stringValue.Contains("<")) + if (_useLabel && _prop_label.stringValue.Contains(ImpliesRichText)) { var style = new GUIStyle(EditorStyles.textField); style.richText = true; diff --git a/Editor/Localization/en-US.json b/Editor/Localization/en-US.json index 8bc6fc02..08c1dcf3 100644 --- a/Editor/Localization/en-US.json +++ b/Editor/Localization/en-US.json @@ -282,6 +282,6 @@ "ro_sim.effect_group.rule_inverted.tooltip": "This rule will be applied when one of its conditions is NOT met", "ro_sim.effect_group.conditions": "Conditions", - "menuitem.rich_text.toggle_on.tooltip": "Use a long name which may contain rich text and line breaks.", - "menuitem.rich_text.toggle_off.tooltip": "Use the GameObject name." + "menuitem.label.long_name.tooltip": "Use a long name which may contain rich text and line breaks.", + "menuitem.label.gameobject_name.tooltip": "Use the GameObject name." }