Skip to content

Commit

Permalink
Fix custom hints
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Dec 16, 2023
1 parent cf2fb67 commit 5c139c4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
28 changes: 7 additions & 21 deletions BloonsTD6 Mod Helper/Api/Bloons/ModRoundSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ public abstract class ModRoundSet : NamedModContent
/// <summary>
/// Whether these rounds should have custom hints, like Alternate Bloons Rounds does
/// </summary>
[Obsolete("No longer needs to be specified, just use return non null from GetHint")]
public virtual bool CustomHints => false;

/// <summary>
/// Whether to bypass the base game hints settings. Useful for using your own ModSetting to control hints.
/// </summary>
public virtual bool AlwaysShowHints => false;

/// <inheritdoc />
public override void Register()
{
Expand Down Expand Up @@ -121,24 +127,6 @@ public override void Register()

}

/// <inheritdoc />
public override void RegisterText(Il2CppSystem.Collections.Generic.Dictionary<string, string> textTable)
{
base.RegisterText(textTable);

if (CustomHints)
{
for (var round = 0; round < DefinedRounds; round++)
{
var hint = GetHint(round);
if (hint != null)
{
textTable.Add(HintKey(round), hint);
}
}
}
}

/// <summary>
/// Called to modify any/all rounds from 1 to <see cref="DefinedRounds" />
/// </summary>
Expand Down Expand Up @@ -175,7 +163,7 @@ public virtual void ModifyImpoppableRoundModels(RoundModel roundModel, int round
}

/// <summary>
/// Gets the custom hint for a specific round. Make sure <see cref="CustomHints" /> is overriden as true.
/// Gets the custom hint for a specific round. This will be shown at the <b>end</b> of that round.
/// <br />
/// For no hint, return null.
/// </summary>
Expand All @@ -190,8 +178,6 @@ public virtual void ModifyGameModel(GameModel gameModel)

}

internal string HintKey(int round) => $"{Id} Hint {round}";

internal RoundSetModel GetDefaultRoundSetModel()
{
var roundSetModel = new RoundSetModel(Id, new Il2CppReferenceArray<RoundModel>(DefinedRounds), "");
Expand Down
9 changes: 1 addition & 8 deletions BloonsTD6 Mod Helper/LATEST.md
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
- Preliminary fixes for v40.0 (thanks @KosmicShovel!)
- Updates for v40.0 UpgradeTypes, VanillaSprites, etc
- The `TopPathUpgrades`, `MiddlePathUpgrades` and `BottomPathUpgrades` properties no longer need to be manually specified for `ModTower`s, they will be inferred
- Same goes for `MaxLevel` in `ModHero`
- Added a `Model.RemoveBehaviors()` extension (no type argument) that simply clears all behaviors
- Fixed a possible visual error with ModSettingFile and ModSettingFolder
- Let a number of api methods use params arguments
- Added GetBloonDisplay method to ModDisplay.cs (thanks @DarkTerraYT!)
- Fixed hints for custom round sets
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using BTD_Mod_Helper.Api.Bloons;
using Il2CppAssets.Scripts.Unity;
using Il2CppAssets.Scripts.Unity.UI_New.InGame;
namespace BTD_Mod_Helper.Patches;

[HarmonyPatch(typeof(InGame), nameof(InGame.CheckAndShowHintMessage))]
internal static class InGame_CheckAndShowHintMessage
{
[HarmonyPrefix]
private static bool Prefix(InGame __instance)
{
if (!ModRoundSet.Cache.TryGetValue(__instance.GetGameModel().roundSet.name, out var modRoundSet)) return true;

if ((modRoundSet.AlwaysShowHints || Game.Player.Data.inGameSettings.gameHints) &&
modRoundSet.GetHint(__instance.UnityToSimulation.GetCurrentRound() + 1) is string hint)
{
__instance.roundHintTxt.SetText(hint);
__instance.roundHintAnimator.SetIntegerString("AnimIndex", 1);
__instance.roundHintTimer = __instance.roundHintAutoHideTime;
}

return false;
}
}

0 comments on commit 5c139c4

Please sign in to comment.