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

Make vertex paint experimental #216

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions Scripts/UI/SabreCSGPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ public static void PreferencesGUI()
SceneView.RepaintAll();
}

EditorGUILayout.Space();
EditorGUI.indentLevel = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying indent level directly like this is probably bad practice, I'd suggest instead using IndentLevelScope

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);
Expand Down
48 changes: 48 additions & 0 deletions Scripts/UI/SabreGUILayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,54 @@ public static T DrawEnumGrid<T>(T value, params GUILayoutOption[] options) where
return value;
}

public static T DrawPartialEnumGrid<T>(T value, T[] enabled, params GUILayoutOption[] options) where T : struct, IConvertible
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A /// summary would be handy here indicating how this differs from DrawEnumGrid

{
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