some of the final code fixes, 3.3.1
This commit is contained in:
parent
a89ba825ee
commit
b5a1c031af
8 changed files with 204 additions and 92 deletions
|
|
@ -124,61 +124,6 @@ namespace PvZ_Fusion_Translator.AssetStore
|
|||
return checkText;
|
||||
}
|
||||
|
||||
public static string TranslateColorText(string originalText, bool isLog = false)
|
||||
{
|
||||
string first = ReplaceInsideColorTags(originalText);
|
||||
string text = ReplaceOutsideColorTags(first);
|
||||
string checkText;
|
||||
#if DEBUG
|
||||
Regex regex = new("\\p{IsCJKUnifiedIdeographs}+");
|
||||
Match match = regex.Match(text);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
// Log.LogDebug("Untranslated String: " + match.Value);
|
||||
FileLoader.DumpUntranslatedStrings(text);
|
||||
}
|
||||
#endif
|
||||
checkText = text;
|
||||
|
||||
return checkText;
|
||||
}
|
||||
|
||||
public static string ReplaceOutsideColorTags(string input)
|
||||
{
|
||||
string pattern = @"(<color[^>]*>.*?</color>)";
|
||||
var parts = Regex.Split(input, pattern);
|
||||
|
||||
for (int i = 0; i < parts.Length; i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
parts[i] = DoTranslateText(parts[i], false);
|
||||
if(Utils.CheckForUntranslatedText(parts[i]))
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(parts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string.Join("", parts);
|
||||
}
|
||||
|
||||
public static string ReplaceInsideColorTags(string input)
|
||||
{
|
||||
string text = Regex.Replace(input, @"(<color=[^>]+>)(.*?)(</color>)", match =>
|
||||
{
|
||||
string translatedText = DoTranslateText(match.Groups[2].Value, false);
|
||||
if (Utils.CheckForUntranslatedText(translatedText))
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(translatedText);
|
||||
}
|
||||
return match.Groups[1].Value + DoTranslateText(match.Groups[2].Value, false) + match.Groups[3].Value;
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public static string TranslateText(string originalText, string pattern, bool isLog = false)
|
||||
{
|
||||
if (TestRegex(originalText, pattern) && translationStringRegex.ContainsKey(pattern))
|
||||
|
|
@ -266,12 +211,73 @@ namespace PvZ_Fusion_Translator.AssetStore
|
|||
|
||||
if (isLog)
|
||||
Log.LogDebug($"Text '{originalText}' not translated");
|
||||
if(Utils.CheckForUntranslatedText(originalText))
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(originalText);
|
||||
}
|
||||
return originalText;
|
||||
}
|
||||
|
||||
public static bool TestRegex(string originalText, string pattern)
|
||||
public static string TranslateColorText(string originalText, bool isLog = false)
|
||||
{
|
||||
return Regex.IsMatch(originalText, pattern);
|
||||
string text = TranslateColorSegments(originalText);
|
||||
string checkText;
|
||||
#if DEBUG
|
||||
Regex regex = new("\\p{IsCJKUnifiedIdeographs}+");
|
||||
Match match = regex.Match(text);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
// Log.LogDebug("Untranslated String: " + match.Value);
|
||||
FileLoader.DumpUntranslatedStrings(text);
|
||||
}
|
||||
#endif
|
||||
checkText = text;
|
||||
|
||||
return checkText;
|
||||
}
|
||||
|
||||
public static string TranslateColorSegments(string input)
|
||||
{
|
||||
string result = "";
|
||||
string pattern = @"<color=[^>]+>[\s\S]*?<\/color>|(?:<(?!color=)|[^<])+";
|
||||
string smallPattern = @"(<color=[^>]+>)(.*?)(</color>)";
|
||||
MatchCollection matches = Regex.Matches(input, pattern);
|
||||
|
||||
for (int i = 0; i < matches.Count; i++)
|
||||
{
|
||||
Match match = matches[i];
|
||||
if (Regex.Match(match.Value, smallPattern, RegexOptions.Singleline).Success)
|
||||
{
|
||||
result += TranslateColorSegment(match.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
result += DoTranslateText(match.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string TranslateColorSegment(string input)
|
||||
{
|
||||
string result = input;
|
||||
string pattern = @"(<color=[^>]+>)(.*?)(</color>)";
|
||||
Match match = Regex.Match(input, pattern, RegexOptions.Singleline);
|
||||
string translatedText = DoTranslateText(match.Groups[2].Value);
|
||||
if(Utils.CheckForUntranslatedText(translatedText))
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(translatedText);
|
||||
}
|
||||
result = match.Groups[1].Value + translatedText + match.Groups[3].Value;
|
||||
|
||||
return result;
|
||||
}
|
||||
public static bool TestRegex(string originalText, string pattern, bool singleLine = false)
|
||||
{
|
||||
RegexOptions options = (singleLine) ? RegexOptions.None : RegexOptions.Singleline;
|
||||
return Regex.IsMatch(originalText, pattern, options);
|
||||
}
|
||||
|
||||
private static TextAlignmentOptions TextAnchorToTMPAlignment(TextAnchor anchor)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ using Il2CppTMPro;
|
|||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using PvZ_Fusion_Translator.Patches.Managers;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine.TextCore.Text;
|
||||
using System.Xml.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
|
||||
{
|
||||
|
|
@ -17,17 +18,45 @@ namespace PvZ_Fusion_Translator.Patches.BaseTextObjects
|
|||
{
|
||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
|
||||
foreach (TextMeshProUGUI txt in __instance.textMeshes)
|
||||
foreach (TextMeshProUGUI txt in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
string travelMatch = TravelMgr_Patch.MatchTravelBuff(txt.text);
|
||||
string originalText = "";
|
||||
|
||||
if (txt.gameObject.name.Contains("shadow"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (travelMatch != "")
|
||||
{
|
||||
txt.text = travelMatch;
|
||||
}
|
||||
else if(Regex.Match(txt.text, @"(<color[^>]*>.*?</color>)", RegexOptions.Singleline).Success)
|
||||
{
|
||||
txt.text = StringStore.TranslateColorText(txt.text, true);
|
||||
if (txt.gameObject.name.Contains("main"))
|
||||
{
|
||||
originalText = txt.text;
|
||||
Transform shadowText = txt.transform.parent.Find("Text_shadow");
|
||||
if (shadowText != null)
|
||||
{
|
||||
shadowText.GetComponent<TextMeshProUGUI>().text = Utils.RemoveColorTags(originalText);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
txt.text = StringStore.TranslateText(txt.text, true);
|
||||
if (txt.gameObject.name.Contains("main"))
|
||||
{
|
||||
originalText = txt.text;
|
||||
Transform shadowText = txt.transform.parent.Find("Text_shadow");
|
||||
if (shadowText != null)
|
||||
{
|
||||
shadowText.GetComponent<TextMeshProUGUI>().text = Utils.RemoveColorTags(originalText);
|
||||
}
|
||||
}
|
||||
}
|
||||
txt.font = fontAsset;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,79 @@
|
|||
using Il2Cpp;
|
||||
using Il2CppTMPro;
|
||||
using PvZ_Fusion_Translator.AssetStore;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||
{
|
||||
[HarmonyPatch(typeof(AdvantureEvolutionMenu))]
|
||||
public static class AdvantureEvolutionMenu_Patch
|
||||
{
|
||||
[HarmonyPatch(nameof(AdvantureMenu.Awake))]
|
||||
[HarmonyPostfix]
|
||||
public static void Awake(AdvantureEvolutionMenu __instance)
|
||||
{
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
text.text = StringStore.TranslateColorText(text.text);
|
||||
}
|
||||
|
||||
Transform baseWindow = __instance.transform.Find("BaseWindow");
|
||||
Transform advancedWindow = __instance.transform.Find("AdvancedWindow");
|
||||
|
||||
if(baseWindow != null)
|
||||
{
|
||||
foreach(TextMeshProUGUI text in baseWindow.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
if(text.gameObject.name.Contains("Name"))
|
||||
{
|
||||
text.text = Utils.GetPlantNameFromAlmanac(__instance.thePlantType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (advancedWindow != null)
|
||||
{
|
||||
foreach (TextMeshProUGUI text in advancedWindow.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
if (text.gameObject.name.Contains("Name"))
|
||||
{
|
||||
text.text = Utils.GetPlantNameFromAlmanac(__instance.thePlantType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AdvantureEvolutionMenu.UpdateText))]
|
||||
[HarmonyPostfix]
|
||||
public static void UpdateText(AdvantureEvolutionMenu __instance)
|
||||
{
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(text.text);
|
||||
text.text = StringStore.TranslateColorText(text.text);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AdvantureEvolutionMenu.RollEvolution))]
|
||||
[HarmonyPostfix]
|
||||
public static void RollEvolution(AdvantureEvolutionMenu __instance)
|
||||
{
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(text.text);
|
||||
text.text = StringStore.TranslateColorText(text.text);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AdvantureEvolutionMenu.RollEvolutionGood))]
|
||||
[HarmonyPostfix]
|
||||
public static void RollEvolutionGood(AdvantureEvolutionMenu __instance)
|
||||
{
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
FileLoader.DumpUntranslatedStrings(text.text);
|
||||
text.text = StringStore.TranslateColorText(text.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,48 +12,48 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
|||
[HarmonyPostfix]
|
||||
private static void Start(AdvantureMenu __instance)
|
||||
{
|
||||
__instance.difficulty.text = Utils.RemoveSizeTags(StringStore.TranslateText(__instance.difficulty.text));
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
}
|
||||
TranslateAdvantureMenu(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AdvantureMenu.ChangeDifficulty))]
|
||||
[HarmonyPostfix]
|
||||
private static void ChangeDifficulty(AdvantureMenu __instance)
|
||||
{
|
||||
__instance.difficulty.text = Utils.RemoveSizeTags(StringStore.TranslateText(__instance.difficulty.text));
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
}
|
||||
TranslateAdvantureMenu(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AdvantureMenu.GetChapterDifficulty))]
|
||||
[HarmonyPostfix]
|
||||
private static void GetChapterDifficulty(AdvantureMenu __instance)
|
||||
{
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
}
|
||||
TranslateAdvantureMenu(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AdvantureMenu.UpdateChapterDifficulty))]
|
||||
[HarmonyPostfix]
|
||||
private static void UpdateChapterDifficulty(AdvantureMenu __instance)
|
||||
{
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
}
|
||||
TranslateAdvantureMenu(__instance);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(AdvantureMenu.UpdateStarCount))]
|
||||
[HarmonyPostfix]
|
||||
private static void UpdateStarCount(AdvantureMenu __instance)
|
||||
{
|
||||
TranslateAdvantureMenu(__instance);
|
||||
}
|
||||
|
||||
public static void TranslateAdvantureMenu(AdvantureMenu __instance)
|
||||
{
|
||||
__instance.difficulty.text = Utils.RemoveSizeTags(StringStore.TranslateText(__instance.difficulty.text));
|
||||
__instance.chapterDifficulty.text = StringStore.TranslateText(__instance.chapterDifficulty.text);
|
||||
__instance.starCount.text = StringStore.TranslateText(__instance.starCount.text);
|
||||
|
||||
foreach (TextMeshProUGUI text in __instance.title)
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
}
|
||||
|
||||
foreach (TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
text.text = StringStore.TranslateText(text.text);
|
||||
|
|
|
|||
|
|
@ -57,15 +57,14 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
|||
{
|
||||
string origText = textTMP.text;
|
||||
string translatedText = origText;
|
||||
string pattern = "([^\\s]+)阶\n([^\\s]+)";
|
||||
string pattern = "(\\d+)阶\n([\\s\\S]+)";
|
||||
if (StringStore.TestRegex(translatedText, pattern))
|
||||
{
|
||||
var regex = new Regex(pattern);
|
||||
var match = regex.Match(translatedText);
|
||||
string regularText = match.Groups[2].Value;
|
||||
string halfText = TranslateHPText(regularText, __instance);
|
||||
var match = Regex.Match(translatedText, pattern, RegexOptions.Singleline);
|
||||
string tier = match.Groups[1].Value;
|
||||
string healthText = TranslateHPText(match.Groups[2].Value, __instance);
|
||||
string fStr = StringStore.translationStringRegex[pattern];
|
||||
translatedText = string.Format(fStr, [match.Groups[1].Value, halfText]);
|
||||
translatedText = string.Format(fStr, [tier, healthText]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -105,8 +104,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
|||
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.Match(originalText, hp.Key, RegexOptions.Singleline).Success)
|
||||
{
|
||||
fIndex = i;
|
||||
found = true;
|
||||
|
|
@ -160,6 +158,7 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.MinorObjects
|
|||
{
|
||||
string fStr = HPStrings.ElementAt(fIndex).Value;
|
||||
string DPS = originalText.Split("\n")[1].Replace("DPS:", "");
|
||||
DPS = StringStore.TranslateText(DPS);
|
||||
|
||||
switch (fIndex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,6 +42,17 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
|||
|
||||
TextMeshProUGUI contentText = contentObject.GetComponent<TextMeshProUGUI>();
|
||||
contentText.text = changelogText;
|
||||
contentText.margin = new Vector4(6, 2, 12, 0);
|
||||
|
||||
contentText.enableWordWrapping = true;
|
||||
contentText.overflowMode = TextOverflowModes.ScrollRect;
|
||||
|
||||
Canvas.ForceUpdateCanvases();
|
||||
contentText.ForceMeshUpdate();
|
||||
|
||||
//float textHeight = contentText.preferredHeight;
|
||||
//RectTransform contentRect = contentObject.GetComponent<RectTransform>();
|
||||
//contentRect.sizeDelta = new Vector2(contentRect.sizeDelta.x, textHeight);
|
||||
|
||||
ContentSizeFitter sizeFitter = contentObject.AddComponent<ContentSizeFitter>();
|
||||
sizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ namespace PvZ_Fusion_Translator.Patches.Managers
|
|||
{
|
||||
[HarmonyPatch(nameof(CanvasUpUI.Start))]
|
||||
[HarmonyPostfix]
|
||||
public static void Start(IZBottomMenu __instance)
|
||||
public static void Start(CanvasUpUI __instance)
|
||||
{
|
||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||
|
||||
foreach(TextMeshProUGUI text in __instance.GetComponentsInChildren<TextMeshProUGUI>())
|
||||
{
|
||||
string originalKey = StringStore.translationString.FirstOrDefault(x => x.Value.Replace("\n", " ") == text.text).Key;
|
||||
string originalKey = StringStore.translationString.FirstOrDefault(x => (x.Value == text.text || x.Value.Replace("\n", "") == text.text)).Key;
|
||||
text.text = (StringStore.translationString.ContainsKey(originalKey + "_MG")) ? StringStore.TranslateText(originalKey + "_MG") : StringStore.TranslateText(text.text);
|
||||
if(text.gameObject.name.Contains("LevelName"))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
<LangVersion>latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate</Configurations>
|
||||
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.3.0_Part1</GamePath>
|
||||
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion_3.3.1</GamePath>
|
||||
<Platforms>AnyCPU;ARM64;x64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue