Skip to content

Commit

Permalink
Button labels, tooltips, icons.
Browse files Browse the repository at this point in the history
First iteration, buttons now have optional tooltips and labels. By default the editor will load with them on, this can be changed in the settings.
  • Loading branch information
maxartz15 committed Apr 18, 2020
1 parent 6c2daeb commit 3532465
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 56 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

namespace MA_TextureAtlasserPro
{
[CustomEditor(typeof(MA_TextureAtlasserProSettings))]
[CanEditMultipleObjects]
public class MA_TextureAtlasserProSettingsEditor : Editor
{
GUIContent reloadButton = new GUIContent("Reload", "Update the editor with the changes made.");

public override void OnInspectorGUI()
{
GUILayout.BeginVertical();
DrawDefaultInspector();

GUILayout.Space(15);

if(GUILayout.Button(reloadButton, GUILayout.Height(40), GUILayout.ExpandWidth(true)))
{
//Update necessary systems.
MA_TextureAtlasserProGuiLoader.LoadEditorGui((MA_TextureAtlasserProSettings)this.target);
}

GUILayout.EndVertical();
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ namespace MA_TextureAtlasserPro
[System.Serializable]
public class MA_TextureAtlasserProSettings : ScriptableObject
{
[Header("Hotkeys:")]
[Header("GUI (requires reload):")]
public MA_TextureAtlasserProGuiSettings editorGuiSettings = new MA_TextureAtlasserProGuiSettings();

[Header("HotKeys:")]
public bool useHotkeys = false;
public EventModifiers modifierKey = EventModifiers.Alt;
public KeyCode addQuadHotKey = KeyCode.Q;
Expand All @@ -36,5 +39,19 @@ public bool GetHotKey(Event e, KeyCode shortKey)
return false;
}
}

[System.Serializable]
public class MA_TextureAtlasserProGuiSettings
{
public MA_EditorGuiMode editorGuiMode = MA_EditorGuiMode.IconAndText;
public bool enableToolTips = true;
}

public enum MA_EditorGuiMode
{
IconAndText = 0,
Icon = 1,
Text = 2
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;

namespace MA_TextureAtlasserPro
{
public static class MA_TextureAtlasserProGuiLoader
{
private const string LOADICONPATH = "Assets/MA_ToolBox/MA_TextureAtlasserPro/Icons/";

public static GUIContent createAtlasGC;
public static GUIContent loadAtlasGC;
public static GUIContent exportAtlasGC;
public static GUIContent createQuadGC;
public static GUIContent removeQuadGC;
public static GUIContent duplicateQuadGC;
public static GUIContent showTexturesOnGC;
public static GUIContent showTexturesOffGC;
public static GUIContent dragHandleGC;
public static GUIContent editGC;
public static GUIContent createExportSettingsGC;

public static void LoadEditorGui(MA_TextureAtlasserProSettings settings)
{
createAtlasGC = new GUIContent();
loadAtlasGC = new GUIContent();
exportAtlasGC = new GUIContent();
createQuadGC = new GUIContent();
removeQuadGC = new GUIContent();
duplicateQuadGC = new GUIContent();
showTexturesOnGC = new GUIContent();
showTexturesOffGC = new GUIContent();
dragHandleGC = new GUIContent();
editGC = new GUIContent();
createExportSettingsGC = new GUIContent();

switch (settings.editorGuiSettings.editorGuiMode)
{
case MA_EditorGuiMode.IconAndText:
LoadIcons();
LoadText();
break;
case MA_EditorGuiMode.Icon:
LoadIcons();
break;
case MA_EditorGuiMode.Text:
LoadText();
break;
default:
LoadIcons();
break;
}

if(settings.editorGuiSettings.enableToolTips)
{
LoadToolTips(settings);
}

//Exceptions.
dragHandleGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "dragHandleIcon" + ".png");
dragHandleGC.text = "";
editGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "editIcon" + ".png");
editGC.text = "";
}

private static void LoadIcons()
{
createAtlasGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "createAtlasIcon" + ".png");
loadAtlasGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "loadAtlasIcon" + ".png");
exportAtlasGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "exportAtlasIcon" + ".png");
createQuadGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "createQuadIcon" + ".png");
removeQuadGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "removeQuadIcon" + ".png");
duplicateQuadGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "duplicateQuadIcon" + ".png");
showTexturesOnGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "showTexturesOnIcon" + ".png");
showTexturesOffGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "showTexturesOffIcon" + ".png");
createExportSettingsGC.image = (Texture)EditorGUIUtility.Load(LOADICONPATH + "createAtlasIcon" + ".png");
}

