PVZFusionTranslation/MelonLoader/Patches/GameObjects/PlayerShootingMenu_Patch.cs

40 lines
No EOL
1.4 KiB
C#

using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
[HarmonyPatch(typeof(PlayerShootingMenu))]
public static class PlayerShootingMenu_Patch
{
[HarmonyPatch(nameof(PlayerShootingMenu.Update))]
[HarmonyPostfix]
private static void Update(PlayerShootingMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
[HarmonyPatch(nameof(PlayerShootingMenu.Refresh))]
[HarmonyPostfix]
private static void Refresh(PlayerShootingMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
Transform refreshTransform = __instance.transform.FindChild("Button");
foreach (TextMeshProUGUI text in refreshTransform.GetComponentsInChildren<TextMeshProUGUI>())
{
text.text = StringStore.TranslateText(text.text);
text.font = fontAsset;
text.autoSizeTextContainer = false;
}
}
}
}