diff --git a/Editor/Inspector/Menu/MenuItemGUI.cs b/Editor/Inspector/Menu/MenuItemGUI.cs index c89c3817..cf1ada0b 100644 --- a/Editor/Inspector/Menu/MenuItemGUI.cs +++ b/Editor/Inspector/Menu/MenuItemGUI.cs @@ -92,11 +92,14 @@ namespace nadena.dev.modular_avatar.core.editor private readonly SerializedProperty _prop_isDefault; private readonly SerializedProperty _prop_automaticValue; + private readonly SerializedProperty _prop_label; + public bool AlwaysExpandContents = false; public bool ExpandContents = false; private readonly Dictionary<string, ProvidedParameter> _knownParameters = new(); private bool _parameterSourceNotDetermined; + private bool _isTryingRichLabel; public MenuItemCoreGUI(SerializedObject obj, Action redraw) { @@ -144,6 +147,8 @@ namespace nadena.dev.modular_avatar.core.editor _prop_isDefault = obj.FindProperty(nameof(ModularAvatarMenuItem.isDefault)); _prop_automaticValue = obj.FindProperty(nameof(ModularAvatarMenuItem.automaticValue)); + _prop_label = obj.FindProperty(nameof(ModularAvatarMenuItem.label)); + _previewGUI = new MenuPreviewGUI(redraw); } @@ -255,11 +260,28 @@ namespace nadena.dev.modular_avatar.core.editor EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(_name, G("menuitem.prop.name")); - if (EditorGUI.EndChangeCheck()) + var needsRichLabel = (!string.IsNullOrEmpty(_prop_label.stringValue) || _isTryingRichLabel); + if (!needsRichLabel) { - _name.serializedObject.ApplyModifiedProperties(); + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(_name, G("menuitem.prop.name")); + if (EditorGUI.EndChangeCheck()) + { + _name.serializedObject.ApplyModifiedProperties(); + } + } + else + { + EditorGUILayout.PropertyField(_prop_label, G("menuitem.prop.name")); + } + + if (needsRichLabel) + { + var style = new GUIStyle(EditorStyles.textField); + style.richText = true; + style.alignment = TextAnchor.MiddleCenter; + + EditorGUILayout.LabelField(" ", _prop_label.stringValue, style, GUILayout.Height(EditorGUIUtility.singleLineHeight * 3)); } EditorGUILayout.PropertyField(_texture, G("menuitem.prop.icon")); @@ -269,7 +291,21 @@ namespace nadena.dev.modular_avatar.core.editor _parameterGUI.DoGUI(true); 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 bc7e8ec8..de041189 100644 --- a/Editor/Localization/en-US.json +++ b/Editor/Localization/en-US.json @@ -280,5 +280,8 @@ "ro_sim.effect_group.rule_inverted": "This rule is inverted", "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" + "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." } diff --git a/Runtime/ModularAvatarMenuItem.cs b/Runtime/ModularAvatarMenuItem.cs index b5fd5d31..d8cf2d36 100644 --- a/Runtime/ModularAvatarMenuItem.cs +++ b/Runtime/ModularAvatarMenuItem.cs @@ -49,6 +49,14 @@ namespace nadena.dev.modular_avatar.core /// </summary> public bool automaticValue; + /// <summary> + /// Although unspecified, the label of a menu may contain rich text and line breaks. + /// If label is not an empty string, this MenuItem will use that as its name. + /// Otherwise, it will use the name of the containing game object as the label. + /// </summary> + [Multiline] + public string label = ""; + private void Reset() { // Init settings only when added or reset manually from the Inspector. @@ -98,7 +106,7 @@ namespace nadena.dev.modular_avatar.core var cloned = new VirtualControl(Control); cloned.subMenu = null; - cloned.name = gameObject.name; + cloned.name = string.IsNullOrEmpty(label) ? gameObject.name : label; FilterSubParameters(cloned);