This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuPatches.cs
241 lines (222 loc) · 12.9 KB
/
MenuPatches.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
using HarmonyLib;
using I2.Loc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using static LoddleAI;
namespace ExtraTrackers
{
[HarmonyPatch(typeof(BiomeManagementMenu))]
public static class BiomeManagementMenu_Patch
{
public static TextMeshProUGUI currentBiomeTextMesh;
public static Vector2 nativeFoodGroupOrigPos;
public static Vector2 nativeFoodGroupOffset = new Vector2(0.0f, 110.0f);
public static Vector2 populationGroupOffset = new Vector2(0.0f, 15.0f);
public static GridLayoutGroup loddleListLayoutGroup;
public static List<TextMeshProUGUI> loddleListLabels = new List<TextMeshProUGUI>();
public static void UpdateBiomeMenuInfoForNonBiome(BiomeManagementMenu __instance, bool playChangeAnimation = false)
{
// Updates the modified "Global Progress" window on the biome management menu.
SwitchToNonBiomeLayout(__instance);
if (playChangeAnimation)
{
__instance.PlayLayoutSwapAnimation();
}
BiomeManager biomeManager = ExtraTrackersMod.nonBiomeManager;
// Update the global cleaned progress
currentBiomeTextMesh.text = "Global Progress";
float globalPollutionAmount = ExtraTrackersMod.GetGlobalPollutionAmount();
//ExtraTrackersMod.log.LogInfo(globalPollutionAmount);
//ExtraTrackersMod.log.LogInfo(Mathf.FloorToInt((1f - globalPollutionAmount) * 100f).ToString());
__instance.cleanText.text = ScriptLocalization.Biome_Menu.Clean_Amount.Replace("{PERCENT}", Mathf.FloorToInt((1f - globalPollutionAmount) * 100f).ToString());
int pollutionStage = (int)Mathf.Ceil(globalPollutionAmount * (__instance.biomeHealthColors.Count() - 1));
__instance.cleanText.color = __instance.biomeHealthColors[pollutionStage];
// Update the goop numbers
__instance.litterAmountText.text = (Mathf.Max(biomeManager.GetNumberOfLitterObjects(), 0).ToString() ?? "");
__instance.goopAmountText.text = (Mathf.Max(biomeManager.GetNumberOfGoopNodes(), 0).ToString() ?? "");
__instance.microplasticsAmountText.text = (Mathf.Max(biomeManager.GetMicroplasticsValue(), 0).ToString() ?? "");
__instance.inhabitantsText.text = ExtraTrackersMod.GetGoopyLoddlesCount().ToString();
// Update the encountered loddle types
UpdateLoddleListLabels();
}
public static void SwitchToNonBiomeLayout(BiomeManagementMenu __instance)
{
CanvasGroup populationCanvasGroup = GetPopulationCanvasGroup(__instance);
// Set the size to the standard biome info size
__instance.parentTransform.sizeDelta = __instance.defaultDimensions;
__instance.currentBiomeTextTransform.anchoredPosition = __instance.defaultTitleTextPosition;
__instance.cleanText.enabled = true;
__instance.contaminantsGroup.alpha = 1f;
__instance.nativeFruitGroup.alpha = 1f;
populationCanvasGroup.alpha = 1f;
// Update the text and positioning of categories
__instance.contaminantsGroup.gameObject.GetComponent<TextMeshProUGUI>().text = "Non-Biome";
populationCanvasGroup.gameObject.GetComponent<TextMeshProUGUI>().text = "Misc";
__instance.nativeFruitGroup.gameObject.GetComponent<TextMeshProUGUI>().text = "Loddles";
loddleListLayoutGroup.gameObject.SetActive(true);
__instance.nativeFruitGroup.transform.Find("Native Fruit Arranger").gameObject.SetActive(false);
populationCanvasGroup.transform.Find("Inhabitants Label").gameObject.GetComponent<TextMeshProUGUI>().text = "Goopy Loddles";
populationCanvasGroup.transform.Find("Eggs Label").gameObject.SetActive(false);
populationCanvasGroup.transform.Find("Eggs Amount").gameObject.SetActive(false);
populationCanvasGroup.transform.Find("Cocoons Label").gameObject.SetActive(false);
populationCanvasGroup.transform.Find("Cocoons Amount").gameObject.SetActive(false);
__instance.nativeFruitGroup.GetComponent<RectTransform>().anchoredPosition = nativeFoodGroupOrigPos + nativeFoodGroupOffset;
__instance.populationGroupTransform.anchoredPosition = __instance.defaultPopulationGroupPosition + populationGroupOffset;
}
public static CanvasGroup GetPopulationCanvasGroup(BiomeManagementMenu __instance)
{
return __instance.populationGroupTransform.gameObject.GetComponent<CanvasGroup>();
}
[HarmonyPatch(nameof(BiomeManagementMenu.Awake))]
[HarmonyPostfix]
public static void Awake_Postfix(BiomeManagementMenu __instance)
{
currentBiomeTextMesh = __instance.currentBiomeText.gameObject.GetComponent<TextMeshProUGUI>();
nativeFoodGroupOrigPos = __instance.nativeFruitGroup.gameObject.GetComponent<RectTransform>().anchoredPosition;
InitializeLoddleListLayoutGroup(__instance);
}
[HarmonyPatch(nameof(BiomeManagementMenu.InitializeBiomeMenu))]
[HarmonyPostfix]
public static void InitializeBiomeMenu_Postfix(BiomeManagementMenu __instance)
{
if (!__instance.isInHomeCove && __instance.currentBiome == null)
{
UpdateBiomeMenuInfoForNonBiome(__instance);
}
}
[HarmonyPatch(nameof(BiomeManagementMenu.SwitchToBiomeLayout))]
[HarmonyPostfix]
public static void SwitchToBiomeLayout_Postfix(BiomeManagementMenu __instance)
{
ResetBiomeInfo(__instance, false);
}
[HarmonyPatch(nameof(BiomeManagementMenu.SwitchToHomeCoveLayout))]
[HarmonyPostfix]
public static void SwitchToHomeCoveLayout_Postfix(BiomeManagementMenu __instance)
{
ResetBiomeInfo(__instance, true);
}
public static void ResetBiomeInfo(BiomeManagementMenu __instance, bool homecove)
{
CanvasGroup populationCanvasGroup = GetPopulationCanvasGroup(__instance);
populationCanvasGroup.alpha = 1f;
__instance.contaminantsGroup.gameObject.GetComponent<Localize>().OnLocalize(true);
populationCanvasGroup.gameObject.GetComponent<Localize>().OnLocalize(true);
__instance.nativeFruitGroup.gameObject.GetComponent<Localize>().OnLocalize(true);
__instance.nativeFruitGroup.transform.Find("Native Fruit Arranger").gameObject.SetActive(true);
populationCanvasGroup.transform.Find("Inhabitants Label").gameObject.GetComponent<Localize>().OnLocalize(true);
populationCanvasGroup.transform.Find("Eggs Label").gameObject.SetActive(true);
populationCanvasGroup.transform.Find("Eggs Amount").gameObject.SetActive(true);
populationCanvasGroup.transform.Find("Cocoons Label").gameObject.SetActive(true);
populationCanvasGroup.transform.Find("Cocoons Amount").gameObject.SetActive(true);
loddleListLayoutGroup.gameObject.SetActive(false);
__instance.nativeFruitGroup.GetComponent<RectTransform>().anchoredPosition = nativeFoodGroupOrigPos;
__instance.populationGroupTransform.anchoredPosition = homecove ? __instance.homeCovePopulationGroupPosition : __instance.defaultPopulationGroupPosition;
}
public static void InitializeLoddleListLayoutGroup(BiomeManagementMenu __instance)
{
// This mod adds a GridLayoutGroup to display the encountered loddle types.
loddleListLabels = new List<TextMeshProUGUI>(); // Reset in case of save/load
GameObject go = new GameObject();
go.name = "Loddle List Grid";
go.transform.parent = __instance.nativeFruitGroup.transform;
go.AddComponent<RectTransform>();
go.GetComponent<RectTransform>().anchoredPosition = __instance.nativeFruitGroup.transform.Find("Native Fruit Arranger").GetComponent<RectTransform>().anchoredPosition;
go.GetComponent<RectTransform>().sizeDelta = __instance.nativeFruitGroup.transform.Find("Native Fruit Arranger").GetComponent<RectTransform>().sizeDelta;
go.AddComponent<GridLayoutGroup>();
// Set the properties of the GridLayoutGroup
loddleListLayoutGroup = go.GetComponent<GridLayoutGroup>();
loddleListLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
loddleListLayoutGroup.constraintCount = 3;
loddleListLayoutGroup.childAlignment = TextAnchor.MiddleCenter;
loddleListLayoutGroup.cellSize = new Vector2(100f, 30f);
go.transform.position = __instance.nativeFruitGroup.transform.position;
go.transform.localScale = new Vector3(1f, 1f, 1f);
go.GetComponent<RectTransform>().anchoredPosition += new Vector2(0f, -100f);
// Create a label with similar properties to the other labels on this screen, to copy for each loddle type
GameObject prototypeLabel = GameObject.Instantiate(__instance.contaminantsGroup.transform.Find("Litter Amount Label").gameObject);
prototypeLabel.name = "Loddle Type Label";
prototypeLabel.GetComponent<TextMeshProUGUI>().enableAutoSizing = false;
prototypeLabel.GetComponent<TextMeshProUGUI>().alignment = TextAlignmentOptions.Center;
prototypeLabel.GetComponent<TextMeshProUGUI>().fontSize = 18f;
prototypeLabel.GetComponent<TextMeshProUGUI>().text = "";
GameObject.Destroy(prototypeLabel.GetComponent<Localize>());
for (int i = 0; i < (int)Mathf.Ceil(ExtraTrackersMod.typeRemarkMapping.Count / 3f)*3; i++)
{
GameObject label = GameObject.Instantiate(prototypeLabel, loddleListLayoutGroup.transform);
loddleListLabels.Add(label.GetComponent<TextMeshProUGUI>());
}
GameObject.Destroy(prototypeLabel);
}
public static void UpdateLoddleListLabels()
{
List<LoddleAI.LoddleType> encounteredLoddleTypes = ExtraTrackersMod.GetEncounteredLoddleTypes();
List<string> loddleStrings = new List<string>();
foreach (LoddleAI.LoddleType loddleType in encounteredLoddleTypes)
{
loddleStrings.Add(ExtraTrackersMod.typeStringMapping[loddleType]);
}
loddleStrings.Sort();
foreach (TextMeshProUGUI tm in loddleListLabels)
{
tm.text = "";
}
for (int i = 0; i < loddleStrings.Count; i++)
{
loddleListLabels[i].text = loddleStrings[i];
// Make the last entry centered
if (i == 12)
{
loddleListLabels[12].text = "";
loddleListLabels[13].text = loddleStrings[12];
}
}
}
}
[HarmonyPatch(typeof(CentralGameMenu))]
public static class CentralGameMenu_Patch
{
[HarmonyPatch(nameof(CentralGameMenu.OpenWorldMapTab))]
[HarmonyPostfix]
public static void OpenWorldMapTab_Postfix(CentralGameMenu __instance)
{
__instance.OpenBiomeMenu(true);
}
[HarmonyPatch(nameof(CentralGameMenu.CloseBiomeMenu))]
[HarmonyPrefix]
public static bool CloseBiomeMenu_Prefix(CentralGameMenu __instance, bool instant = false, bool forceClose = false)
{
// Hook into the method to close the individual biome menu, to display the global progress instead of closing the menu.
__instance.ClearPrimedBiome(CentralGameMenu.WorldLocation.NONE, true);
BiomeManagementMenu_Patch.UpdateBiomeMenuInfoForNonBiome(__instance.biomeMenu, __instance.currentBiomeMenuLocation == CentralGameMenu.WorldLocation.NONE);
__instance.ClearPrimedBiome(CentralGameMenu.WorldLocation.NONE, true);
__instance.OpenBiomeMenu(true);
return false;
}
}
[HarmonyPatch(typeof(MainMenu))]
public static class MainMenu_Patch
{
[HarmonyPatch(nameof(MainMenu.Start))]
[HarmonyPostfix]
public static void MainMenuStart_Postfix(MainMenu __instance)
{
// Add a mod version label on the title screen
GameObject versionLabelObject = UnityEngine.GameObject.Find("Version Text");
TextMeshProUGUI versionLabel = versionLabelObject.GetComponent<TextMeshProUGUI>();
string version = versionLabel.text;
versionLabel.text = $"{version}\n{ExtraTrackersPlugin.pluginName} v{ExtraTrackersPlugin.versionString}";
versionLabel.alignment = TextAlignmentOptions.BottomRight;
ExtraTrackersMod.nonBiomeIsComplete = false;
ExtraTrackersMod.allHoloBadgesFound = false;
ExtraTrackersMod.allLoddleTypesFound = false;
ExtraTrackersMod.allGoopyLoddlesCleaned = false;
}
}
}