Merge pull request #1 from Teyliu/Dyna
Added new Back to Index button for Adventure: Snow | Modded almanac support
This commit is contained in:
commit
4fd61ab9a8
5 changed files with 126 additions and 33 deletions
|
|
@ -94,6 +94,14 @@ namespace PvZ_Fusion_Translator__BepInEx_.Patches.GameObjects.ButtonObjects
|
|||
StringStore.TranslateTextTransform(pageScaryPotTransform.Find("Nextpage"));
|
||||
StringStore.TranslateTextTransform(pageScaryPotTransform.Find("LastPage"));
|
||||
}
|
||||
|
||||
Transform pageNewAdvantureLevelTransform = levelTransform.transform.Find("PageNewAdvantureLevel");
|
||||
if (pageNewAdvantureLevelTransform != null)
|
||||
{
|
||||
StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("BackToIndex"));
|
||||
StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("Nextpage"));
|
||||
StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("LastPage"));
|
||||
}
|
||||
}
|
||||
|
||||
StringStore.TranslateTextTransform(parentTransform.Find("CameraSize"));
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using Il2Cpp;
|
||||
using MelonLoader;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using PvZ_Fusion_Translator.Patches.OtherManagers;
|
||||
using System.Text.Encodings.Web;
|
||||
|
|
@ -301,12 +300,17 @@ namespace PvZ_Fusion_Translator
|
|||
}
|
||||
|
||||
string json = File.ReadAllText(jsonFile);
|
||||
JObject untranslatedStrings = JObject.Parse(json);
|
||||
var untranslatedStrings = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
|
||||
|
||||
if (!untranslatedStrings.ContainsKey(text))
|
||||
{
|
||||
untranslatedStrings[text] = text;
|
||||
File.WriteAllText(jsonFile, untranslatedStrings.ToString());
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
WriteIndented = true
|
||||
};
|
||||
File.WriteAllText(jsonFile, JsonSerializer.Serialize(untranslatedStrings, options));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -94,6 +94,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
|||
StringStore.TranslateTextTransform(pageScaryPotTransform.Find("Nextpage"));
|
||||
StringStore.TranslateTextTransform(pageScaryPotTransform.Find("LastPage"));
|
||||
}
|
||||
|
||||
Transform pageNewAdvantureLevelTransform = levelTransform.transform.Find("PageNewAdvantureLevel");
|
||||
if (pageNewAdvantureLevelTransform != null)
|
||||
{
|
||||
StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("BackToIndex"));
|
||||
StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("Nextpage"));
|
||||
StringStore.TranslateTextTransform(pageNewAdvantureLevelTransform.Find("LastPage"));
|
||||
}
|
||||
}
|
||||
|
||||
StringStore.TranslateTextTransform(parentTransform.Find("CameraSize"));
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
using Il2Cpp;
|
||||
using Il2CppTMPro;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using static PvZ_Fusion_Translator.FileLoader;
|
||||
using UnityEngine;
|
||||
using static PvZ_Fusion_Translator.FileLoader;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.Managers
|
||||
{
|
||||
|
|
@ -11,8 +11,8 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
public static partial class AlmanacMgrZombie_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(AlmanacMgrZombie.InitNameAndInfoFromJson))]
|
||||
[HarmonyPrefix]
|
||||
private static bool InitNameAndInfoFromJson(AlmanacMgrZombie __instance)
|
||||
[HarmonyPostfix]
|
||||
private static void InitNameAndInfoFromJson(AlmanacMgrZombie __instance)
|
||||
{
|
||||
#if MULTI_LANGUAGE
|
||||
string currentLanguage = Utils.Language.ToString();
|
||||
|
|
@ -22,11 +22,12 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
string currentLanguage = "English";
|
||||
#endif
|
||||
string path = Path.Combine(almanacDir, "ZombieStringsTranslate.json");
|
||||
string moddedPath = Path.Combine(almanacDir, "ModdedZombiesTranslate.json");
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
Log.LogError($"ZombieStringsTranslate.json file not found at path: {path}");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
#if OBFUSCATE
|
||||
|
|
@ -77,12 +78,38 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
component.font = fontAsset;
|
||||
component2.font = fontAsset;
|
||||
component3.font = fontAsset;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
if (File.Exists(moddedPath))
|
||||
{
|
||||
string moddedJson;
|
||||
moddedJson = File.ReadAllText(moddedPath);
|
||||
|
||||
AlmanacMgrZombie.ZombieAlmanacData moddedZombieData = JsonUtility.FromJson<AlmanacMgrZombie.ZombieAlmanacData>(moddedJson);
|
||||
|
||||
foreach (AlmanacMgrZombie.ZombieInfo zombieInfo in moddedZombieData.zombies)
|
||||
{
|
||||
if (zombieInfo.theZombieType == __instance.theZombieType)
|
||||
{
|
||||
component.text = zombieInfo.info + "\n\n" + zombieInfo.introduce;
|
||||
component.overflowMode = TextOverflowModes.Page;
|
||||
component2.text = zombieInfo.name;
|
||||
component2.autoSizeTextContainer = true;
|
||||
component3.text = Utils.RemoveColorTags(zombieInfo.name);
|
||||
component3.autoSizeTextContainer = true;
|
||||
|
||||
if (hasAlmanacFont)
|
||||
component.font = almanacFontAsset;
|
||||
else
|
||||
component.font = fontAsset;
|
||||
component2.font = fontAsset;
|
||||
component3.font = fontAsset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AlmanacMgrZombie.OnMouseDown))]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
using HarmonyLib;
|
||||
using Il2Cpp;
|
||||
using Il2CppTMPro;
|
||||
using MelonLoader;
|
||||
using MelonLoader.TinyJSON;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using UnityEngine;
|
||||
using static PvZ_Fusion_Translator.FileLoader;
|
||||
|
|
@ -24,6 +22,7 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
string currentLanguage = "English";
|
||||
#endif
|
||||
string path = Path.Combine(almanacDir, "LawnStringsTranslate.json");
|
||||
string moddedPath = Path.Combine(almanacDir, "ModdedPlantsTranslate.json");
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
|
|
@ -61,23 +60,24 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
TextMeshPro component3 = __instance.plantName.transform.GetChild(0).GetComponent<TextMeshPro>();
|
||||
TextMeshPro component4 = __instance.cost.GetComponent<TextMeshPro>();
|
||||
|
||||
Il2Cpp.AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<Il2Cpp.AlmanacPlantBank.PlantData>(json);
|
||||
AlmanacPlantBank.PlantData plantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(json);
|
||||
|
||||
foreach (Il2Cpp.AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in plantData.plants)
|
||||
{
|
||||
if (plantInfo.seedType == __instance.theSeedType)
|
||||
{
|
||||
component.autoSizeTextContainer = false;
|
||||
component.text = plantInfo.info + "\n\n" + plantInfo.introduce;
|
||||
component.autoSizeTextContainer = false;
|
||||
component.text = plantInfo.info + "\n\n" + plantInfo.introduce;
|
||||
component.overflowMode = TextOverflowModes.Page;
|
||||
|
||||
//fix dimensions for cost text
|
||||
component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f);
|
||||
// fix dimensions for cost text
|
||||
component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f);
|
||||
component.rectTransform.offsetMin = new Vector2(component.rectTransform.offsetMin.x, -29.3079f);
|
||||
component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f);
|
||||
component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f);
|
||||
component.transform.localPosition = new Vector3(component.transform.localPosition.x, component.transform.localPosition.y + 0.15f, component.transform.localPosition.z);
|
||||
|
||||
component2.text = plantInfo.name;
|
||||
|
||||
component2.text = plantInfo.name;
|
||||
component2.autoSizeTextContainer = true;
|
||||
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name);
|
||||
|
|
@ -85,7 +85,7 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
|
||||
component4.text = plantInfo.cost;
|
||||
|
||||
if (hasAlmanacFont)
|
||||
if (hasAlmanacFont)
|
||||
{
|
||||
component.font = almanacFontAsset;
|
||||
component4.font = almanacFontAsset;
|
||||
|
|
@ -100,12 +100,58 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
}
|
||||
}
|
||||
|
||||
if (File.Exists(moddedPath))
|
||||
{
|
||||
string moddedJson;
|
||||
moddedJson = File.ReadAllText(moddedPath);
|
||||
|
||||
AlmanacPlantBank.PlantData moddedPlantData = JsonUtility.FromJson<AlmanacPlantBank.PlantData>(moddedJson);
|
||||
|
||||
foreach (AlmanacPlantBank.PlantInfo plantInfo in moddedPlantData.plants)
|
||||
{
|
||||
if (plantInfo.seedType == __instance.theSeedType)
|
||||
{
|
||||
component.autoSizeTextContainer = false;
|
||||
component.text = plantInfo.info + "\n\n" + plantInfo.introduce;
|
||||
component.overflowMode = TextOverflowModes.Page;
|
||||
|
||||
// fix dimensions for cost text
|
||||
component.rectTransform.offsetMax = new Vector2(component.rectTransform.offsetMax.x, 27.3839f);
|
||||
component.rectTransform.offsetMin = new Vector2(component.rectTransform.offsetMin.x, -29.3079f);
|
||||
component.rectTransform.sizeDelta = new Vector2(component.rectTransform.sizeDelta.x, 50.917f);
|
||||
component.transform.localPosition = new Vector3(component.transform.localPosition.x, component.transform.localPosition.y + 0.15f, component.transform.localPosition.z);
|
||||
|
||||
|
||||
component2.text = plantInfo.name;
|
||||
component2.autoSizeTextContainer = true;
|
||||
|
||||
component3.text = Utils.RemoveColorTags(plantInfo.name);
|
||||
component3.autoSizeTextContainer = true;
|
||||
|
||||
component4.text = plantInfo.cost;
|
||||
|
||||
if (hasAlmanacFont)
|
||||
{
|
||||
component.font = almanacFontAsset;
|
||||
component4.font = almanacFontAsset;
|
||||
}
|
||||
else
|
||||
{
|
||||
component.font = fontAsset;
|
||||
component4.font = fontAsset;
|
||||
}
|
||||
component2.font = fontAsset;
|
||||
component3.font = fontAsset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AlmanacPlantBank.OnMouseDown))]
|
||||
[HarmonyPatch(nameof(AlmanacPlantBank.OnMouseDown))]
|
||||
[HarmonyPrefix]
|
||||
private static bool OnMouseDown(Il2Cpp.AlmanacPlantBank __instance)
|
||||
private static bool OnMouseDown(AlmanacPlantBank __instance)
|
||||
{
|
||||
TextMeshPro component = __instance.introduce.GetComponent<TextMeshPro>();
|
||||
if (component != null)
|
||||
|
|
@ -116,15 +162,15 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
return true;
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AlmanacPlantBank.PVPInit))]
|
||||
[HarmonyPostfix]
|
||||
private static void PVPInit(Il2Cpp.AlmanacPlantBank __instance)
|
||||
{
|
||||
TextMeshPro component = __instance.introduce.GetComponent<TextMeshPro>();
|
||||
if (component != null)
|
||||
{
|
||||
[HarmonyPatch(nameof(AlmanacPlantBank.PVPInit))]
|
||||
[HarmonyPostfix]
|
||||
private static void PVPInit(Il2Cpp.AlmanacPlantBank __instance)
|
||||
{
|
||||
TextMeshPro component = __instance.introduce.GetComponent<TextMeshPro>();
|
||||
if (component != null)
|
||||
{
|
||||
component.autoSizeTextContainer = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue