-
Notifications
You must be signed in to change notification settings - Fork 3
/
BonnieUI.cs
234 lines (201 loc) · 8.4 KB
/
BonnieUI.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
using System;
using System.Collections;
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Api.Components;
using BTD_Mod_Helper.Api.Enums;
using BTD_Mod_Helper.Api.Helpers;
using BTD_Mod_Helper.Extensions;
using HarmonyLib;
using Il2CppAssets.Scripts.Models.ServerEvents;
using Il2CppAssets.Scripts.Simulation.Towers.Behaviors;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu;
using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu.TowerSelectionMenuThemes;
using Il2CppInterop.Runtime.Attributes;
using MelonLoader;
using UnityEngine;
namespace BonnieHeroMod;
[RegisterTypeInIl2Cpp(false)]
[HarmonyPatch]
public class BonnieUI : MonoBehaviour
{
private ModHelperPanel _bonniePanel = null!;
private ModHelperText _cartTier = null!;
private ModHelperButton _cartUpgrade = null!;
private ModHelperText upgradeText = null!;
private ModHelperButton cartSell = null!;
private ModHelperText sellText = null!;
public void SyncUI()
{
if (TowerSelectionMenu.instance.selectedTower == null ||
TowerSelectionMenu.instance.selectedTower.tower.towerModel.baseId != ModContent.TowerID<BonnieHero>() ||
TowerSelectionMenu.instance.selectedTower.tower.towerModel.tier < 2)
{
_bonniePanel.SetActive(false);
return;
}
if(!TowerSelectionMenu.instance.selectedTower.tower.GetBonnieData(out var towerLogic))
{
_bonniePanel.SetActive(false);
return;
}
_bonniePanel.SetActive(true);
var nextUpgradePrice = 0;
var cartWorth = 25f;
var mods = BonnieHeroMod.CurrentMods.ToIl2CppList();
for (int i = 0;
i < towerLogic.CurrentTier;
i++)
{
switch (i)
{
case < 5:
cartWorth += 15f;
break;
case < 10:
cartWorth += 40f;
break;
case < 15:
cartWorth += 100f;
break;
case < 20:
cartWorth += 160f;
break;
case < 25:
cartWorth += 280f;
break;
case < 30:
cartWorth += 400f;
break;
case < 35:
cartWorth += 600f;
break;
case < 40:
cartWorth += 800f;
break;
}
}
nextUpgradePrice = (towerLogic.CurrentTier + 1) switch
{
<= 5 => CostHelper.CostForDifficulty(300, mods),
<= 10 => CostHelper.CostForDifficulty(1000, mods),
<= 15 => CostHelper.CostForDifficulty(2700, mods),
<= 20 => CostHelper.CostForDifficulty(4800, mods),
<= 25 => CostHelper.CostForDifficulty(8800, mods),
<= 30 => CostHelper.CostForDifficulty(13000, mods),
<= 35 => CostHelper.CostForDifficulty(21000, mods),
<= 40 => CostHelper.CostForDifficulty(29000, mods),
_ => nextUpgradePrice
};
_cartTier.SetText("Cart tier: " + towerLogic
.CurrentTier + "\n Worth: " + cartWorth);
sellText.SetText("Sell \n(" + towerLogic.SellAmount + ")");
if (towerLogic.CurrentTier <
BonnieData.GetMaxTier(TowerSelectionMenu.instance.selectedTower.tower.towerModel.tier)) {
upgradeText.SetText("Upgrade \n(" + nextUpgradePrice + ")");
}
else
{
upgradeText.SetText("Max Tier Reached");
}
}
[HideFromIl2Cpp]
[HarmonyPatch(typeof(MenuThemeManager), nameof(MenuThemeManager.SetTheme))]
[HarmonyPostfix]
private static void MenuThemeManager_SetTheme(
MenuThemeManager __instance, BaseTSMTheme newTheme)
{
if (!__instance.selectionMenu.Is(out TowerSelectionMenu _))
return;
var bonnieUI = newTheme.gameObject.GetComponent<BonnieUI>();
if (bonnieUI == null)
newTheme.gameObject.AddComponent<BonnieUI>().Setup();
else
bonnieUI.SyncUI();
}
[HideFromIl2Cpp]
[HarmonyPatch(typeof(MenuThemeManager), nameof(MenuThemeManager.UpdateTheme))]
[HarmonyPostfix]
private static void MenuThemeManager_UpdateTheme(
MenuThemeManager __instance)
{
if (!__instance.selectionMenu.Is(out TowerSelectionMenu _))
return;
if (!__instance.currentTheme.Is(out BaseTSMTheme theme))
return;
var bonnieUI = theme.gameObject.GetComponent<BonnieUI>();
if (bonnieUI == null)
theme.gameObject.AddComponent<BonnieUI>().Setup();
else
bonnieUI.SyncUI();
}
[HideFromIl2Cpp]
[HarmonyPatch(typeof(TowerSelectionMenu), nameof(TowerSelectionMenu.TowerUpgraded))]
[HarmonyPatch(typeof(TowerSelectionMenu), nameof(TowerSelectionMenu.UpdateTower))]
[HarmonyPostfix]
private static void TowerSelectionMenu_UpdateTower(
TowerSelectionMenu __instance)
{
var themeManager = __instance.themeManager;
var currentTheme = themeManager.CurrentTheme;
if (currentTheme == null) return;
var bonnieUI = currentTheme.gameObject.GetComponent<BonnieUI>();
if (bonnieUI == null)
currentTheme.gameObject.AddComponent<BonnieUI>().Setup();
else
bonnieUI.SyncUI();
}
private void Setup()
{
_bonniePanel = gameObject.AddModHelperPanel(new Info("BonniePanel",
InfoPreset.FillParent));
_cartTier = _bonniePanel.AddText(new Info("CartTier", 220, -120, 400, 145),
"Cart tier: " +
"\n Worth: ", 40, Il2CppTMPro.TextAlignmentOptions.TopRight);
var _cartUpgrade = _bonniePanel.AddButton(new Info("CartUpgrade", -225, -580, 300, 145), VanillaSprites.GreenBtnLong,
new Action(() =>
{
if (TowerSelectionMenu.instance.selectedTower.tower.GetBonnieData(out var towerLogic) &&
towerLogic.CurrentTier < BonnieData.GetMaxTier(
TowerSelectionMenu.instance.selectedTower.tower.towerModel.tier))
{
var currentUpgradePrice = 0;
var mods = BonnieHeroMod.CurrentMods.ToIl2CppList();
// CURRENT Upgrade price switch case
currentUpgradePrice = towerLogic.CurrentTier switch
{
< 5 => CostHelper.CostForDifficulty(300, mods),
< 10 => CostHelper.CostForDifficulty(1000, mods),
< 15 => CostHelper.CostForDifficulty(2700, mods),
< 20 => CostHelper.CostForDifficulty(4800, mods),
< 25 => CostHelper.CostForDifficulty(8800, mods),
< 30 => CostHelper.CostForDifficulty(13300, mods),
< 35 => CostHelper.CostForDifficulty(21000, mods),
< 40 => CostHelper.CostForDifficulty(29000, mods),
_ => currentUpgradePrice
};
if (currentUpgradePrice < InGame.instance.GetCash())
{
InGame.instance.SetCash(InGame.instance.GetCash() - currentUpgradePrice);
towerLogic.CurrentTier++; //upgrade cart tier by 1
towerLogic.SellAmount += (float)Math.Floor(currentUpgradePrice * 0.7); //add cash to "bank"
}
TowerSelectionMenu.instance.selectedTower.tower.SetBonnieData(towerLogic);
}
SyncUI();
}));
upgradeText = _cartUpgrade.AddText(new Info("CartUpgradeText", 0, 5, 300, 145), "Upgrade \n(" + 0 + ")");
cartSell = _bonniePanel.AddButton(new Info("CartSell", 225, -580, 300, 145), VanillaSprites.RedBtnLong,
new Action(() =>
{
if (TowerSelectionMenu.instance.selectedTower.tower.GetBonnieData(out BonnieData bonnieData))
{
TowerSelectionMenu.instance.selectedTower.tower.SellCarts();
SyncUI();
}
}));
sellText = cartSell.AddText(new Info("CartSellText", 0, 5, 300, 135),
"Sell \n(" + ")", 40);
SyncUI();
}
}