diff --git a/MelonLoader/Patches/GameObjects/AbyssBagMenu_Patch.cs b/MelonLoader/Patches/GameObjects/AbyssBagMenu_Patch.cs new file mode 100644 index 0000000..58c6166 --- /dev/null +++ b/MelonLoader/Patches/GameObjects/AbyssBagMenu_Patch.cs @@ -0,0 +1,31 @@ +using HarmonyLib; +using Il2Cpp; +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 +{ + + [HarmonyPatch(typeof(AbyssCheckInBag))] + public static class AbyssCheckInBag_Patch + { + [HarmonyPatch(nameof(AbyssCheckInBag.MoveFromBag))] + [HarmonyPostfix] + private static void MoveFromBag(AbyssCheckInBag __instance) + { + AbyssMenu2.Instance.UpdateIcons(); + } + + [HarmonyPatch(nameof(AbyssCheckInBag.SellIcon))] + [HarmonyPostfix] + private static void SellIcon(AbyssCheckInBag __instance) + { + AbyssMenu2.Instance.UpdateIcons(); + } + } +} diff --git a/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs b/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs index aebc69d..d3c30e6 100644 --- a/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs +++ b/MelonLoader/Patches/GameObjects/BaseMenu_Patch.cs @@ -1,5 +1,6 @@ using HarmonyLib; using Il2Cpp; +using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using UnityEngine; @@ -104,6 +105,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects StringStore.TranslateTextTransform(pageScaryPotTransform.Find("Nextpage")); StringStore.TranslateTextTransform(pageScaryPotTransform.Find("LastPage")); } + + foreach(TextMeshProUGUI txt in mainTransform.GetComponentsInChildren()) + { + txt.text = StringStore.TranslateText(txt.text); + } } } } diff --git a/MelonLoader/Patches/GameObjects/ButtonObjects/AbyssBuffButton_Patch.cs b/MelonLoader/Patches/GameObjects/ButtonObjects/AbyssBuffButton_Patch.cs index 7e28372..f83d585 100644 --- a/MelonLoader/Patches/GameObjects/ButtonObjects/AbyssBuffButton_Patch.cs +++ b/MelonLoader/Patches/GameObjects/ButtonObjects/AbyssBuffButton_Patch.cs @@ -1,18 +1,48 @@ #if FIX +using System.Text.RegularExpressions; using HarmonyLib; using Il2Cpp; using Il2CppTMPro; using PvZ_Fusion_Translator.AssetStore; using UnityEngine; +using MelonLoader; namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects { [HarmonyPatch(typeof(AbyssBuffButton))] public static class AbyssBuffButton_Patch { - [HarmonyPatch(nameof(AbyssBuffButton.Start))] + [HarmonyPatch(nameof(AbyssBuffButton.SetType))] [HarmonyPostfix] - private static void Start(AbyssBuffButton __instance) + private static void SetType(AbyssBuffButton __instance) + { + TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); + + Regex regex = new Regex("([^\\s]+)\n价格:(\\d+)"); + + if (regex.IsMatch(__instance.description.text)) + { + Match match = regex.Match(__instance.description.text); + int groupCount = match.Groups.Count; + + List dynamicParts = []; + + for (int i = 1; i < groupCount; i++) + { + string groupValue = match.Groups[i].Value; + string translatedValue = StringStore.translationString.ContainsKey(groupValue) ? StringStore.translationString[groupValue] : groupValue; + dynamicParts.Add(translatedValue); + MelonLogger.Msg(translatedValue); + } + + __instance.description.text = string.Format(StringStore.translationStringRegex["([^\\s]+)\n价格:(\\d+)"], [.. dynamicParts]); + __instance.description.font = fontAsset; + } + } + + [HarmonyPatch(nameof(AbyssBuffButton.SetSold))] + [HarmonyPostfix] + private static void SetSold(AbyssBuffButton __instance) { TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString()); diff --git a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj index 618c8c5..218e184 100644 --- a/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj +++ b/MelonLoader/PvZ Fusion Translator [MelonLoader].csproj @@ -448,6 +448,7 @@ +