PVZFusionTranslation/BepInEx/Patches/Managers/CanvasUpUI_Patch.cs
2026-02-06 00:13:35 +07:00

34 lines
No EOL
1.2 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. 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;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
{
[HarmonyPatch(typeof(CanvasUpUI))]
public static class CanvasUpUI_Patch
{
[HarmonyPatch(nameof(CanvasUpUI.Start))]
[HarmonyPostfix]
public static void Start(CanvasUpUI __instance)
{
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
{
string originalKey = StringStore.translationString.FirstOrDefault(x => (x.Value == text.text || x.Value.Replace("\n", "") == text.text)).Key;
text.text = (StringStore.translationString.ContainsKey(originalKey + "_MG")) ? StringStore.TranslateText(originalKey + "_MG") : StringStore.TranslateText(text.text);
if(text.gameObject.name.Contains("LevelName"))
{
text.text = text.text.Replace("\n", " ");
}
text.font = fontAsset;
}
}
}
}