diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/EveBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/EveBtn_Patch.cs deleted file mode 100644 index 101f112..0000000 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/EveBtn_Patch.cs +++ /dev/null @@ -1,42 +0,0 @@ -using HarmonyLib; -using Il2Cpp; -using Il2CppTMPro; -using PvZ_Fusion_Translator.AssetStore; -using UnityEngine; - -namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects -{ - [HarmonyPatch(typeof(EveManager))] - public static class EveManager_UIButton_Patch - { - [HarmonyPostfix] - [HarmonyPatch(nameof(EveManager.Balanced))] - private static void Start(EveManager __instance) - { - Transform sceneText = __instance.transform.FindChild("text"); - if(sceneText != null) - { - TextMeshProUGUI sceneTextTMP = sceneText.transform.GetComponent(); - if(sceneTextTMP != null) - { - sceneTextTMP.text = StringStore.TranslateText(sceneTextTMP.text); - } - } - Transform sceneTextShadow = sceneText.transform.FindChild("text2"); - if(sceneTextShadow != null) - { - TextMeshProUGUI sceneTextShadowTMP = sceneTextShadow.transform.GetComponent(); - if (sceneTextShadowTMP != null) - { - sceneTextShadowTMP.text = StringStore.TranslateText(sceneTextShadowTMP.text); - } - } - - if (__instance.name.Equals("Balanced")) - { - __instance.gameObject.SetActive(false); - __instance.gameObject.SetActive(true); - } - } - } -} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs index d497e4d..ec2228f 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton_Patch.cs @@ -2,9 +2,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 { @@ -13,29 +10,32 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects { [HarmonyPatch(nameof(UIButton.Start))] [HarmonyPostfix] - private static void Postfix_Start(UIButton __instance) + public static void Start(UIButton __instance) { - Text[] textComponents = __instance.GetComponentsInChildren(true); - - foreach (Text textComponent in textComponents) + try { - 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; - //Debug.Log($"Converted and translated text: {textComponent.text} -> {translatedText}"); - } - } - } + 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 OnMouseUpAsButton(UIButton __instance) + { + try + { + 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 @@ -