From 685db5a19a4d2773eb43a868f61285ac6570e866 Mon Sep 17 00:00:00 2001 From: SillyStar-Github <90102598+SillyStar-Github@users.noreply.github.com> Date: Mon, 14 Jul 2025 15:25:21 -0400 Subject: [PATCH] just updating my branch --- MelonLoader/Core.cs | 2 +- .../ButtonObjects/UIButton_Patch.cs | 59 ++++++++++++++----- ...PvZ Fusion Translator [MelonLoader].csproj | 1 - 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/MelonLoader/Core.cs b/MelonLoader/Core.cs index d218420..d89b0e0 100644 --- a/MelonLoader/Core.cs +++ b/MelonLoader/Core.cs @@ -3,7 +3,7 @@ using MelonLoader.Utils; using PvZ_Fusion_Translator.AssetStore; using UnityEngine; -[assembly: MelonInfo(typeof(PvZ_Fusion_Translator.Core), "PvZ Fusion Translator", "231.0.0", "dynaslash / arifrios1st / lancerx0", null)] +[assembly: MelonInfo(typeof(PvZ_Fusion_Translator.Core), "PvZ Fusion Translator", "231.0.0", "dynaslash / arifrios1st / lancerx0 / JustNull / Dakosha / Mamoru-kun", null)] [assembly: MelonGame("LanPiaoPiao", "PlantsVsZombiesRH")] namespace PvZ_Fusion_Translator diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index d497e4d..bd66319 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -3,7 +3,6 @@ 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,27 +14,59 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects [HarmonyPostfix] private static void Postfix_Start(UIButton __instance) { - Text[] textComponents = __instance.GetComponentsInChildren(true); - - foreach (Text textComponent in textComponents) + try { - if (textComponent != null && !string.IsNullOrEmpty(textComponent.text)) + // Convert and translate legacy Text components + Text[] textComponents = __instance.GetComponentsInChildren(true); + foreach (Text textComponent in textComponents) { - string translatedText = StringStore.TranslateText(textComponent.text); - if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text) + if (textComponent != null && !string.IsNullOrEmpty(textComponent.text)) { - TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); - - TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true); - - if (newTMP != null) + string translatedText = StringStore.TranslateText(textComponent.text); + if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text) { - newTMP.text = translatedText; - //Debug.Log($"Converted and translated text: {textComponent.text} -> {translatedText}"); + 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.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; + } } + catch (Exception) { } + } + + [HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))] + [HarmonyPostfix] + public static void Postfix_OnMouseUpAsButton(UIButton __instance) + { + try + { + 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.autoSizeTextContainer = textShadow.autoSizeTextContainer = true; + } + } + catch (Exception) { } } } } diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 19d1b93..7c0a33c 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -439,7 +439,6 @@ -