-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCustomModeMenu.cs
60 lines (48 loc) · 2.01 KB
/
CustomModeMenu.cs
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
using Il2Cpp;
namespace ModSettings {
internal static class CustomModeMenu {
private static readonly int numPositions = (Position.BelowAll.Index - Position.AboveAll.Index) + 1;
private static readonly HashSet<ModSettingsBase> settings = new HashSet<ModSettingsBase>();
private static readonly List<ModSettingsBase>[] settingsAtPosition = new List<ModSettingsBase>[numPositions];
private static bool guiBuilt = false;
static CustomModeMenu() {
for (int i = 0; i < numPositions; ++i) {
settingsAtPosition[i] = new List<ModSettingsBase>();
}
}
internal static void RegisterSettings(ModSettingsBase modSettings, Position targetPosition) {
if (targetPosition == null) {
throw new ArgumentNullException("targetPosition");
} else if (settings.Contains(modSettings)) {
throw new ArgumentException("[ModSettings] Cannot add the same settings object multiple times", "modSettings");
} else if (guiBuilt) {
throw new InvalidOperationException("[ModSettings] RegisterSettings called after the GUI has been built.\n"
+ "Call this method before Panel_CustomXPSetup::Awake, preferably from your mod's OnLoad method");
}
settings.Add(modSettings);
settingsAtPosition[targetPosition.Index].Add(modSettings);
}
internal static void BuildGUI() {
guiBuilt = true;
CustomModeGUIBuilder guiBuilder = new CustomModeGUIBuilder(InterfaceManager.LoadPanel<Panel_CustomXPSetup>());
for (int position = 0; position < numPositions; ++position) {
List<ModSettingsBase> settingsAtCurrentPos = settingsAtPosition[position];
foreach (ModSettingsBase modSettings in settingsAtCurrentPos) {
guiBuilder.AddSettings(modSettings);
}
guiBuilder.NextSection();
}
guiBuilder.Finish();
}
internal static void SetSettingsVisible(bool enable) {
foreach (ModSettingsBase setting in settings) {
setting.SetMenuVisible(enable);
}
}
internal static void CallOnConfirm() {
foreach (ModSettingsBase settings in settings) {
settings.CallOnConfirm();
}
}
}
}