97 lines
2.9 KiB
C#
97 lines
2.9 KiB
C#
using HarmonyLib;
|
||
using Il2Cpp;
|
||
using Il2CppTMPro;
|
||
using PvZ_Fusion_Translator.Patches.Managers;
|
||
using PvZ_Fusion_Translator.AssetStore;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
|
||
{
|
||
[HarmonyPatch(typeof(TextMeshProUGUI))]
|
||
public static class TextMeshProUGUI_Patch
|
||
{
|
||
[HarmonyPatch(nameof(TextMeshProUGUI.OnEnable))]
|
||
[HarmonyPostfix]
|
||
private static void OnEnable(TextMeshProUGUI __instance)
|
||
{
|
||
if (!string.IsNullOrEmpty(__instance.text))
|
||
{
|
||
if(__instance.transform.parent.parent != null)
|
||
{
|
||
if (__instance.transform.parent.parent.name.Contains("AbyssBagMenu"))
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
__instance = StringStore.TranslateText(__instance);
|
||
__instance.autoSizeTextContainer = false;
|
||
|
||
if (__instance.name.StartsWith("LevelName"))
|
||
{
|
||
__instance.text = __instance.text.Replace("\n", " ");
|
||
|
||
if (__instance.name == "LevelName2" || __instance.name == "LevelName3")
|
||
{
|
||
TowerManager_Patch.updatedText.Add(__instance.transform);
|
||
}
|
||
}
|
||
if (__instance.transform.parent != null && __instance.transform.parent.name.StartsWith("Window"))
|
||
{
|
||
__instance.fontSizeMin = 10;
|
||
__instance.fontSize = 12;
|
||
}
|
||
|
||
// __instance.ForceMeshUpdate();
|
||
}
|
||
}
|
||
|
||
[HarmonyPatch(nameof(TextMeshProUGUI.Awake))]
|
||
[HarmonyPostfix]
|
||
private static void Awake(TextMeshProUGUI __instance)
|
||
{
|
||
if (!string.IsNullOrEmpty(__instance.text))
|
||
{
|
||
if (__instance.transform.parent.parent != null)
|
||
{
|
||
if (__instance.transform.parent.parent.name.Contains("AbyssBagMenu"))
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
__instance = StringStore.TranslateText(__instance);
|
||
__instance.autoSizeTextContainer = false;
|
||
|
||
if (__instance.transform.parent != null && __instance.transform.parent.name.StartsWith("Window"))
|
||
{
|
||
__instance.fontSizeMin = 10;
|
||
__instance.fontSize = 12;
|
||
}
|
||
|
||
if (__instance.text == "Полный Хаос" && __instance.transform.parent.parent.Find("Image").GetComponent<Image>().activeSprite.name == "Present")
|
||
{
|
||
__instance.text += "\nБесконечно";
|
||
}
|
||
|
||
// __instance.ForceMeshUpdate();
|
||
}
|
||
}
|
||
}
|
||
[HarmonyPatch(typeof(TMP_SubMeshUI))]
|
||
public static class TMP_SubMeshUI_Patch
|
||
{
|
||
[HarmonyPatch(nameof(TMP_SubMeshUI.OnEnable))]
|
||
[HarmonyPostfix]
|
||
public static void OnEnable(TMP_SubMeshUI __instance)
|
||
{
|
||
if (!string.IsNullOrEmpty(__instance.textComponent.text))
|
||
{
|
||
string text = StringStore.TranslateText(__instance.textComponent.text);
|
||
__instance.m_TextComponent.text = StringStore.TranslateText(text);
|
||
__instance.textComponent.text = StringStore.TranslateText(text);
|
||
}
|
||
}
|
||
}
|
||
}
|