Skip to content

Commit

Permalink
Fix Paragon cost inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Jul 31, 2023
1 parent 557edf1 commit b72659f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion LATEST.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Fixed for BTD6 v36
- Fixed Paragon costs getting included for Temple Sacrifice UI
4 changes: 2 additions & 2 deletions ModHelperData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public static class ModHelperData
{
public const string WorksOnVersion = "36.0";
public const string Version = "2.3.3";
public const string WorksOnVersion = "38.1";
public const string Version = "2.3.4";
public const string Name = "Sacrifice Helper";

public const string Description =
Expand Down
32 changes: 24 additions & 8 deletions SacrificeHelperMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
using BTD_Mod_Helper.Api.Components;
using BTD_Mod_Helper.Api.Enums;
using BTD_Mod_Helper.Api.ModOptions;
using BTD_Mod_Helper.Extensions;
using HarmonyLib;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu.TowerSelectionMenuThemes;
using MelonLoader;
using SacrificeHelper;

Expand Down Expand Up @@ -164,20 +167,33 @@ private static void Postfix(TowerSelectionMenu __instance)
{
var themeManager = __instance.themeManager;
var currentTheme = themeManager.CurrentTheme;
if (currentTheme == null)

if (currentTheme == null) return;

var ui = currentTheme.GetComponent<SacrificeHelperUI>();
if (ui != null)
{
TaskScheduler.ScheduleTask(() => Postfix(__instance), () => themeManager.CurrentTheme != null);
return;
ui.TowerInfoChanged();
}
}
}


[HarmonyPatch(typeof(MenuThemeManager), nameof(MenuThemeManager.SetTheme))]
internal static class MenuThemeManager_SetTheme
{
[HarmonyPostfix]
private static void Postfix(MenuThemeManager __instance, BaseTSMTheme newTheme)
{
if (!__instance.selectionMenu.Is(out TowerSelectionMenu menu)) return;

var ui = currentTheme.GetComponent<SacrificeHelperUI>();
var ui = newTheme.GetComponent<SacrificeHelperUI>();
if (ui == null)
{
ui = currentTheme.gameObject.AddComponent<SacrificeHelperUI>();
ui.Initialise(themeManager);
ui = newTheme.gameObject.AddComponent<SacrificeHelperUI>();
ui.Initialise(menu);
ui.TowerInfoChanged();
}

ui.TowerInfoChanged();
}
}
}
33 changes: 14 additions & 19 deletions SacrificeHelperUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SacrificeHelperUI : MonoBehaviour

private static bool showingExtraParagonInfo;

public TowerSelectionMenuThemeManager manager;
public TowerSelectionMenu menu;

private ModHelperPanel paragonStuff;
private ModHelperButton degreeButton;
Expand All @@ -43,9 +43,9 @@ public SacrificeHelperUI(IntPtr ptr) : base(ptr)
{
}

public void Initialise(TowerSelectionMenuThemeManager themeManager)
public void Initialise(TowerSelectionMenu towerSelectionMenu)
{
manager = themeManager;
menu = towerSelectionMenu;

CreateParagonStuff();
CreateTempleStuff();
Expand All @@ -54,7 +54,7 @@ public void Initialise(TowerSelectionMenuThemeManager themeManager)
private void CreateParagonStuff()
{
paragonStuff = gameObject.AddModHelperPanel(new Info("ParagonStuff", InfoPreset.FillParent));
degreeButton = paragonStuff.AddButton(new Info("ParagonButton", 340, -100, 130),
degreeButton = paragonStuff.AddButton(new Info("ParagonButton", 375, -75, 135),
UpgradeContainerParagon, new Action(() =>
{
showingExtraParagonInfo = !showingExtraParagonInfo;
Expand All @@ -73,14 +73,14 @@ private void CreateParagonStuff()
private void CreateTempleStuff()
{
templeStuff = gameObject.AddModHelperPanel(new Info("TempleStuff", InfoPreset.FillParent));
sacrificeToggle = templeStuff.AddButton(new Info("TempleButton", 340, -100, 130),
sacrificeToggle = templeStuff.AddButton(new Info("TempleButton", 375, -75, 120),
NotificationYellow, new Action(() =>
{
SacrificeHelperMod.templeSacrificesOff = !SacrificeHelperMod.templeSacrificesOff;
UpdateUpgradeCosts();
UpdateExtraInfo();
}));
sacrificeToggle.AddImage(new Info("SacrificeIcon", 90), BuffIconBloodSacrifice);
sacrificeToggle.AddImage(new Info("SacrificeIcon", 80), BuffIconBloodSacrifice);

extraSacrificeInfo = templeStuff.AddPanel(new Info("ExtraSacrificeInfo", 50, -50, InfoWidth)
{
Expand All @@ -93,19 +93,16 @@ private void CreateTempleStuff()

public void TowerInfoChanged()
{
if (manager.selectionMenu.Is(out TowerSelectionMenu menu))
var tower = menu.selectedTower;
if (tower == null)
{
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();
ModHelper.Warning<SacrificeHelperMod>("Couldn't update Paragon Helper UI because tower was null");
return;
}

UpdateParagonStuff(tower);
UpdateTempleStuff(tower);
UpdateExtraInfo();
}

private void UpdateParagonStuff(TowerToSimulation tower)
Expand Down Expand Up @@ -158,8 +155,6 @@ private void UpdateExtraInfo()

private void UpdateUpgradeCosts()
{
if (!manager.selectionMenu.Is(out TowerSelectionMenu menu)) return;

var gameModel = InGame.instance.GetGameModel();
var templeUpgrade = gameModel.GetUpgrade(SunTemple);
var godUpgrade = gameModel.GetUpgrade(TrueSunGod);
Expand Down
1 change: 1 addition & 0 deletions Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static Dictionary<string, Color> GetColors(Dictionary<string, float> wort
public static bool IsValidTower(Tower tower) => !tower.towerModel.isPowerTower &&
!tower.towerModel.isGeraldoItem &&
!tower.towerModel.IsBeastHandlerPet &&
!tower.towerModel.isParagon &&
tower.towerModel.baseId != "TempleBase-TempleBase";

public static Dictionary<string, float> GetTowerWorths(Tower tower) =>
Expand Down

0 comments on commit b72659f

Please sign in to comment.