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
/
ActionMenu.cs
80 lines (70 loc) · 4.21 KB
/
ActionMenu.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
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using ActionMenuApi;
using ActionMenuApi.Api;
using ActionMenuApi.Pedals;
using TeleporterVR.Logic;
using TeleporterVR.Utils;
using MelonLoader;
namespace TeleporterVR
{
public static class ActionMenu {
private static readonly string[] AmApiOutdatedVersions = { "0.1.0" , "0.1.2", "0.2.0", "0.2.1", "0.2.2", "0.2.3", "0.3.0", "0.3.1", "0.3.2", "0.3.3", "0.3.4" };
// Tested versions to be good => 0.3.5
public static bool hasAMApiInstalled, AMApiOutdated, hasStarted;
private static PedalOption VRTP, TP2Name, TP2Coord, Save, Load;
private static PedalSubMenu subMenu;
public static void InitUi() {
if (!MelonHandler.Mods.Any(m => m.Info.Name.Equals("ActionMenuApi"))) return;
hasAMApiInstalled = true;
if (!Main.ActionMenuApiIntegration.Value) return;
if (MelonHandler.Mods.Single(m => m.Info.Name.Equals("ActionMenuApi")).Info.Version.Equals(AmApiOutdatedVersions)) {
AMApiOutdated = true;
Main.Logger.Warning("ActionMenuApi Outdated. older versions are not supported, please update the other mod.");
} else BuildActionMenu();
}
private static void BuildActionMenu() {
subMenu = VRCActionMenuPage.AddSubMenu(ActionMenuPage.Main, "<color=#13cf13>TeleporterVR</color>", () =>
{
VRTP = CustomSubMenu.AddToggle("VR " + Language.TheWordTeleport, VRUtils.Active, VRUtils.ToggleVRTeleport, ResourceManager.AMVRTP);
TP2Name = CustomSubMenu.AddButton(Language.TpToNameText, Menu.OpenKeyboardForPlayerTP, ResourceManager.AMMain);
TP2Coord = CustomSubMenu.AddButton(Language.TpToCoordText, Menu.OpenKeyboardForCoordTP, ResourceManager.AMMain);
Save = CustomSubMenu.AddSubMenu(Language.SavePos, () =>
{
CustomSubMenu.AddButton(Language.SavePos, () => Menu.SaveAction(1), ResourceManager.AMSL1);
CustomSubMenu.AddButton(Language.SavePos, () => Menu.SaveAction(2), ResourceManager.AMSL2);
CustomSubMenu.AddButton(Language.SavePos, () => Menu.SaveAction(3), ResourceManager.AMSL3);
CustomSubMenu.AddButton(Language.SavePos, () => Menu.SaveAction(4), ResourceManager.AMSL4);
}, ResourceManager.AMSave);
Load = CustomSubMenu.AddSubMenu(Language.LoadPos, () =>
{
CustomSubMenu.AddButton(Language.LoadPos, () => Menu.LoadAction(1), ResourceManager.AMSL1);
CustomSubMenu.AddButton(Language.LoadPos, () => Menu.LoadAction(2), ResourceManager.AMSL2);
CustomSubMenu.AddButton(Language.LoadPos, () => Menu.LoadAction(3), ResourceManager.AMSL3);
CustomSubMenu.AddButton(Language.LoadPos, () => Menu.LoadAction(4), ResourceManager.AMSL4);
}, ResourceManager.AMSave);
}, ResourceManager.AMMain);
subMenu.locked = true;
hasStarted = true;
if (Main.IsDebug) Main.Logger.Msg(ConsoleColor.Green, "Finished creating ActionMenu");
}
internal static IEnumerator UpdateIcon(bool ignoreWait = true) {
if (!Main.ActionMenuApiIntegration.Value) yield break;
if (!ignoreWait) yield return new WaitForSeconds(1f);
try { subMenu.icon = CheckWorldAllowed.RiskyFunctionAllowed ? ResourceManager.AMMain : ResourceManager.AMBad; }
catch { if (hasAMApiInstalled) Main.Logger.Error("Failed to change subMenu Icon"); }
try { AMUtils.RefreshActionMenu(); } catch { if (hasAMApiInstalled) Main.Logger.Error("Failed to Refresh ActionMenu"); }
}
internal static void CheckForRiskyFunctions(bool locked) {
if (!Main.ActionMenuApiIntegration.Value) return;
try { subMenu.locked = locked; }
catch { if (hasAMApiInstalled) Main.Logger.Error("ActionMenu subMenu could not be locked"); }
}
}
}