This repository was archived by the owner on Dec 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuHelper.cs
More file actions
93 lines (77 loc) · 3.29 KB
/
MenuHelper.cs
File metadata and controls
93 lines (77 loc) · 3.29 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
88
89
90
91
92
93
using BoneLib;
using BoneLib.BoneMenu;
using MelonLoader;
using FusionIntermediateServerHelper;
using Prefs = FusionIntermediateServerHelper.Main.Prefs;
using UnityEngine;
internal static class MenuHelper
{
// By Camobiwon under "Here ya go" license
internal static IntElement CreateIntPref(this Page page, string name, Color color, ref MelonPreferences_Entry<int> value, int increment, int minValue, int maxValue, Action<int> callback = null, string prefName = null, int prefDefaultValue = default)
{
prefName ??= name;
if(!Prefs.GlobalCategory.HasEntry(prefName))
value = Prefs.GlobalCategory.CreateEntry(prefName, prefDefaultValue);
MelonPreferences_Entry<int> val = value;
return page.CreateInt(name, color, val.Value, increment, minValue, maxValue, (x) =>
{
val.Value = x;
Prefs.GlobalCategory.SaveToFile(false);
callback?.InvokeActionSafe(x);
});
}
internal static FloatElement CreateFloatPref(this Page page, string name, Color color, ref MelonPreferences_Entry<float> value, float increment, float minValue, float maxValue, Action<float> callback = null, string prefName = null, float prefDefaultValue = default)
{
prefName ??= name;
if(!Prefs.GlobalCategory.HasEntry(prefName))
value = Prefs.GlobalCategory.CreateEntry(prefName, prefDefaultValue);
MelonPreferences_Entry<float> val = value;
return page.CreateFloat(name, color, val.Value, increment, minValue, maxValue, (x) =>
{
val.Value = x;
Prefs.GlobalCategory.SaveToFile(false);
callback?.InvokeActionSafe(x);
});
}
internal static BoolElement CreateBoolPref(this Page page, string name, Color color, ref MelonPreferences_Entry<bool> value, Action<bool> callback = null, string prefName = null, bool prefDefaultValue = default)
{
prefName ??= name;
if(!Prefs.GlobalCategory.HasEntry(prefName))
value = Prefs.GlobalCategory.CreateEntry(prefName, prefDefaultValue);
MelonPreferences_Entry<bool> val = value;
return page.CreateBool(name, color, val.Value, (x) =>
{
val.Value = x;
Prefs.GlobalCategory.SaveToFile(false);
callback?.InvokeActionSafe(x);
});
}
internal static EnumElement CreateEnumPref<T>(this Page page, string name, Color color, ref MelonPreferences_Entry<T> value, Action<Enum> callback = null, string prefName = null, Enum prefDefaultValue = default) where T : Enum
{
prefName ??= name;
if(!Prefs.GlobalCategory.HasEntry(prefName))
value = Prefs.GlobalCategory.CreateEntry(prefName, (T)prefDefaultValue);
MelonPreferences_Entry<T> val = value;
return page.CreateEnum(name, color, val.Value, (x) =>
{
val.Value = (T)x;
Prefs.GlobalCategory.SaveToFile(false);
callback?.InvokeActionSafe(x);
});
}
internal static StringElement CreateStringPref(this Page page, string name, Color color, ref MelonPreferences_Entry<string> value, Action<string> callback = null, string prefName = null, string prefDefaultValue = default)
{
prefName ??= name;
if(!Prefs.GlobalCategory.HasEntry(prefName))
value = Prefs.GlobalCategory.CreateEntry(prefName, prefDefaultValue);
MelonPreferences_Entry<string> val = value;
StringElement element = page.CreateString(name, color, val.Value, (x) =>
{
val.Value = x;
Prefs.GlobalCategory.SaveToFile(false);
callback?.InvokeActionSafe(x);
});
element.Value = value.Value; //BoneMenu temp hack fix
return element;
}
}