just updating my branch
This commit is contained in:
parent
dd1cba7631
commit
685db5a19a
3 changed files with 46 additions and 16 deletions
|
|
@ -3,7 +3,7 @@ using MelonLoader.Utils;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[assembly: MelonInfo(typeof(PvZ_Fusion_Translator.Core), "PvZ Fusion Translator", "231.0.0", "dynaslash / arifrios1st / lancerx0", null)]
|
[assembly: MelonInfo(typeof(PvZ_Fusion_Translator.Core), "PvZ Fusion Translator", "231.0.0", "dynaslash / arifrios1st / lancerx0 / JustNull / Dakosha / Mamoru-kun", null)]
|
||||||
[assembly: MelonGame("LanPiaoPiao", "PlantsVsZombiesRH")]
|
[assembly: MelonGame("LanPiaoPiao", "PlantsVsZombiesRH")]
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator
|
namespace PvZ_Fusion_Translator
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ using Il2Cpp;
|
||||||
using Il2CppTMPro;
|
using Il2CppTMPro;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.TextCore.Text;
|
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
|
|
@ -15,27 +14,59 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
private static void Postfix_Start(UIButton __instance)
|
private static void Postfix_Start(UIButton __instance)
|
||||||
{
|
{
|
||||||
Text[] textComponents = __instance.GetComponentsInChildren<Text>(true);
|
try
|
||||||
|
|
||||||
foreach (Text textComponent in textComponents)
|
|
||||||
{
|
{
|
||||||
if (textComponent != null && !string.IsNullOrEmpty(textComponent.text))
|
// Convert and translate legacy Text components
|
||||||
|
Text[] textComponents = __instance.GetComponentsInChildren<Text>(true);
|
||||||
|
foreach (Text textComponent in textComponents)
|
||||||
{
|
{
|
||||||
string translatedText = StringStore.TranslateText(textComponent.text);
|
if (textComponent != null && !string.IsNullOrEmpty(textComponent.text))
|
||||||
if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text)
|
|
||||||
{
|
{
|
||||||
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
string translatedText = StringStore.TranslateText(textComponent.text);
|
||||||
|
if (!string.IsNullOrEmpty(translatedText) && translatedText != textComponent.text)
|
||||||
TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true);
|
|
||||||
|
|
||||||
if (newTMP != null)
|
|
||||||
{
|
{
|
||||||
newTMP.text = translatedText;
|
TMP_FontAsset fontAsset = FontStore.LoadTMPFont(Utils.Language.ToString());
|
||||||
//Debug.Log($"Converted and translated text: {textComponent.text} -> {translatedText}");
|
TextMeshProUGUI newTMP = StringStore.ConvertToTextMeshPro(textComponent, fontAsset, true);
|
||||||
|
|
||||||
|
if (newTMP != null)
|
||||||
|
{
|
||||||
|
newTMP.text = translatedText;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also handle TMP components directly under the button
|
||||||
|
if (__instance.transform.childCount >= 2)
|
||||||
|
{
|
||||||
|
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
||||||
|
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
||||||
|
|
||||||
|
StringStore.TranslateTextUI(text, false);
|
||||||
|
StringStore.TranslateTextUI(textShadow, false);
|
||||||
|
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(nameof(UIButton.OnMouseUpAsButton))]
|
||||||
|
[HarmonyPostfix]
|
||||||
|
public static void Postfix_OnMouseUpAsButton(UIButton __instance)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (__instance.transform.childCount >= 2)
|
||||||
|
{
|
||||||
|
TextMeshProUGUI text = __instance.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
|
||||||
|
TextMeshProUGUI textShadow = __instance.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
||||||
|
|
||||||
|
StringStore.TranslateTextUI(text, false);
|
||||||
|
StringStore.TranslateTextUI(textShadow, false);
|
||||||
|
text.autoSizeTextContainer = textShadow.autoSizeTextContainer = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -439,7 +439,6 @@
|
||||||
<Compile Include="Patches\Managers\AlmanacPlantBank_Patch.cs" />
|
<Compile Include="Patches\Managers\AlmanacPlantBank_Patch.cs" />
|
||||||
<Compile Include="Patches\Managers\DifficultyMgr_Patch.cs" />
|
<Compile Include="Patches\Managers\DifficultyMgr_Patch.cs" />
|
||||||
<Compile Include="Patches\Managers\EndlessMgr_Patch.cs" />
|
<Compile Include="Patches\Managers\EndlessMgr_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\ButtonObjects\EveBtn_Patch.cs" />
|
|
||||||
<Compile Include="Patches\GameObjects\GardenPlant_Patch.cs" />
|
<Compile Include="Patches\GameObjects\GardenPlant_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\Close_Patch.cs" />
|
<Compile Include="Patches\GameObjects\Close_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\CustomSettings_Patch.cs" />
|
<Compile Include="Patches\GameObjects\CustomSettings_Patch.cs" />
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue