abyss button fixes

This commit is contained in:
SillyStar-Github 2025-04-27 15:23:32 -04:00
parent 2799304951
commit 4740ab6bc9
4 changed files with 88 additions and 0 deletions

View file

@ -4,6 +4,9 @@ using Il2CppTMPro;
using MelonLoader;
using PvZ_Fusion_Translator.AssetStore;
using UnityEngine;
using UnityEngine.TextCore.Text;
using UnityEngine.UI;
using static MelonLoader.MelonLogger;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
@ -49,12 +52,45 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
}
}
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(AbyssMenu2.Start))]
[HarmonyPostfix]
private static void Start(AbyssMenu2 __instance)
{
UpdateAbyss2Text(__instance);
ConvertButtonText(__instance.transform, "Goback");
ConvertButtonText(__instance.transform, "Help");
ConvertButtonText(__instance.transform, "Bag");
}
[HarmonyPatch(nameof(AbyssMenu2.UpdateIcons))]

View file

@ -6,12 +6,43 @@ using PvZ_Fusion_Translator.AssetStore;
using Unity.VisualScripting;
using UnityEngine;
using System.Text.RegularExpressions;
using UnityEngine.UI;
using MelonLoader.Utils;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
[HarmonyPatch(typeof(AbyssMenu))]
public static class AbyssMenu_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(AbyssMenu.Awake))]
[HarmonyPostfix]
@ -24,6 +55,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
txt.text = StringStore.TranslateText(txt.text, false);
txt.font = fontAsset;
}
ConvertButtonText(__instance.transform, "Goback");
}
[HarmonyPatch(nameof(AbyssMenu.UpdateLevelInfo))]

View file

@ -0,0 +1,18 @@
using HarmonyLib;
using Il2Cpp;
using Il2CppTMPro;
using PvZ_Fusion_Translator.AssetStore;
namespace PvZ_Fusion_Translator.Patches.GameObjects
{
[HarmonyPatch(typeof(AbyssStoreMenu))]
public static class AbyssStoreMenu_Patch
{
[HarmonyPatch(nameof(AbyssStoreMenu.Update))]
[HarmonyPostfix]
private static void UpdateInfo(AbyssStoreMenu __instance)
{
__instance.yourMoney.text = StringStore.TranslateText(__instance.yourMoney.text);
}
}
}

View file

@ -448,6 +448,7 @@
<Compile Include="Log.cs" />
<Compile Include="ModFeatures.cs" />
<Compile Include="AssetStore\AudioStore.cs" />
<Compile Include="Patches\GameObjects\AbyssStoreMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\AbyssSettlementMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssCheckSellMenu_Patch.cs" />
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssBuffButton_Patch.cs" />