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

Commit 9524401

Browse files
committed
use guilayout
1 parent 5cb5156 commit 9524401

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

AstralUI.UIMGUI.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
using System.Collections.Generic;
66
using UnityEngine;
77

8-
[assembly: MelonInfo(typeof(Astrum.AstralUI.UIMGUI), "AstralUI.UIMGUI", "1.0.0", downloadLink: "github.com/Astrum-Project/AstralUI.UIMGUI")]
8+
[assembly: MelonInfo(typeof(Astrum.AstralUI.UIMGUI), "AstralUI.UIMGUI", "1.1.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+
private static readonly UnhollowerBaseLib.Il2CppReferenceArray<GUILayoutOption> options = new(0);
16+
1517
public static Color32 color = new(0x56, 0x00, 0xA5, 0xFF);
1618
public static Module currentModule = null;
1719

1820
private static Rect position = new(Screen.width / 2 - 78, Screen.height / 2 - 307, 156, 482);
21+
private static Vector2 scrollModules = default;
22+
private static Vector2 scrollCommands = default;
1923

2024
public override void OnApplicationStart()
2125
{
@@ -46,37 +50,39 @@ public override void OnGUI()
4650

4751
private void ModulesWindow(int id)
4852
{
49-
int i = 0;
53+
scrollModules = GUILayout.BeginScrollView(scrollModules, options);
5054

5155
foreach (KeyValuePair<string, Module> module in CoreUI.Modules)
52-
if (GUI.Button(new Rect(3, i++ * 22 + 21, 150, 20), module.Key))
56+
if (GUILayout.Button(module.Key, options))
5357
currentModule = module.Value;
58+
59+
GUILayout.EndScrollView(true);
5460

5561
GUI.DragWindow(new Rect(0, 0, 156, 20));
5662
}
5763

5864
private void CommandsWindow(int windowID)
5965
{
60-
int i = 0;
66+
scrollCommands = GUILayout.BeginScrollView(scrollCommands, options);
6167

6268
foreach (KeyValuePair<string, UIBase> command in currentModule.Commands)
6369
{
6470
if (command.Value is UIFieldProp<bool> cb)
65-
cb.Value = GUI.Toggle(CreateRect(ref i), cb.Value, command.Key);
71+
cb.Value = GUILayout.Toggle(cb.Value, command.Key, options);
6672
else if (command.Value is UIFieldProp<float> cf)
6773
{
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);
74+
GUILayout.Label(command.Key + $": ({cf.Value:0.00})", options);
75+
cf.Value = GUILayout.HorizontalSlider(cf.Value, cf.Value - 10, cf.Value + 10, options);
7076
}
7177
else if (command.Value is UIButton)
7278
{
73-
if (GUI.Button(CreateRect(ref i), command.Key))
79+
if (GUILayout.Button(command.Key, options))
7480
(command.Value as UIButton)?.Click();
7581
}
76-
else GUI.Label(CreateRect(ref i), command.Key + " (Unsupported type)");
82+
else GUILayout.Label(command.Key + " (Unsupported type)", options);
7783
}
78-
}
7984

80-
private static Rect CreateRect(ref int i) => new(3, i++ * 22 + 21, 300, 20);
85+
GUILayout.EndScrollView(true);
86+
}
8187
}
8288
}

0 commit comments

Comments
 (0)