Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.

Commit 3d9d218

Browse files
committed
c# 10, add menu color melonpref
1 parent 7569ef7 commit 3d9d218

2 files changed

Lines changed: 31 additions & 19 deletions

File tree

AstralUI.UIMGUI.cs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,38 @@
55
using static Astrum.AstralCore.Managers.CommandManager;
66
using static Astrum.AstralCore.Managers.ModuleManager;
77

8-
[assembly: MelonInfo(typeof(Astrum.AstralUI.UIMGUI), "AstralUI.UIMGUI", "0.1.0", downloadLink: "github.com/Astrum-Project/AstralUI.UIMGUI")]
8+
[assembly: MelonInfo(typeof(Astrum.AstralUI.UIMGUI), "AstralUI.UIMGUI", "0.2.0", downloadLink: "github.com/Astrum-Project/AstralUI.UIMGUI")]
99
[assembly: MelonColor(ConsoleColor.DarkMagenta)]
1010

1111
namespace Astrum.AstralUI
1212
{
1313
public class UIMGUI : MelonMod
1414
{
15-
public Module currentModule = null;
16-
private Rect position = new Rect(Screen.width / 2 - 78, Screen.height / 2 - 307, 156, 482);
15+
public static Color32 color = new(0x56, 0x00, 0xA5, 0xFF);
16+
public static Module currentModule = null;
17+
18+
private static Rect position = new(Screen.width / 2 - 78, Screen.height / 2 - 307, 156, 482);
19+
20+
public override void OnApplicationStart()
21+
{
22+
MelonPreferences_Category category = MelonPreferences.CreateCategory("Astrum-AstralUI-UIMGUI", "AstralUI UIMGUI");
23+
24+
category.CreateEntry(nameof(color), new Color32(0x56, 0x00, 0xA5, 0xFF), "Color");
25+
}
26+
27+
public override void OnPreferencesSaved() => OnPreferencesLoaded();
28+
public override void OnPreferencesLoaded()
29+
{
30+
MelonPreferences_Category category = MelonPreferences.GetCategory("Astrum-AstralUI-UIMGUI");
31+
32+
color = category.GetEntry<Color32>(nameof(color)).Value;
33+
}
1734

1835
public override void OnGUI()
1936
{
2037
if (!Input.GetKey(KeyCode.Tab)) return;
2138

22-
GUI.backgroundColor = new Color32(0x56, 0x00, 0xA5, 0xFF);
39+
GUI.backgroundColor = color;
2340
GUI.color = Color.white;
2441

2542
position = GUI.Window(25, position, (GUI.WindowFunction)ModulesWindow, "Modules");
@@ -44,28 +61,22 @@ private void CommandsWindow(int windowID)
4461

4562
foreach (KeyValuePair<string, Command> command in currentModule.commands)
4663
{
47-
if (command.Value is ConVar<bool>)
48-
{
49-
ConVar<bool> c = (ConVar<bool>)command.Value;
50-
c.Value = GUI.Toggle(CreateRect(ref i), c.Value, command.Key);
51-
}
52-
else if (command.Value is ConVar<float>)
64+
if (command.Value is ConVar<bool> cb)
65+
cb.Value = GUI.Toggle(CreateRect(ref i), cb.Value, command.Key);
66+
else if (command.Value is ConVar<float> cf)
5367
{
54-
ConVar<float> c = (ConVar<float>)command.Value;
55-
GUI.Label(CreateRect(ref i), command.Key + $": ({c.Value.ToString("0.00")})");
56-
c.Value = GUI.HorizontalSlider(CreateRect(ref i), c.Value, c.Value - 10, c.Value + 10);
68+
GUI.Label(CreateRect(ref i), command.Key + $": ({cf.Value:0.00})");
69+
cf.Value = GUI.HorizontalSlider(CreateRect(ref i), cf.Value, cf.Value - 10, cf.Value + 10);
5770
}
58-
else if (command.Value is Button) {
71+
else if (command.Value is Button)
72+
{
5973
if (GUI.Button(CreateRect(ref i), command.Key))
6074
(command.Value as Button)?.onClick();
6175
}
62-
else
63-
{
64-
GUI.Label(CreateRect(ref i), command.Key + " (Unsupported type)");
65-
}
76+
else GUI.Label(CreateRect(ref i), command.Key + " (Unsupported type)");
6677
}
6778
}
6879

69-
private static Rect CreateRect(ref int i) => new Rect(3, i++ * 22 + 21, 300, 20);
80+
private static Rect CreateRect(ref int i) => new(3, i++ * 22 + 21, 300, 20);
7081
}
7182
}

AstralUI.UIMGUI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<RootNamespace>Astrum.AstralUI</RootNamespace>
1111
<AssemblyName>AstralUI.UIMGUI</AssemblyName>
1212
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
<LangVersion>10.0</LangVersion>
1314
<FileAlignment>512</FileAlignment>
1415
<Deterministic>true</Deterministic>
1516
</PropertyGroup>

0 commit comments

Comments
 (0)