From 366379e118b1f747ae66961c3ac477b65acaeed3 Mon Sep 17 00:00:00 2001 From: TuanAnh2901 Date: Thu, 5 Jun 2025 15:25:15 +0700 Subject: [PATCH] add some more bugs =))) progress is on Discord --- MelonLoader/AssetStore/StringStore.cs | 2 +- .../GameObjects/ButtonObjects/UIButton.cs | 17 +++++++++++---- .../Patches/GameObjects/TowerOption_Patch.cs | 21 +++++++++++++++++++ ...PvZ Fusion Translator [MelonLoader].csproj | 1 + 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 MelonLoader/Patches/GameObjects/TowerOption_Patch.cs diff --git a/MelonLoader/AssetStore/StringStore.cs b/MelonLoader/AssetStore/StringStore.cs index d2a13c8..d666b66 100644 --- a/MelonLoader/AssetStore/StringStore.cs +++ b/MelonLoader/AssetStore/StringStore.cs @@ -1250,7 +1250,7 @@ namespace PvZ_Fusion_Translator.AssetStore }; } - static TextMeshProUGUI ConvertToTextMeshPro(UnityEngine.UI.Text oldText, TMP_FontAsset fontAsset, bool isLog = false) + public static TextMeshProUGUI ConvertToTextMeshPro(UnityEngine.UI.Text oldText, TMP_FontAsset fontAsset, bool isLog = false) { if (oldText == null) { diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs index b5551c2..4f608d3 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs @@ -3,6 +3,7 @@ using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using UnityEngine; +using UnityEngine.TextCore.Text; using UnityEngine.UI; namespace PvZ_Fusion_Translator.Patches.GameObjects @@ -15,17 +16,25 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects private static void Postfix_Start(UIButton __instance) { Text[] textComponents = __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) { - textComponent.text = translatedText; - // TODO: Add a new font handler for UnityEngine.Font + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true); + + if (newTMP != null) + { + newTMP.text = translatedText; + + // Optional: Log successful conversion and translation + //Debug.Log($"Converted and translated text: {textComponent.text} -> {translatedText}"); + } } } } diff --git a/MelonLoader/Patches/GameObjects/TowerOption_Patch.cs b/MelonLoader/Patches/GameObjects/TowerOption_Patch.cs new file mode 100644 index 0000000..a50ecbb --- /dev/null +++ b/MelonLoader/Patches/GameObjects/TowerOption_Patch.cs @@ -0,0 +1,21 @@ +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 diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 7400b48..fb34bed 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -423,6 +423,7 @@ +