diff --git a/MelonLoader/Patches/GameObjects/AbyssMenu2_Patch.cs b/MelonLoader/Patches/GameObjects/AbyssMenu2_Patch.cs index d877194..05a0fb2 100644 --- a/MelonLoader/Patches/GameObjects/AbyssMenu2_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AbyssMenu2_Patch.cs @@ -4,6 +4,9 @@ using Il2CppTMPro; using MelonLoader; using PvZ_Fusion_Translator.AssetStore; using UnityEngine; +using UnityEngine.TextCore.Text; +using UnityEngine.UI; +using static MelonLoader.MelonLogger; namespace PvZ_Fusion_Translator.Patches.GameObjects { @@ -49,12 +52,45 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects } } + public static GameObject ConvertToTextMeshProUGUI(GameObject originalText, Transform parent, string name) + { + GameObject newObj = new GameObject(name); + newObj.transform.position = originalText.transform.position; + newObj.AddComponent(); + newObj.AddComponent(); + newObj.AddComponent(); + newObj.transform.SetParent(parent); + newObj.transform.localScale = Vector3.one; + + UnityEngine.Object.Destroy(originalText); + return newObj; + } + + private static void ConvertButtonText(Transform original, string name) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + Transform transform = original.FindChild(name); + Transform textTransform = transform.FindChild("text"); + string text = textTransform.GetComponent().text; + Color color = textTransform.GetComponent().color; + + TextMeshProUGUI newGoBackText = ConvertToTextMeshProUGUI(textTransform.gameObject, transform, "text2").GetComponent(); + newGoBackText.autoSizeTextContainer = true; + newGoBackText.text = StringStore.TranslateText(text, false); + newGoBackText.font = fontAsset; + newGoBackText.color = color; + } + [HarmonyPatch(nameof(AbyssMenu2.Start))] [HarmonyPostfix] private static void Start(AbyssMenu2 __instance) { UpdateAbyss2Text(__instance); + ConvertButtonText(__instance.transform, "Goback"); + ConvertButtonText(__instance.transform, "Help"); + ConvertButtonText(__instance.transform, "Bag"); } [HarmonyPatch(nameof(AbyssMenu2.UpdateIcons))] diff --git a/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs index f3160c2..4c9473d 100644 --- a/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/AbyssMenu_Patch.cs @@ -6,12 +6,43 @@ using PvZ_Fusion_Translator.AssetStore; using Unity.VisualScripting; using UnityEngine; using System.Text.RegularExpressions; +using UnityEngine.UI; +using MelonLoader.Utils; namespace PvZ_Fusion_Translator.Patches.GameObjects { [HarmonyPatch(typeof(AbyssMenu))] public static class AbyssMenu_Patch { + public static GameObject ConvertToTextMeshProUGUI(GameObject originalText, Transform parent, string name) + { + GameObject newObj = new GameObject(name); + newObj.transform.position = originalText.transform.position; + newObj.AddComponent(); + newObj.AddComponent(); + newObj.AddComponent(); + newObj.transform.SetParent(parent); + newObj.transform.localScale = Vector3.one; + + UnityEngine.Object.Destroy(originalText); + return newObj; + } + + private static void ConvertButtonText(Transform original, string name) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + Transform transform = original.FindChild(name); + Transform textTransform = transform.FindChild("text"); + string text = textTransform.GetComponent().text; + Color color = textTransform.GetComponent().color; + + TextMeshProUGUI newGoBackText = ConvertToTextMeshProUGUI(textTransform.gameObject, transform, "text2").GetComponent(); + newGoBackText.autoSizeTextContainer = true; + newGoBackText.text = StringStore.TranslateText(text, false); + newGoBackText.font = fontAsset; + newGoBackText.color = color; + } [HarmonyPatch(nameof(AbyssMenu.Awake))] [HarmonyPostfix] @@ -24,6 +55,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects txt.text = StringStore.TranslateText(txt.text, false); txt.font = fontAsset; } + + ConvertButtonText(__instance.transform, "Goback"); } [HarmonyPatch(nameof(AbyssMenu.UpdateLevelInfo))] diff --git a/MelonLoader/Patches/GameObjects/AbyssStoreMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AbyssStoreMenu_Patch.cs new file mode 100644 index 0000000..366f2e1 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/AbyssStoreMenu_Patch.cs @@ -0,0 +1,18 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(AbyssStoreMenu))] + public static class AbyssStoreMenu_Patch + { + [HarmonyPatch(nameof(AbyssStoreMenu.Update))] + [HarmonyPostfix] + private static void UpdateInfo(AbyssStoreMenu __instance) + { + __instance.yourMoney.text = StringStore.TranslateText(__instance.yourMoney.text); + } + } +} diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 50bdf1d..b3f4153 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -448,6 +448,7 @@ +