-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUi.cs
More file actions
87 lines (70 loc) · 2.57 KB
/
Ui.cs
File metadata and controls
87 lines (70 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using SimpleModMenu.Tabs;
using UnityEngine;
namespace SimpleModMenu
{
internal class Ui
{
public bool menuOpen;
public Color themeColor; // Todo: Add theme color functionality
private static Vector2 menuSize = new Vector2(800, 600);
private static Rect menuRect = new Rect(Screen.width / 2 - menuSize.x / 2, Screen.height / 2 - menuSize.y / 2, menuSize.x, menuSize.y);
public Ui()
{
this.menuOpen = false;
this.themeColor = new Vector4(1f, 0f, 0f, 1f); // Red
}
/// <summary>
/// Draws the mod menu if it is open. Should be called in a MelonEvents.OnGUI event.
/// </summary>
public void DrawMenu()
{
if (!menuOpen) return;
menuRect = GUI.Window(1, menuRect, DrawMenuWindow, "Simple Mod Menu");
}
private void DrawMenuWindow(int windowID)
{
GUIStyle centeredStyle = new GUIStyle(GUI.skin.label);
centeredStyle.alignment = TextAnchor.MiddleCenter;
DrawTabs();
GUI.Label(new Rect(menuRect.width / 2 - 100, menuRect.height - 40, 200, 20), "Made by Samisalami", centeredStyle);
// Make the window draggable
GUI.DragWindow(new Rect(0, 0, menuRect.width, 20));
}
private void DrawTabs()
{
GUILayoutOption gUILayoutOption = GUILayout.MinHeight(40);
GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
buttonStyle.fontSize = 20;
GUILayout.BeginHorizontal();
int i = 0;
foreach (Tab tab in API.GetTabs()) {
if (GUILayout.Button(tab.title, buttonStyle, gUILayoutOption))
{
Core.selectedTab = i;
}
i++;
}
GUILayout.EndHorizontal();
DrawTabContent();
}
private void DrawTabContent()
{
Rect tabContentRect = new Rect(0, 40, menuRect.width, menuRect.height - 40);
GUI.BeginGroup(tabContentRect);
// Draw the content of the selected tab
if (Core.selectedTab >= 0 && Core.selectedTab < API.GetTabCount())
{
API.GetTab(Core.selectedTab).DrawTab();
}
GUI.EndGroup();
}
/// <summary>
/// Returns the rectangle for the menu window.
/// </summary>
/// <returns>The rectangle</returns>
public static Rect GetMenuRect()
{
return menuRect;
}
}
}