From e2f13d58ca1009ee15a2b8c235d8c5b1595b2367 Mon Sep 17 00:00:00 2001 From: jazz mickle Date: Sun, 13 Jan 2019 14:51:50 +0100 Subject: [PATCH 1/3] Move vertex paint mode to experimental option --- Scripts/CurrentSettings.cs | 23 +++++++++++++++ Scripts/UI/SabreCSGPreferences.cs | 8 ++++++ Scripts/UI/SabreGUILayout.cs | 48 +++++++++++++++++++++++++++++++ Scripts/UI/Toolbar.cs | 2 +- 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/Scripts/CurrentSettings.cs b/Scripts/CurrentSettings.cs index 2bce6d6a..e6be9877 100644 --- a/Scripts/CurrentSettings.cs +++ b/Scripts/CurrentSettings.cs @@ -372,6 +372,29 @@ public static bool AlwaysSnapToCurrentGrid { PlayerPrefs.SetInt(KEY_PREFIX + "alwaysSnapToCurrentGrid", value ? 1 : 0); } } + + // Experimental options + + public static MainMode[] enabledModes { + get { + MainMode[] output = (MainMode[]) Enum.GetValues(typeof(MainMode)); + + if (!VertexPaintToolEnabled) { + output = Array.FindAll(output, e => { return e != MainMode.Paint; }); + } + + return output; + } + } + + public static bool VertexPaintToolEnabled { + get { + return PlayerPrefs.GetInt(KEY_PREFIX + "VertexPaintToolEnabled") == 1; + } + set { + PlayerPrefs.SetInt(KEY_PREFIX + "VertexPaintToolEnabled", value ? 1 : 0); + } + } } } diff --git a/Scripts/UI/SabreCSGPreferences.cs b/Scripts/UI/SabreCSGPreferences.cs index 5018b461..aa674cc5 100644 --- a/Scripts/UI/SabreCSGPreferences.cs +++ b/Scripts/UI/SabreCSGPreferences.cs @@ -116,6 +116,14 @@ public static void PreferencesGUI() SceneView.RepaintAll(); } + EditorGUILayout.Space(); + EditorGUI.indentLevel = 1; + EditorGUILayout.LabelField("Experimental Options", EditorStyles.boldLabel); + EditorGUI.indentLevel = 0; + EditorGUILayout.Space(); + + CurrentSettings.VertexPaintToolEnabled = GUILayout.Toggle(CurrentSettings.VertexPaintToolEnabled, "Vertex paint tool"); + EditorGUILayout.Space(); EditorGUI.indentLevel = 1; EditorGUILayout.LabelField("Developer Options", EditorStyles.boldLabel); diff --git a/Scripts/UI/SabreGUILayout.cs b/Scripts/UI/SabreGUILayout.cs index 11abf3b6..5be2d14f 100644 --- a/Scripts/UI/SabreGUILayout.cs +++ b/Scripts/UI/SabreGUILayout.cs @@ -347,6 +347,54 @@ public static T DrawEnumGrid(T value, params GUILayoutOption[] options) where return value; } + public static T DrawPartialEnumGrid(T value, T[] enabled, params GUILayoutOption[] options) where T : struct, IConvertible + { + if (!typeof(T).IsEnum) + { + throw new ArgumentException("DrawEnumGrid must be passed an enum"); + } + GUILayout.BeginHorizontal(); + + T[] enabledList = enabled; + T[] baseList = (T[]) Enum.GetValues(value.GetType()); + + for (int i = 0; i < baseList.Length; i++) + { + if (Array.IndexOf(enabledList, baseList[i]) == -1) { + continue; + } + + GUIStyle activeStyle; + if (baseList.Length == 1) // Only one button + { + activeStyle = EditorStyles.miniButton; + } + else if (i == 0) // Left-most button + { + activeStyle = EditorStyles.miniButtonLeft; + } + else if (i == baseList.Length - 1) // Right-most button + { + activeStyle = EditorStyles.miniButtonRight; + } + else // Normal mid button + { + activeStyle = EditorStyles.miniButtonMid; + } + + bool isActive = (Convert.ToInt32(value) == i); + // string displayName = StringHelper.ParseDisplayString(names[i]); + string displayName = baseList[i].ToString(); + if (GUILayout.Toggle(isActive, displayName, activeStyle, options)) + { + value = (T)Enum.ToObject(typeof(T), i); + } + } + + GUILayout.EndHorizontal(); + return value; + } + public static bool DrawUVField(Rect rect, float? sourceFloat, ref string floatString, string controlName, GUIStyle style) { if (!sourceFloat.HasValue) diff --git a/Scripts/UI/Toolbar.cs b/Scripts/UI/Toolbar.cs index 3b578b0c..d5055f44 100644 --- a/Scripts/UI/Toolbar.cs +++ b/Scripts/UI/Toolbar.cs @@ -135,7 +135,7 @@ private static void OnTopToolbarGUI(int windowID) { currentMode = (MainMode)(-1); } - MainMode newMainMode = SabreGUILayout.DrawEnumGrid(currentMode, GUILayout.Width(50)); + MainMode newMainMode = SabreGUILayout.DrawPartialEnumGrid(currentMode, CurrentSettings.enabledModes, GUILayout.Width(50)); if(newMainMode != currentMode) { csgModel.SetCurrentMode(newMainMode); From 035026b0d20b24b28d05d4d342e0b6d848097760 Mon Sep 17 00:00:00 2001 From: jazz mickle Date: Sun, 13 Jan 2019 17:11:21 +0100 Subject: [PATCH 2/3] Replace EditorGUI.indentLevel with EditorGUI.IndentLevelScope --- Scripts/UI/SabreCSGPreferences.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Scripts/UI/SabreCSGPreferences.cs b/Scripts/UI/SabreCSGPreferences.cs index aa674cc5..225b1660 100644 --- a/Scripts/UI/SabreCSGPreferences.cs +++ b/Scripts/UI/SabreCSGPreferences.cs @@ -117,17 +117,17 @@ public static void PreferencesGUI() } EditorGUILayout.Space(); - EditorGUI.indentLevel = 1; - EditorGUILayout.LabelField("Experimental Options", EditorStyles.boldLabel); - EditorGUI.indentLevel = 0; + using (new EditorGUI.IndentLevelScope()) { + EditorGUILayout.LabelField("Experimental Options", EditorStyles.boldLabel); + } EditorGUILayout.Space(); CurrentSettings.VertexPaintToolEnabled = GUILayout.Toggle(CurrentSettings.VertexPaintToolEnabled, "Vertex paint tool"); EditorGUILayout.Space(); - EditorGUI.indentLevel = 1; - EditorGUILayout.LabelField("Developer Options", EditorStyles.boldLabel); - EditorGUI.indentLevel = 0; + using (new EditorGUI.IndentLevelScope()) { + EditorGUILayout.LabelField("Developer Options", EditorStyles.boldLabel); + } EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); From b0732d03d5ea426c4ac35b4e1c90500ee20d07e9 Mon Sep 17 00:00:00 2001 From: jazz mickle Date: Sun, 13 Jan 2019 17:11:36 +0100 Subject: [PATCH 3/3] Add summaries to DrawEnumGrid and DrawPartialEnumGrid --- Scripts/UI/SabreGUILayout.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Scripts/UI/SabreGUILayout.cs b/Scripts/UI/SabreGUILayout.cs index 5be2d14f..8de28a88 100644 --- a/Scripts/UI/SabreGUILayout.cs +++ b/Scripts/UI/SabreGUILayout.cs @@ -305,6 +305,11 @@ public static GUIStyle FormatStyle(Color textColor, int fontSize, FontStyle font } } + /// + /// Displays a list of enum buttons. + /// + /// The active value enum. + /// The enum selected when the user clicks one of the buttons. public static T DrawEnumGrid(T value, params GUILayoutOption[] options) where T : struct, IConvertible { if (!typeof(T).IsEnum) @@ -347,6 +352,12 @@ public static T DrawEnumGrid(T value, params GUILayoutOption[] options) where return value; } + /// + /// Displays a list of enum buttons, using only the provided enums. + /// + /// The active value enum. + /// The visible enum values. + /// The enum selected when the user clicks one of the buttons. public static T DrawPartialEnumGrid(T value, T[] enabled, params GUILayoutOption[] options) where T : struct, IConvertible { if (!typeof(T).IsEnum)