Hotfix for survival mode pagination
This commit is contained in:
parent
449b9db9f0
commit
2eeaf52d6d
1 changed files with 43 additions and 12 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
using Il2Cpp;
|
using Il2Cpp;
|
||||||
using Il2CppTMPro;
|
using Il2CppTMPro;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
{
|
{
|
||||||
|
|
@ -10,30 +12,59 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
{
|
{
|
||||||
[HarmonyPatch(nameof(UIButton.Start))]
|
[HarmonyPatch(nameof(UIButton.Start))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void Start(UIButton __instance)
|
private static void Postfix_Start(UIButton __instance)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
// Convert and translate legacy Text components
|
||||||
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
Text[] textComponents = __instance.GetComponentsInChildren<Text>(true);
|
||||||
StringStore.TranslateTextUI(text, false);
|
foreach (Text textComponent in textComponents)
|
||||||
StringStore.TranslateTextUI(textShadow, false);
|
{
|
||||||
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
|
if (textComponent != null && !string.IsNullOrEmpty(textComponent.text))
|
||||||
|
{
|
||||||
|
string translatedText = StringStore.TranslateText(textComponent.text);
|
||||||
|
if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text)
|
||||||
|
{
|
||||||
|
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||||
|
TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true);
|
||||||
|
|
||||||
|
if (newTMP != null)
|
||||||
|
{
|
||||||
|
newTMP.text = translatedText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also handle TMP components directly under the button
|
||||||
|
if (__instance.transform.childCount >= 2)
|
||||||
|
{
|
||||||
|
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) { }
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))]
|
[HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void OnMouseUpAsButton(UIButton __instance)
|
public static void Postfix_OnMouseUpAsButton(UIButton __instance)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
if (__instance.transform.childCount >= 2)
|
||||||
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
{
|
||||||
StringStore.TranslateTextUI(text, false);
|
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
||||||
StringStore.TranslateTextUI(textShadow, false);
|
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
||||||
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
|
|
||||||
|
StringStore.TranslateTextUI(text, false);
|
||||||
|
StringStore.TranslateTextUI(textShadow, false);
|
||||||
|
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue