PVZFusionTranslation/MelonLoader/Patches/BaseTextObjects/InGameText_Patch.cs
2025-11-16 00:43:59 -05:00

43 lines
No EOL
1.2 KiB
C#

using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using PvZ_Fusion_Translator.Patches.Managers;
namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
{
[HarmonyPatch(typeof(InGameText))]
public static class InGameText_Patch
{
[HarmonyPatch(nameof(InGameText.ShowText), new Type[] { typeof(string), typeof(float), typeof(bool) })]
[HarmonyPrefix]
private static void ShowText(InGameText __instance, ref string text) => text = StringStore.TranslateText(text, true);
[HarmonyPatch(nameof(InGameText.ShowText), new Type[] { typeof(string), typeof(float), typeof(bool) })]
[HarmonyPostfix]
private static void ShowText(InGameText __instance)
{
#if MULTI_LANGUAGE
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
#else
TMP_FontAsset fontAsset = FontStore.LoadTMPFont();
#endif
foreach (TextMeshProUGUI txt in __instance.textMeshes)
{
string travelMatch = TravelMgr_Patch.MatchTravelBuff(txt.text);
if(travelMatch != "")
{
txt.text = travelMatch;
}
else
{
txt.text = StringStore.TranslateText(txt.text, true);
}
txt.font = fontAsset;
}
}
}
}