private static void LoadText()
{
createAtlasGC.text = "Create Atlas";
loadAtlasGC.text = "Load Atlas";
exportAtlasGC.text = "Export Atlas";
createQuadGC.text = "Create Quad";
removeQuadGC.text = "Remove Quad";
duplicateQuadGC.text = "Duplicate Quad";
showTexturesOnGC.text = "Hide Textures";
showTexturesOffGC.text = "Show Textures";
createExportSettingsGC.text = "Create Export Settings";
}

private static void LoadToolTips(MA_TextureAtlasserProSettings settings)
{
createAtlasGC.tooltip = "Opens the create atlas window.";
loadAtlasGC.tooltip = "Load an existing atlas.";
exportAtlasGC.tooltip = "Opens the export window.";
if (settings.useHotkeys)
{
createQuadGC.tooltip = string.Format("({0} + {1}), Creates a new quad.", settings.modifierKey, settings.addQuadHotKey);
removeQuadGC.tooltip = string.Format("({0} + {1}), Removes the selected quad.", settings.modifierKey, settings.removeQuadHotKey);
duplicateQuadGC.tooltip = string.Format("({0} + {1}), Duplicates the selected quad.", settings.modifierKey, settings.duplicateHotKey);
}
else
{
createQuadGC.tooltip = "Creates a new quad.";
removeQuadGC.tooltip = "Removes the selected quad.";
duplicateQuadGC.tooltip = "Duplicates the selected quad.";
}
showTexturesOnGC.tooltip = "Hides the preview of the first texture on the quads.";
showTexturesOffGC.tooltip = "Shows a preview of the first texture on the quads.";
createExportSettingsGC.tooltip = "Opens the create export settings window.";
}
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override void UpdateView(Event e, Rect editorViewRect)
//Textures
GUILayout.BeginHorizontal();
GUILayout.Label("Textures", GUILayout.ExpandWidth(true));
if(GUILayout.Button(MA_TextureAtlasserProIcons.editIcon, EditorStyles.miniButton, GUILayout.Width(36), GUILayout.Height(15)))
if(GUILayout.Button(MA_TextureAtlasserProGuiLoader.editGC, EditorStyles.miniButton, GUILayout.Width(36), GUILayout.Height(15)))
{
isEditing = !isEditing;
}
Expand Down Expand Up @@ -140,7 +140,7 @@ public override void UpdateView(Event e, Rect editorViewRect)
}
else
{
labelStyle.normal.textColor = Color.black;
labelStyle.normal.textColor = GUI.skin.label.normal.textColor;
}

GUILayout.Label("x " + curWindow.textureAtlas.selectedTextureQuad.guiRect.x.ToString() + ", y " + curWindow.textureAtlas.selectedTextureQuad.guiRect.y.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,42 @@ public override void UpdateView(Event e, Rect editorViewRect)
GUILayout.BeginArea(editorViewRect, EditorStyles.helpBox);
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));

