Skip to content

Commit

Permalink
review:
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
hai-vr committed Sep 3, 2024
1 parent b7441dd commit 3622606
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
34 changes: 19 additions & 15 deletions Editor/Inspector/Menu/MenuItemGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ public void DoGUI()
EditorGUILayout.BeginHorizontal();

EditorGUILayout.BeginVertical();

EditorGUILayout.BeginHorizontal();
var needsRichLabel = (!string.IsNullOrEmpty(_prop_label.stringValue) || _isTryingRichLabel);
if (!needsRichLabel)
{
Expand All @@ -234,8 +236,24 @@ public void DoGUI()
{
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;
Expand Down Expand Up @@ -326,20 +344,6 @@ public void DoGUI()

EditorGUILayout.EndHorizontal();

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)
Expand Down
4 changes: 2 additions & 2 deletions Editor/Localization/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,6 @@
"reactive_object.material-setter.set-to": "Set material to: ",
"reactive_object.shape-changer.target-renderer": "Target Renderer",
"menuitem.misc.add_toggle": "Add toggle",
"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."
}

0 comments on commit 3622606

Please sign in to comment.