UIButton patch
This commit is contained in:
parent
55e4d5b937
commit
294532e87b
3 changed files with 23 additions and 66 deletions
|
|
@ -1,42 +0,0 @@
|
||||||
using HarmonyLib;
|
|
||||||
using Il2Cpp;
|
|
||||||
using Il2CppTMPro;
|
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
|
||||||
{
|
|
||||||
[HarmonyPatch(typeof(EveManager))]
|
|
||||||
public static class EveManager_UIButton_Patch
|
|
||||||
{
|
|
||||||
[HarmonyPostfix]
|
|
||||||
[HarmonyPatch(nameof(EveManager.Balanced))]
|
|
||||||
private static void Start(EveManager __instance)
|
|
||||||
{
|
|
||||||
Transform sceneText = __instance.transform.FindChild("text");
|
|
||||||
if(sceneText != null)
|
|
||||||
{
|
|
||||||
TextMeshProUGUI sceneTextTMP = sceneText.transform.GetComponent<TextMeshProUGUI>();
|
|
||||||
if(sceneTextTMP != null)
|
|
||||||
{
|
|
||||||
sceneTextTMP.text = StringStore.TranslateText(sceneTextTMP.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Transform sceneTextShadow = sceneText.transform.FindChild("text2");
|
|
||||||
if(sceneTextShadow != null)
|
|
||||||
{
|
|
||||||
TextMeshProUGUI sceneTextShadowTMP = sceneTextShadow.transform.GetComponent<TextMeshProUGUI>();
|
|
||||||
if (sceneTextShadowTMP != null)
|
|
||||||
{
|
|
||||||
sceneTextShadowTMP.text = StringStore.TranslateText(sceneTextShadowTMP.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (__instance.name.Equals("Balanced"))
|
|
||||||
{
|
|
||||||
__instance.gameObject.SetActive(false);
|
|
||||||
__instance.gameObject.SetActive(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,9 +2,6 @@
|
||||||
using Il2Cpp;
|
using Il2Cpp;
|
||||||
using Il2CppTMPro;
|
using Il2CppTMPro;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.TextCore.Text;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
{
|
{
|
||||||
|
|
@ -13,29 +10,32 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
{
|
{
|
||||||
[HarmonyPatch(nameof(UIButton.Start))]
|
[HarmonyPatch(nameof(UIButton.Start))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
private static void Postfix_Start(UIButton __instance)
|
public static void Start(UIButton __instance)
|
||||||
{
|
{
|
||||||
Text[] textComponents = __instance.GetComponentsInChildren<Text>(true);
|
try
|
||||||
|
{
|
||||||
|
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
||||||
|
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
||||||
|
StringStore.TranslateTextUI(text, false);
|
||||||
|
StringStore.TranslateTextUI(textShadow, false);
|
||||||
|
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Text textComponent in textComponents)
|
[HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))]
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void OnMouseUpAsButton(UIButton __instance)
|
||||||
{
|
{
|
||||||
if (textComponent != null && !string.IsNullOrEmpty(textComponent.text))
|
try
|
||||||
{
|
{
|
||||||
string translatedText = StringStore.TranslateText(textComponent.text);
|
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
||||||
if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text)
|
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
||||||
{
|
StringStore.TranslateTextUI(text, false);
|
||||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
StringStore.TranslateTextUI(textShadow, false);
|
||||||
|
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
|
||||||
TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true);
|
|
||||||
|
|
||||||
if (newTMP != null)
|
|
||||||
{
|
|
||||||
newTMP.text = translatedText;
|
|
||||||
//Debug.Log($"Converted and translated text: {textComponent.text} -> {translatedText}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -439,7 +439,6 @@
|
||||||
<Compile Include="Patches\Managers\AlmanacPlantBank_Patch.cs" />
|
<Compile Include="Patches\Managers\AlmanacPlantBank_Patch.cs" />
|
||||||
<Compile Include="Patches\Managers\DifficultyMgr_Patch.cs" />
|
<Compile Include="Patches\Managers\DifficultyMgr_Patch.cs" />
|
||||||
<Compile Include="Patches\Managers\EndlessMgr_Patch.cs" />
|
<Compile Include="Patches\Managers\EndlessMgr_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\ButtonObjects\EveBtn_Patch.cs" />
|
|
||||||
<Compile Include="Patches\GameObjects\GardenPlant_Patch.cs" />
|
<Compile Include="Patches\GameObjects\GardenPlant_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\Close_Patch.cs" />
|
<Compile Include="Patches\GameObjects\Close_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\CustomSettings_Patch.cs" />
|
<Compile Include="Patches\GameObjects\CustomSettings_Patch.cs" />
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue