Skip to content

Commit 3ef8330

Browse files
committed
modbuilder + workshop
Modified the ModBuilder to allow building with Newtonsoft.Json Modified the ModBuilder to allow creating the lib folder on first launch Added Workshop GUI, currently on the old MLL api (the levels don't work obv) Moved some calls to the api to threaded code, so game doesn't hang waiting for requests to complete. Added a "Loading x levels.." so users know why the workshop takes so long to load. + Other small changes
1 parent c525077 commit 3ef8330

17 files changed

+1186
-182
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ lib
44
.vs
55
exportBundle.cs
66
*.klm
7-
*.klmi
7+
*.klmi
8+
_ModBuilder
9+
packages

ColorPicker.cs

+19-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class ColorPicker
1313
public static Texture2D imRight, imLeft, imCircle;
1414
int wid;
1515
Rect pos;
16+
public float wX { get => pos.x; }
17+
public float wY { get => pos.y; }
1618
public Color color;
1719
public void UpdateColor()
1820
{
@@ -29,7 +31,7 @@ public void UpdateColor()
2931

3032
public ColorPicker(Color _color, int x, int y) {
3133
wid = ImGUI_WID.GetWindowId();
32-
pos = new Rect(x, y, 165, 200);
34+
pos = new Rect(x, y, 165, 215);
3335
color = _color;
3436

3537
RGBToHSV(_color, out h, out s, out v);
@@ -77,7 +79,7 @@ public void DrawWindow()
7779
#region https://github.com/mattatz/unity-immediate-color-picker
7880
// Licensed under MIT license. Copyright (c) 2016 mattatz
7981
// Check their repo for full license and copyright notice
80-
public static Color HSVToRGB(float H, float S, float V, bool hdr = false)
82+
public static Color HSVToRGB(float H, float S, float V, float keepAlpha = -1, bool hdr = false)
8183
{
8284
Color white = Color.white;
8385
if (S == 0f)
@@ -153,6 +155,8 @@ public static Color HSVToRGB(float H, float S, float V, bool hdr = false)
153155
white.b = Mathf.Clamp(white.b, 0f, 1f);
154156
}
155157
}
158+
if(keepAlpha != -1)
159+
white.a = Mathf.Clamp(keepAlpha, 0, 1);
156160
return white;
157161
}
158162

@@ -272,12 +276,18 @@ void DrawManualInput(ref Color c)
272276
c.g = float.Parse(GUILayout.TextField(c.g.ToString("0.00"), GUILayout.Height(20), GUILayout.Width(35)));
273277
c.b = float.Parse(GUILayout.TextField(c.b.ToString("0.00"), GUILayout.Height(20), GUILayout.Width(35)));
274278
c.a = float.Parse(GUILayout.TextField(c.a.ToString("0.00"), GUILayout.Height(20), GUILayout.Width(35)));
275-
// clamp values
276-
c.r = Mathf.Clamp(c.r, 0, 1);
277-
c.g = Mathf.Clamp(c.g, 0, 1);
278-
c.b = Mathf.Clamp(c.b, 0, 1);
279-
c.a = Mathf.Clamp(c.a, 0, 1);
280279
}
280+
using (new GUILayout.HorizontalScope())
281+
{
282+
GUILayout.Space(-3);
283+
c.a = GUILayout.HorizontalSlider(c.a, 0, 1, GUILayout.Height(20), GUILayout.Width(150));
284+
}
285+
286+
// clamp values
287+
c.r = Mathf.Clamp(c.r, 0, 1);
288+
c.g = Mathf.Clamp(c.g, 0, 1);
289+
c.b = Mathf.Clamp(c.b, 0, 1);
290+
c.a = Mathf.Clamp(c.a, 0, 1);
281291
}
282292

283293
void UpdateSVTexture(Color c, Texture2D tex)
@@ -311,7 +321,7 @@ void DrawSVHandler(Rect rect, ref Color c)
311321
{
312322
s = (p.x - rect.x) / rect.width;
313323
v = 1f - (p.y - rect.y) / rect.height;
314-
c = HSVToRGB(h, s, v);
324+
c = HSVToRGB(h, s, v, c.a);
315325

316326
e.Use();
317327
}
@@ -328,7 +338,7 @@ void DrawHueHandler(Rect rect, ref Color c)
328338
if (e.button == 0 && (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && rect.Contains(p))
329339
{
330340
h = 1f - (p.y - rect.y) / rect.height;
331-
c = HSVToRGB(h, s, v);
341+
c = HSVToRGB(h, s, v, c.a);
332342
UpdateSVTexture(c, svTexture);
333343

334344
e.Use();

GUIex.cs

+40
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,45 @@ public static bool Toggle(Rect pos, ref bool toggle, string onText="On", string
1818
}
1919
return false;
2020
}
21+
22+
public class Dropdown
23+
{
24+
public Dropdown(string[] options, int defaultIdx)
25+
{
26+
Options = options;
27+
Index = defaultIdx;
28+
buttonText = new GUIStyle();
29+
buttonText.normal.background = Texture2D.blackTexture;
30+
buttonText.alignment = TextAnchor.MiddleCenter;
31+
}
32+
public string[] Options;
33+
public int Index;
34+
private bool dropped = false;
35+
GUIStyle buttonText;
36+
public void Draw(Rect pos)
37+
{
38+
if(!dropped)
39+
{
40+
if (GUI.Button(pos, Options[Index])) dropped = true;
41+
GUI.Label(new Rect(pos.x + pos.width - pos.height, pos.y, pos.height, pos.height), "▼");
42+
}
43+
else
44+
{
45+
if (GUI.Button(pos, Options[Index])) dropped = false;
46+
GUI.Label(new Rect(pos.x + pos.width - pos.height, pos.y, pos.height, pos.height), "▲");
47+
GUI.Box(new Rect(pos.x, pos.y + pos.height, pos.width, pos.height * Options.Length), "");
48+
for (int i = 0; i < Options.Length; i++)
49+
{
50+
string color = "<color=white>";
51+
if (i == Index) color = "<color=green>";
52+
if (GUI.Button(new Rect(pos.x, pos.y + pos.height * (i + 1), pos.width, pos.height), color + Options[i] + "</color>", buttonText))
53+
{
54+
Index = i;
55+
dropped = false;
56+
}
57+
}
58+
}
59+
}
60+
}
2161
}
2262
}

0 commit comments

Comments
 (0)