This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
UIXMenuReplacement.cs
176 lines (149 loc) · 8.31 KB
/
UIXMenuReplacement.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
using System;
using System.Collections.Generic;
using System.Linq;
using MelonLoader;
using TeleporterVR.Logic;
using TeleporterVR.Rendering;
using TeleporterVR.Utils;
using UIExpansionKit.API;
using UnityEngine;
using UnityEngine.UI;
using static TeleporterVR.Menu;
namespace TeleporterVR {
class UIXMenuReplacement {
internal static ICustomShowableLayoutedMenu menu = ExpansionKitApi.CreateCustomQuickMenuPage(LayoutDescription.QuickMenu4Columns);
static string color(string c, string s) { return $"<color={c}>{s}</color> "; }
static Dictionary<string, Transform> buttons = new Dictionary<string, Transform>();
static Dictionary<string, Transform> permbuttons = new Dictionary<string, Transform>();
internal static GameObject MainMenuBTN, TPVRButton, UserTPButton;
internal static bool runOnce_start;
public static void Init() {
ExpansionKitApi.GetExpandedMenu(ExpandedMenu.QuickMenu).AddSimpleButton(color("#13cf13", "TeleporterVR") + "\nMenu", () => {
if (!runOnce_start) {
TheMenu();
runOnce_start = true;
menu.Show();
TPVRButton.SetActive(Main.UIXTPVR.Value);
} else if (runOnce_start) {
menu.Show();
UpdateText();
UpdateWorldStatusText();
}
});
ExpansionKitApi.GetExpandedMenu(ExpandedMenu.QuickMenu).AddSimpleButton(VRUtils.active ? Language.theWord_Teleport + color("#00ff00", "\nON") :
Language.theWord_Teleport + color("red", "\nOFF"), () => {
ToggleVRTeleport(!VRUtils.active);
UpdateText();
}, (obj2) => {
permbuttons["TPActive_1"] = obj2.transform;
TPVRButton = obj2;
obj2.SetActive(false);
});
ExpansionKitApi.GetExpandedMenu(ExpandedMenu.UserQuickMenu).AddSimpleButton($"{Language.theWord_Teleport} to Player", () => {
if (!CheckWorldAllowed.RiskyFunctionAllowed) return;
PlayerActions.Teleport(PlayerActions.SelVRCPlayer());
}, (ob) => {
permbuttons["UserTeleport"] = ob.transform;
UserTPButton = ob;
ob.SetActive(Main.VRTeleportVisible.Value);
});
Main.Log("Finished creating UIXMenus", Main.IsDebug);
}
static void TheMenu() {
buttons.Clear();
menu.AddSimpleButton(color("red", "Close") + "Menu", () => menu.Hide());
menu.AddSimpleButton($"World\n{(CheckWorldAllowed.RiskyFunctionAllowed ? color("#00ff00", "Allowed") : color("red", "Disallowed"))}", null, (button) => buttons["WorldStatus"] = button.transform);
menu.AddSpacer();
menu.AddSimpleButton(VRUtils.active ? Language.theWord_Teleport + color("#00ff00", "\nON") : Language.theWord_Teleport + color("red", "\nOFF"), () => {
if (CheckWorldAllowed.RiskyFunctionAllowed) {
VRUtils.active = !VRUtils.active;
TPLocationIndicator.Toggle();
}
UpdateText();
}, (button) => buttons["TPActive_2"] = button.transform);
menu.AddSimpleButton(Language.TPtoName_Text, OpenKeyboardForPlayerTP, (button) => buttons["KeyboardTP"] = button.transform);
menu.AddSimpleButton(Language.TPtoCoord_Text, OpenKeyboardForCoordTP, (button) => buttons["CoordTP"] = button.transform);
menu.AddSpacer();
menu.AddSimpleButton(Main.PreferRightHand.Value ? Language.preferedHanded_Text_ON : Language.preferedHanded_Text_OFF, () => {
Main.PreferRightHand.Value = !Main.PreferRightHand.Value;
UpdateText();
}, (button) => buttons["preferRightHand"] = button.transform);
menu.AddSimpleButton(Language.SavePos + "\n1", () => SaveAction(1), (button) => buttons["Save_1"] = button.transform);
menu.AddSimpleButton(Language.SavePos + "\n2", () => SaveAction(2), (button) => buttons["Save_2"] = button.transform);
menu.AddSimpleButton(Language.SavePos + "\n3", () => SaveAction(3), (button) => buttons["Save_3"] = button.transform);
menu.AddSimpleButton(Language.SavePos + "\n4", () => SaveAction(4), (button) => buttons["Save_4"] = button.transform);
menu.AddSimpleButton(Language.LoadPos + "\n1", () => LoadAction(1), (button) => buttons["Load_1"] = button.transform);
menu.AddSimpleButton(Language.LoadPos + "\n2", () => LoadAction(2), (button) => buttons["Load_2"] = button.transform);
menu.AddSimpleButton(Language.LoadPos + "\n3", () => LoadAction(3), (button) => buttons["Load_3"] = button.transform);
menu.AddSimpleButton(Language.LoadPos + "\n4", () => LoadAction(4), (button) => buttons["Load_4"] = button.transform);
menu.AddSpacer();
menu.AddSimpleButton("Discord", () => OpenWebpage("https://discord.gg/7EQCmgrUnH"));
menu.AddSimpleButton("GitHub", () => OpenWebpage(BuildInfo.DownloadLink));
menu.AddSpacer();
Main.Log("Finished creating UIXMenus", Main.IsDebug);
}
internal static void ToggleVRTeleport(bool state) {
if (CheckWorldAllowed.RiskyFunctionAllowed) {
VRUtils.active = state;
TPLocationIndicator.Toggle();
//CustomToggle.UpdateToggleState();
}
}
static string text(string buttonName, string text) {
if (buttons[buttonName] != null)
return buttons[buttonName].GetComponentInChildren<Text>().text = text;
return null;
}
internal static void UpdateWorldStatusText() {
try {
text("WorldStatus", $"World\n{(CheckWorldAllowed.RiskyFunctionAllowed ? color("#00ff00", "Allowed") : color("red", "Disallowed"))}");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
}
public static void UpdateText() {
if (menu == null) return;
try {
if (permbuttons["TPActive_1"] != null)
permbuttons["TPActive_1"].GetComponentInChildren<Text>().text = VRUtils.active ? Language.theWord_Teleport + color("#00ff00", "\nON") :
Language.theWord_Teleport + color("red", "\nOFF");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("TPActive_2", VRUtils.active ? Language.theWord_Teleport + color("#00ff00", "\nON") : Language.theWord_Teleport + color("red", "\nOFF"));
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("KeyboardTP", Language.TPtoName_Text);
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("CoordTP", Language.TPtoCoord_Text);
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("preferRightHand", Main.PreferRightHand.Value ? Language.preferedHanded_Text_ON : Language.preferedHanded_Text_OFF);
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("Save_1", Language.SavePos + "\n1");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("Save_2", Language.SavePos + "\n2");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("Save_3", Language.SavePos + "\n3");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("Save_4", Language.SavePos + "\n4");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("Load_1", Language.LoadPos + "\n1");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("Load_2", Language.LoadPos + "\n2");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("Load_3", Language.LoadPos + "\n3");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
try {
text("Load_4", Language.LoadPos + "\n4");
} catch (Exception e) { Main.Logger.Error($"{e}"); }
}
}
}
*/