PVZFusionTranslation/BepInEx/Patches/GameObjects/ExploreMakeMenu_Patch.cs
2025-11-18 19:07:53 +07:00

79 lines
No EOL
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using HarmonyLib;
using TMPro;
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
using PvZ_Fusion_Translator__BepInEx_;
using System.Text.RegularExpressions;
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.Json;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
{
[HarmonyPatch(typeof(ExploreMakeMenu))]
public static class ExploreMakeMenu_Patch
{
[HarmonyPatch(nameof(ExploreMakeMenu.Awake))]
[HarmonyPostfix]
private static void Awake(ExploreMakeMenu __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(ExploreMakeMenu.InitMenu))]
[HarmonyPostfix]
private static void InitMenu(ExploreMakeMenu __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
if(txt.text.Contains("关卡制作中:"))
{
string plantName = Utils.GetPlantNameFromAlmanac(txt.text.Split(":")[1]);
txt.text = String.Format(StringStore.translationStringRegex["关卡制作中:([^\\s]+)"], plantName);
}
else
{
txt.text = StringStore.TranslateText(txt.text);
}
}
}
[HarmonyPatch(nameof(ExploreMakeMenu.ViewScene))]
[HarmonyPostfix]
private static void ViewScene(ExploreMakeMenu __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(ExploreMakeMenu.InitZombieButtons))]
[HarmonyPostfix]
private static void InitZombieButtons(ExploreMakeMenu __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;
}
}
}
}