more code changes
This commit is contained in:
parent
19cb5b93b0
commit
75060fc05e
9 changed files with 122 additions and 118 deletions
|
|
@ -12,8 +12,12 @@ namespace PvZ_Fusion_Translator.AssetStore
|
||||||
|
|
||||||
public static Dictionary<string, string> translationString = new();
|
public static Dictionary<string, string> translationString = new();
|
||||||
|
|
||||||
|
public static Dictionary<string, string> izLevelTipDictionary = new();
|
||||||
|
|
||||||
public static Dictionary<string, string> izTipCollectionString = new();
|
public static Dictionary<string, string> izTipCollectionString = new();
|
||||||
|
|
||||||
|
public static Dictionary<string, string> fsLevelTipDictionary = new();
|
||||||
|
|
||||||
public static Dictionary<string, string> fsTipCollectionString = new();
|
public static Dictionary<string, string> fsTipCollectionString = new();
|
||||||
|
|
||||||
public static Dictionary<string, Dictionary<string, string>> patchesStore = new()
|
public static Dictionary<string, Dictionary<string, string>> patchesStore = new()
|
||||||
|
|
@ -74,7 +78,9 @@ namespace PvZ_Fusion_Translator.AssetStore
|
||||||
{
|
{
|
||||||
translationString.Clear();
|
translationString.Clear();
|
||||||
translationStringRegex.Clear();
|
translationStringRegex.Clear();
|
||||||
|
izLevelTipDictionary.Clear();
|
||||||
izTipCollectionString.Clear();
|
izTipCollectionString.Clear();
|
||||||
|
fsLevelTipDictionary.Clear();
|
||||||
fsTipCollectionString.Clear();
|
fsTipCollectionString.Clear();
|
||||||
FileLoader.LoadStrings();
|
FileLoader.LoadStrings();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,14 @@ using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
using MelonLoader.TinyJSON;
|
using MelonLoader.TinyJSON;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using PvZ_Fusion_Translator.Patches.GameObjects;
|
using PvZ_Fusion_Translator.Patches.GameObjects;
|
||||||
using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects;
|
using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects;
|
||||||
using PvZ_Fusion_Translator.Patches.Modes.Odyssey;
|
using PvZ_Fusion_Translator.Patches.Modes.Odyssey;
|
||||||
using PvZ_Fusion_Translator.Patches.OtherManagers;
|
using PvZ_Fusion_Translator.Patches.OtherManagers;
|
||||||
|
using System.CodeDom.Compiler;
|
||||||
|
using System.Text;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
@ -77,17 +80,21 @@ namespace PvZ_Fusion_Translator
|
||||||
|
|
||||||
if(travelBuffsContent != null)
|
if(travelBuffsContent != null)
|
||||||
{
|
{
|
||||||
TravelMgr_Patch.translatedTravelBuffs = JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(travelBuffsContent);
|
TravelMgr_Patch.translatedTravelBuffs = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(travelBuffsContent);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string travelBuffsPath = Path.Combine(GetAssetDir(AssetType.Strings, Utils.Language), "travel_buffs.json");
|
string travelBuffsPath = Path.Combine(GetAssetDir(AssetType.Strings, Utils.Language), "travel_buffs.json");
|
||||||
if(File.Exists(travelBuffsPath))
|
if(File.Exists(travelBuffsPath))
|
||||||
{
|
{
|
||||||
TravelMgr_Patch.translatedTravelBuffs = JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(File.ReadAllText(travelBuffsPath));
|
TravelMgr_Patch.translatedTravelBuffs = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(File.ReadAllText(travelBuffsPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load changelog
|
||||||
|
|
||||||
|
LoadChangelogText();
|
||||||
|
|
||||||
// load tips
|
// load tips
|
||||||
string izTipsContent = Utils.GetDataFromWeb($"https://raw.githubusercontent.com/Teyliu/PVZF-Translation/refs/heads/main/PvZ_Fusion_Translator/Localization/{Utils.Language.ToString()}/Strings/tips_iz.json").Result;
|
string izTipsContent = Utils.GetDataFromWeb($"https://raw.githubusercontent.com/Teyliu/PVZF-Translation/refs/heads/main/PvZ_Fusion_Translator/Localization/{Utils.Language.ToString()}/Strings/tips_iz.json").Result;
|
||||||
|
|
||||||
|
|
@ -152,6 +159,8 @@ namespace PvZ_Fusion_Translator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load abyss buffs
|
||||||
|
|
||||||
Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData();
|
Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData();
|
||||||
|
|
||||||
SaveStrings();
|
SaveStrings();
|
||||||
|
|
@ -192,7 +201,7 @@ namespace PvZ_Fusion_Translator
|
||||||
}
|
}
|
||||||
else if(fileName.EndsWith("travel_buffs"))
|
else if(fileName.EndsWith("travel_buffs"))
|
||||||
{
|
{
|
||||||
TravelMgr_Patch.translatedTravelBuffs = JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(jsonString);
|
TravelMgr_Patch.translatedTravelBuffs = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, SortedDictionary<int, string>>>(jsonString);
|
||||||
}
|
}
|
||||||
else if(fileName.EndsWith("tips_iz"))
|
else if(fileName.EndsWith("tips_iz"))
|
||||||
{
|
{
|
||||||
|
|
@ -202,6 +211,10 @@ namespace PvZ_Fusion_Translator
|
||||||
{
|
{
|
||||||
LoadFSStrings(jsonString);
|
LoadFSStrings(jsonString);
|
||||||
}
|
}
|
||||||
|
else if(fileName.EndsWith("abyss_buffs"))
|
||||||
|
{
|
||||||
|
Patches.Modes.Abyss.AbyssBuffMenu_Patch.LoadAbyssBuffData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
string almanacDir = GetAssetDir(AssetType.Almanac, Utils.Language);
|
||||||
|
|
@ -255,7 +268,7 @@ namespace PvZ_Fusion_Translator
|
||||||
var izLevelData = izDump.Item1;
|
var izLevelData = izDump.Item1;
|
||||||
var izLevelDataDump = izDump.Item2;
|
var izLevelDataDump = izDump.Item2;
|
||||||
|
|
||||||
var izTranslatedTips = JsonSerializer.Deserialize<Dictionary<string, string>>(content);
|
var izTranslatedTips = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(content);
|
||||||
|
|
||||||
foreach (var level in izLevelData)
|
foreach (var level in izLevelData)
|
||||||
{
|
{
|
||||||
|
|
@ -265,6 +278,7 @@ namespace PvZ_Fusion_Translator
|
||||||
{
|
{
|
||||||
if(izTranslatedTips.ContainsKey(level.name) && !StringStore.izTipCollectionString.ContainsKey(levelData.tips))
|
if(izTranslatedTips.ContainsKey(level.name) && !StringStore.izTipCollectionString.ContainsKey(levelData.tips))
|
||||||
{
|
{
|
||||||
|
StringStore.izLevelTipDictionary.Add(level.name, izTranslatedTips[level.name]);
|
||||||
StringStore.izTipCollectionString.Add(levelData.tips, izTranslatedTips[level.name]);
|
StringStore.izTipCollectionString.Add(levelData.tips, izTranslatedTips[level.name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -277,7 +291,7 @@ namespace PvZ_Fusion_Translator
|
||||||
var fusionShowcaseData = fusionShowcaseDump.Item1;
|
var fusionShowcaseData = fusionShowcaseDump.Item1;
|
||||||
var fusionShowcaseDataDump = fusionShowcaseDump.Item2;
|
var fusionShowcaseDataDump = fusionShowcaseDump.Item2;
|
||||||
|
|
||||||
var fsTranslatedTips = JsonSerializer.Deserialize<Dictionary<string, string>>(content);
|
var fsTranslatedTips = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(content);
|
||||||
|
|
||||||
foreach (var level in fusionShowcaseData)
|
foreach (var level in fusionShowcaseData)
|
||||||
{
|
{
|
||||||
|
|
@ -287,6 +301,7 @@ namespace PvZ_Fusion_Translator
|
||||||
{
|
{
|
||||||
if (fsTranslatedTips.ContainsKey(level.name) && !StringStore.fsTipCollectionString.ContainsKey(levelData.tips))
|
if (fsTranslatedTips.ContainsKey(level.name) && !StringStore.fsTipCollectionString.ContainsKey(levelData.tips))
|
||||||
{
|
{
|
||||||
|
StringStore.fsLevelTipDictionary.Add(level.name, fsTranslatedTips[level.name]);
|
||||||
StringStore.fsTipCollectionString.Add(levelData.tips, fsTranslatedTips[level.name]);
|
StringStore.fsTipCollectionString.Add(levelData.tips, fsTranslatedTips[level.name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -503,51 +518,31 @@ namespace PvZ_Fusion_Translator
|
||||||
|
|
||||||
// save regexs
|
// save regexs
|
||||||
|
|
||||||
string translationStringRegex = System.Text.Json.JsonSerializer.Serialize(StringStore.translationStringRegex, new JsonSerializerOptions
|
string translationStringRegex = SerializeWithIndentation(StringStore.translationStringRegex, 2);
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(stringDir, "translation_regexs.json"), translationStringRegex);
|
File.WriteAllText(Path.Combine(stringDir, "translation_regexs.json"), translationStringRegex);
|
||||||
|
|
||||||
// save strings
|
// save strings
|
||||||
|
|
||||||
string translationString = System.Text.Json.JsonSerializer.Serialize(StringStore.translationString, new JsonSerializerOptions
|
string translationString = SerializeWithIndentation(StringStore.translationString, 2);
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(stringDir, "translation_strings.json"), translationString);
|
File.WriteAllText(Path.Combine(stringDir, "translation_strings.json"), translationString);
|
||||||
|
|
||||||
// save iz tips
|
// save iz tips
|
||||||
|
|
||||||
string izTipCollectionString = System.Text.Json.JsonSerializer.Serialize(StringStore.izTipCollectionString, new JsonSerializerOptions
|
string izTipCollectionString = SerializeWithIndentation(StringStore.izLevelTipDictionary, 1, ' ');
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(stringDir, "tips_iz.json"), izTipCollectionString);
|
File.WriteAllText(Path.Combine(stringDir, "tips_iz.json"), izTipCollectionString);
|
||||||
|
|
||||||
// save fs tips
|
// save fs tips
|
||||||
|
|
||||||
string fsTipCollectionString = System.Text.Json.JsonSerializer.Serialize(StringStore.fsTipCollectionString, new JsonSerializerOptions
|
string fsLevelTipDictionary = SerializeWithIndentation(StringStore.fsLevelTipDictionary);
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(stringDir, "tips_fs.json"), fsTipCollectionString);
|
File.WriteAllText(Path.Combine(stringDir, "tips_fs.json"), fsLevelTipDictionary);
|
||||||
|
|
||||||
// save travel buffs
|
// save travel buffs
|
||||||
|
|
||||||
string travelBuffs = System.Text.Json.JsonSerializer.Serialize(TravelMgr_Patch.translatedTravelBuffs, new JsonSerializerOptions
|
string travelBuffs = SerializeWithIndentation(TravelMgr_Patch.translatedTravelBuffs);
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(stringDir, "travel_buffs.json"), travelBuffs);
|
File.WriteAllText(Path.Combine(stringDir, "travel_buffs.json"), travelBuffs);
|
||||||
|
|
||||||
|
|
@ -562,11 +557,7 @@ namespace PvZ_Fusion_Translator
|
||||||
|
|
||||||
if(Patches.Modes.Abyss.AbyssBuffMenu_Patch.abyssBuffData != new Dictionary<string, string>())
|
if(Patches.Modes.Abyss.AbyssBuffMenu_Patch.abyssBuffData != new Dictionary<string, string>())
|
||||||
{
|
{
|
||||||
string abyssBuffData = System.Text.Json.JsonSerializer.Serialize(Patches.Modes.Abyss.AbyssBuffMenu_Patch.abyssBuffData, new JsonSerializerOptions
|
string abyssBuffData = SerializeWithIndentation(Patches.Modes.Abyss.AbyssBuffMenu_Patch.abyssBuffData, 2);
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
File.WriteAllText(Path.Combine(stringDir, "abyss_buffs.json"), abyssBuffData);
|
File.WriteAllText(Path.Combine(stringDir, "abyss_buffs.json"), abyssBuffData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -576,27 +567,36 @@ namespace PvZ_Fusion_Translator
|
||||||
|
|
||||||
if(AlmanacPlantMenu_Patch.almanacJson != "")
|
if(AlmanacPlantMenu_Patch.almanacJson != "")
|
||||||
{
|
{
|
||||||
string plantAlmanac = System.Text.Json.JsonSerializer.Serialize(AlmanacPlantMenu_Patch.almanacJson, new JsonSerializerOptions
|
string plantAlmanac = SerializeWithIndentation(AlmanacPlantMenu_Patch.almanacJson);
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(almanacDir, "LawnStringsTranslate.json"), AlmanacPlantMenu_Patch.almanacJson);
|
File.WriteAllText(Path.Combine(almanacDir, "LawnStringsTranslate.json"), AlmanacPlantMenu_Patch.almanacJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(AlmanacZombieMenu_Patch.almanacJson != "")
|
if(AlmanacZombieMenu_Patch.almanacJson != "")
|
||||||
{
|
{
|
||||||
string zombieAlmanac = System.Text.Json.JsonSerializer.Serialize(AlmanacZombieMenu_Patch.almanacJson, new JsonSerializerOptions
|
string zombieAlmanac = SerializeWithIndentation(AlmanacZombieMenu_Patch.almanacJson);
|
||||||
{
|
|
||||||
WriteIndented = true,
|
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(almanacDir, "ZombieStringsTranslate.json"), AlmanacZombieMenu_Patch.almanacJson);
|
File.WriteAllText(Path.Combine(almanacDir, "ZombieStringsTranslate.json"), AlmanacZombieMenu_Patch.almanacJson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string SerializeWithIndentation<T>(T value, int size = 4, char indentChar = ' ')
|
||||||
|
{
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
|
var stringWriter = new StringWriter();
|
||||||
|
using (JsonTextWriter writer = new JsonTextWriter(stringWriter))
|
||||||
|
{
|
||||||
|
writer.Formatting = Formatting.Indented;
|
||||||
|
writer.Indentation = size;
|
||||||
|
writer.IndentChar = indentChar;
|
||||||
|
|
||||||
|
Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
|
||||||
|
serializer.Serialize(writer, value, typeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
return stringWriter.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
public static void DumpJson()
|
public static void DumpJson()
|
||||||
{
|
{
|
||||||
string dumpDir = GetAssetDir(AssetType.Dumps);
|
string dumpDir = GetAssetDir(AssetType.Dumps);
|
||||||
|
|
@ -617,18 +617,18 @@ namespace PvZ_Fusion_Translator
|
||||||
var izLevelData = izDump.Item1;
|
var izLevelData = izDump.Item1;
|
||||||
var izLevelDataDump = izDump.Item2;
|
var izLevelDataDump = izDump.Item2;
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(dumpDir, "tips_iz.json"), JsonSerializer.Serialize(izLevelDataDump, new JsonSerializerOptions
|
File.WriteAllText(Path.Combine(dumpDir, "tips_iz.json"), System.Text.Json.JsonSerializer.Serialize(izLevelDataDump, new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
WriteIndented = true,
|
WriteIndented = true,
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// dump fusion showcase tips
|
// dump fusion showcase tips
|
||||||
var fusionShowcaseDump = DumpIZStrings();
|
var fusionShowcaseDump = DumpFSStrings();
|
||||||
var fusionShowcaseData = izDump.Item1;
|
var fusionShowcaseData = fusionShowcaseDump.Item1;
|
||||||
var fusionShowcaseDataDump = izDump.Item2;
|
var fusionShowcaseDataDump = fusionShowcaseDump.Item2;
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(dumpDir, "tips_fs.json"), JsonSerializer.Serialize(fusionShowcaseDataDump, new JsonSerializerOptions
|
File.WriteAllText(Path.Combine(dumpDir, "tips_fs.json"), System.Text.Json.JsonSerializer.Serialize(fusionShowcaseDataDump, new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
WriteIndented = true,
|
WriteIndented = true,
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||||
|
|
@ -639,7 +639,7 @@ namespace PvZ_Fusion_Translator
|
||||||
{
|
{
|
||||||
achievementsList.Add(entry.Key, new AchievementObject(entry.Key, entry.Value.Item1, entry.Value.Item2));
|
achievementsList.Add(entry.Key, new AchievementObject(entry.Key, entry.Value.Item1, entry.Value.Item2));
|
||||||
}
|
}
|
||||||
File.WriteAllText(Path.Combine(dumpDir, "AchievementsText.json"), JsonSerializer.Serialize(achievementsList, new JsonSerializerOptions
|
File.WriteAllText(Path.Combine(dumpDir, "AchievementsText.json"), System.Text.Json.JsonSerializer.Serialize(achievementsList, new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
WriteIndented = true,
|
WriteIndented = true,
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||||
|
|
@ -695,7 +695,7 @@ namespace PvZ_Fusion_Translator
|
||||||
}
|
}
|
||||||
|
|
||||||
string json = File.ReadAllText(jsonFile);
|
string json = File.ReadAllText(jsonFile);
|
||||||
var untranslatedStrings = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
|
var untranslatedStrings = System.Text.Json.JsonSerializer.Deserialize<Dictionary<string, string>>(json);
|
||||||
|
|
||||||
if (!untranslatedStrings.ContainsKey(text))
|
if (!untranslatedStrings.ContainsKey(text))
|
||||||
{
|
{
|
||||||
|
|
@ -705,7 +705,7 @@ namespace PvZ_Fusion_Translator
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||||
WriteIndented = true
|
WriteIndented = true
|
||||||
};
|
};
|
||||||
File.WriteAllText(jsonFile, JsonSerializer.Serialize(untranslatedStrings, options));
|
File.WriteAllText(jsonFile, System.Text.Json.JsonSerializer.Serialize(untranslatedStrings, options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@ namespace PvZ_Fusion_Translator
|
||||||
public enum ModType
|
public enum ModType
|
||||||
{
|
{
|
||||||
ReloadStrings,
|
ReloadStrings,
|
||||||
ReloadTextures,
|
ReloadTextures
|
||||||
SwapLocalData
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ModFeature
|
private class ModFeature
|
||||||
|
|
@ -44,22 +43,13 @@ namespace PvZ_Fusion_Translator
|
||||||
Core.ShowToast("Textures Reloaded!");
|
Core.ShowToast("Textures Reloaded!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.ModType == ModType.SwapLocalData)
|
|
||||||
{
|
|
||||||
Utils.SwapLocalData();
|
|
||||||
string toast = (Utils.useLocal) ? "Using Local Data..." : "Using Online Data...";
|
|
||||||
Core.ShowToast(toast);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dictionary<ModType, ModFeature> featureLists = new()
|
private static Dictionary<ModType, ModFeature> featureLists = new()
|
||||||
{
|
{
|
||||||
{ModType.ReloadStrings,new ModFeature("Reload Strings",ModType.ReloadStrings,KeyCode.Home, true)},
|
{ModType.ReloadStrings,new ModFeature("Reload Strings",ModType.ReloadStrings,KeyCode.Home, true)},
|
||||||
{ModType.ReloadTextures,new ModFeature("Reload Textures",ModType.ReloadTextures,KeyCode.End, true)},
|
{ModType.ReloadTextures,new ModFeature("Reload Textures",ModType.ReloadTextures,KeyCode.End, true)}
|
||||||
{ModType.SwapLocalData,new ModFeature("Swap Level Data Type",ModType.SwapLocalData,KeyCode.PageUp, true)},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void ShowText(InGameText __instance)
|
public static void ShowText(InGameText __instance)
|
||||||
{
|
{
|
||||||
|
if(__instance.textHead == null) return;
|
||||||
|
|
||||||
|
if(!__instance.textHead.active) return;
|
||||||
|
|
||||||
TranslateInGameText(__instance);
|
TranslateInGameText(__instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,6 +31,10 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void DebugWarning(InGameText __instance)
|
public static void DebugWarning(InGameText __instance)
|
||||||
{
|
{
|
||||||
|
if(__instance.textHead == null) return;
|
||||||
|
|
||||||
|
if(!__instance.textHead.active) return;
|
||||||
|
|
||||||
TranslateInGameText(__instance);
|
TranslateInGameText(__instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,6 +42,10 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void Update(InGameText __instance)
|
public static void Update(InGameText __instance)
|
||||||
{
|
{
|
||||||
|
if(__instance.textHead == null) return;
|
||||||
|
|
||||||
|
if(!__instance.textHead.active) return;
|
||||||
|
|
||||||
TranslateInGameText(__instance);
|
TranslateInGameText(__instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,6 +53,8 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
|
||||||
{
|
{
|
||||||
if (__instance.textMesh == null) return;
|
if (__instance.textMesh == null) return;
|
||||||
|
|
||||||
|
if(!__instance.textHead.active) return;
|
||||||
|
|
||||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||||
|
|
||||||
currentText = __instance.textMesh.text;
|
currentText = __instance.textMesh.text;
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
private static List<Utils.ToggleEnum> AvailableToggles;
|
private static List<Utils.ToggleEnum> AvailableToggles;
|
||||||
private const int LanguagesPerPage = 5;
|
private const int LanguagesPerPage = 5;
|
||||||
private static int currentPage = 0;
|
private static int currentPage = 0;
|
||||||
private static OptionBtn[] buttonSlots = new OptionBtn[6]; // 5 language buttons + 1 next button
|
public static OptionBtn[] buttonSlots = new OptionBtn[6]; // 5 language buttons + 1 next button
|
||||||
private static OptionBtn[] toggleSlots = new OptionBtn[3];
|
public static OptionBtn[] toggleSlots = new OptionBtn[3];
|
||||||
|
|
||||||
public static void CreateLanguageButtons(OptionBtn templateButton)
|
public static void CreateLanguageButtons(OptionBtn templateButton)
|
||||||
{
|
{
|
||||||
|
|
@ -160,7 +160,13 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
data.Toggle = toggle;
|
data.Toggle = toggle;
|
||||||
data.IsNextButton = false;
|
data.IsNextButton = false;
|
||||||
btn.gameObject.SetActive(true);
|
btn.gameObject.SetActive(true);
|
||||||
UpdateButtonText(btn, StringStore.TranslateText(Utils.ToggleNames[toggle]), FontStore.LoadTMPFont(Utils.Language.ToString()));
|
string buttonText = Utils.ToggleNames[toggle];
|
||||||
|
UpdateButtonText(btn, StringStore.TranslateText(buttonText), FontStore.LoadTMPFont(Utils.Language.ToString()));
|
||||||
|
if(i == 2)
|
||||||
|
{
|
||||||
|
string sourceMsg = "<size=10>" + (!(Utils.useLocal) ? "Translation Source:\nOnline" : "Translation Source:\nLocal");
|
||||||
|
FlashMessage(btn, sourceMsg, 0.1f, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -211,7 +217,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FlashMessage(OptionBtn button, string message, float yShift = 0.0f)
|
public static void FlashMessage(OptionBtn button, string message, float yShift = 0.0f, bool useTimer = true)
|
||||||
{
|
{
|
||||||
var child = button.transform.GetChild(0);
|
var child = button.transform.GetChild(0);
|
||||||
if (child != null)
|
if (child != null)
|
||||||
|
|
@ -236,13 +242,16 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
}
|
}
|
||||||
child.gameObject.SetActive(true);
|
child.gameObject.SetActive(true);
|
||||||
|
|
||||||
System.Threading.Tasks.Task.Delay(1000).ContinueWith(_ =>
|
if(useTimer)
|
||||||
{
|
{
|
||||||
if (button != null && child != null && child.gameObject.activeSelf)
|
System.Threading.Tasks.Task.Delay(1000).ContinueWith(_ =>
|
||||||
{
|
{
|
||||||
child.gameObject.SetActive(false);
|
if (button != null && child != null && child.gameObject.activeSelf)
|
||||||
}
|
{
|
||||||
});
|
child.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,7 +275,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
|
|
||||||
if (type == "SwapLocal")
|
if (type == "SwapLocal")
|
||||||
{
|
{
|
||||||
Utils.SwapLocalData();
|
Utils.WarnLocalData();
|
||||||
}
|
}
|
||||||
|
|
||||||
MelonPreferences.Save();
|
MelonPreferences.Save();
|
||||||
|
|
@ -327,11 +336,6 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
else if (toggleType == "Audio")
|
else if (toggleType == "Audio")
|
||||||
{
|
{
|
||||||
FlashMessage(toggleData.Button, "<size=10>Toggled custom audio!", 0.1f);
|
FlashMessage(toggleData.Button, "<size=10>Toggled custom audio!", 0.1f);
|
||||||
}
|
|
||||||
else if (toggleType == "SwapLocal")
|
|
||||||
{
|
|
||||||
string message = (Utils.useLocal) ? "<size=10>Switched to local translations!" : "<size=10>Switched to online translations!";
|
|
||||||
FlashMessage(toggleData.Button, message, 0.1f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,6 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[HarmonyPatch(nameof(DrawCardManager.Update))]
|
[HarmonyPatch(nameof(DrawCardManager.Update))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
private static void Postfix_Update(DrawCardManager __instance)
|
private static void Postfix_Update(DrawCardManager __instance)
|
||||||
|
|
@ -55,7 +53,6 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
private static void Start(InGameUI __instance)
|
private static void Start(InGameUI __instance)
|
||||||
{
|
{
|
||||||
foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
foreach(TextMeshProUGUI text in __instance.T)
|
||||||
{
|
{
|
||||||
if (text.text == null) continue;
|
if (text.text == null) continue;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,44 +9,17 @@ namespace PvZ_Fusion_Translator.Patches.Modes.Harvest
|
||||||
[HarmonyPatch(typeof(GardenBagMenu))]
|
[HarmonyPatch(typeof(GardenBagMenu))]
|
||||||
public static class GardenBagMenu_Patch
|
public static class GardenBagMenu_Patch
|
||||||
{
|
{
|
||||||
[HarmonyPatch(nameof(GardenBagMenu.SetTreasureCards))]
|
[HarmonyPatch(nameof(GardenBagMenu.Awake))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
private static void SetTreasureCards(GardenBagMenu __instance)
|
private static void Awake(GardenBagMenu __instance)
|
||||||
{
|
{
|
||||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||||
|
|
||||||
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
Transform closeButtonTransform = __instance.transform.Find("Close");
|
||||||
|
foreach(TextMeshProUGUI text in closeButtonTransform.GetComponentsInChildren<TextMeshProUGUI>())
|
||||||
{
|
{
|
||||||
if (txt.transform.parent.name.Contains("Close"))
|
text.text = StringStore.TranslateText("合上");
|
||||||
{
|
|
||||||
txt.text = StringStore.TranslateText("合上");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
txt.text = StringStore.TranslateText(txt.text);
|
|
||||||
}
|
|
||||||
txt.font = fontAsset;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//[HarmonyPatch(nameof(GardenBagMenu.SetTreasureCard))]
|
|
||||||
//[HarmonyPostfix]
|
|
||||||
//private static void SetTreasureCard(GardenBagMenu __instance)
|
|
||||||
//{
|
|
||||||
// //TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
|
||||||
|
|
||||||
// //foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
|
||||||
// //{
|
|
||||||
// // if (txt.transform.parent.name.Contains("Close"))
|
|
||||||
// // {
|
|
||||||
// // txt.text = StringStore.TranslateText("合上");
|
|
||||||
// // }
|
|
||||||
// // else
|
|
||||||
// // {
|
|
||||||
// // txt.text = StringStore.TranslateText(txt.text);
|
|
||||||
// // }
|
|
||||||
// // txt.font = fontAsset;
|
|
||||||
// //}
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,12 +6,14 @@ using MelonLoader.TinyJSON;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using PvZ_Fusion_Translator.Patches.GameObjects;
|
using PvZ_Fusion_Translator.Patches.GameObjects;
|
||||||
|
using PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects;
|
||||||
using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects;
|
using PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects;
|
||||||
using PvZ_Fusion_Translator.Patches.Modes.Super_Editor;
|
using PvZ_Fusion_Translator.Patches.Modes.Super_Editor;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Unity.Burst.Intrinsics;
|
using Unity.Burst.Intrinsics;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
using UnityEngine.Experimental.Rendering;
|
using UnityEngine.Experimental.Rendering;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using static Il2Cpp.AlmanacPlantBank;
|
using static Il2Cpp.AlmanacPlantBank;
|
||||||
|
|
@ -340,11 +342,29 @@ namespace PvZ_Fusion_Translator
|
||||||
|
|
||||||
public static bool useLocal = MelonPreferences.GetEntryValue<bool>("PvZ_Fusion_Translator", "UseLocal");
|
public static bool useLocal = MelonPreferences.GetEntryValue<bool>("PvZ_Fusion_Translator", "UseLocal");
|
||||||
|
|
||||||
|
public static void WarnLocalData()
|
||||||
|
{
|
||||||
|
BaseMenu newMenu = GameAPP.UIManager.Push(UIType.ConfirmMenu, GameAPP.canvasUp);
|
||||||
|
ConfirmMenu confirmMenu = newMenu.gameObject.GetComponent<ConfirmMenu>();
|
||||||
|
|
||||||
|
string modeTo = (Utils.useLocal) ? "online mode" : "local mode";
|
||||||
|
confirmMenu.SetTitle($"<size=40%>WARNING: This button is meant for translator testing and can overwrite/interfere with the translation files saved in your installation. Proceed with caution. <color=red>You are switching to {modeTo}.</color>\nOnline Mode: Default, strings will auto-sync with the latest version when opening the game\nLocal Mode: Strings are only loaded from your installaion and do not update (meant for translators)");
|
||||||
|
confirmMenu.transform.Find("window/text").GetComponent<TextMeshProUGUI>().text = Utils.RemoveColorTags(confirmMenu.transform.Find("window/text").GetComponent<TextMeshProUGUI>().text);
|
||||||
|
UIButton confirmButton = confirmMenu.transform.Find("Image").GetComponent<UIButton>();
|
||||||
|
UIButton cancelButton = confirmMenu.transform.Find("Image2").GetComponent<UIButton>();
|
||||||
|
|
||||||
|
confirmButton.clickEvent = new UnityEvent();
|
||||||
|
confirmButton.clickEvent.AddListener(new Action(() => SwapLocalData()));
|
||||||
|
confirmButton.clickEvent.AddListener(new Action(() => GameAPP.UIManager.Pop()));
|
||||||
|
}
|
||||||
|
|
||||||
public static void SwapLocalData()
|
public static void SwapLocalData()
|
||||||
{
|
{
|
||||||
Utils.useLocal = (Utils.useLocal) ? false : true;
|
Utils.useLocal = (Utils.useLocal) ? false : true;
|
||||||
MelonPreferences.SetEntryValue<bool>("PvZ_Fusion_Translator", "UseLocal", Utils.useLocal);
|
MelonPreferences.SetEntryValue<bool>("PvZ_Fusion_Translator", "UseLocal", Utils.useLocal);
|
||||||
StringStore.Reload();
|
StringStore.Reload();
|
||||||
|
string sourceMsg = "<size=10>" + (!(Utils.useLocal) ? "Translation Source:\nOnline" : "Translation Source:\nLocal");
|
||||||
|
OptLanguageBtn_Patch.FlashMessage(OptLanguageBtn_Patch.toggleSlots[2], sourceMsg, 0.1f, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<string> GetDataFromWeb(string url, bool isLog = true)
|
public static async Task<string> GetDataFromWeb(string url, bool isLog = true)
|
||||||
|
|
@ -460,7 +480,7 @@ namespace PvZ_Fusion_Translator
|
||||||
{
|
{
|
||||||
{ ToggleEnum.Textures, "Textures"},
|
{ ToggleEnum.Textures, "Textures"},
|
||||||
{ ToggleEnum.Audio, "Audio"},
|
{ ToggleEnum.Audio, "Audio"},
|
||||||
{ ToggleEnum.SwapLocal, "<size=85%>Swap Local\nTranslations"}
|
{ ToggleEnum.SwapLocal, "<size=85%>Change Translation\nSource"}
|
||||||
};
|
};
|
||||||
|
|
||||||
public enum ToggleEnum
|
public enum ToggleEnum
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue