diff --git a/MelonLoader/Core.cs b/MelonLoader/Core.cs index 2f82659..dbcc538 100644 --- a/MelonLoader/Core.cs +++ b/MelonLoader/Core.cs @@ -1,6 +1,8 @@ -using MelonLoader; +using Il2CppTMPro; +using MelonLoader; using MelonLoader.Utils; using PvZ_Fusion_Translator.AssetStore; +using PvZ_Fusion_Translator.Patches.Managers; using UnityEngine; [assembly: MelonInfo(typeof(PvZ_Fusion_Translator.Core), "PvZ Fusion Translator", "231.0.0", "dynaslash / arifrios1st / lancerx0 / JustNull / Dakosha / Mamoru-kun / cassidy / Teyliu", null)] @@ -71,6 +73,8 @@ namespace PvZ_Fusion_Translator { Utils.OpenTrello(); } + + TowerManager_Patch.UpdateText(); } public override void OnGUI() diff --git a/MelonLoader/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs b/MelonLoader/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs index d231998..5c5d48d 100644 --- a/MelonLoader/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs +++ b/MelonLoader/Patches/BaseTextObjects/TextMeshProUGUI_Patch.cs @@ -1,6 +1,9 @@ using HarmonyLib; +using Il2Cpp; using Il2CppTMPro; +using PvZ_Fusion_Translator.Patches.Managers; using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; using UnityEngine.UI; namespace PvZ_Fusion_Translator.Patches.BaseTextObjects @@ -20,7 +23,11 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects if (__instance.name.StartsWith("LevelName")) { __instance.text = __instance.text.Replace("\n", " "); - } + if (__instance.name == "LevelName2" || __instance.name == "LevelName3") + { + TowerManager_Patch.updatedText.Add(__instance.transform); + } + } if (__instance.transform.parent != null && __instance.transform.parent.name.StartsWith("Window")) { __instance.fontSizeMin = 10; diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index 9d52845..375793f 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -16,37 +16,43 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects { try { - // Convert and translate legacy Text components - Text[] textComponents = __instance.GetComponentsInChildren(true); - TextMeshProUGUI[] textMeshComponents = __instance.GetComponentsInChildren(true); - foreach (Text textComponent in textComponents) - { - if (textComponent != null && !string.IsNullOrEmpty(textComponent.text)) - { - string translatedText = StringStore.TranslateText(textComponent.text); - if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text) - { - TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true); - - if (newTMP != null) - { - newTMP.text = translatedText; - } - } - } - } - // Also handle TMP components directly under the button if (__instance.transform.childCount >= 2) { TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent(); - StringStore.TranslateTextUI(text, false); - StringStore.TranslateTextUI(textShadow, false); + text.text = StringStore.TranslateText(text.text, false); + textShadow.text = StringStore.TranslateText(textShadow.text, false); + + text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + textShadow.font = FontStore.LoadTMPFont(Utils.Language.ToString()); text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; } + else + { + // Convert and translate legacy Text components + Text[] textComponents = __instance.GetComponentsInChildren(true); + TextMeshProUGUI[] textMeshComponents = __instance.GetComponentsInChildren(true); + foreach (Text textComponent in textComponents) + { + if (textComponent != null && !string.IsNullOrEmpty(textComponent.text)) + { + string translatedText = StringStore.TranslateText(textComponent.text); + if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true); + + if (newTMP != null) + { + newTMP.text = translatedText; + } + } + } + } + } + } catch (Exception) { } } @@ -62,8 +68,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent(); TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent(); - StringStore.TranslateTextUI(text, false); - StringStore.TranslateTextUI(textShadow, false); + text.text = StringStore.TranslateText(text.text, false); + textShadow.text = StringStore.TranslateText(textShadow.text, false); + + text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + textShadow.font = FontStore.LoadTMPFont(Utils.Language.ToString()); text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; } } diff --git a/MelonLoader/Patches/GameObjects/PlayerShootingMenu_Patch.cs b/MelonLoader/Patches/GameObjects/PlayerShootingMenu_Patch.cs new file mode 100644 index 0000000..db4c48a --- /dev/null +++ b/MelonLoader/Patches/GameObjects/PlayerShootingMenu_Patch.cs @@ -0,0 +1,25 @@ +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()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/PlayerShootingWindow_Patch.cs b/MelonLoader/Patches/GameObjects/PlayerShootingWindow_Patch.cs new file mode 100644 index 0000000..de7a336 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/PlayerShootingWindow_Patch.cs @@ -0,0 +1,37 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(PlayerShootingWindow))] + public static class PlayerShootingWindow_Patch + { + [HarmonyPatch(nameof(PlayerShootingWindow.SetType))] + [HarmonyPostfix] + private static void SetType(PlayerShootingWindow __instance) + { + Transform introduceTransform = __instance.transform.FindChild("Images").FindChild("Introduce"); + TextMeshProUGUI introduceText = introduceTransform.GetComponent(); + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + introduceText.text = StringStore.TranslateText(introduceText.text); + introduceText.font = fontAsset; + } + + [HarmonyPatch(nameof(PlayerShootingWindow.OnAnimOver))] + [HarmonyPostfix] + private static void OnAnimOver(PlayerShootingWindow __instance) + { + Transform introduceTransform = __instance.transform.FindChild("Images").FindChild("Introduce"); + TextMeshProUGUI introduceText = introduceTransform.GetComponent(); + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + introduceText.text = StringStore.TranslateText(introduceText.text); + introduceText.font = fontAsset; + } + } +} diff --git a/MelonLoader/Patches/GameObjects/TowerOption_Patch.cs b/MelonLoader/Patches/GameObjects/TowerOption_Patch.cs index a50ecbb..1dcceda 100644 --- a/MelonLoader/Patches/GameObjects/TowerOption_Patch.cs +++ b/MelonLoader/Patches/GameObjects/TowerOption_Patch.cs @@ -1,21 +1,21 @@ -using HarmonyLib; -using Il2Cpp; -using Il2CppTMPro; -using PvZ_Fusion_Translator.AssetStore; -using UnityEngine; +//using HarmonyLib; +//using Il2Cpp; +//using Il2CppTMPro; +//using PvZ_Fusion_Translator.AssetStore; +//using UnityEngine; -namespace PvZ_Fusion_Translator.Patches.GameObjects -{ - [HarmonyPatch(typeof(TowerOption))] - public static class TowerOption_Patch - { - [HarmonyPatch(nameof(TowerOption.Start))] - [HarmonyPostfix] - private static void Postfix_Start(TowerOption __instance) - { - //TextMeshProUGUI[] allTexts = __instance.GetComponentsInChildren(true); - __instance.introduce.text = StringStore.TranslateText(__instance.introduce.text); - __instance.introduce.font = FontStore.LoadTMPFont(Utils.Language.ToString()); - } - } -} \ No newline at end of file +//namespace PvZ_Fusion_Translator.Patches.GameObjects +//{ +// [HarmonyPatch(typeof(TowerOption))] +// public static class TowerOption_Patch +// { +// [HarmonyPatch(nameof(TowerOption.Start))] +// [HarmonyPostfix] +// private static void Postfix_Start(TowerOption __instance) +// { +// //TextMeshProUGUI[] allTexts = __instance.GetComponentsInChildren(true); +// __instance.introduce.text = StringStore.TranslateText(__instance.introduce.text); +// __instance.introduce.font = FontStore.LoadTMPFont(Utils.Language.ToString()); +// } +// } +//}} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/TowerUpgradeMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TowerUpgradeMenu_Patch.cs new file mode 100644 index 0000000..3ad6c1c --- /dev/null +++ b/MelonLoader/Patches/GameObjects/TowerUpgradeMenu_Patch.cs @@ -0,0 +1,23 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(TowerUpgradeMenu))] + public static class TowerUpgradeMenu_Patch + { + [HarmonyPatch(nameof(TowerUpgradeMenu.Update))] + [HarmonyPostfix] + private static void Update(TowerUpgradeMenu __instance) + { + foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren()) + { + text.text = StringStore.TranslateText(text.text); + text.font = FontStore.LoadTMPFont(Utils.Language.ToString()); + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/Managers/TowerManager_Patch.cs b/MelonLoader/Patches/Managers/TowerManager_Patch.cs new file mode 100644 index 0000000..a88387f --- /dev/null +++ b/MelonLoader/Patches/Managers/TowerManager_Patch.cs @@ -0,0 +1,32 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.Managers +{ + [HarmonyPatch(typeof(TowerManager))] + public static class TowerManager_Patch + { + public static List updatedText = []; + + public static void UpdateText() + { + foreach (Transform transform in updatedText) + { + if (transform != null) + { + transform.GetComponent().text = StringStore.TranslateText(transform.GetComponent().text); + } + } + } + + [HarmonyPatch(nameof(TowerManager.Update))] + [HarmonyPostfix] + public static void Update(TowerManager __instance) + { + + } + } +} diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index fa1cbfe..bc11b36 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -13,7 +13,7 @@ latest enable Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate - C:\Users\rainb\Desktop\PC_PVZ-Fusion-2.7 + C:\Users\rainb\Desktop\PC_PVZ-Fusion-2.8 AnyCPU;ARM64;x64 @@ -402,6 +402,8 @@ + + @@ -432,6 +434,7 @@ + @@ -439,6 +442,7 @@ +