-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMenuPatch.cs
122 lines (106 loc) · 4.03 KB
/
MenuPatch.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
using HarmonyLib;
using Kitchen;
using Kitchen.Modules;
using KitchenData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace PlateupPrepGhost
{
[HarmonyPatch(typeof(MainMenu), nameof(MainMenu.Setup))]
class MenuPatch
{
[HarmonyPrefix]
public static void Setup_AddPrepGhostMenu(MainMenu __instance)
{
MethodInfo m_addButtonMenu = GetMethod(__instance.GetType(), "AddSubmenuButton");
m_addButtonMenu.Invoke(__instance, new object[3] { "PrepGhost", typeof(PrepGhostOptionsMenu), false });
}
public static MethodInfo GetMethod(Type _typeOfOriginal, string _name, Type _genericT = null)
{
MethodInfo retVal = _typeOfOriginal.GetMethod(_name, BindingFlags.NonPublic | BindingFlags.Instance);
if (_genericT != null)
{
retVal = retVal.MakeGenericMethod(_genericT);
}
return retVal;
}
}
[HarmonyPatch(typeof(PlayerPauseView), "SetupMenus")]
class PausePatch
{
[HarmonyPrefix]
public static void SetupMenus_AddPrepGhostMenu(PlayerPauseView __instance)
{
ModuleList moduleList = (ModuleList)__instance.GetType().GetField("ModuleList", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
MethodInfo mInfo = MenuPatch.GetMethod(__instance.GetType(), "AddMenu");
mInfo.Invoke(__instance, new object[2] { typeof(PrepGhostOptionsMenu), new PrepGhostOptionsMenu(__instance.ButtonContainer, moduleList) });
}
}
class PrepGhostOptionsMenu : Menu<PauseMenuAction>
{
public Option<bool> EnableOption;
// Default player set while ghost mode is activated
public Option<float> SpeedOption;
public PrepGhostOptionsMenu(Transform container, ModuleList module_list) : base(container, module_list) {}
public override void Setup(int player_id)
{
EnableOption = GetEnableOption();
this.AddLabel("Ghost Mode");
Add(EnableOption);
SpeedOption = GetSpeedOption();
this.AddLabel("Ghost Speed");
Add(SpeedOption);
AddButton(Localisation["MENU_BACK_SETTINGS"], (Action<int>)(i => RequestPreviousMenu()));
}
private Option<bool> GetEnableOption()
{
List<bool> enableOptions = new List<bool>
{
false, true
};
bool current = GhostPatch.GhostModeActivated;
List<string> localizationOptions = new List<string>
{
this.Localisation["SETTING_DISABLED"],
this.Localisation["SETTING_ENABLED"]
};
Option<bool> enableOption = new Option<bool>(enableOptions, current, localizationOptions, null);
enableOption.OnChanged += delegate (object _, bool value)
{
GhostPatch.GhostModeActivated = value;
GhostPatch.GhostModeSetByMenu = true;
GhostPatch.GhostSpeedSet = false;
};
return enableOption;
}
private Option<float> GetSpeedOption()
{
List<float> speedOptions = new List<float>()
{
1f
};
List<string> localization = new List<string>
{
this.Localisation["SETTING_DISABLED"]
};
for (float i = 1.5f; i <= 10f; i += 0.5f)
{
speedOptions.Add(i);
localization.Add(i + "");
}
float current = GhostPatch.GhostSpeed;
Option<float> speedOption = new Option<float>(speedOptions, current, localization, null);
speedOption.OnChanged += delegate (object _, float value)
{
GhostPatch.GhostSpeed = value;
GhostPatch.GhostSpeedSet = false;
};
return speedOption;
}
}
}