3.0 part 2

This commit is contained in:
SillyStar-Github 2025-09-27 23:14:58 -04:00
parent f2f5a87813
commit 17d233d8d1
13 changed files with 447 additions and 5 deletions

View file

@ -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<TextMeshProUGUI>())
{
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<TextMeshProUGUI>())
{
StringStore.TranslateText(txt);
}
__instance.nameText.text = Utils.GetPlantNameFromAlmanac(thePlantType);
}
}
}

View file

@ -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<TextMeshProUGUI>())
{
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<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
}
}
}
}

View file

@ -17,8 +17,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>()) foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{ {
FileLoader.DumpUntranslatedStrings(txt.text); if(txt.transform.parent.name.Contains("Close"))
txt.text = StringStore.TranslateText(txt.text); {
txt.text = StringStore.TranslateText("合上");
}
else
{
txt.text = StringStore.TranslateText(txt.text);
}
txt.font = fontAsset; txt.font = fontAsset;
} }
} }
@ -31,8 +37,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>()) foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{ {
FileLoader.DumpUntranslatedStrings(txt.text); if (txt.transform.parent.name.Contains("Close"))
txt.text = StringStore.TranslateText(txt.text); {
txt.text = StringStore.TranslateText("合上");
}
else
{
txt.text = StringStore.TranslateText(txt.text);
}
txt.font = fontAsset; txt.font = fontAsset;
} }
} }

View file

@ -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);
}
}
}

View file

@ -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<TextMeshProUGUI>())
{
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<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText("合上");
}
}
}
}

View file

@ -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<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
}

View file

@ -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<TextMeshProUGUI>())
{
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<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
}

View file

@ -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<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
}

View file

@ -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<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
}

View file

@ -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<TextMeshProUGUI>())
{
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<TextMeshProUGUI>())
{
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<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
}

View file

@ -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<TextMeshProUGUI>())
{
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<TextMeshProUGUI>())
{
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<TextMeshProUGUI>())
{
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<TextMeshProUGUI>())
{
txt.text = StringStore.TranslateText(txt.text);
txt.font = fontAsset;
}
}
}
}

View file

@ -401,12 +401,22 @@
<Compile Include="ModFeatures.cs" /> <Compile Include="ModFeatures.cs" />
<Compile Include="AssetStore\AudioStore.cs" /> <Compile Include="AssetStore\AudioStore.cs" />
<Compile Include="Patches\GameObjects\Board_Patch.cs" /> <Compile Include="Patches\GameObjects\Board_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\TreasureMoney_Patch.cs" />
<Compile Include="Patches\GameObjects\PlantInfoWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\GardenCard_Patch.cs" /> <Compile Include="Patches\GameObjects\GardenCard_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\UIProgress2_Patch.cs" /> <Compile Include="Patches\GameObjects\MinorObjects\UIProgress2_Patch.cs" />
<Compile Include="Patches\GameObjects\MinorObjects\Jigsaw_Patch.cs" /> <Compile Include="Patches\GameObjects\MinorObjects\Jigsaw_Patch.cs" />
<Compile Include="Patches\GameObjects\ExploreEnterWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\PlayerShootingWindow_Patch.cs" /> <Compile Include="Patches\GameObjects\PlayerShootingWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\PlayerShootingMenu_Patch.cs" /> <Compile Include="Patches\GameObjects\PlayerShootingMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\GardenBagMenu_Patch.cs" /> <Compile Include="Patches\GameObjects\GardenBagMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ExploreMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureEquipmentMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureConfirmMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureUpgradeMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureStoreMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureWarehouseMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\TreasureMainMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ShootingSelectWindow_Patch.cs" /> <Compile Include="Patches\GameObjects\ShootingSelectWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\FruitNinjaSelectWindow_Patch.cs" /> <Compile Include="Patches\GameObjects\FruitNinjaSelectWindow_Patch.cs" />
<Compile Include="Patches\GameObjects\RogueCardWindow_Patch.cs" /> <Compile Include="Patches\GameObjects\RogueCardWindow_Patch.cs" />

View file

@ -1,4 +1,5 @@
using Il2CppTMPro; using Il2Cpp;
using Il2CppTMPro;
using MelonLoader; using MelonLoader;
using PvZ_Fusion_Translator.AssetStore; using PvZ_Fusion_Translator.AssetStore;
using System.Diagnostics; using System.Diagnostics;
@ -6,6 +7,8 @@ using System.Text.RegularExpressions;
using UnityEngine; using UnityEngine;
using UnityEngine.Experimental.Rendering; using UnityEngine.Experimental.Rendering;
using UnityEngine.UI; using UnityEngine.UI;
using static MelonLoader.MelonLogger;
using static PvZ_Fusion_Translator.FileLoader;
namespace PvZ_Fusion_Translator namespace PvZ_Fusion_Translator
{ {
@ -108,6 +111,39 @@ namespace PvZ_Fusion_Translator
newGoBackText.color = color; 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<AlmanacPlantBank.PlantData>(json);
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
{
if (plantInfo.seedType == (int)thePlantType)
{
thePlantName = plantInfo.name;
}
}
}
return thePlantName;
}
#if MULTI_LANGUAGE #if MULTI_LANGUAGE
internal static void ChangeLanguage(string language) internal static void ChangeLanguage(string language)
{ {