-
Notifications
You must be signed in to change notification settings - Fork 0
/
SacrificeHelperUI.cs
188 lines (163 loc) · 6.72 KB
/
SacrificeHelperUI.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
using System;
using System.Collections.Generic;
using System.Linq;
using Il2CppAssets.Scripts.Models.Towers;
using Il2CppAssets.Scripts.Unity.Bridge;
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 BTD_Mod_Helper;
using BTD_Mod_Helper.Api.Components;
using BTD_Mod_Helper.Api.Enums;
using BTD_Mod_Helper.Extensions;
using Il2CppTMPro;
using MelonLoader;
using UnityEngine;
using static BTD_Mod_Helper.Api.Enums.UpgradeType;
using static BTD_Mod_Helper.Api.Enums.VanillaSprites;
namespace SacrificeHelper;
[RegisterTypeInIl2Cpp(false)]
public class SacrificeHelperUI : MonoBehaviour
{
public const int InfoWidth = 500;
public const int InfoHeight = 100;
private static bool showingExtraParagonInfo;
public TowerSelectionMenu menu;
private ModHelperPanel paragonStuff;
private ModHelperButton degreeButton;
private ModHelperText degreeText;
private ModHelperPanel extraParagonInfo;
private Il2CppSystem.Collections.Generic.List<ModHelperText> paragonDetails;
private ModHelperPanel templeStuff;
private ModHelperButton sacrificeToggle;
private ModHelperPanel extraSacrificeInfo;
private Il2CppSystem.Collections.Generic.List<ModHelperText> sacrificeTowerSets;
public SacrificeHelperUI(IntPtr ptr) : base(ptr)
{
}
public void Initialise(TowerSelectionMenu towerSelectionMenu)
{
menu = towerSelectionMenu;
CreateParagonStuff();
CreateTempleStuff();
}
private void CreateParagonStuff()
{
paragonStuff = gameObject.AddModHelperPanel(new Info("ParagonStuff", InfoPreset.FillParent));
degreeButton = paragonStuff.AddButton(new Info("ParagonButton", 375, -75, 135),
UpgradeContainerParagon, new Action(() =>
{
showingExtraParagonInfo = !showingExtraParagonInfo;
UpdateExtraInfo();
}));
degreeText = degreeButton.AddText(new Info("DegreeText", InfoPreset.FillParent), "0", 60);
extraParagonInfo = paragonStuff.AddPanel(new Info("ExtraParagonInfo", 50, -50, InfoWidth)
{
PivotY = 1
}, null, RectTransform.Axis.Vertical);
paragonDetails = ParagonDetail.CreateTexts(extraParagonInfo).ToIl2CppList();
}
private void CreateTempleStuff()
{
templeStuff = gameObject.AddModHelperPanel(new Info("TempleStuff", InfoPreset.FillParent));
sacrificeToggle = templeStuff.AddButton(new Info("TempleButton", 375, -75, 120),
NotificationYellow, new Action(() =>
{
SacrificeHelperMod.templeSacrificesOff = !SacrificeHelperMod.templeSacrificesOff;
UpdateUpgradeCosts();
UpdateExtraInfo();
}));
sacrificeToggle.AddImage(new Info("SacrificeIcon", 80), BuffIconBloodSacrifice);
extraSacrificeInfo = templeStuff.AddPanel(new Info("ExtraSacrificeInfo", 50, -50, InfoWidth)
{
PivotY = 1
}, null, RectTransform.Axis.Vertical);
var modHelperTexts = TowerSetType.All.ToList()
.Select(s => CreateInfoLine(extraSacrificeInfo, s, $"MainMenuUiAtlas[{s}Btn]"));
sacrificeTowerSets = modHelperTexts.ToIl2CppList();
}
public void TowerInfoChanged()
{
var tower = menu.selectedTower;
if (tower == null)
{
ModHelper.Warning<SacrificeHelperMod>("Couldn't update Paragon Helper UI because tower was null");
return;
}
UpdateParagonStuff(tower);
UpdateTempleStuff(tower);
UpdateExtraInfo();
}
private void UpdateParagonStuff(TowerToSimulation tower)
{
var canUpgradeToParagon = tower.CanUpgradeToParagon(true);
paragonStuff.SetActive(canUpgradeToParagon);
if (canUpgradeToParagon)
{
var degree = Utils.GetParagonDegree(tower, out var investmentInfo);
degreeText.SetText($"{degree}");
degreeText.Text.color = degree >= 100 ? Color.green : Color.white;
var details = paragonDetails.ToList();
for (var i = 0; i < ParagonDetail.AllDetails.Count; i++)
{
ParagonDetail.AllDetails[i].Update(details[i], investmentInfo);
}
}
}
private void UpdateTempleStuff(TowerToSimulation tower)
{
var canUpgradeToTemple = tower.Def.upgrades?.Any(model => model.upgrade == SunTemple) == true;
var canUpgradeToGod = tower.Def.upgrades?.Any(model => model.upgrade == TrueSunGod) == true;
templeStuff.SetActive(canUpgradeToTemple || canUpgradeToGod);
if (canUpgradeToTemple || canUpgradeToGod)
{
var worths = Utils.GetTowerWorths(tower.tower);
var colors = Utils.GetColors(worths, canUpgradeToGod);
var towerSets = TowerSetType.All.ToList();
var details = sacrificeTowerSets.ToList();
for (var i = 0; i < details.Count; i++)
{
var towerSet = towerSets[i];
var detail = details[i];
detail.SetText($"${worths[towerSet]:N0}");
detail.Text.color = colors[towerSet];
}
}
}
private void UpdateExtraInfo()
{
extraParagonInfo.SetActive(showingExtraParagonInfo);
extraSacrificeInfo.SetActive(!SacrificeHelperMod.templeSacrificesOff);
sacrificeToggle.Image.SetSprite(SacrificeHelperMod.templeSacrificesOff ? NotificationRed : NotificationYellow);
}
private void UpdateUpgradeCosts()
{
var gameModel = InGame.instance.GetGameModel();
var templeUpgrade = gameModel.GetUpgrade(SunTemple);
var godUpgrade = gameModel.GetUpgrade(TrueSunGod);
if (SacrificeHelperMod.templeSacrificesOff)
{
Utils.ModifyTemple(templeUpgrade);
Utils.ModifyGod(godUpgrade);
}
else
{
Utils.DefaultTemple(templeUpgrade);
Utils.DefaultGod(godUpgrade);
}
for (var i = 0; i < menu.upgradeButtons.Count; i++)
{
var upgradeButton = menu.upgradeButtons[i];
upgradeButton.UpdateCost();
upgradeButton.UpdateVisuals(i, false);
}
}
private static ModHelperText CreateInfoLine(ModHelperPanel parent, string id, string icon)
{
var panel = parent.AddPanel(new Info(id, InfoWidth, InfoHeight), null, RectTransform.Axis.Horizontal, 25);
panel.AddImage(new Info("Icon", InfoHeight), icon);
var text = panel.AddText(new Info("Amount", InfoWidth - InfoHeight - 50, InfoHeight), "", 69);
text.Text.alignment = TextAlignmentOptions.MidlineLeft;
return text;
}
}