diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/EveBtn_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/EveBtn_Patch.cs index 157230c..101f112 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/EveBtn_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/EveBtn_Patch.cs @@ -6,12 +6,12 @@ using UnityEngine; namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects { - [HarmonyPatch(typeof(UIButton))] + [HarmonyPatch(typeof(EveManager))] public static class EveManager_UIButton_Patch { [HarmonyPostfix] - [HarmonyPatch(nameof(UIButton.Start))] - private static void Start(UIButton __instance) + [HarmonyPatch(nameof(EveManager.Balanced))] + private static void Start(EveManager __instance) { Transform sceneText = __instance.transform.FindChild("text"); if(sceneText != null) diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs new file mode 100644 index 0000000..b5551c2 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/UIButton.cs @@ -0,0 +1,34 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using UnityEngine.UI; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(UIButton))] + public static class UIButton_Patch + { + [HarmonyPatch(nameof(UIButton.Start))] + [HarmonyPostfix] + 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 + } + } + } + } + } +} diff --git a/MelonLoader/Patches/GameObjects/TravelLookMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TravelLookMenu_Patch.cs new file mode 100644 index 0000000..7c2b029 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/TravelLookMenu_Patch.cs @@ -0,0 +1,34 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(TravelLookMenu))] + public static class TravelLookMenu_Patch + { + [HarmonyPatch(nameof(TravelLookMenu.Start))] + [HarmonyPostfix] + private static void Postfix_Start(TravelLookMenu __instance) + { + Transform quitButtonTransform = __instance.transform.Find("Quit"); + if (quitButtonTransform != null) + { + TextMeshProUGUI[] allTexts = quitButtonTransform.GetComponentsInChildren(true); + + foreach (var textComp in allTexts) + { + if (textComp != null && textComp.text == StringStore.TranslateText("关闭")) + { + textComp.text = StringStore.TranslateText("关闭_close"); + + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + textComp.font = fontAsset; + } + } + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 775186b..7400b48 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -405,6 +405,7 @@ + @@ -423,6 +424,7 @@ + @@ -468,7 +470,7 @@ - +