3.2.1 version 1 code (no almanac keyword/formula search)
This commit is contained in:
parent
42f5667d57
commit
ade617e3e4
11 changed files with 234 additions and 109 deletions
|
|
@ -35,7 +35,7 @@ namespace PvZ_Fusion_Translator
|
|||
AudioStore.Init();
|
||||
FontStore.Init();
|
||||
Utils.RegisterPlantIndices();
|
||||
|
||||
//Utils.RegisterRecipeLinks();
|
||||
}
|
||||
|
||||
public override void OnLateInitializeMelon()
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using Unity.Collections;
|
|||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using static Il2Cpp.AlmanacPlantBank;
|
||||
using static PvZ_Fusion_Translator.FileLoader;
|
||||
using static PvZ_Fusion_Translator.Utils;
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
|||
public static bool SearchChanged(AlmanacPlantMenu __instance, ref TMP_InputField inputField)
|
||||
{
|
||||
string search = inputField.text;
|
||||
if (search != StringStore.TranslateText("搜索"))
|
||||
if (search != StringStore.TranslateText("搜索") && search != "")
|
||||
{
|
||||
string currentLanguage = Utils.Language.ToString();
|
||||
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
||||
|
|
@ -62,30 +63,12 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
|||
|
||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(currentLanguage);
|
||||
|
||||
AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
|
||||
PlantData plantData = JsonUtility.FromJson<PlantData>(json);
|
||||
|
||||
Il2CppSystem.Collections.Generic.List<PlantType> searchedPlants = new();
|
||||
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
||||
foreach (PlantInfo plantInfo in plantData.plants)
|
||||
{
|
||||
//List<int> uniqueIngredients = GetIngredients(plantInfo.seedType);
|
||||
|
||||
//// ingredient-based search
|
||||
|
||||
//foreach(int i in uniqueIngredients)
|
||||
//{
|
||||
// string name = Utils.GetPlantNameFromAlmanac((PlantType)i);
|
||||
|
||||
// if(name.ToLower().Contains(search.ToLower()))
|
||||
// {
|
||||
// searchedPlants.Add((PlantType)i);
|
||||
// }
|
||||
//}
|
||||
|
||||
// keyword-based search
|
||||
|
||||
// name-based search
|
||||
|
||||
if (plantInfo.name.ToLower().Contains(search.ToLower()))
|
||||
{
|
||||
searchedPlants.Add((PlantType)plantInfo.seedType);
|
||||
|
|
@ -99,65 +82,5 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static List<int> GetIngredients(int theSeedType)
|
||||
{
|
||||
List<int> ingredientPairs = new();
|
||||
Il2CppSystem.Array mixData = MixData.data.Cast<Il2CppSystem.Array>();
|
||||
int rows = mixData.GetLength(0);
|
||||
int columns = mixData.GetLength(1);
|
||||
|
||||
for(int i = 0; i < rows; i++)
|
||||
{
|
||||
for(int j = 0; j < columns; j++)
|
||||
{
|
||||
if(ContainsFormula(theSeedType))
|
||||
{
|
||||
if (mixData.GetValue(i, j).Unbox<int>() == theSeedType)
|
||||
{
|
||||
if (!ingredientPairs.Contains(i))
|
||||
{
|
||||
ingredientPairs.Add(i);
|
||||
}
|
||||
|
||||
if (!ingredientPairs.Contains(j))
|
||||
{
|
||||
ingredientPairs.Add(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ingredientPairs;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return ingredientPairs;
|
||||
}
|
||||
|
||||
private static bool ContainsFormula(int theSeedType)
|
||||
{
|
||||
bool contains = false;
|
||||
|
||||
Il2CppSystem.Array mixData = MixData.data.Cast<Il2CppSystem.Array>();
|
||||
int rows = mixData.GetLength(0);
|
||||
int columns = mixData.GetLength(1);
|
||||
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
for (int j = 0; j < columns; j++)
|
||||
{
|
||||
if (mixData.GetValue(i, j).Unbox<int>() == theSeedType)
|
||||
{
|
||||
contains = true;
|
||||
return contains;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return contains;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
|||
[HarmonyPatch(nameof(ExploreMakeZombieButton.Start))]
|
||||
public static void Start(ExploreMakeZombieButton __instance)
|
||||
{
|
||||
//__instance.sceneText.text = Utils.GetZombieNameFromAlmanac(__instance.theZombieType);
|
||||
//__instance.sceneText.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
}
|
||||
__instance.sceneText.text = Utils.GetZombieNameFromAlmanac(__instance.theZombieType);
|
||||
__instance.sceneText.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -41,5 +41,45 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))]
|
||||
[HarmonyPostfix]
|
||||
public static void Postfix_OnMouseUpAsButton(UIButton __instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (__instance.transform.childCount >= 2)
|
||||
{
|
||||
if (__instance.name == "EditMode")
|
||||
{
|
||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
|
||||
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
||||
TextMeshProUGUI[] extraTexts = __instance.transform.GetChild(1).GetComponentsInChildren<TextMeshProUGUI>();
|
||||
|
||||
text.text = StringStore.TranslateText(text.text, false);
|
||||
text.font = fontAsset;
|
||||
|
||||
foreach (TextMeshProUGUI extraText in extraTexts)
|
||||
{
|
||||
extraText.text = StringStore.TranslateText(extraText.text, false);
|
||||
extraText.font = fontAsset;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
||||
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
||||
|
||||
text.text = StringStore.TranslateText(text.text, false);
|
||||
textShadow.text = StringStore.TranslateText(textShadow.text, false);
|
||||
|
||||
text.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
textShadow.font = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
38
MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs
Normal file
38
MelonLoader/Patches/GameObjects/EveBuffMenu_Patch.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using HarmonyLib;
|
||||
using Il2Cpp;
|
||||
using Il2CppTMPro;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using UnityEngine;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||
{
|
||||
[HarmonyPatch(typeof(EveBuffMenu))]
|
||||
public static class EveBuffMenu_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(EveBuffMenu.Start))]
|
||||
[HarmonyPostfix]
|
||||
private static void Start(EveBuffMenu __instance)
|
||||
{
|
||||
foreach (EveOptionWindow window in __instance.windows)
|
||||
{
|
||||
EveOptionWindow_Patch.TranslateEveOptionWindow(window);
|
||||
}
|
||||
|
||||
foreach (TextMeshProUGUI text in __instance.quitButton.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
text.text = StringStore.TranslateText("合上");
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(EveBuffMenu.InitWindows))]
|
||||
[HarmonyPostfix]
|
||||
private static void InitWindows(EveBuffMenu __instance)
|
||||
{
|
||||
foreach(EveOptionWindow window in __instance.windows)
|
||||
{
|
||||
EveOptionWindow_Patch.TranslateEveOptionWindow(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
50
MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs
Normal file
50
MelonLoader/Patches/GameObjects/EveOptionWindow_Patch.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using HarmonyLib;
|
||||
using Il2Cpp;
|
||||
using Il2CppTMPro;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using UnityEngine;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||
{
|
||||
[HarmonyPatch(typeof(EveOptionWindow))]
|
||||
public static class EveOptionWindow_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(EveOptionWindow.SetType))]
|
||||
[HarmonyPostfix]
|
||||
private static void SetType(EveOptionWindow __instance)
|
||||
{
|
||||
TranslateEveOptionWindow(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(EveOptionWindow.OnAnimOver))]
|
||||
[HarmonyPostfix]
|
||||
private static void OnAnimOver(EveOptionWindow __instance)
|
||||
{
|
||||
TranslateEveOptionWindow(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(EveOptionWindow.SelectedByRow))]
|
||||
[HarmonyPostfix]
|
||||
private static void SelectedByRow(EveOptionWindow __instance)
|
||||
{
|
||||
TranslateEveOptionWindow(__instance);
|
||||
}
|
||||
|
||||
public static void TranslateEveOptionWindow(EveOptionWindow __instance)
|
||||
{
|
||||
Transform introduceTransform = __instance.transform.FindChild("Images").FindChild("Introduce");
|
||||
TextMeshProUGUI introduceText = introduceTransform.GetComponent<TextMeshProUGUI>();
|
||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
|
||||
introduceText.text = StringStore.TranslateText(introduceText.text);
|
||||
introduceText.font = fontAsset;
|
||||
|
||||
foreach (TextMeshProUGUI text in __instance.buttonText)
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
text.font = fontAsset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
|||
|
||||
string changelogText = File.ReadAllText(changelogDir);
|
||||
|
||||
GameObject contentObject = __instance.transform.FindChild("Scroll View").GetChild(0).GetChild(0).gameObject; //bc normal Find or FindChild didn't work
|
||||
GameObject contentObject = __instance.transform.FindChild("Scroll View/Viewport/Content").gameObject;
|
||||
|
||||
TextMeshProUGUI contentText = contentObject.GetComponent<TextMeshProUGUI>();
|
||||
contentText.text = changelogText;
|
||||
|
|
|
|||
37
MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs
Normal file
37
MelonLoader/Patches/GameObjects/PlantDamageMenu_Patch.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using HarmonyLib;
|
||||
using Il2Cpp;
|
||||
using Il2CppTMPro;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using UnityEngine;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||
{
|
||||
[HarmonyPatch(typeof(PlantDamageMenu))]
|
||||
public static class PlantDamageMenu_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(PlantDamageMenu.Awake))]
|
||||
[HarmonyPostfix]
|
||||
private static void Awake(PlantDamageMenu __instance)
|
||||
{
|
||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
text.font = fontAsset;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(PlantDamageMenu.InitCards))]
|
||||
[HarmonyPostfix]
|
||||
private static void InitCards(PlantDamageMenu __instance)
|
||||
{
|
||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
text.font = fontAsset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,24 +14,19 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
[HarmonyPostfix]
|
||||
public static void ChangeStringz(IZBottomMenu __instance)
|
||||
{
|
||||
TextMeshProUGUI[] array =
|
||||
[
|
||||
__instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>(),
|
||||
__instance.transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>(),
|
||||
];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
foreach(TextMeshProUGUI text in __instance.levelName)
|
||||
{
|
||||
string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"];
|
||||
string[] parts = array[i].text.Split(",推荐难度:");
|
||||
string[] parts = text.text.Split(",推荐难度:");
|
||||
|
||||
if(new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text))
|
||||
if(new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(text.text))
|
||||
{
|
||||
string customName = (StringStore.translationString.ContainsKey(parts[0] + "_IZ")) ? parts[0] + "_IZ" : parts[0];
|
||||
array[i].text = string.Format(fStr, StringStore.TranslateText(customName), parts[1]);
|
||||
text.text = string.Format(fStr, StringStore.TranslateText(customName), parts[1]);
|
||||
}
|
||||
|
||||
array[i] = StringStore.TranslateText(array[i]);
|
||||
array[i].text = array[i].text.Replace("\n", " ");
|
||||
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
text.text = text.text.Replace("\n", " ");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,23 +34,18 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
[HarmonyPostfix]
|
||||
public static void SetLevelName(IZBottomMenu __instance)
|
||||
{
|
||||
TextMeshProUGUI[] array =
|
||||
[
|
||||
__instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>(),
|
||||
__instance.transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>(),
|
||||
];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
foreach(TextMeshProUGUI text in __instance.levelName)
|
||||
{
|
||||
string fStr = StringStore.translationStringRegex["([^\\s]+),推荐难度:(\\d+)"];
|
||||
string[] parts = array[i].text.Split(",推荐难度:");
|
||||
string[] parts = text.text.Split(",推荐难度:");
|
||||
|
||||
if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(array[i].text))
|
||||
if (new Regex("([^\\s]+),推荐难度:(\\d+)").IsMatch(text.text))
|
||||
{
|
||||
array[i].text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]);
|
||||
text.text = string.Format(fStr, StringStore.TranslateText(parts[0]), parts[1]);
|
||||
}
|
||||
|
||||
array[i] = StringStore.TranslateText(array[i]);
|
||||
array[i].text = array[i].text.Replace("\n", " ");
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
text.text = text.text.Replace("\n", " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -406,6 +406,9 @@
|
|||
<Compile Include="Patches\GameObjects\AlmanacPlantMenu_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\AlmanacPlantWindow_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\Almanac_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\PlantDamageMenu_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\EveBuffMenu_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\EveOptionWindow_Patch.cs" />
|
||||
<Compile Include="Patches\Managers\GameAPP_Patch.cs" />
|
||||
<Compile Include="Patches\Managers\OppositeBuffManager_Patch.cs" />
|
||||
<Compile Include="Patches\GameObjects\ButtonObjects\ExploreMakeSceneButton_Patch.cs" />
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using PvZ_Fusion_Translator.AssetStore;
|
|||
using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
using Unity.Burst.Intrinsics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
using UnityEngine.UI;
|
||||
|
|
@ -299,6 +300,49 @@ namespace PvZ_Fusion_Translator
|
|||
}
|
||||
}
|
||||
|
||||
public static Dictionary<int, List<int>> recipeLinks = new Dictionary<int, List<int>>();
|
||||
|
||||
public static void RegisterRecipeLinks()
|
||||
{
|
||||
recipeLinks.Clear();
|
||||
|
||||
Il2CppSystem.Array mixData = MixData.data.Cast<Il2CppSystem.Array>();
|
||||
int rows = mixData.GetLength(0);
|
||||
int columns = mixData.GetLength(1);
|
||||
|
||||
foreach (PlantType plantType in Enum.GetValues(typeof(PlantType)))
|
||||
{
|
||||
int seedType = (int)plantType;
|
||||
|
||||
recipeLinks.Add(seedType, new());
|
||||
|
||||
if(seedType > 0)
|
||||
{
|
||||
foreach (PlantType checkType in Enum.GetValues(typeof(PlantType)))
|
||||
{
|
||||
if(checkType > 0)
|
||||
{
|
||||
int[] checks = [mixData.GetValue(seedType, (int)checkType).Unbox<int>(), mixData.GetValue((int)checkType, seedType).Unbox<int>()];
|
||||
|
||||
if (checks[0] != 0)
|
||||
{
|
||||
recipeLinks[seedType].Add(checks[0]);
|
||||
}
|
||||
|
||||
if (checks[1] != 0)
|
||||
{
|
||||
recipeLinks[seedType].Add(checks[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (recipeLinks[seedType].Count > 0)
|
||||
{
|
||||
Log.LogDebug($"Found {recipeLinks[seedType].Count} fusions for {seedType}!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckForUntranslatedText(string text)
|
||||
{
|
||||
Regex regex = new("\\p{IsCJKUnifiedIdeographs}+");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue