diff --git a/MelonLoader/Patches/GameObjects/WarningMenu_Patch.cs b/MelonLoader/Patches/GameObjects/WarningMenu_Patch.cs new file mode 100644 index 0000000..b9b9b8b --- /dev/null +++ b/MelonLoader/Patches/GameObjects/WarningMenu_Patch.cs @@ -0,0 +1,88 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(WarningMenu))] + public static class WarningMenu_Patch + { + [HarmonyPatch(nameof(WarningMenu.Start))] + [HarmonyPostfix] + private static void Start(WarningMenu __instance) + { + TranslateInvestmentWarning(__instance); + } + + [HarmonyPatch(nameof(WarningMenu.EnableChallengeMode))] + [HarmonyPostfix] + private static void EnableChallengeMode(WarningMenu __instance) + { + TranslateInvestmentWarning(__instance); + } + + [HarmonyPatch(nameof(WarningMenu.Cancel))] + [HarmonyPostfix] + private static void Cancel(WarningMenu __instance) + { + TranslateInvestmentWarning(__instance); + } + + public static void TranslateInvestmentWarning(WarningMenu __instance) + { + Transform normalModeTransform = __instance.transform.Find("Normal"); + Transform challengeModeTransform = __instance.transform.Find("Challenge"); + + if (normalModeTransform != null) + { + TextMeshProUGUI text = normalModeTransform.Find("text").GetComponent(); + TextMeshProUGUI textShadow = normalModeTransform.Find("text (1)").GetComponent(); + + text.text = Utils.RemoveColorTags(StringStore.TranslateText(text.text)); + textShadow.text = Utils.RemoveColorTags(textShadow.text); + } + + if (challengeModeTransform != null) + { + TextMeshProUGUI text = challengeModeTransform.Find("text").GetComponent(); + TextMeshProUGUI textShadow = challengeModeTransform.Find("text (1)").GetComponent(); + + text.text = Utils.RemoveColorTags(StringStore.TranslateText(text.text)); + textShadow.text = Utils.RemoveColorTags(textShadow.text); + } + + if (__instance.tutor != null) + { + foreach (TextMeshProUGUI text in __instance.tutor.GetComponentsInChildren()) + { + if (text.gameObject.name == "text1") + { + text.text = StringStore.TranslateText(text.text); + if (text.transform.parent.Find("text").TryGetComponent(out TextMeshProUGUI textShadow)) + { + textShadow.text = Utils.RemoveColorTags(text.text); + } + } + } + } + + if (__instance.challenge != null) + { + foreach (TextMeshProUGUI text in __instance.challenge.GetComponentsInChildren()) + { + if (text.gameObject.name == "text1") + { + text.text = StringStore.TranslateText(text.text); + if (text.transform.parent.Find("text").TryGetComponent(out TextMeshProUGUI textShadow)) + { + textShadow.text = Utils.RemoveColorTags(text.text); + } + } + } + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index bc9ed8c..d79cce5 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -400,6 +400,7 @@ +