diff --git a/MelonLoader/Patches/GameObjects/ExploreEnterWindow_Patch.cs b/MelonLoader/Patches/GameObjects/ExploreEnterWindow_Patch.cs new file mode 100644 index 0000000..386f040 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/ExploreEnterWindow_Patch.cs @@ -0,0 +1,41 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; +using System.Text.RegularExpressions; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(ExploreEnterWindow))] + public static class ExploreEnterWindow_Patch + { + [HarmonyPatch(nameof(ExploreEnterWindow.Awake))] + [HarmonyPostfix] + private static void Awake(ExploreEnterWindow __instance) + { + PlantType thePlantType = (PlantType)__instance.selfType; + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + StringStore.TranslateText(txt); + } + + __instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType); + } + + [HarmonyPatch(nameof(ExploreEnterWindow.SetInfo))] + [HarmonyPostfix] + private static void SetInfo(ExploreEnterWindow __instance) + { + PlantType thePlantType = (PlantType)__instance.selfType; + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + StringStore.TranslateText(txt); + } + + __instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType); + } + } +} diff --git a/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs b/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs new file mode 100644 index 0000000..0a3dc9b --- /dev/null +++ b/MelonLoader/Patches/GameObjects/ExploreMenu_Patch.cs @@ -0,0 +1,44 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(ExploreMenu))] + public static class ExploreMenu_Patch + { + [HarmonyPatch(nameof(ExploreMenu.Awake))] + [HarmonyPostfix] + private static void Awake(ExploreMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + if(txt.name.Contains("Text (TMP)")) + { + txt.autoSizeTextContainer = true; + if(txt.name == "Text (TMP)") + { + txt.transform.localPosition = new Vector3(94.4225f, -45.1565f, 0f); + } + } + } + } + + [HarmonyPatch(nameof(ExploreMenu.UpdateWindows))] + [HarmonyPostfix] + private static void UpdateWindows(ExploreMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/GardenBagMenu_Patch.cs b/MelonLoader/Patches/GameObjects/GardenBagMenu_Patch.cs index da1ea0f..093cacd 100644 --- a/MelonLoader/Patches/GameObjects/GardenBagMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/GardenBagMenu_Patch.cs @@ -17,8 +17,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) { - FileLoader.DumpUntranslatedStrings(txt.text); - txt.text = StringStore.TranslateText(txt.text); + if(txt.transform.parent.name.Contains("Close")) + { + txt.text = StringStore.TranslateText("合上"); + } + else + { + txt.text = StringStore.TranslateText(txt.text); + } txt.font = fontAsset; } } @@ -31,8 +37,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) { - FileLoader.DumpUntranslatedStrings(txt.text); - txt.text = StringStore.TranslateText(txt.text); + if (txt.transform.parent.name.Contains("Close")) + { + txt.text = StringStore.TranslateText("合上"); + } + else + { + txt.text = StringStore.TranslateText(txt.text); + } txt.font = fontAsset; } } diff --git a/MelonLoader/Patches/GameObjects/MinorObjects/TreasureMoney_Patch.cs b/MelonLoader/Patches/GameObjects/MinorObjects/TreasureMoney_Patch.cs new file mode 100644 index 0000000..60dc971 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/MinorObjects/TreasureMoney_Patch.cs @@ -0,0 +1,17 @@ +using HarmonyLib; +using Il2Cpp; +using PvZ_Fusion_Translator.AssetStore; + +namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects +{ + [HarmonyPatch(typeof(TreasureMoney))] + public static class TreasureMoney_Patch + { + [HarmonyPostfix] + [HarmonyPatch(nameof(TreasureMoney.Update))] + private static void Update(TreasureMoney __instance) + { + __instance.text = StringStore.TranslateText(__instance.text); + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/PlantInfoWindow_Patch.cs b/MelonLoader/Patches/GameObjects/PlantInfoWindow_Patch.cs new file mode 100644 index 0000000..bbe52fc --- /dev/null +++ b/MelonLoader/Patches/GameObjects/PlantInfoWindow_Patch.cs @@ -0,0 +1,53 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using MelonLoader.TinyJSON; +using PvZ_Fusion_Translator.AssetStore; +using Unity.Collections; +using UnityEngine; +using UnityEngine.UIElements; +using static PvZ_Fusion_Translator.FileLoader; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(PlantInfoWindow))] + public static class PlantInfoWindow_Patch + { + [HarmonyPatch(nameof(PlantInfoWindow.InitText))] + [HarmonyPostfix] + private static void InitText(PlantInfoWindow __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + PlantType thePlantType = __instance.plant.thePlantType; + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + if(txt.name.Contains("Introduce")) + { + string text = txt.text; + string[] lines = text.Split("\n"); + + lines[0] = Utils.GetPlantNameFromAlmanac(thePlantType); + string updatedText = String.Join("\n", lines); + + txt.text = StringStore.TranslateText(updatedText); + } + else + { + txt.text = StringStore.TranslateText(txt.text); + } + + txt.font = fontAsset; + } + + Transform parentWindowTransform = __instance.transform.parent; + Transform returnPlantTransform = parentWindowTransform.FindChild("Close"); + + foreach(TextMeshProUGUI txt in returnPlantTransform.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText("合上"); + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/TreasureConfirmMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TreasureConfirmMenu_Patch.cs new file mode 100644 index 0000000..9cbf1a0 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/TreasureConfirmMenu_Patch.cs @@ -0,0 +1,25 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureConfirmMenu))] + public static class TreasureConfirmMenu_Patch + { + [HarmonyPatch(nameof(TreasureConfirmMenu.SetText))] + [HarmonyPostfix] + private static void SetText(TreasureConfirmMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/TreasureEquipmentMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TreasureEquipmentMenu_Patch.cs new file mode 100644 index 0000000..f80e26d --- /dev/null +++ b/MelonLoader/Patches/GameObjects/TreasureEquipmentMenu_Patch.cs @@ -0,0 +1,38 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureEquipmentMenu))] + public static class TreasureEquipmentMenu_Patch + { + [HarmonyPatch(nameof(TreasureEquipmentMenu.Awake))] + [HarmonyPostfix] + private static void Awake(TreasureEquipmentMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureEquipmentMenu.UpdateCards))] + [HarmonyPostfix] + private static void UpdateCards(TreasureEquipmentMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/TreasureMainMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TreasureMainMenu_Patch.cs new file mode 100644 index 0000000..ea0478e --- /dev/null +++ b/MelonLoader/Patches/GameObjects/TreasureMainMenu_Patch.cs @@ -0,0 +1,25 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureMainMenu))] + public static class TreasureMainMenu_Patch + { + [HarmonyPatch(nameof(TreasureMainMenu.Update))] + [HarmonyPostfix] + private static void Update(TreasureMainMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/TreasureStoreMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TreasureStoreMenu_Patch.cs new file mode 100644 index 0000000..1b771c6 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/TreasureStoreMenu_Patch.cs @@ -0,0 +1,25 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureStoreMenu))] + public static class TreasureStoreMenu_Patch + { + [HarmonyPatch(nameof(TreasureStoreMenu.InitCards))] + [HarmonyPostfix] + private static void InitCards(TreasureStoreMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs new file mode 100644 index 0000000..1b3c411 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/TreasureUpgradeMenu_Patch.cs @@ -0,0 +1,52 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using System.Text.RegularExpressions; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureUpgradeMenu))] + public static class TreasureUpgradeMenu_Patch + { + [HarmonyPatch(nameof(TreasureUpgradeMenu.Start))] + [HarmonyPostfix] + private static void Start(TreasureUpgradeMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureUpgradeMenu.UpgradeWareHouse))] + [HarmonyPostfix] + private static void UpgradeWareHouse(TreasureUpgradeMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureUpgradeMenu.InitWareHouseUpgrade))] + [HarmonyPostfix] + private static void InitWareHouseUpgrade(TreasureUpgradeMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + } +} \ No newline at end of file diff --git a/MelonLoader/Patches/GameObjects/TreasureWarehouseMenu_Patch.cs b/MelonLoader/Patches/GameObjects/TreasureWarehouseMenu_Patch.cs new file mode 100644 index 0000000..fb7d1a9 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/TreasureWarehouseMenu_Patch.cs @@ -0,0 +1,64 @@ +using HarmonyLib; +using Il2Cpp; +using Il2CppTMPro; +using PvZ_Fusion_Translator.AssetStore; +using UnityEngine; + +namespace PvZ_Fusion_Translator.Patches.GameObjects +{ + [HarmonyPatch(typeof(TreasureWarehouseMenu))] + public static class TreasureWarehouseMenu_Patch + { + [HarmonyPatch(nameof(TreasureWarehouseMenu.InitCards))] + [HarmonyPostfix] + private static void InitCards(TreasureWarehouseMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureWarehouseMenu.QuickSell))] + [HarmonyPostfix] + private static void QuickSell(TreasureWarehouseMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureWarehouseMenu.FastSell))] + [HarmonyPostfix] + private static void FastSell(TreasureWarehouseMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.font = fontAsset; + } + } + + [HarmonyPatch(nameof(TreasureWarehouseMenu.EnterStore))] + [HarmonyPostfix] + private static void EnterStore(TreasureWarehouseMenu __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + txt.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 1b47970..c6c57b0 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -401,12 +401,22 @@ + + + + + + + + + + diff --git a/MelonLoader/Utils.cs b/MelonLoader/Utils.cs index 01fe81a..6422342 100644 --- a/MelonLoader/Utils.cs +++ b/MelonLoader/Utils.cs @@ -1,4 +1,5 @@ -using Il2CppTMPro; +using Il2Cpp; +using Il2CppTMPro; using MelonLoader; using PvZ_Fusion_Translator.AssetStore; using System.Diagnostics; @@ -6,6 +7,8 @@ using System.Text.RegularExpressions; using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.UI; +using static MelonLoader.MelonLogger; +using static PvZ_Fusion_Translator.FileLoader; namespace PvZ_Fusion_Translator { @@ -108,6 +111,39 @@ namespace PvZ_Fusion_Translator newGoBackText.color = color; } + public static string GetPlantNameFromAlmanac(PlantType thePlantType) + { + string json; + string thePlantName = ""; + + string currentLanguage = Utils.Language.ToString(); + string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language); + string path = Path.Combine(almanacDir, "LawnStringsTranslate.json"); + string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json"); + + if (!File.Exists(path)) + { + Log.LogError($"LawnStringsTranslate.json file not found at path: {path}"); + Log.LogError("Plant name could not be found! (Big Garden)"); + thePlantName = ""; + } + else + { + json = File.ReadAllText(path); + AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson(json); + + foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants) + { + if (plantInfo.seedType == (int)thePlantType) + { + thePlantName = plantInfo.name; + } + } + } + + return thePlantName; + } + #if MULTI_LANGUAGE internal static void ChangeLanguage(string language) {