-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: menu name may use string field #1008
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,8 @@ internal static ImmutableList<ProvidedParameter> GetParametersForObject(GameObje | |
|
||
internal class MenuItemCoreGUI | ||
{ | ||
private const string ImpliesRichText = "<"; | ||
|
||
private static readonly ObjectIDGenerator IdGenerator = new ObjectIDGenerator(); | ||
private readonly GameObject _parameterReference; | ||
private readonly Action _redraw; | ||
|
@@ -92,11 +94,14 @@ internal class MenuItemCoreGUI | |
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 _useLabel; | ||
|
||
public MenuItemCoreGUI(SerializedObject obj, Action redraw) | ||
{ | ||
|
@@ -144,6 +149,8 @@ public MenuItemCoreGUI(SerializedObject obj, Action redraw) | |
_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); | ||
} | ||
|
||
|
@@ -260,11 +267,69 @@ public void DoGUI() | |
EditorGUILayout.BeginHorizontal(); | ||
|
||
EditorGUILayout.BeginVertical(); | ||
EditorGUI.BeginChangeCheck(); | ||
EditorGUILayout.PropertyField(_name, G("menuitem.prop.name")); | ||
if (EditorGUI.EndChangeCheck()) | ||
|
||
EditorGUILayout.BeginHorizontal(); | ||
|
||
if (_parameterReference == null) | ||
{ | ||
_name.serializedObject.ApplyModifiedProperties(); | ||
EditorGUI.BeginChangeCheck(); | ||
if (_obj != null && _obj.isEditingMultipleObjects) | ||
{ | ||
EditorGUILayout.PropertyField(_prop_label, G("menuitem.prop.name")); | ||
} | ||
else | ||
{ | ||
EditorGUILayout.PropertyField(_name, G("menuitem.prop.name")); | ||
} | ||
if (EditorGUI.EndChangeCheck()) | ||
{ | ||
_name.serializedObject.ApplyModifiedProperties(); | ||
} | ||
} | ||
else | ||
{ | ||
_useLabel |= !string.IsNullOrEmpty(_prop_label.stringValue); | ||
|
||
if (!_useLabel) | ||
{ | ||
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 | ||
{ | ||
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; | ||
} | ||
Comment on lines
+317
to
+321
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's some confusing behavior that occurs when you do the following:
Expected behavior: The displayed name in the inspector should match the game object name. Actual behavior: The displayed name in the inspector is the old label value, until you change focus away from the name field (at which point it'll reset to the gameobject name). |
||
} | ||
|
||
EditorGUILayout.EndHorizontal(); | ||
|
||
if (_useLabel && _prop_label.stringValue.Contains(ImpliesRichText)) | ||
{ | ||
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")); | ||
|
@@ -274,7 +339,7 @@ public void DoGUI() | |
_parameterGUI.DoGUI(true); | ||
|
||
ShowInnateParameterGUI(); | ||
|
||
EditorGUILayout.EndVertical(); | ||
|
||
if (_texture != null) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One note: Please make sure this doesn't break in some terrible way when multiple items are selected...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm stuck on this, I can't figure out how to properly handle multi-editing. Best I can do right now is to maintain the current behaviour where it just edits the GameObject name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's maybe better to multi-edit the label field in that case. Seems like less surprising behavior than editing the name of all the GameObjects at once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be current behaviour as of the latest commit