if(GUILayout.Button(MA_TextureAtlasserProIcons.createAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
if(GUILayout.Button(MA_TextureAtlasserProGuiLoader.createAtlasGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
MA_TextureAtlasserProCreateWindow.InitEditorWindow(curWindow);
}
if(GUILayout.Button(MA_TextureAtlasserProIcons.loadAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
if(GUILayout.Button(MA_TextureAtlasserProGuiLoader.loadAtlasGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
curWindow.textureAtlas = MA_TextureAtlasserProUtils.LoadTextureAtlas();
}

if(curWindow.textureAtlas != null)
{
if(GUILayout.Button(MA_TextureAtlasserProIcons.exportAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
if(GUILayout.Button(MA_TextureAtlasserProGuiLoader.exportAtlasGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
MA_TextureAtlasserProExportWindow.InitEditorWindow(curWindow);
//MA_TextureAtlasserProUtils.ExportAtlas(curWindow.textureAtlas);
}
GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET);
if(curWindow.textureAtlas.showTextures && GUILayout.Button(MA_TextureAtlasserProIcons.showTexturesOnIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
if(curWindow.textureAtlas.showTextures && GUILayout.Button(MA_TextureAtlasserProGuiLoader.showTexturesOnGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
curWindow.textureAtlas.showTextures = false;
}
else if(!curWindow.textureAtlas.showTextures && GUILayout.Button(MA_TextureAtlasserProIcons.showTexturesOffIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
else if(!curWindow.textureAtlas.showTextures && GUILayout.Button(MA_TextureAtlasserProGuiLoader.showTexturesOffGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
curWindow.textureAtlas.showTextures = true;
}
GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET);
if(GUILayout.Button(MA_TextureAtlasserProIcons.createQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
if(GUILayout.Button(MA_TextureAtlasserProGuiLoader.createQuadGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
MA_TextureAtlasserProUtils.CreateTextureQuad(curWindow.textureAtlas, "new Quad", new Rect(0, 0, 128, 128), curWindow.settings.autoFocus);
}
if(curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProIcons.removeQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
if(curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProGuiLoader.removeQuadGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
if(curWindow.textureAtlas.selectedTextureQuad != null)
MA_TextureAtlasserProUtils.RemoveTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus);
}
if (curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProIcons.duplicateQuadIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
if (curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProGuiLoader.duplicateQuadGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
if (curWindow.textureAtlas.selectedTextureQuad != null)
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ private void DrawQuadGUI()
{
if(q.isSelected)
{
GUI.Button(new Rect(q.dragRectPos.x, q.dragRectPos.y, q.dragRectPos.width, q.dragRectPos.height), MA_TextureAtlasserProIcons.dragHandleIcon);
GUI.Button(new Rect(q.dragRectWidth.x, q.dragRectWidth.y, q.dragRectWidth.width, q.dragRectWidth.height), MA_TextureAtlasserProIcons.dragHandleIcon);
GUI.Button(new Rect(q.dragRectHeight.x, q.dragRectHeight.y, q.dragRectHeight.width, q.dragRectHeight.height), MA_TextureAtlasserProIcons.dragHandleIcon);
GUI.Button(new Rect(q.dragRectPos.x, q.dragRectPos.y, q.dragRectPos.width, q.dragRectPos.height), MA_TextureAtlasserProGuiLoader.dragHandleGC);
GUI.Button(new Rect(q.dragRectWidth.x, q.dragRectWidth.y, q.dragRectWidth.width, q.dragRectWidth.height), MA_TextureAtlasserProGuiLoader.dragHandleGC);
GUI.Button(new Rect(q.dragRectHeight.x, q.dragRectHeight.y, q.dragRectHeight.width, q.dragRectHeight.height), MA_TextureAtlasserProGuiLoader.dragHandleGC);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void DrawExportMenu()
{
GUILayout.BeginHorizontal(EditorStyles.helpBox, GUILayout.Height(44));

if (GUILayout.Button(MA_TextureAtlasserProIcons.createAtlasIcon, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
if (GUILayout.Button(MA_TextureAtlasserProGuiLoader.createExportSettingsGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
MA_TextureAtlasserProCreateExportWindow.InitWindow(curWindow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static void Init()
private void OnEnable()
{
//Load the icons
MA_TextureAtlasserProIcons.LoadIcons();
//MA_TextureAtlasserProGuiLoader.LoadEditorGui(thisWindow.settings.editorGuiSettings);
}

private static void GetCurrentWindow()
Expand All @@ -59,6 +59,7 @@ private static void CreateViews()
}

thisWindow.settings = MA_TextureAtlasserProUtils.LoadSettings();
MA_TextureAtlasserProGuiLoader.LoadEditorGui(thisWindow.settings);
thisWindow.workView = new MA_TextureAtlasserProWorkView(thisWindow, "workView");
thisWindow.menuView = new MA_TextureAtlasserProMenuView(thisWindow, "menuView");
thisWindow.inspectorView = new MA_TextureAtlasserProInspectorView(thisWindow, "inspectorView");
Expand Down

0 comments on commit 3532465

Please sign in to comment.