Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #216 from jmickle66666666/make-vertex-paint-experi…
Browse files Browse the repository at this point in the history
…mental

Make vertex paint experimental
  • Loading branch information
Henry00IS authored Feb 1, 2019
2 parents 9ec30b0 + b0732d0 commit 0f6ab8d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
23 changes: 23 additions & 0 deletions Scripts/CurrentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions Scripts/UI/SabreCSGPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@ public static void PreferencesGUI()
CurrentSettings.OverrideFlyCamera = GUILayout.Toggle(CurrentSettings.OverrideFlyCamera, "Linear fly camera");

EditorGUILayout.Space();
EditorGUI.indentLevel = 1;
EditorGUILayout.LabelField("Developer 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();
using (new EditorGUI.IndentLevelScope()) {
EditorGUILayout.LabelField("Developer Options", EditorStyles.boldLabel);
}
EditorGUILayout.Space();

EditorGUI.BeginChangeCheck();
Expand Down
59 changes: 59 additions & 0 deletions Scripts/UI/SabreGUILayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ public static GUIStyle FormatStyle(Color textColor, int fontSize, FontStyle font
}
}

/// <summary>
/// Displays a list of enum buttons.
/// </summary>
/// <param name="value">The active value enum.</param>
/// <returns>The enum selected when the user clicks one of the buttons.</returns>
public static T DrawEnumGrid<T>(T value, params GUILayoutOption[] options) where T : struct, IConvertible
{
if (!typeof(T).IsEnum)
Expand Down Expand Up @@ -347,6 +352,60 @@ public static T DrawEnumGrid<T>(T value, params GUILayoutOption[] options) where
return value;
}

/// <summary>
/// Displays a list of enum buttons, using only the provided enums.
/// </summary>
/// <param name="value">The active value enum.</param>
/// <param name="enabled">The visible enum values.</param>
/// <returns>The enum selected when the user clicks one of the buttons.</returns>
public static T DrawPartialEnumGrid<T>(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)
Expand Down
2 changes: 1 addition & 1 deletion Scripts/UI/Toolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0f6ab8d

Please sign in to comment.