53 lines
2 KiB
C#
53 lines
2 KiB
C#
using HarmonyLib;
|
|
|
|
using TMPro;
|
|
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
|
|
using UnityEngine;
|
|
using UnityEngine.TextCore.Text;
|
|
using UnityEngine.UI;
|
|
|
|
namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
|
|
{
|
|
|
|
[HarmonyPatch(typeof(AbyssBagMenu))]
|
|
public static class AbyssBagMenu_Patch
|
|
{
|
|
public static GameObject ConvertToTextMeshProUGUI(GameObject originalText, Transform parent, string name)
|
|
{
|
|
GameObject newObj = new GameObject(name);
|
|
newObj.transform.position = originalText.transform.position;
|
|
newObj.AddComponent<CanvasRenderer>();
|
|
newObj.AddComponent<RectTransform>();
|
|
newObj.AddComponent<TextMeshProUGUI>();
|
|
newObj.transform.SetParent(parent);
|
|
newObj.transform.localScale = Vector3.one;
|
|
|
|
UnityEngine.Object.Destroy(originalText);
|
|
return newObj;
|
|
}
|
|
|
|
private static void ConvertButtonText(Transform original, string name)
|
|
{
|
|
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
|
|
|
Transform transform = original.FindChild(name);
|
|
Transform textTransform = transform.FindChild("text");
|
|
string text = textTransform.GetComponent<Text>().text;
|
|
Color color = textTransform.GetComponent<Text>().color;
|
|
|
|
TextMeshProUGUI newGoBackText = ConvertToTextMeshProUGUI(textTransform.gameObject, transform, "text2").GetComponent<TextMeshProUGUI>();
|
|
newGoBackText.autoSizeTextContainer = true;
|
|
newGoBackText.text = StringStore.TranslateText(text, false);
|
|
newGoBackText.font = fontAsset;
|
|
newGoBackText.color = color;
|
|
}
|
|
|
|
[HarmonyPatch(nameof(AbyssBagMenu.Awake))]
|
|
[HarmonyPostfix]
|
|
private static void MoveFromBag(AbyssCheckInBag __instance)
|
|
{
|
|
AbyssMenu2.Instance.UpdateIcons();
|
|
ConvertButtonText(__instance.transform, "Goback");
|
|
}
|
|
}
|
|
}
|