Skip to content

Commit f4e79db

Browse files
committed
Create dropdown for accessing icon set definition names
1 parent 20fa610 commit f4e79db

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

org.mixedrealitytoolkit.uxcore/Editor/Inspectors/FontIconSet/FontIconSetInspector.cs

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ public class FontIconSetInspector : UnityEditor.Editor
3535

3636
private SerializedProperty iconFontAssetProp = null;
3737
private SerializedProperty fontIconSetDefinitionProp = null;
38+
private bool anyInvalidName = false;
3839

3940
private SortedList<uint, string> iconEntries = new SortedList<uint, string>();
41+
private List<string> validNames = new List<string>();
42+
private List<string> availableNames = new List<string>();
43+
private string[] availableNamesArray = Array.Empty<string>();
4044

4145
/// <summary>
4246
/// A Unity event function that is called when the script component has been enabled.
@@ -88,6 +92,7 @@ public override void OnInspectorGUI()
8892
{
8993
FontIconSet fontIconSet = target as FontIconSet;
9094
TMP_FontAsset fontAsset = iconFontAssetProp.objectReferenceValue as TMP_FontAsset;
95+
FontIconSetDefinition setDefinition = fontIconSetDefinitionProp.objectReferenceValue as FontIconSetDefinition;
9196

9297
showAvailableIcons = EditorGUILayout.Foldout(showAvailableIcons, "Available Icons", true);
9398
if (showAvailableIcons)
@@ -125,6 +130,29 @@ public override void OnInspectorGUI()
125130
{
126131
EditorGUILayout.HelpBox("It's recommended to use a Font Icon Set Definition to ensure consistent icon names across icon sets.", MessageType.Warning);
127132
}
133+
else
134+
{
135+
if (anyInvalidName)
136+
{
137+
EditorGUILayout.HelpBox("Icon names highlighted yellow are not present in the selected Font Icon Set Definition and should be updated.", MessageType.Warning);
138+
anyInvalidName = false;
139+
}
140+
141+
validNames.Clear();
142+
availableNames.Clear();
143+
// Reserve space for the current icon's name
144+
availableNames.Add(string.Empty);
145+
foreach (string name in setDefinition.IconNames)
146+
{
147+
validNames.Add(name);
148+
if (!iconEntries.Values.Contains(name))
149+
{
150+
availableNames.Add(name);
151+
}
152+
}
153+
154+
availableNamesArray = availableNames.ToArray();
155+
}
128156

129157
int column = 0;
130158
string iconToRemove = null;
@@ -153,11 +181,37 @@ public override void OnInspectorGUI()
153181
textureRect.height = GlyphDrawSize;
154182
EditorDrawTMPGlyph(textureRect, iconEntry.Key, fontAsset);
155183

156-
string currentName = EditorGUILayout.TextField(iconEntry.Value);
157-
if (currentName != iconEntry.Value)
184+
if (fontIconSetDefinitionProp.objectReferenceValue != null)
158185
{
159-
iconToRename = currentName;
160-
iconToRemove = iconEntry.Value;
186+
// Place the current icon's name in the array
187+
availableNamesArray[0] = iconEntry.Value;
188+
189+
using (var check = new EditorGUI.ChangeCheckScope())
190+
{
191+
// If the currently selected name isn't in our icon set map names, highlight the popup
192+
Color oldColor = GUI.backgroundColor;
193+
if (!validNames.Contains(iconEntry.Value))
194+
{
195+
GUI.backgroundColor = Color.yellow;
196+
anyInvalidName = true;
197+
}
198+
int selected = EditorGUILayout.Popup(string.Empty, 0, availableNamesArray, GUILayout.MaxWidth(ButtonDimension));
199+
if (check.changed)
200+
{
201+
iconToRename = availableNamesArray[selected];
202+
iconToRemove = iconEntry.Value;
203+
}
204+
GUI.backgroundColor = oldColor;
205+
}
206+
}
207+
else
208+
{
209+
string currentName = EditorGUILayout.TextField(iconEntry.Value);
210+
if (currentName != iconEntry.Value)
211+
{
212+
iconToRename = currentName;
213+
iconToRemove = iconEntry.Value;
214+
}
161215
}
162216
EditorGUILayout.EndVertical();
163217

0 commit comments

Comments
 (0)