Merge branch 'cassidy'
This commit is contained in:
commit
07b49647d3
6 changed files with 178 additions and 19 deletions
|
|
@ -13,7 +13,7 @@
|
||||||
https://nuget.samboy.dev/v3/index.json
|
https://nuget.samboy.dev/v3/index.json
|
||||||
</RestoreAdditionalProjectSources>
|
</RestoreAdditionalProjectSources>
|
||||||
<RootNamespace>PvZ_Fusion_Translator__BepInEx_</RootNamespace>
|
<RootNamespace>PvZ_Fusion_Translator__BepInEx_</RootNamespace>
|
||||||
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion_2.5-BepInEx</GamePath>
|
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion_2.5.1-BepInEx</GamePath>
|
||||||
<Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate;DebugMulti</Configurations>
|
<Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate;DebugMulti</Configurations>
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Il2Cpp;
|
using Il2Cpp;
|
||||||
using Il2CppTMPro;
|
using Il2CppTMPro;
|
||||||
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
|
|
@ -30,6 +31,11 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
foreach(TextMeshProUGUI text in __instance.transform.GetComponentsInChildren<TextMeshProUGUI>())
|
||||||
|
{
|
||||||
|
text.text = StringStore.TranslateText(text.text);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using Il2Cpp;
|
using Il2Cpp;
|
||||||
using Il2CppTMPro;
|
using Il2CppTMPro;
|
||||||
|
using MelonLoader;
|
||||||
using PvZ_Fusion_Translator;
|
using PvZ_Fusion_Translator;
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
public class OptionButtonData
|
public class OptionButtonData
|
||||||
|
|
@ -12,7 +14,9 @@ public class OptionButtonData
|
||||||
public OptionBtn Button { get; set; }
|
public OptionBtn Button { get; set; }
|
||||||
public Vector3 Position { get; set; }
|
public Vector3 Position { get; set; }
|
||||||
public Utils.LanguageEnum? Language { get; set; } // Null if it's the "Next" button
|
public Utils.LanguageEnum? Language { get; set; } // Null if it's the "Next" button
|
||||||
|
public Utils.ToggleEnum? Toggle { get; set; } // Null if it's the "Next" button
|
||||||
public bool IsNextButton { get; set; }
|
public bool IsNextButton { get; set; }
|
||||||
|
public bool shifted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
|
|
@ -20,19 +24,27 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
internal class OptLanguageBtn_Patch
|
internal class OptLanguageBtn_Patch
|
||||||
{
|
{
|
||||||
public static Dictionary<int, OptionButtonData> LanguageBtnDict = new();
|
public static Dictionary<int, OptionButtonData> LanguageBtnDict = new();
|
||||||
private static bool buttonsCreated = false;
|
public static Dictionary<int, OptionButtonData> ToggleBtnDict = new();
|
||||||
private static OptionBtn cachedTemplateButton;
|
private static bool buttonsCreated = false;
|
||||||
|
private static bool togglesCreated = false;
|
||||||
|
private static OptionBtn cachedTemplateButton;
|
||||||
|
private static OptionBtn cachedTemplateToggleButton;
|
||||||
|
|
||||||
private const float startX = 4.3241f + 2.56f;
|
private const float startX = 4.3241f + 2.56f;
|
||||||
private const float startY = 2.7769f;
|
private const float startY = 2.7769f;
|
||||||
private const float ySpacing = 1.2505f;
|
private const float ySpacing = 1.2505f;
|
||||||
|
|
||||||
private static List<Utils.LanguageEnum> AvailableLanguages;
|
private const float toggleStartX = 4.3241f;
|
||||||
private const int LanguagesPerPage = 5;
|
private const float toggleStartY = -2.2251f;
|
||||||
|
|
||||||
|
private static List<Utils.LanguageEnum> AvailableLanguages;
|
||||||
|
private static List<Utils.ToggleEnum> AvailableToggles;
|
||||||
|
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
|
private static OptionBtn[] buttonSlots = new OptionBtn[6]; // 5 language buttons + 1 next button
|
||||||
|
private static OptionBtn[] toggleSlots = new OptionBtn[2];
|
||||||
|
|
||||||
public static void CreateLanguageButtons(OptionBtn templateButton)
|
public static void CreateLanguageButtons(OptionBtn templateButton)
|
||||||
{
|
{
|
||||||
if (buttonsCreated) return;
|
if (buttonsCreated) return;
|
||||||
buttonsCreated = true;
|
buttonsCreated = true;
|
||||||
|
|
@ -64,12 +76,45 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
UpdatePage();
|
UpdatePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void CreateToggleButtons(OptionBtn templateButton)
|
||||||
|
{
|
||||||
|
if (togglesCreated) return;
|
||||||
|
togglesCreated = true;
|
||||||
|
cachedTemplateToggleButton = templateButton;
|
||||||
|
|
||||||
|
AvailableToggles = Enum.GetValues(typeof(Utils.ToggleEnum))
|
||||||
|
.Cast<Utils.ToggleEnum>()
|
||||||
|
.Where(lang => lang != Utils.ToggleEnum.TOGGLE_END)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
var newButton = Object.Instantiate(templateButton, templateButton.transform.parent);
|
||||||
|
newButton.optionType = 100 + i;
|
||||||
|
|
||||||
|
float yPos = toggleStartY - i * ySpacing;
|
||||||
|
Vector3 pos = new(toggleStartX, yPos);
|
||||||
|
newButton.transform.position = pos;
|
||||||
|
|
||||||
|
toggleSlots[i] = newButton;
|
||||||
|
|
||||||
|
ToggleBtnDict[newButton.GetInstanceID()] = new OptionButtonData
|
||||||
|
{
|
||||||
|
Button = newButton,
|
||||||
|
Position = pos
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdatePage();
|
||||||
|
}
|
||||||
|
|
||||||
private static void UpdatePage()
|
private static void UpdatePage()
|
||||||
{
|
{
|
||||||
int startIndex = currentPage * LanguagesPerPage;
|
int startIndex = currentPage * LanguagesPerPage;
|
||||||
int langCount = AvailableLanguages.Count;
|
int langCount = AvailableLanguages.Count;
|
||||||
|
int toggleCount = (togglesCreated) ? AvailableToggles.Count : 0;
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
var btn = buttonSlots[i];
|
var btn = buttonSlots[i];
|
||||||
var data = LanguageBtnDict[btn.GetInstanceID()];
|
var data = LanguageBtnDict[btn.GetInstanceID()];
|
||||||
|
|
@ -90,6 +135,30 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (togglesCreated)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
var btn = toggleSlots[i];
|
||||||
|
var data = ToggleBtnDict[btn.GetInstanceID()];
|
||||||
|
|
||||||
|
if (i < toggleCount)
|
||||||
|
{
|
||||||
|
var toggle = AvailableToggles[i];
|
||||||
|
data.Toggle = toggle;
|
||||||
|
data.IsNextButton = false;
|
||||||
|
btn.gameObject.SetActive(true);
|
||||||
|
UpdateButtonText(btn, toggle.ToString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data.Language = null;
|
||||||
|
data.IsNextButton = false;
|
||||||
|
btn.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// "Next" button always visible at index 5
|
// "Next" button always visible at index 5
|
||||||
var nextBtn = buttonSlots[5];
|
var nextBtn = buttonSlots[5];
|
||||||
var nextData = LanguageBtnDict[nextBtn.GetInstanceID()];
|
var nextData = LanguageBtnDict[nextBtn.GetInstanceID()];
|
||||||
|
|
@ -130,15 +199,28 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FlashMessage(OptionBtn button, string message)
|
private static void FlashMessage(OptionBtn button, string message, float yShift = 0.0f)
|
||||||
{
|
{
|
||||||
var child = button.transform.GetChild(0);
|
var child = button.transform.GetChild(0);
|
||||||
if (child != null)
|
if (child != null)
|
||||||
{
|
{
|
||||||
var text = child.GetComponent<TextMeshProUGUI>();
|
var text = child.GetComponent<TextMeshProUGUI>();
|
||||||
if (text != null)
|
if (text != null)
|
||||||
{
|
{
|
||||||
text.text = message;
|
text.text = message;
|
||||||
|
OptionButtonData data;
|
||||||
|
bool isToggle = ToggleBtnDict.TryGetValue(button.GetInstanceID(), out data);
|
||||||
|
|
||||||
|
if(isToggle)
|
||||||
|
{
|
||||||
|
text.transform.position = new Vector3(text.transform.position.x, text.transform.position.y + (ToggleBtnDict[button.GetInstanceID()].shifted ? 0.0f : yShift), text.transform.position.z);
|
||||||
|
ToggleBtnDict[button.GetInstanceID()].shifted = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
text.transform.position = new Vector3(text.transform.position.x, text.transform.position.y + (LanguageBtnDict[button.GetInstanceID()].shifted ? 0.0f : yShift), text.transform.position.z);
|
||||||
|
LanguageBtnDict[button.GetInstanceID()].shifted = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
child.gameObject.SetActive(true);
|
child.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
|
@ -152,6 +234,24 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ToggleCustomAssets(string type)
|
||||||
|
{
|
||||||
|
if (type != "Textures" && type != "Audio") return;
|
||||||
|
|
||||||
|
if(type == "Textures")
|
||||||
|
{
|
||||||
|
Utils.customTextures = (Utils.customTextures) ? false : true;
|
||||||
|
MelonPreferences.SetEntryValue<bool>("PvZ_Fusion_Translator", "DefaultTextures", !Utils.customTextures);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == "Audio")
|
||||||
|
{
|
||||||
|
Utils.customAudio = (Utils.customAudio) ? false : true;
|
||||||
|
MelonPreferences.SetEntryValue<bool>("PvZ_Fusion_Translator", "DefaultAudio", !Utils.customAudio);
|
||||||
|
}
|
||||||
|
MelonPreferences.Save();
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPatch(typeof(OptionBtn))]
|
[HarmonyPatch(typeof(OptionBtn))]
|
||||||
public static class OptLangBtn_Patch
|
public static class OptLangBtn_Patch
|
||||||
{
|
{
|
||||||
|
|
@ -162,8 +262,10 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
if (!buttonsCreated || cachedTemplateButton == null)
|
if (!buttonsCreated || cachedTemplateButton == null)
|
||||||
{
|
{
|
||||||
buttonsCreated = false;
|
buttonsCreated = false;
|
||||||
CreateLanguageButtons(__instance);
|
togglesCreated = false;
|
||||||
}
|
CreateLanguageButtons(__instance);
|
||||||
|
CreateToggleButtons(__instance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch("OnMouseUpAsButton")]
|
[HarmonyPatch("OnMouseUpAsButton")]
|
||||||
|
|
@ -195,7 +297,21 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (ToggleBtnDict.TryGetValue(__instance.GetInstanceID(), out var toggleData))
|
||||||
|
{
|
||||||
|
string toggleType = toggleData.Toggle.ToString();
|
||||||
|
ToggleCustomAssets(toggleType);
|
||||||
|
if (toggleType == "Textures")
|
||||||
|
{
|
||||||
|
FlashMessage(toggleData.Button, "<size=10>Toggled custom textures! (Restart game to apply changes.)", 0.1f);
|
||||||
|
}
|
||||||
|
else if (toggleType == "Audio")
|
||||||
|
{
|
||||||
|
FlashMessage(toggleData.Button, "<size=10>Toggled custom audio! (Restart game to apply changes.)", 0.1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPatch(nameof(OptionBtn.Update))]
|
[HarmonyPatch(nameof(OptionBtn.Update))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
|
|
@ -205,7 +321,12 @@ namespace PvZ_Fusion_Translator.Patches.GameObjects.ButtonObjects
|
||||||
{
|
{
|
||||||
btnData.Button.transform.position = btnData.Position;
|
btnData.Button.transform.position = btnData.Position;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (ToggleBtnDict.TryGetValue(__instance.GetInstanceID(), out var toggleData))
|
||||||
|
{
|
||||||
|
toggleData.Button.transform.position = toggleData.Position;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
MelonLoader/Patches/GameObjects/OtherMenu_Patch.cs
Normal file
20
MelonLoader/Patches/GameObjects/OtherMenu_Patch.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
using HarmonyLib;
|
||||||
|
using Il2Cpp;
|
||||||
|
using Il2CppTMPro;
|
||||||
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace PvZ_Fusion_Translator.Patches.GameObjects
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(OtherMenu))]
|
||||||
|
public static class OtherMenu_Patch
|
||||||
|
{
|
||||||
|
[HarmonyPatch(nameof(OtherMenu.UpdateText))]
|
||||||
|
[HarmonyPostfix]
|
||||||
|
private static void UpdateText(OtherMenu __instance)
|
||||||
|
{
|
||||||
|
__instance.text1 = StringStore.TranslateText(__instance.text1);
|
||||||
|
__instance.text2 = StringStore.TranslateText(__instance.text2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate</Configurations>
|
<Configurations>Debug;DebugEnglish;ReleaseMulti;ReleaseEnglish;DebugTesting;ReleaseOther;DebugObfuscate;ReleaseObfuscate</Configurations>
|
||||||
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion_2.4.2</GamePath>
|
<GamePath>C:\Users\rainb\Desktop\PC_PVZ-Fusion_2.5.1</GamePath>
|
||||||
<Platforms>AnyCPU;ARM64;x64</Platforms>
|
<Platforms>AnyCPU;ARM64;x64</Platforms>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
@ -452,6 +452,7 @@
|
||||||
<Compile Include="Patches\GameObjects\AbyssCheckInBag_Patch.cs" />
|
<Compile Include="Patches\GameObjects\AbyssCheckInBag_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\AbyssStoreMenu_Patch.cs" />
|
<Compile Include="Patches\GameObjects\AbyssStoreMenu_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\AbyssSettlementMenu_Patch.cs" />
|
<Compile Include="Patches\GameObjects\AbyssSettlementMenu_Patch.cs" />
|
||||||
|
<Compile Include="Patches\GameObjects\OtherMenu_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssCheckSellMenu_Patch.cs" />
|
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssCheckSellMenu_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssBuffButton_Patch.cs" />
|
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssBuffButton_Patch.cs" />
|
||||||
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssLevelEnter_Patch.cs" />
|
<Compile Include="Patches\GameObjects\ButtonObjects\AbyssLevelEnter_Patch.cs" />
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using PvZ_Fusion_Translator.AssetStore;
|
using MelonLoader;
|
||||||
|
using PvZ_Fusion_Translator.AssetStore;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
@ -104,7 +105,10 @@ namespace PvZ_Fusion_Translator
|
||||||
|
|
||||||
public static Utils.LanguageEnum Language;
|
public static Utils.LanguageEnum Language;
|
||||||
|
|
||||||
public enum LanguageEnum
|
public static bool customTextures = !MelonPreferences.GetEntryValue<bool>("PvZ_Fusion_Translator", "DefaultTextures");
|
||||||
|
public static bool customAudio = !MelonPreferences.GetEntryValue<bool>("PvZ_Fusion_Translator", "DefaultAudio");
|
||||||
|
|
||||||
|
public enum LanguageEnum
|
||||||
{
|
{
|
||||||
// first column
|
// first column
|
||||||
English,
|
English,
|
||||||
|
|
@ -131,5 +135,12 @@ namespace PvZ_Fusion_Translator
|
||||||
|
|
||||||
LANG_END
|
LANG_END
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ToggleEnum
|
||||||
|
{
|
||||||
|
Textures,
|
||||||
|
Audio,
|
||||||
|
TOGGLE_END
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue