Merge branch 'cassidy'
This commit is contained in:
commit
4c5ade0ac5
2 changed files with 155 additions and 175 deletions
|
|
@ -17,6 +17,52 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
|||
[HarmonyPostfix]
|
||||
private static void InitNameAndInfoFromJson(AlmanacMgrZombie __instance)
|
||||
{
|
||||
TranslateTextAlmanac(__instance);
|
||||
DumpAlmanacModdedZombies(__instance);
|
||||
return;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AlmanacMgrZombie.OnMouseDown))]
|
||||
[HarmonyPrefix]
|
||||
private static bool OnMouseDown(AlmanacMgrZombie __instance)
|
||||
{
|
||||
TextMeshPro component = __instance.info.GetComponent<TextMeshPro>();
|
||||
if (component != null)
|
||||
{
|
||||
component.pageToDisplay = component.pageToDisplay > component.m_pageNumber ? 1 : component.pageToDisplay + 1;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPatch(typeof(AlmanacMgrZombie))]
|
||||
public static partial class AlmanacMgrZombie_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(AlmanacMgrZombie.OnMouseDown))]
|
||||
[HarmonyPostfix]
|
||||
public static void DumpAlmanacModdedZombies(AlmanacMgrZombie __instance)
|
||||
{
|
||||
// Dump the texts if needed using Ctrl key
|
||||
if (Input.GetKey(KeyCode.LeftControl))
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(__instance.info.GetComponent<TextMeshPro>().text);
|
||||
//Log.LogInfo($"Info: {__instance.info.GetComponent<TextMeshPro>().text}");
|
||||
FileLoader.DumpUntranslatedStrings(__instance.zombieName.GetComponent<TextMeshPro>().text);
|
||||
//Log.LogInfo($"Zombie Name: {__instance.zombieName.GetComponent<TextMeshPro>().text}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Patch to translate the modded almanac zombie names and info
|
||||
[HarmonyPatch(typeof(AlmanacMgrZombie))]
|
||||
public static partial class AlmanacMgrZombie_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(AlmanacMgrZombie.Start))]
|
||||
[HarmonyPostfix]
|
||||
public static void TranslateTextAlmanac(AlmanacMgrZombie __instance)
|
||||
{
|
||||
#if MULTI_LANGUAGE
|
||||
string currentLanguage = Utils.Language.ToString();
|
||||
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
||||
|
|
@ -131,84 +177,6 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
|||
Log.LogError($"Error parsing modded JSON in AlmanacMgrZombie_Patch: {ex.Message}");
|
||||
}
|
||||
}
|
||||
DumpAlmanacModdedZombies(__instance);
|
||||
return;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AlmanacMgrZombie.OnMouseDown))]
|
||||
[HarmonyPrefix]
|
||||
private static bool OnMouseDown(AlmanacMgrZombie __instance)
|
||||
{
|
||||
TextMeshPro component = __instance.info.GetComponent<TextMeshPro>();
|
||||
if (component != null)
|
||||
{
|
||||
component.pageToDisplay = component.pageToDisplay > component.m_pageNumber ? 1 : component.pageToDisplay + 1;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPatch(typeof(AlmanacMgrZombie))]
|
||||
public static partial class AlmanacMgrZombie_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(AlmanacMgrZombie.OnMouseDown))]
|
||||
[HarmonyPostfix]
|
||||
public static void DumpAlmanacModdedZombies(AlmanacMgrZombie __instance)
|
||||
{
|
||||
// Dump the texts if needed using Ctrl key
|
||||
if (Input.GetKey(KeyCode.LeftControl))
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(__instance.info.GetComponent<TextMeshPro>().text);
|
||||
//Log.LogInfo($"Info: {__instance.info.GetComponent<TextMeshPro>().text}");
|
||||
FileLoader.DumpUntranslatedStrings(__instance.zombieName.GetComponent<TextMeshPro>().text);
|
||||
//Log.LogInfo($"Zombie Name: {__instance.zombieName.GetComponent<TextMeshPro>().text}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Patch to translate the modded almanac zombie names and info
|
||||
[HarmonyPatch(typeof(AlmanacMgrZombie))]
|
||||
public static partial class AlmanacMgrZombie_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(AlmanacMgrZombie.Start))]
|
||||
[HarmonyPostfix]
|
||||
public static void TranslateTextAlmanac(AlmanacMgrZombie __instance)
|
||||
{
|
||||
string currentLanguage = Utils.Language.ToString();
|
||||
__instance.introduce.text = StringStore.TranslateText(__instance.introduce.text);
|
||||
__instance.introduce.font = FontStore.LoadTMPFont(currentLanguage);
|
||||
|
||||
DumpAlmanacModdedZombies(__instance);
|
||||
// translate all TMP components in info
|
||||
foreach (TextMeshPro text in __instance.info.GetComponentsInChildren<TextMeshPro>())
|
||||
{
|
||||
if (text != null)
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
text.name = StringStore.TranslateText(text.name);
|
||||
text.font = FontStore.LoadTMPFont(currentLanguage);
|
||||
}
|
||||
}
|
||||
foreach (TextMeshPro text in __instance.zombieName.GetComponentsInChildren<TextMeshPro>())
|
||||
{
|
||||
if (text != null)
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
text.name = StringStore.TranslateText(text.name);
|
||||
text.font = FontStore.LoadTMPFont(currentLanguage);
|
||||
}
|
||||
}
|
||||
|
||||
// Translate zombieName and its child
|
||||
__instance.zombieName.name = StringStore.TranslateText(__instance.zombieName.name);
|
||||
__instance.zombieName.GetComponent<TextMeshPro>().font = FontStore.LoadTMPFont(currentLanguage);
|
||||
__instance.zombieName.transform.GetChild(0).name = StringStore.TranslateText(__instance.zombieName.transform.GetChild(0).name);
|
||||
// Get both for less testing
|
||||
__instance.zombieName.GetComponent<TextMeshPro>().text = StringStore.TranslateText(__instance.zombieName.GetComponent<TextMeshPro>().text);
|
||||
__instance.zombieName.transform.GetChild(0).GetComponent<TextMeshPro>().text = StringStore.TranslateText(__instance.zombieName.transform.GetChild(0).GetComponent<TextMeshPro>().text);
|
||||
__instance.zombieName.transform.GetChild(0).GetComponent<TextMeshPro>().font = FontStore.LoadTMPFont(currentLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
using System.IO;
|
||||
using HarmonyLib;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime;
|
||||
using PvZ_Fusion_Translator__BepInEx_;
|
||||
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
|
||||
using System.IO;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TextCore.Text;
|
||||
using static PvZ_Fusion_Translator__BepInEx_.FileLoader;
|
||||
|
||||
namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
||||
|
|
@ -16,6 +17,39 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
|||
[HarmonyPostfix]
|
||||
public static void InitNameAndInfoFromJson(AlmanacPlantBank __instance)
|
||||
{
|
||||
TranslateTextAlmanac(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AlmanacPlantBank.OnMouseDown))]
|
||||
[HarmonyPrefix]
|
||||
private static bool OnMouseDown(AlmanacPlantBank __instance)
|
||||
{
|
||||
TranslateTextAlmanac(__instance);
|
||||
TextMeshPro component = __instance.introduce.GetComponent<TextMeshPro>();
|
||||
if (component != null)
|
||||
{
|
||||
component.pageToDisplay = component.pageToDisplay > component.m_pageNumber ? 1 : component.pageToDisplay + 1;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// This method is used to translate the text in the AlmanacPlantBank when it starts. And some plants like LibraHp plants have different text type in the Almanac.
|
||||
[HarmonyPatch(nameof(AlmanacPlantBank.Start))]
|
||||
[HarmonyPostfix]
|
||||
public static void TranslateTextAlmanac(AlmanacPlantBank __instance)
|
||||
{
|
||||
|
||||
// Dump the texts if needed
|
||||
if (Input.GetKey(KeyCode.LeftControl))
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(__instance.introduce.GetComponent<TextMeshPro>().text);
|
||||
//Log.LogInfo($"Info: {__instance.introduce.GetComponent<TextMeshPro>().text}");
|
||||
FileLoader.DumpUntranslatedStrings(__instance.plantName.GetComponent<TextMeshPro>().text);
|
||||
//Log.LogInfo($"PlantName Name: {__instance.plantName.GetComponent<TextMeshPro>().text}");
|
||||
//Log.LogInfo($"PlantShadow Name: {__instance.plantName.transform.GetChild(0).GetComponent<TextMeshPro>().text}");
|
||||
}
|
||||
|
||||
#if MULTI_LANGUAGE
|
||||
string currentLanguage = Utils.Language.ToString();
|
||||
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
||||
|
|
@ -154,35 +188,13 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AlmanacPlantBank.OnMouseDown))]
|
||||
[HarmonyPrefix]
|
||||
private static bool OnMouseDown(AlmanacPlantBank __instance)
|
||||
{
|
||||
TextMeshPro component = __instance.introduce.GetComponent<TextMeshPro>();
|
||||
if (component != null)
|
||||
{
|
||||
component.pageToDisplay = component.pageToDisplay > component.m_pageNumber ? 1 : component.pageToDisplay + 1;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AlmanacPlantBank.PVPInit))]
|
||||
[HarmonyPostfix]
|
||||
private static void PVPInit(AlmanacPlantBank __instance)
|
||||
{
|
||||
TextMeshPro component = __instance.introduce.GetComponent<TextMeshPro>();
|
||||
if (component != null)
|
||||
{
|
||||
string originalText = component.text;
|
||||
component.autoSizeTextContainer = false;
|
||||
component.text = StringStore.TranslateText(component.text);
|
||||
__instance.introduce.GetComponent<TextMeshPro>().text = component.text;
|
||||
}
|
||||
TranslateTextAlmanac(__instance);
|
||||
|
||||
Transform banTransform = __instance.transform.FindChild("Ban").GetChild(0);
|
||||
if (banTransform != null)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue