Merge branch 'cassidy'
This commit is contained in:
commit
72b5765926
11 changed files with 268 additions and 264 deletions
|
|
@ -13,7 +13,7 @@ using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[BepInPlugin("PVZFusionTranslator_BepInEx", "PvZ Fusion Translator", "2.8.1")]
|
[BepInPlugin("PVZFusionTranslator_BepInEx", "PvZ Fusion Translator", "3.0.1")]
|
||||||
[BepInProcess("PlantsVsZombiesRH.exe")]
|
[BepInProcess("PlantsVsZombiesRH.exe")]
|
||||||
public class Core : BasePlugin
|
public class Core : BasePlugin
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,15 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
|
||||||
{
|
{
|
||||||
[HarmonyPatch(nameof(AbyssBagMenu.Awake))]
|
[HarmonyPatch(nameof(AbyssBagMenu.Awake))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
private static void MoveFromBag(AbyssCheckInBag __instance)
|
private static void Awake_Post(AbyssCheckInBag __instance)
|
||||||
{
|
{
|
||||||
AbyssMenu2.Instance.UpdateIcons();
|
|
||||||
Utils.ConvertButtonText(__instance.transform, "Goback");
|
|
||||||
|
|
||||||
foreach (TextMeshProUGUI text in __instance.transform.FindChild("Background").GetComponentsInChildren<TextMeshProUGUI>())
|
foreach (TextMeshProUGUI text in __instance.transform.FindChild("Background").GetComponentsInChildren<TextMeshProUGUI>())
|
||||||
{
|
{
|
||||||
|
text.text = text.text + "_深渊";
|
||||||
text.text = StringStore.TranslateText("背包_深渊");
|
text.text = StringStore.TranslateText("背包_深渊");
|
||||||
text.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
text.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||||
}
|
}
|
||||||
|
AbyssMenu2.Instance.UpdateIcons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,11 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
|
||||||
UpdateAbyss2Text(__instance);
|
UpdateAbyss2Text(__instance);
|
||||||
|
|
||||||
Utils.ConvertButtonText(__instance.transform, "Help");
|
Utils.ConvertButtonText(__instance.transform, "Help");
|
||||||
|
|
||||||
|
// custom bag text :D
|
||||||
|
|
||||||
|
__instance.transform.FindChild("Bag").FindChild("text").GetComponent<Text>().text += "_深渊";
|
||||||
|
|
||||||
Utils.ConvertButtonText(__instance.transform, "Bag");
|
Utils.ConvertButtonText(__instance.transform, "Bag");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
|
||||||
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||||
{
|
{
|
||||||
string text = txt.text;
|
string text = txt.text;
|
||||||
Transform menuTransform = __instance.transform.parent.parent.parent.parent.parent.parent;
|
Transform menuTransform = __instance.transform.parent.parent.parent.parent.parent.parent; // guys i'm really sorry please forgive me
|
||||||
string customIZStringKey = StringStore.translationString.FirstOrDefault(x => x.Value == text).Key + "_IZ";
|
string customIZStringKey = StringStore.translationString.FirstOrDefault(x => x.Value == text).Key + "_IZ"; // dawg what the fuck
|
||||||
bool hasCustomIZString = StringStore.translationString.ContainsKey(customIZStringKey);
|
bool hasCustomIZString = StringStore.translationString.ContainsKey(customIZStringKey);
|
||||||
|
|
||||||
if (hasCustomIZString && menuTransform.name.Contains("IZMenu"))
|
if (hasCustomIZString && menuTransform.name.Contains("IZMenu"))
|
||||||
|
|
@ -31,6 +31,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
|
||||||
{
|
{
|
||||||
txt.text = StringStore.TranslateText(text);
|
txt.text = StringStore.TranslateText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
txt.font = fontAsset;
|
txt.font = fontAsset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,26 +6,26 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
|
||||||
[HarmonyPatch(typeof(MainMenu_Btn))]
|
[HarmonyPatch(typeof(MainMenu_Btn))]
|
||||||
public static class MainMenu_Btn_Patch
|
public static class MainMenu_Btn_Patch
|
||||||
{
|
{
|
||||||
[HarmonyPatch(nameof(MainMenu_Btn.OnMouseEnter))]
|
//[HarmonyPatch(nameof(MainMenu_Btn.OnMouseEnter))]
|
||||||
[HarmonyPostfix]
|
//[HarmonyPostfix]
|
||||||
private static void OnMouseEnter(MainMenu_Btn __instance)
|
//private static void OnMouseEnter(MainMenu_Btn __instance)
|
||||||
{
|
//{
|
||||||
string textToShow = null;
|
// string textToShow = null;
|
||||||
|
|
||||||
if (__instance.transform.parent.name == "recipe")
|
// if (__instance.transform.parent.name == "recipe")
|
||||||
{
|
// {
|
||||||
textToShow = "探索模式";
|
// textToShow = "探索模式";
|
||||||
}
|
// }
|
||||||
else if (__instance.name == "mysterious")
|
// else if (__instance.name == "mysterious")
|
||||||
{
|
// {
|
||||||
textToShow = "神秘模式";
|
// textToShow = "神秘模式";
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (textToShow != null)
|
// if (textToShow != null)
|
||||||
{
|
// {
|
||||||
InGameText.Instance.ShowText(textToShow, 2.0f);
|
// InGameText.Instance.ShowText(textToShow, 2.0f);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void UpdateHealthText(TrainingDummy __instance)
|
public static void UpdateHealthText(TrainingDummy __instance)
|
||||||
{
|
{
|
||||||
Zombie_Patch.TranslateHpUI(__instance.healthText, null);
|
Zombie_Patch.TranslateHpUI_T(__instance.healthText, __instance);
|
||||||
Zombie_Patch.TranslateHpUI(__instance.healthTextShadow, null);
|
Zombie_Patch.TranslateHpUI_T(__instance.healthTextShadow, __instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,6 +17,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects
|
||||||
{ "最后一击:(\\d+)\nDPS:([^\\s]+)\n总伤害:(\\d+)", "Last Damage: {0}\nDPS: {1}\nTotal: {2}" },
|
{ "最后一击:(\\d+)\nDPS:([^\\s]+)\n总伤害:(\\d+)", "Last Damage: {0}\nDPS: {1}\nTotal: {2}" },
|
||||||
{ "^HP:(\\d+)/(\\d+)\n一类:(\\d+)/(\\d+)\n二类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}\nType 2 armor: {4}/{5}" },
|
{ "^HP:(\\d+)/(\\d+)\n一类:(\\d+)/(\\d+)\n二类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}\nType 2 armor: {4}/{5}" },
|
||||||
{ "^HP:(\\d+)/(\\d+)\n一类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}" },
|
{ "^HP:(\\d+)/(\\d+)\n一类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 1 armor: {2}/{3}" },
|
||||||
|
{ "^HP:(\\d+)/(\\d+)\n二类:(\\d+)/(\\d+)$", "HP: {0}/{1}\nType 2 armor: {2}/{3}" },
|
||||||
{ "^HP:(\\d+)/(\\d+)$", "HP: {0}/{1}" },
|
{ "^HP:(\\d+)/(\\d+)$", "HP: {0}/{1}" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -31,13 +32,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void Start(Zombie __instance)
|
public static void Start(Zombie __instance)
|
||||||
{
|
{
|
||||||
TranslateHpUI(__instance.healthText);
|
TranslateHpUI(__instance.healthText, __instance);
|
||||||
TranslateHpUI(__instance.healthTextShadow);
|
TranslateHpUI(__instance.healthTextShadow, __instance);
|
||||||
if (__instance.theFirstArmorHealth == 0 && __instance.theSecondArmorHealth != 0)
|
|
||||||
{
|
|
||||||
__instance.healthText.text = __instance.healthText.text.Replace("Type 1", "Type 2");
|
|
||||||
__instance.healthTextShadow.text = __instance.healthText.text.Replace("Type 1", "Type 2");
|
|
||||||
}
|
|
||||||
if (__instance.healthText.transform.rotation != Quaternion.Euler(0, 0, 0))
|
if (__instance.healthText.transform.rotation != Quaternion.Euler(0, 0, 0))
|
||||||
__instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
__instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
||||||
}
|
}
|
||||||
|
|
@ -48,23 +45,19 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects
|
||||||
{
|
{
|
||||||
if (__instance.theZombieType == ZombieType.TrainingDummy || !Board.Instance.showZombieHealth)
|
if (__instance.theZombieType == ZombieType.TrainingDummy || !Board.Instance.showZombieHealth)
|
||||||
return;
|
return;
|
||||||
TranslateHpUI(__instance.healthText);
|
TranslateHpUI(__instance.healthText, __instance);
|
||||||
TranslateHpUI(__instance.healthTextShadow);
|
TranslateHpUI(__instance.healthTextShadow, __instance);
|
||||||
if (__instance.theFirstArmorHealth == 0 && __instance.theSecondArmorHealth != 0)
|
|
||||||
{
|
|
||||||
__instance.healthText.text = __instance.healthText.text.Replace("Type 1", "Type 2");
|
|
||||||
__instance.healthTextShadow.text = __instance.healthText.text.Replace("Type 1", "Type 2");
|
|
||||||
}
|
|
||||||
if (__instance.healthText.transform.rotation != Quaternion.Euler(0f, 0f, 0f))
|
if (__instance.healthText.transform.rotation != Quaternion.Euler(0f, 0f, 0f))
|
||||||
__instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
__instance.healthText.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TranslateHpUI(TextMeshPro textTMP, Zombie __instance = null)
|
public static void TranslateHpUI(TextMeshPro textTMP, Zombie __instance)
|
||||||
{
|
{
|
||||||
if (textTMP)
|
if (textTMP)
|
||||||
{
|
{
|
||||||
string origText = textTMP.text;
|
string origText = textTMP.text;
|
||||||
string translatedText = __instance == null ? TranslateHPText(origText) : TranslateHPText(origText, __instance);
|
string translatedText = TranslateHPText(origText, __instance);
|
||||||
textTMP.text = translatedText == origText ? origText : translatedText;
|
textTMP.text = translatedText == origText ? origText : translatedText;
|
||||||
textTMP.autoSizeTextContainer = false;
|
textTMP.autoSizeTextContainer = false;
|
||||||
if (translatedText != origText)
|
if (translatedText != origText)
|
||||||
|
|
@ -72,30 +65,95 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.MinorObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string TranslateHPText(string originalText)
|
public static void TranslateHpUI_T(TextMeshPro textTMP, TrainingDummy __instance)
|
||||||
{
|
{
|
||||||
foreach (var entry in HPStrings)
|
if (textTMP)
|
||||||
{
|
{
|
||||||
var regex = new Regex(entry.Key);
|
string origText = textTMP.text;
|
||||||
|
string translatedText = TranslateHPText_T(origText, __instance);
|
||||||
|
textTMP.text = translatedText == origText ? origText : translatedText;
|
||||||
|
textTMP.autoSizeTextContainer = false;
|
||||||
|
if (translatedText != origText)
|
||||||
|
textTMP.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string TranslateHPText(string originalText, Zombie __instance)
|
||||||
|
{
|
||||||
|
string finalText = __instance.healthText.text;
|
||||||
|
int fIndex = -1;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < HPStrings.Count; i++)
|
||||||
|
{
|
||||||
|
var hp = HPStrings.ElementAt(i);
|
||||||
|
Regex regex = new Regex(hp.Key);
|
||||||
if (regex.IsMatch(originalText))
|
if (regex.IsMatch(originalText))
|
||||||
{
|
{
|
||||||
var match = regex.Match(originalText);
|
fIndex = i;
|
||||||
int groupCount = match.Groups.Count;
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<string> dynamicParts = new List<string>();
|
if (fIndex > -1 && found)
|
||||||
|
|
||||||
for (int i = 1; i < groupCount; i++)
|
|
||||||
{
|
{
|
||||||
string groupValue = match.Groups[i].Value;
|
string fStr = HPStrings.ElementAt(fIndex).Value;
|
||||||
string translatedValue = StringStore.translationString.ContainsKey(groupValue)
|
|
||||||
? StringStore.translationString[groupValue]
|
switch (fIndex)
|
||||||
: groupValue;
|
{
|
||||||
dynamicParts.Add(translatedValue);
|
case 1:
|
||||||
}
|
finalText = string.Format(fStr, __instance.theHealth, __instance.theMaxHealth, __instance.theFirstArmorHealth, __instance.theFirstArmorMaxHealth, __instance.theSecondArmorHealth, __instance.theSecondArmorMaxHealth);
|
||||||
return originalText = string.Format(entry.Value, [.. dynamicParts]);
|
break;
|
||||||
|
case 2:
|
||||||
|
finalText = string.Format(fStr, __instance.theHealth, __instance.theMaxHealth, __instance.theFirstArmorHealth, __instance.theFirstArmorMaxHealth);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
finalText = string.Format(fStr, __instance.theHealth, __instance.theMaxHealth, __instance.theSecondArmorHealth, __instance.theSecondArmorMaxHealth);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
finalText = string.Format(fStr, __instance.theHealth, __instance.theMaxHealth);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return originalText;
|
|
||||||
|
return finalText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string TranslateHPText_T(string originalText, TrainingDummy __instance)
|
||||||
|
{
|
||||||
|
string finalText = __instance.healthText.text;
|
||||||
|
int fIndex = -1;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < HPStrings.Count; i++)
|
||||||
|
{
|
||||||
|
var hp = HPStrings.ElementAt(i);
|
||||||
|
Regex regex = new Regex(hp.Key);
|
||||||
|
if (regex.IsMatch(originalText))
|
||||||
|
{
|
||||||
|
fIndex = i;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fIndex > -1 && found)
|
||||||
|
{
|
||||||
|
string fStr = HPStrings.ElementAt(fIndex).Value;
|
||||||
|
string DPS = originalText.Split("\n")[1].Replace("DPS:", "");
|
||||||
|
|
||||||
|
switch (fIndex)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
finalText = string.Format(fStr, __instance.lastDamage, DPS, __instance.totalDamage);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string TranslateHPText(string originalText, Zombie __instance)
|
public static string TranslateHPText(string originalText, Zombie __instance)
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
|
||||||
private static void Update(TravelStore __instance)
|
private static void Update(TravelStore __instance)
|
||||||
{
|
{
|
||||||
foreach (TextMeshProUGUI intr in __instance.introduces)
|
foreach (TextMeshProUGUI intr in __instance.introduces)
|
||||||
StringStore.TranslateTextUI(intr);
|
intr.text = StringStore.TranslateText(intr.text);
|
||||||
foreach (var textMesh in __instance.points)
|
foreach (var textMesh in __instance.points)
|
||||||
StringStore.TranslateTextUI(textMesh);
|
textMesh.text = StringStore.TranslateText(textMesh.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(nameof(TravelStore.RefreshBuff))]
|
[HarmonyPatch(nameof(TravelStore.RefreshBuff))]
|
||||||
|
|
@ -27,7 +27,7 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects
|
||||||
foreach (TravelBuff buff in __instance.travelBuffs)
|
foreach (TravelBuff buff in __instance.travelBuffs)
|
||||||
{
|
{
|
||||||
TextMeshProUGUI cost = buff.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
TextMeshProUGUI cost = buff.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
||||||
StringStore.TranslateTextUI(cost);
|
cost.text = StringStore.TranslateText(cost.text);
|
||||||
cost.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
cost.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||||
FileLoader.DumpUntranslatedStrings(cost.text);
|
FileLoader.DumpUntranslatedStrings(cost.text);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
||||||
];
|
];
|
||||||
for (int i = 0; i < array.Length; i++)
|
for (int i = 0; i < array.Length; i++)
|
||||||
{
|
{
|
||||||
string pattern = "([^\\s]+),推荐难度:(\\d+)";
|
string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"];
|
||||||
string[] parts = array[i].text.Split(",推荐难度:");
|
string[] parts = array[i].text.Split(",推荐难度:");
|
||||||
|
|
||||||
if (new Regex(pattern).IsMatch(array[i].text))
|
if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text))
|
||||||
{
|
{
|
||||||
if (StringStore.translationStringRegex.TryGetValue(pattern, out string fmt))
|
array[i].text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]);
|
||||||
{
|
|
||||||
array[i].text = string.Format(fmt, StringStore.TranslateText(parts[0]), parts[1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
array[i] = StringStore.TranslateText(array[i]);
|
array[i] = StringStore.TranslateText(array[i]);
|
||||||
|
|
@ -48,15 +45,12 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
||||||
];
|
];
|
||||||
for (int i = 0; i < array.Length; i++)
|
for (int i = 0; i < array.Length; i++)
|
||||||
{
|
{
|
||||||
string pattern = "([^\\s]+),推荐难度:(\\d+)";
|
string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"];
|
||||||
string[] parts = array[i].text.Split(",推荐难度:");
|
string[] parts = array[i].text.Split(",推荐难度:");
|
||||||
|
|
||||||
if (new Regex(pattern).IsMatch(array[i].text))
|
if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text))
|
||||||
{
|
{
|
||||||
if (StringStore.translationStringRegex.TryGetValue(pattern, out string fmt))
|
array[i].text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]);
|
||||||
{
|
|
||||||
array[i].text = string.Format(fmt, StringStore.TranslateText(parts[0]), parts[1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
array[i] = StringStore.TranslateText(array[i]);
|
array[i] = StringStore.TranslateText(array[i]);
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
||||||
for (int i = 0; i < array2.Length; i++)
|
for (int i = 0; i < array2.Length; i++)
|
||||||
{
|
{
|
||||||
array2[i].text = array2[i].text.Replace("\n", " ");
|
array2[i].text = array2[i].text.Replace("\n", " ");
|
||||||
|
|
||||||
Regex checkFusionChallenge = new Regex("^超级([^\\s:]+)(:?挑战1?)");
|
Regex checkFusionChallenge = new Regex("^超级([^\\s:]+)(:?挑战1?)");
|
||||||
|
|
||||||
if (array2[i].text.Contains("配方:") && !checkFusionChallenge.IsMatch(array2[i].text))
|
if (array2[i].text.Contains("配方:") && !checkFusionChallenge.IsMatch(array2[i].text))
|
||||||
|
|
@ -48,101 +47,5 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.Managers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(nameof(InGameUI.Update))]
|
|
||||||
[HarmonyPostfix]
|
|
||||||
private static void Update(InGameUI __instance)
|
|
||||||
{
|
|
||||||
ApplyShovelBankTranslations(__instance.transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void ApplyShovelBankTranslations(Transform root)
|
|
||||||
{
|
|
||||||
var shovelBank = root.Find("ShovelBank");
|
|
||||||
if (!shovelBank) return;
|
|
||||||
|
|
||||||
string currentLanguage = Utils.Language.ToString();
|
|
||||||
var fontAsset = FontStore.LoadTMPFont(currentLanguage);
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < shovelBank.childCount; i++)
|
|
||||||
{
|
|
||||||
var child = shovelBank.GetChild(i);
|
|
||||||
var tmp = child.GetComponent<TextMeshProUGUI>();
|
|
||||||
if (tmp == null) continue;
|
|
||||||
|
|
||||||
string orig = tmp.text;
|
|
||||||
string translated = StringStore.TranslateText(orig, false);
|
|
||||||
if (translated != orig)
|
|
||||||
{
|
|
||||||
tmp.text = translated;
|
|
||||||
if (fontAsset != null) tmp.font = fontAsset;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (fontAsset != null) tmp.font = fontAsset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(InGameUI_IZ))]
|
|
||||||
public static class InGameUI_IZ_Patch
|
|
||||||
{
|
|
||||||
[HarmonyPatch(nameof(InGameUI_IZ.Awake))]
|
|
||||||
[HarmonyPostfix]
|
|
||||||
private static void Awake(InGameUI_IZ __instance)
|
|
||||||
{
|
|
||||||
TextMeshProUGUI[] array = new TextMeshProUGUI[]
|
|
||||||
{
|
|
||||||
__instance.transform.GetChild(4).GetComponent<TextMeshProUGUI>(),
|
|
||||||
__instance.transform.GetChild(4).GetChild(0).GetComponent<TextMeshProUGUI>(),
|
|
||||||
__instance.transform.GetChild(5).GetComponent<TextMeshProUGUI>(),
|
|
||||||
__instance.transform.GetChild(5).GetChild(0).GetComponent<TextMeshProUGUI>(),
|
|
||||||
__instance.transform.GetChild(6).GetComponent<TextMeshProUGUI>(),
|
|
||||||
__instance.transform.GetChild(6).GetChild(0).GetComponent<TextMeshProUGUI>()};
|
|
||||||
TextMeshProUGUI[] array2 = array;
|
|
||||||
for (int i = 0; i < array2.Length; i++)
|
|
||||||
{
|
|
||||||
array2[i] = StringStore.TranslateText(array2[i]);
|
|
||||||
array2[i].text = array2[i].text.Replace("\n", " ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// [HarmonyPatch(nameof(InGameUI_IZ.Update))]
|
|
||||||
// [HarmonyPostfix]
|
|
||||||
// private static void Update(InGameUI_IZ __instance)
|
|
||||||
// {
|
|
||||||
// ApplyShovelBankTranslations(__instance.transform);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static void ApplyShovelBankTranslations(Transform root)
|
|
||||||
// {
|
|
||||||
// var shovelBank = root.Find("ShovelBank");
|
|
||||||
// if (!shovelBank) return;
|
|
||||||
|
|
||||||
// string currentLanguage = Utils.Language.ToString();
|
|
||||||
// var fontAsset = FontStore.LoadTMPFont(currentLanguage);
|
|
||||||
|
|
||||||
|
|
||||||
// for (int i = 0; i < shovelBank.childCount; i++)
|
|
||||||
// {
|
|
||||||
// var child = shovelBank.GetChild(i);
|
|
||||||
// var tmp = child.GetComponent<TextMeshProUGUI>();
|
|
||||||
// if (tmp == null) continue;
|
|
||||||
|
|
||||||
// string orig = tmp.text;
|
|
||||||
// string translated = StringStore.TranslateText(orig, false);
|
|
||||||
// if (translated != orig)
|
|
||||||
// {
|
|
||||||
// tmp.text = translated;
|
|
||||||
// if (fontAsset != null) tmp.font = fontAsset;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// if (fontAsset != null) tmp.font = fontAsset;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
144
BepInEx/Utils.cs
144
BepInEx/Utils.cs
|
|
@ -1,4 +1,8 @@
|
||||||
using System;
|
using BepInEx;
|
||||||
|
using BepInEx.Configuration;
|
||||||
|
using PvZ_Fusion_Translator__BepInEx_.AssetStore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
@ -10,8 +14,8 @@ using Unity.VisualScripting.FullSerializer;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Experimental.Rendering;
|
using UnityEngine.Experimental.Rendering;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using static AlmanacPlantBank;
|
||||||
using static PvZ_Fusion_Translator__BepInEx_.FileLoader;
|
using static PvZ_Fusion_Translator__BepInEx_.FileLoader;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator__BepInEx_
|
namespace PvZ_Fusion_Translator__BepInEx_
|
||||||
{
|
{
|
||||||
|
|
@ -166,51 +170,6 @@ namespace PvZ_Fusion_Translator__BepInEx_
|
||||||
newGoBackText.color = color;
|
newGoBackText.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static string GetPlantNameFromAlmanac(PlantType thePlantType)
|
|
||||||
//{
|
|
||||||
// string json;
|
|
||||||
// string thePlantName = "";
|
|
||||||
|
|
||||||
// string currentLanguage = Utils.Language.ToString();
|
|
||||||
// string almanacDir = FileLoader.GetAssetDir(FileLoader.AssetType.Almanac, Utils.Language);
|
|
||||||
// string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
|
|
||||||
// string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json");
|
|
||||||
|
|
||||||
// if (!File.Exists(path))
|
|
||||||
// {
|
|
||||||
// Log.LogError($"LawnStringsTranslate.json file not found at path: {path}");
|
|
||||||
// Log.LogError("Plant name could not be found! (Big Garden)");
|
|
||||||
// thePlantName = "";
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// json = File.ReadAllText(path);
|
|
||||||
// AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
|
|
||||||
// if (plantData != null && plantData.plants != null)
|
|
||||||
// {
|
|
||||||
// foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
|
||||||
// {
|
|
||||||
// if (plantInfo.seedType == (int)thePlantType)
|
|
||||||
// {
|
|
||||||
// // Remove any ID numbers from the name (e.g., "Peashooter (0)" -> "Peashooter", "Peashooter26" -> "Peashooter")
|
|
||||||
// // thePlantName = System.Text.RegularExpressions.Regex.Replace(plantInfo.name, @"\s*\(\d+\)$|\d+$", "");
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch (System.Exception ex)
|
|
||||||
// {
|
|
||||||
// Log.LogError($"Error parsing JSON in GetPlantNameFromAlmanac: {ex.Message}");
|
|
||||||
// thePlantName = "";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return thePlantName;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static string GetPlantNameFromAlmanac(PlantType thePlantType)
|
public static string GetPlantNameFromAlmanac(PlantType thePlantType)
|
||||||
{
|
{
|
||||||
string json;
|
string json;
|
||||||
|
|
@ -219,12 +178,11 @@ namespace PvZ_Fusion_Translator__BepInEx_
|
||||||
string currentLanguage = Utils.Language.ToString();
|
string currentLanguage = Utils.Language.ToString();
|
||||||
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
||||||
string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
|
string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
|
||||||
string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json");
|
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
Log.LogError($"LawnStringsTranslate.json file not found at path: {path}");
|
Log.LogError($"LawnStringsTranslate.json file not found at path: {path}");
|
||||||
Log.LogError("Plant name could not be found! (Big Garden)");
|
Log.LogError("Plant name could not be found!");
|
||||||
thePlantName = "";
|
thePlantName = "";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -250,6 +208,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
|
||||||
string translatedJson;
|
string translatedJson;
|
||||||
string thePlantName = "";
|
string thePlantName = "";
|
||||||
|
|
||||||
|
string currentLanguage = Utils.Language.ToString();
|
||||||
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
||||||
string dumpDir = GetAssetDir(AssetType.Dumps);
|
string dumpDir = GetAssetDir(AssetType.Dumps);
|
||||||
string originalPath = Path.Combine(dumpDir, "LawnStrings.json");
|
string originalPath = Path.Combine(dumpDir, "LawnStrings.json");
|
||||||
|
|
@ -258,6 +217,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
|
||||||
if ((!File.Exists(path)) || (!File.Exists(originalPath)))
|
if ((!File.Exists(path)) || (!File.Exists(originalPath)))
|
||||||
{
|
{
|
||||||
Log.LogError($"LawnStringsTranslate.json file not found at path: {path}");
|
Log.LogError($"LawnStringsTranslate.json file not found at path: {path}");
|
||||||
|
Log.LogError("Plant name could not be found!");
|
||||||
thePlantName = "";
|
thePlantName = "";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -271,7 +231,7 @@ namespace PvZ_Fusion_Translator__BepInEx_
|
||||||
|
|
||||||
for (int i = 0; i < originalPlantData.plants.Count; i++)
|
for (int i = 0; i < originalPlantData.plants.Count; i++)
|
||||||
{
|
{
|
||||||
var originalPlantInfo = originalPlantData.plants[i];
|
AlmanacPlantBank.PlantInfo originalPlantInfo = originalPlantData.plants[i];
|
||||||
KeyValuePair<int, string> translatedPlantInfo = plantIndices[originalPlantInfo.seedType];
|
KeyValuePair<int, string> translatedPlantInfo = plantIndices[originalPlantInfo.seedType];
|
||||||
|
|
||||||
if (originalPlantInfo.name == theOriginalPlantName)
|
if (originalPlantInfo.name == theOriginalPlantName)
|
||||||
|
|
@ -291,6 +251,90 @@ namespace PvZ_Fusion_Translator__BepInEx_
|
||||||
return thePlantName;
|
return thePlantName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetZombieNameFromAlmanac(ZombieType theZombieType)
|
||||||
|
{
|
||||||
|
string json;
|
||||||
|
string theZombieName = "";
|
||||||
|
|
||||||
|
string currentLanguage = Utils.Language.ToString();
|
||||||
|
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
||||||
|
string path = Path.Combine(almanacDir, "ZombieStringsTranslate.json");
|
||||||
|
|
||||||
|
if (!File.Exists(path))
|
||||||
|
{
|
||||||
|
Log.LogError($"ZombieStringsTranslate.json file not found at path: {path}");
|
||||||
|
Log.LogError("Zombie name could not be found!");
|
||||||
|
theZombieName = "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
json = File.ReadAllText(path);
|
||||||
|
AlmanacMgrZombie.ZombieAlmanacData zombieData = JsonUtility.FromJson<AlmanacMgrZombie.ZombieAlmanacData>(json);
|
||||||
|
|
||||||
|
foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in zombieData.zombies)
|
||||||
|
{
|
||||||
|
if ((int)zombieInfo.theZombieType == (int)theZombieType)
|
||||||
|
{
|
||||||
|
theZombieName = zombieInfo.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return theZombieName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dictionary<int, KeyValuePair<int, string>> plantIndices = new Dictionary<int, KeyValuePair<int, string>>();
|
||||||
|
|
||||||
|
public static void RegisterPlantIndices()
|
||||||
|
{
|
||||||
|
plantIndices = new Dictionary<int, KeyValuePair<int, string>>();
|
||||||
|
string originalJson;
|
||||||
|
string translatedJson;
|
||||||
|
|
||||||
|
string currentLanguage = Utils.Language.ToString();
|
||||||
|
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
||||||
|
string dumpDir = GetAssetDir(AssetType.Dumps);
|
||||||
|
string originalPath = Path.Combine(dumpDir, "LawnStrings.json");
|
||||||
|
string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
|
||||||
|
|
||||||
|
if ((!File.Exists(path)))
|
||||||
|
{
|
||||||
|
Log.LogError($"LawnStringsTranslate.json file not found at path: {path}");
|
||||||
|
}
|
||||||
|
else if ((!File.Exists(originalPath)))
|
||||||
|
{
|
||||||
|
Log.LogError($"LawnStrings.json file not found at path: {originalPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
originalJson = File.ReadAllText(originalPath);
|
||||||
|
translatedJson = File.ReadAllText(path);
|
||||||
|
AlmanacPlantBank.PlantData originalPlantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(originalJson);
|
||||||
|
AlmanacPlantBank.PlantData translatedPlantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(translatedJson);
|
||||||
|
|
||||||
|
for (int i = 0; i < originalPlantData.plants.Count; i++)
|
||||||
|
{
|
||||||
|
PlantInfo originalPlantInfo = originalPlantData.plants[i];
|
||||||
|
PlantInfo translatedPlantInfo = null;
|
||||||
|
|
||||||
|
foreach (PlantInfo info in translatedPlantData.plants)
|
||||||
|
{
|
||||||
|
if (info.seedType == originalPlantInfo.seedType)
|
||||||
|
{
|
||||||
|
translatedPlantInfo = info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (translatedPlantInfo != null)
|
||||||
|
{
|
||||||
|
KeyValuePair<int, string> temp = new KeyValuePair<int, string>(translatedPlantInfo.seedType, translatedPlantInfo.name);
|
||||||
|
plantIndices.Add(originalPlantInfo.seedType, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static bool CheckForUntranslatedText(string text)
|
public static bool CheckForUntranslatedText(string text)
|
||||||
{
|
{
|
||||||
Regex regex = new("\\p{IsCJKUnifiedIdeographs}+");
|
Regex regex = new("\\p{IsCJKUnifiedIdeographs}+");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue