From 776f08be3f1c6e8de8772e425a7931cfc05e484a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AF=7E?= Date: Tue, 3 Sep 2024 22:25:20 +0200 Subject: [PATCH] review: - Add a link/unlink icon to the right of the name field. - Only show the rich text preview when there is the character '<' in the label field. - Toggling link from ON to OFF will set the label to the current GameObject name. --- Editor/Inspector/Menu/MenuItemGUI.cs | 34 ++++++++++++++++------------ Editor/Localization/en-US.json | 4 ++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Editor/Inspector/Menu/MenuItemGUI.cs b/Editor/Inspector/Menu/MenuItemGUI.cs index cf1ada0b..a48a35de 100644 --- a/Editor/Inspector/Menu/MenuItemGUI.cs +++ b/Editor/Inspector/Menu/MenuItemGUI.cs @@ -260,6 +260,8 @@ namespace nadena.dev.modular_avatar.core.editor EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); + + EditorGUILayout.BeginHorizontal(); var needsRichLabel = (!string.IsNullOrEmpty(_prop_label.stringValue) || _isTryingRichLabel); if (!needsRichLabel) { @@ -274,8 +276,24 @@ namespace nadena.dev.modular_avatar.core.editor { 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) + { + _isTryingRichLabel = true; + _prop_label.stringValue = _name.stringValue; + } + else + { + _isTryingRichLabel = false; + _prop_label.stringValue = ""; + } + } + EditorGUILayout.EndHorizontal(); - if (needsRichLabel) + if (needsRichLabel && _prop_label.stringValue.Contains("<")) { var style = new GUIStyle(EditorStyles.textField); style.richText = true; @@ -292,20 +310,6 @@ namespace nadena.dev.modular_avatar.core.editor ShowInnateParameterGUI(); - var newRichValue = EditorGUILayout.Toggle(G("menuitem.prop.rich_text"), needsRichLabel); - if (newRichValue != needsRichLabel) - { - if (newRichValue) - { - _isTryingRichLabel = true; - } - else - { - _isTryingRichLabel = false; - _prop_label.stringValue = ""; - } - } - EditorGUILayout.EndVertical(); if (_texture != null) diff --git a/Editor/Localization/en-US.json b/Editor/Localization/en-US.json index de041189..8bc6fc02 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.prop.rich_text": "Rich text", - "menuitem.prop.rich_text.tooltip": "Use a long name which may contain rich text and line breaks." + "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." }