From 16306f9ca8c4684225da367bd09540ed31394009 Mon Sep 17 00:00:00 2001 From: Nicolas Gnyra Date: Fri, 19 Jan 2024 21:07:40 -0500 Subject: [PATCH] Update for Beat Saber 1.34.5 --- .../BeatSaberMarkupLanguage.csproj | 91 ++++++++++--------- BeatSaberMarkupLanguage/BeatSaberUI.cs | 3 +- .../Components/CustomListTableData.cs | 7 ++ .../Components/LocalizableText.cs | 14 --- .../Components/ModalKeyboard.cs | 3 +- .../Components/Settings/BoolSetting.cs | 2 +- .../Components/TabSelector.cs | 2 +- .../FontAssetDefaultValueSetters.cs | 35 +++++++ .../Harmony Patches/LocalizationLoader.cs | 23 +++++ .../LocalizationModelSilencer.cs | 33 +++++++ .../Harmony Patches/MainMenuInstaller.cs | 3 +- .../Harmony Patches/MainSystemInitAwaiter.cs | 28 ++++++ BeatSaberMarkupLanguage/Plugin.cs | 17 +--- .../Settings/BSMLSettings.cs | 2 +- .../Settings/UI/ModSettingsFlowCoordinator.cs | 2 +- BeatSaberMarkupLanguage/Tags/BSMLTag.cs | 16 ++-- BeatSaberMarkupLanguage/Tags/ButtonTag.cs | 2 +- BeatSaberMarkupLanguage/Tags/ModifierTag.cs | 5 +- BeatSaberMarkupLanguage/Tags/ScrollViewTag.cs | 3 +- .../Tags/ScrollableSettingsContainerTag.cs | 2 + .../Tags/Settings/ColorSettingTag.cs | 2 +- .../Tags/Settings/DropdownListSettingTag.cs | 2 +- .../Tags/Settings/GenericSliderSettingTag.cs | 2 +- .../Tags/Settings/IncDecSettingTag.cs | 2 +- .../Tags/Settings/StringSettingTag.cs | 2 +- .../Tags/Settings/SubmenuTag.cs | 3 +- .../Tags/Settings/ToggleSettingTag.cs | 2 +- .../Tags/TextPageScrollViewTag.cs | 6 +- BeatSaberMarkupLanguage/Tags/TextTag.cs | 4 + .../LocalizedTextMeshProUGUIHandler.cs | 4 +- .../TypeHandlers/RectTransformHandler.cs | 2 +- .../Util/LocalizationModelExtensions.cs | 18 ++++ .../{ => Util}/MenuInitAwaiter.cs | 6 +- BeatSaberMarkupLanguage/Util/VoidResult.cs | 6 ++ BeatSaberMarkupLanguage/manifest.json | 4 +- 35 files changed, 248 insertions(+), 110 deletions(-) delete mode 100644 BeatSaberMarkupLanguage/Components/LocalizableText.cs create mode 100644 BeatSaberMarkupLanguage/Harmony Patches/FontAssetDefaultValueSetters.cs create mode 100644 BeatSaberMarkupLanguage/Harmony Patches/LocalizationLoader.cs create mode 100644 BeatSaberMarkupLanguage/Harmony Patches/LocalizationModelSilencer.cs create mode 100644 BeatSaberMarkupLanguage/Harmony Patches/MainSystemInitAwaiter.cs create mode 100644 BeatSaberMarkupLanguage/Util/LocalizationModelExtensions.cs rename BeatSaberMarkupLanguage/{ => Util}/MenuInitAwaiter.cs (85%) create mode 100644 BeatSaberMarkupLanguage/Util/VoidResult.cs diff --git a/BeatSaberMarkupLanguage/BeatSaberMarkupLanguage.csproj b/BeatSaberMarkupLanguage/BeatSaberMarkupLanguage.csproj index 315a82d0..4b3d4b53 100644 --- a/BeatSaberMarkupLanguage/BeatSaberMarkupLanguage.csproj +++ b/BeatSaberMarkupLanguage/BeatSaberMarkupLanguage.csproj @@ -13,45 +13,51 @@ - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll + + $(BeatSaberDir)\Libs\0Harmony.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\BGLib.AppFlow.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.ImageConversionModule.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\BGLib.Polyglot.dll False + True - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.InputLegacyModule.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\GameplayCore.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.PhysicsModule.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\HMLib.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.TextCoreFontEngineModule.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\HMUI.dll False + True - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.TextRenderingModule.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UI.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll False True - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UIModule.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\Menu.ColorSettings.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UnityWebRequestModule.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\Menu.CommonLib.dll + False + + + $(BeatSaberDir)\Libs\Newtonsoft.Json.dll False @@ -59,52 +65,53 @@ False True - - $(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll False True - - $(BeatSaberDir)\Beat Saber_Data\Managed\GameplayCore.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\HMLib.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.ImageConversionModule.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\HMUI.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.InputLegacyModule.dll False True - - $(BeatSaberDir)\Beat Saber_Data\Managed\Menu.ColorSettings.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.PhysicsModule.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\Menu.CommonLib.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.TextCoreFontEngineModule.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\Polyglot.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.TextRenderingModule.dll False - - $(BeatSaberDir)\Beat Saber_Data\Managed\VRUI.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UI.dll False True - - $(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UIModule.dll False - - $(BeatSaberDir)\Libs\0Harmony.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UnityWebRequestModule.dll False - - $(BeatSaberDir)\Libs\Newtonsoft.Json.dll + + $(BeatSaberDir)\Beat Saber_Data\Managed\VRUI.dll False + True $(BeatSaberDir)\Beat Saber_Data\Managed\Zenject.dll diff --git a/BeatSaberMarkupLanguage/BeatSaberUI.cs b/BeatSaberMarkupLanguage/BeatSaberUI.cs index 5fa6d253..26faa610 100644 --- a/BeatSaberMarkupLanguage/BeatSaberUI.cs +++ b/BeatSaberMarkupLanguage/BeatSaberUI.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using BeatSaberMarkupLanguage.Animations; +using BGLib.Polyglot; using HMUI; using IPA.Utilities.Async; using TMPro; @@ -275,7 +276,7 @@ public static T CreateText(RectTransform parent, string text, Vector2 anchore public static void SetButtonText(this Button button, string text) { - Polyglot.LocalizedTextMeshProUGUI localizer = button.GetComponentInChildren(true); + LocalizedTextMeshProUGUI localizer = button.GetComponentInChildren(true); if (localizer != null) { Object.Destroy(localizer); diff --git a/BeatSaberMarkupLanguage/Components/CustomListTableData.cs b/BeatSaberMarkupLanguage/Components/CustomListTableData.cs index d99ea34c..0402c104 100644 --- a/BeatSaberMarkupLanguage/Components/CustomListTableData.cs +++ b/BeatSaberMarkupLanguage/Components/CustomListTableData.cs @@ -184,6 +184,13 @@ public int NumberOfCells() return data.Count(); } + private void OnDestroy() + { + Destroy(songListTableCellInstance); + Destroy(levelPackTableCellInstance); + Destroy(simpleTextTableCellInstance); + } + public class CustomCellInfo { public string text; diff --git a/BeatSaberMarkupLanguage/Components/LocalizableText.cs b/BeatSaberMarkupLanguage/Components/LocalizableText.cs deleted file mode 100644 index c83403a5..00000000 --- a/BeatSaberMarkupLanguage/Components/LocalizableText.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Polyglot; -using TMPro; - -namespace BeatSaberMarkupLanguage.Components -{ - public class LocalizableText : LocalizedTextMeshProUGUI - { - public TextMeshProUGUI TextMesh - { - get => localizedComponent; - set => localizedComponent = value; - } - } -} diff --git a/BeatSaberMarkupLanguage/Components/ModalKeyboard.cs b/BeatSaberMarkupLanguage/Components/ModalKeyboard.cs index 58c335d2..710da016 100644 --- a/BeatSaberMarkupLanguage/Components/ModalKeyboard.cs +++ b/BeatSaberMarkupLanguage/Components/ModalKeyboard.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using BeatSaberMarkupLanguage.Parser; +using BGLib.Polyglot; using HMUI; using TMPro; using UnityEngine; @@ -569,7 +570,7 @@ public KEY(KEYBOARD kb, Vector2 position, string text, float width, float height highlightedColors[i] = new Color(0.1f, 1, 0.1f, graphicColor.a); } - Polyglot.LocalizedTextMeshProUGUI localizer = mybutton.GetComponentInChildren(true); + LocalizedTextMeshProUGUI localizer = mybutton.GetComponentInChildren(true); if (localizer != null) { Object.Destroy(localizer); diff --git a/BeatSaberMarkupLanguage/Components/Settings/BoolSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/BoolSetting.cs index 6f533c44..57ab9243 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/BoolSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/BoolSetting.cs @@ -1,5 +1,5 @@ using System; -using Polyglot; +using BGLib.Polyglot; namespace BeatSaberMarkupLanguage.Components.Settings { diff --git a/BeatSaberMarkupLanguage/Components/TabSelector.cs b/BeatSaberMarkupLanguage/Components/TabSelector.cs index cbb1fa86..3746db68 100644 --- a/BeatSaberMarkupLanguage/Components/TabSelector.cs +++ b/BeatSaberMarkupLanguage/Components/TabSelector.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; using BeatSaberMarkupLanguage.Parser; +using BGLib.Polyglot; using HMUI; -using Polyglot; using UnityEngine; using UnityEngine.UI; diff --git a/BeatSaberMarkupLanguage/Harmony Patches/FontAssetDefaultValueSetters.cs b/BeatSaberMarkupLanguage/Harmony Patches/FontAssetDefaultValueSetters.cs new file mode 100644 index 00000000..8b38fb8b --- /dev/null +++ b/BeatSaberMarkupLanguage/Harmony Patches/FontAssetDefaultValueSetters.cs @@ -0,0 +1,35 @@ +using System.Linq; +using HarmonyLib; +using TMPro; +using UnityEngine; + +namespace BeatSaberMarkupLanguage.Harmony_Patches +{ + [HarmonyPatch(typeof(ShaderUtilities), nameof(ShaderUtilities.ShaderRef_MobileSDF), MethodType.Getter)] + internal static class ShaderUtilities_ShaderRef_MobileSDF + { + public static bool Prefix(ref Shader __result) + { + if (ShaderUtilities.k_ShaderRef_MobileSDF == null) + { + ShaderUtilities.k_ShaderRef_MobileSDF = Resources.FindObjectsOfTypeAll().First(s => s.name == "TextMeshPro/Mobile/Distance Field"); + } + + __result = ShaderUtilities.k_ShaderRef_MobileSDF; + + return false; + } + } + + [HarmonyPatch(typeof(TMP_Settings), nameof(TMP_Settings.instance), MethodType.Getter)] + internal static class TMP_Settings_GetFontAsset + { + public static void Postfix() + { + if (TMP_Settings.s_Instance.m_defaultFontAsset == null) + { + TMP_Settings.s_Instance.m_defaultFontAsset = Resources.FindObjectsOfTypeAll().First(f => f.name == "Teko-Medium SDF"); + } + } + } +} diff --git a/BeatSaberMarkupLanguage/Harmony Patches/LocalizationLoader.cs b/BeatSaberMarkupLanguage/Harmony Patches/LocalizationLoader.cs new file mode 100644 index 00000000..fc1294b4 --- /dev/null +++ b/BeatSaberMarkupLanguage/Harmony Patches/LocalizationLoader.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using BGLib.Polyglot; +using HarmonyLib; +using UnityEngine; + +namespace BeatSaberMarkupLanguage.Harmony_Patches +{ + [HarmonyPatch(typeof(LocalizationAsyncInstaller), "LoadResourcesBeforeInstall")] + internal class LocalizationLoader + { + public static void Prefix(IList assets) + { + using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BeatSaberMarkupLanguage.Resources.beat-saber-markup-language.csv")) + using (StreamReader reader = new(stream)) + { + string content = reader.ReadToEnd(); + assets.Add(new TextAsset(content)); + } + } + } +} diff --git a/BeatSaberMarkupLanguage/Harmony Patches/LocalizationModelSilencer.cs b/BeatSaberMarkupLanguage/Harmony Patches/LocalizationModelSilencer.cs new file mode 100644 index 00000000..90107f4d --- /dev/null +++ b/BeatSaberMarkupLanguage/Harmony Patches/LocalizationModelSilencer.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Reflection.Emit; +using BGLib.Polyglot; +using HarmonyLib; +using UnityEngine; + +namespace BeatSaberMarkupLanguage.Harmony_Patches +{ + [HarmonyPatch(typeof(LocalizationModel))] + internal static class LocalizationModelSilencer + { + private static readonly MethodInfo UnityDebugLogWarning = AccessTools.DeclaredMethod(typeof(Debug), nameof(Debug.LogWarning), new Type[] { typeof(object) }); + + [HarmonyPatch(nameof(LocalizationModel.Get))] + [HarmonyPatch(nameof(LocalizationModel.TryGet))] + private static IEnumerable Transpiler(IEnumerable instructions) + { + foreach (CodeInstruction instruction in instructions) + { + if (instruction.Calls(UnityDebugLogWarning)) + { + yield return new CodeInstruction(OpCodes.Pop); + } + else + { + yield return instruction; + } + } + } + } +} diff --git a/BeatSaberMarkupLanguage/Harmony Patches/MainMenuInstaller.cs b/BeatSaberMarkupLanguage/Harmony Patches/MainMenuInstaller.cs index ccfc0af5..e31f0bb4 100644 --- a/BeatSaberMarkupLanguage/Harmony Patches/MainMenuInstaller.cs +++ b/BeatSaberMarkupLanguage/Harmony Patches/MainMenuInstaller.cs @@ -2,6 +2,7 @@ using BeatSaberMarkupLanguage.Animations; using BeatSaberMarkupLanguage.MenuButtons; using BeatSaberMarkupLanguage.Settings; +using BeatSaberMarkupLanguage.Util; using HarmonyLib; using Zenject; @@ -44,7 +45,7 @@ private static void Prefix(MainSettingsMenuViewControllersInstaller __instance) container.Bind(typeof(IInitializable), typeof(IDisposable)).To().AsSingle(); #if DEBUG - container.Bind(typeof(IInitializable)).To().AsSingle(); + container.Bind(typeof(IInitializable)).To().AsSingle(); #endif } } diff --git a/BeatSaberMarkupLanguage/Harmony Patches/MainSystemInitAwaiter.cs b/BeatSaberMarkupLanguage/Harmony Patches/MainSystemInitAwaiter.cs new file mode 100644 index 00000000..51231772 --- /dev/null +++ b/BeatSaberMarkupLanguage/Harmony Patches/MainSystemInitAwaiter.cs @@ -0,0 +1,28 @@ +using System.Threading.Tasks; +using BeatSaberMarkupLanguage.Util; +using HarmonyLib; + +namespace BeatSaberMarkupLanguage.Harmony_Patches +{ + [HarmonyPatch] + internal static class MainSystemInitAwaiter + { + private static TaskCompletionSource taskCompletionSource = new(); + + public static Task WaitForMainSystemInitAsync() => taskCompletionSource.Task; + + [HarmonyPatch(typeof(MainSystemInit), nameof(MainSystemInit.Init))] + [HarmonyPostfix] + private static void OnInit() + { + taskCompletionSource.SetResult(default); + } + + [HarmonyPatch(typeof(AppInit), "OnDestroy")] + [HarmonyPostfix] + private static void OnDestroy() + { + taskCompletionSource = new(); + } + } +} diff --git a/BeatSaberMarkupLanguage/Plugin.cs b/BeatSaberMarkupLanguage/Plugin.cs index 31473a39..8586c0fa 100644 --- a/BeatSaberMarkupLanguage/Plugin.cs +++ b/BeatSaberMarkupLanguage/Plugin.cs @@ -1,16 +1,15 @@ using System; -using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Threading.Tasks; using BeatSaberMarkupLanguage.Animations; +using BeatSaberMarkupLanguage.Harmony_Patches; +using BeatSaberMarkupLanguage.Util; using HarmonyLib; using IPA; using IPA.Config.Stores; -using Polyglot; using TMPro; -using UnityEngine; using Conf = IPA.Config.Config; using IPALogger = IPA.Logging.Logger; @@ -48,7 +47,6 @@ public void OnStart() { LoadAndSetUpFontFallbacksAsync().ContinueWith((task) => Logger.Log.Error($"Failed to set up fallback fonts\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted); AnimationController.instance.InitializeLoadingAnimation().ContinueWith((task) => Logger.Log.Error($"Failed to initialize loading animation\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted); - AddLocalization(); } [OnExit] @@ -56,19 +54,10 @@ public void OnExit() { } - private void AddLocalization() - { - using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BeatSaberMarkupLanguage.Resources.beat-saber-markup-language.csv")) - using (StreamReader reader = new(stream)) - { - string content = reader.ReadToEnd(); - Localization.Instance.InputFiles.Add(new LocalizationAsset { Format = GoogleDriveDownloadFormat.CSV, TextAsset = new TextAsset(content) }); - } - } - private async Task LoadAndSetUpFontFallbacksAsync() { await FontManager.AsyncLoadSystemFonts(); + await MainSystemInitAwaiter.WaitForMainSystemInitAsync(); if (!FontManager.TryGetTMPFontByFullName("Segoe UI", out TMP_FontAsset fallback) && !FontManager.TryGetTMPFontByFamily("Arial", out fallback)) diff --git a/BeatSaberMarkupLanguage/Settings/BSMLSettings.cs b/BeatSaberMarkupLanguage/Settings/BSMLSettings.cs index f315e0d2..9c0194dc 100644 --- a/BeatSaberMarkupLanguage/Settings/BSMLSettings.cs +++ b/BeatSaberMarkupLanguage/Settings/BSMLSettings.cs @@ -6,8 +6,8 @@ using System.Threading.Tasks; using BeatSaberMarkupLanguage.Attributes; using BeatSaberMarkupLanguage.Util; +using BGLib.Polyglot; using HMUI; -using Polyglot; using UnityEngine; using UnityEngine.UI; using Zenject; diff --git a/BeatSaberMarkupLanguage/Settings/UI/ModSettingsFlowCoordinator.cs b/BeatSaberMarkupLanguage/Settings/UI/ModSettingsFlowCoordinator.cs index 4a85e6d5..2d5c3066 100644 --- a/BeatSaberMarkupLanguage/Settings/UI/ModSettingsFlowCoordinator.cs +++ b/BeatSaberMarkupLanguage/Settings/UI/ModSettingsFlowCoordinator.cs @@ -3,8 +3,8 @@ using System.Reflection; using BeatSaberMarkupLanguage.Attributes; using BeatSaberMarkupLanguage.Settings.UI.ViewControllers; +using BGLib.Polyglot; using HMUI; -using Polyglot; using UnityEngine; namespace BeatSaberMarkupLanguage.Settings diff --git a/BeatSaberMarkupLanguage/Tags/BSMLTag.cs b/BeatSaberMarkupLanguage/Tags/BSMLTag.cs index 9143d885..96dd95ef 100644 --- a/BeatSaberMarkupLanguage/Tags/BSMLTag.cs +++ b/BeatSaberMarkupLanguage/Tags/BSMLTag.cs @@ -1,6 +1,6 @@ using System; -using BeatSaberMarkupLanguage.Components; -using Polyglot; +using BeatSaberMarkupLanguage.Util; +using BGLib.Polyglot; using TMPro; using UnityEngine; using Zenject; @@ -23,7 +23,7 @@ public virtual void Setup() { } - protected LocalizableText CreateLocalizableText(GameObject gameObject) + protected LocalizedTextMeshProUGUI CreateLocalizableText(GameObject gameObject) { if (!gameObject.TryGetComponent(out TextMeshProUGUI textMesh)) { @@ -33,14 +33,14 @@ protected LocalizableText CreateLocalizableText(GameObject gameObject) bool wasActive = gameObject.activeSelf; gameObject.SetActive(false); - LocalizableText localizableText = gameObject.AddComponent(); + LocalizedTextMeshProUGUI localizedText = gameObject.AddComponent(); - localizableText.enabled = false; - localizableText.TextMesh = textMesh; + localizedText.enabled = false; + localizedText.localizedComponent = textMesh; gameObject.SetActive(wasActive); - return localizableText; + return localizedText; } protected LocalizedTextMeshProUGUI ConfigureLocalizedText(GameObject gameObject) @@ -48,7 +48,7 @@ protected LocalizedTextMeshProUGUI ConfigureLocalizedText(GameObject gameObject) LocalizedTextMeshProUGUI localizedText = gameObject.GetComponent(); localizedText.enabled = false; - localizedText.Key = string.Empty; + localizedText.key = string.Empty; Localization.Instance.RemoveOnLocalizeEvent(localizedText); return localizedText; diff --git a/BeatSaberMarkupLanguage/Tags/ButtonTag.cs b/BeatSaberMarkupLanguage/Tags/ButtonTag.cs index 0f87f5f8..46dab8cd 100644 --- a/BeatSaberMarkupLanguage/Tags/ButtonTag.cs +++ b/BeatSaberMarkupLanguage/Tags/ButtonTag.cs @@ -1,6 +1,6 @@ using System.Linq; using BeatSaberMarkupLanguage.Components; -using Polyglot; +using BGLib.Polyglot; using TMPro; using UnityEngine; using UnityEngine.UI; diff --git a/BeatSaberMarkupLanguage/Tags/ModifierTag.cs b/BeatSaberMarkupLanguage/Tags/ModifierTag.cs index 4ef81531..1cd03df1 100644 --- a/BeatSaberMarkupLanguage/Tags/ModifierTag.cs +++ b/BeatSaberMarkupLanguage/Tags/ModifierTag.cs @@ -2,6 +2,7 @@ using System.Linq; using BeatSaberMarkupLanguage.Components; using BeatSaberMarkupLanguage.Components.Settings; +using BGLib.Polyglot; using HMUI; using TMPro; using UnityEngine; @@ -36,8 +37,8 @@ public override GameObject CreateObject(Transform parent) TextMeshProUGUI text = nameText.GetComponent(); text.text = "Default Text"; - LocalizableText localizedText = CreateLocalizableText(nameText); - localizedText.MaintainTextAlignment = true; + LocalizedTextMeshProUGUI localizedText = CreateLocalizableText(nameText); + localizedText.maintainTextAlignment = true; List externalComponents = gameObject.AddComponent().components; externalComponents.Add(text); diff --git a/BeatSaberMarkupLanguage/Tags/ScrollViewTag.cs b/BeatSaberMarkupLanguage/Tags/ScrollViewTag.cs index 0de4c314..b59ab056 100644 --- a/BeatSaberMarkupLanguage/Tags/ScrollViewTag.cs +++ b/BeatSaberMarkupLanguage/Tags/ScrollViewTag.cs @@ -1,4 +1,3 @@ -using System.Linq; using BeatSaberMarkupLanguage.Components; using HMUI; using UnityEngine; @@ -17,7 +16,7 @@ public static TextPageScrollView ScrollViewTemplate { if (scrollViewTemplate == null) { - scrollViewTemplate = Resources.FindObjectsOfTypeAll().First()._textPageScrollView; + scrollViewTemplate = Object.FindObjectOfType(true)._textPageScrollView; } return scrollViewTemplate; diff --git a/BeatSaberMarkupLanguage/Tags/ScrollableSettingsContainerTag.cs b/BeatSaberMarkupLanguage/Tags/ScrollableSettingsContainerTag.cs index e0441ea0..67d6da74 100644 --- a/BeatSaberMarkupLanguage/Tags/ScrollableSettingsContainerTag.cs +++ b/BeatSaberMarkupLanguage/Tags/ScrollableSettingsContainerTag.cs @@ -12,6 +12,8 @@ public override GameObject CreateObject(Transform parent) GameObject content = base.CreateObject(parent); ExternalComponents externalComponents = content.GetComponent(); RectTransform scrollTransform = externalComponents.Get(); + scrollTransform.anchorMin = Vector2.zero; + scrollTransform.anchorMax = Vector2.one; scrollTransform.anchoredPosition = new Vector2(2, 6); scrollTransform.sizeDelta = new Vector2(0, -20); scrollTransform.gameObject.name = "BSMLScrollableSettingsContainer"; diff --git a/BeatSaberMarkupLanguage/Tags/Settings/ColorSettingTag.cs b/BeatSaberMarkupLanguage/Tags/Settings/ColorSettingTag.cs index 63ac2706..fd4d22c6 100644 --- a/BeatSaberMarkupLanguage/Tags/Settings/ColorSettingTag.cs +++ b/BeatSaberMarkupLanguage/Tags/Settings/ColorSettingTag.cs @@ -2,8 +2,8 @@ using System.Linq; using BeatSaberMarkupLanguage.Components; using BeatSaberMarkupLanguage.Components.Settings; +using BGLib.Polyglot; using HMUI; -using Polyglot; using TMPro; using UnityEngine; using UnityEngine.UI; diff --git a/BeatSaberMarkupLanguage/Tags/Settings/DropdownListSettingTag.cs b/BeatSaberMarkupLanguage/Tags/Settings/DropdownListSettingTag.cs index 685ad1ac..7d9fc92a 100644 --- a/BeatSaberMarkupLanguage/Tags/Settings/DropdownListSettingTag.cs +++ b/BeatSaberMarkupLanguage/Tags/Settings/DropdownListSettingTag.cs @@ -2,8 +2,8 @@ using System.Linq; using BeatSaberMarkupLanguage.Components; using BeatSaberMarkupLanguage.Components.Settings; +using BGLib.Polyglot; using HMUI; -using Polyglot; using UnityEngine; using UnityEngine.UI; diff --git a/BeatSaberMarkupLanguage/Tags/Settings/GenericSliderSettingTag.cs b/BeatSaberMarkupLanguage/Tags/Settings/GenericSliderSettingTag.cs index 6dc3a0e1..d573b0a4 100644 --- a/BeatSaberMarkupLanguage/Tags/Settings/GenericSliderSettingTag.cs +++ b/BeatSaberMarkupLanguage/Tags/Settings/GenericSliderSettingTag.cs @@ -2,8 +2,8 @@ using System.Linq; using BeatSaberMarkupLanguage.Components; using BeatSaberMarkupLanguage.Components.Settings; +using BGLib.Polyglot; using HMUI; -using Polyglot; using TMPro; using UnityEngine; using UnityEngine.UI; diff --git a/BeatSaberMarkupLanguage/Tags/Settings/IncDecSettingTag.cs b/BeatSaberMarkupLanguage/Tags/Settings/IncDecSettingTag.cs index 523156af..a52c6c6e 100644 --- a/BeatSaberMarkupLanguage/Tags/Settings/IncDecSettingTag.cs +++ b/BeatSaberMarkupLanguage/Tags/Settings/IncDecSettingTag.cs @@ -2,7 +2,7 @@ using System.Linq; using BeatSaberMarkupLanguage.Components; using BeatSaberMarkupLanguage.Components.Settings; -using Polyglot; +using BGLib.Polyglot; using TMPro; using UnityEngine; using UnityEngine.UI; diff --git a/BeatSaberMarkupLanguage/Tags/Settings/StringSettingTag.cs b/BeatSaberMarkupLanguage/Tags/Settings/StringSettingTag.cs index 8c80f9ac..21f8ccb2 100644 --- a/BeatSaberMarkupLanguage/Tags/Settings/StringSettingTag.cs +++ b/BeatSaberMarkupLanguage/Tags/Settings/StringSettingTag.cs @@ -2,8 +2,8 @@ using System.Linq; using BeatSaberMarkupLanguage.Components; using BeatSaberMarkupLanguage.Components.Settings; +using BGLib.Polyglot; using HMUI; -using Polyglot; using TMPro; using UnityEngine; using UnityEngine.UI; diff --git a/BeatSaberMarkupLanguage/Tags/Settings/SubmenuTag.cs b/BeatSaberMarkupLanguage/Tags/Settings/SubmenuTag.cs index 71f6cf32..f3d3a580 100644 --- a/BeatSaberMarkupLanguage/Tags/Settings/SubmenuTag.cs +++ b/BeatSaberMarkupLanguage/Tags/Settings/SubmenuTag.cs @@ -1,5 +1,6 @@ using BeatSaberMarkupLanguage.Components; using BeatSaberMarkupLanguage.Settings; +using BGLib.Polyglot; using HMUI; using TMPro; using UnityEngine; @@ -34,7 +35,7 @@ public override GameObject CreateObject(Transform parent) clickableText.color = Color.white; clickableText.rectTransform.sizeDelta = new Vector2(90, 8); - LocalizableText localizedText = CreateLocalizableText(gameObj); + LocalizedTextMeshProUGUI localizedText = CreateLocalizableText(gameObj); ViewController submenuController = BeatSaberUI.CreateViewController(); SettingsMenu.SetupViewControllerTransform(submenuController); diff --git a/BeatSaberMarkupLanguage/Tags/Settings/ToggleSettingTag.cs b/BeatSaberMarkupLanguage/Tags/Settings/ToggleSettingTag.cs index d7e37a1e..2f185762 100644 --- a/BeatSaberMarkupLanguage/Tags/Settings/ToggleSettingTag.cs +++ b/BeatSaberMarkupLanguage/Tags/Settings/ToggleSettingTag.cs @@ -2,8 +2,8 @@ using System.Linq; using BeatSaberMarkupLanguage.Components; using BeatSaberMarkupLanguage.Components.Settings; +using BGLib.Polyglot; using HMUI; -using Polyglot; using TMPro; using UnityEngine; using UnityEngine.UI; diff --git a/BeatSaberMarkupLanguage/Tags/TextPageScrollViewTag.cs b/BeatSaberMarkupLanguage/Tags/TextPageScrollViewTag.cs index 09f0da60..72ff44f0 100644 --- a/BeatSaberMarkupLanguage/Tags/TextPageScrollViewTag.cs +++ b/BeatSaberMarkupLanguage/Tags/TextPageScrollViewTag.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -using System.Linq; using BeatSaberMarkupLanguage.Components; +using BGLib.Polyglot; using HMUI; using TMPro; using UnityEngine; @@ -17,7 +17,7 @@ public override GameObject CreateObject(Transform parent) { if (pageTemplate == null) { - pageTemplate = Resources.FindObjectsOfTypeAll().First()._textPageScrollView; + pageTemplate = Object.FindObjectOfType(true)._textPageScrollView; } TextPageScrollView scrollView = DiContainer.InstantiatePrefabForComponent(pageTemplate, parent); @@ -27,7 +27,7 @@ public override GameObject CreateObject(Transform parent) TextMeshProUGUI textMesh = scrollView._text; textMesh.text = "Default Text"; - LocalizableText localizedText = CreateLocalizableText(textMesh.gameObject); + LocalizedTextMeshProUGUI localizedText = CreateLocalizableText(textMesh.gameObject); textMesh.gameObject.AddComponent().scrollView = scrollView; diff --git a/BeatSaberMarkupLanguage/Tags/TextTag.cs b/BeatSaberMarkupLanguage/Tags/TextTag.cs index c7cfe49d..b5283bd8 100644 --- a/BeatSaberMarkupLanguage/Tags/TextTag.cs +++ b/BeatSaberMarkupLanguage/Tags/TextTag.cs @@ -14,6 +14,7 @@ public override GameObject CreateObject(Transform parent) layer = 5, }; + gameObj.SetActive(false); gameObj.transform.SetParent(parent, false); FormattableText textMesh = gameObj.AddComponent(); @@ -27,6 +28,9 @@ public override GameObject CreateObject(Transform parent) textMesh.rectTransform.anchorMax = new Vector2(0.5f, 0.5f); CreateLocalizableText(gameObj); + + gameObj.SetActive(true); + return gameObj; } } diff --git a/BeatSaberMarkupLanguage/TypeHandlers/LocalizedTextMeshProUGUIHandler.cs b/BeatSaberMarkupLanguage/TypeHandlers/LocalizedTextMeshProUGUIHandler.cs index 3da6a6cf..eaac262a 100644 --- a/BeatSaberMarkupLanguage/TypeHandlers/LocalizedTextMeshProUGUIHandler.cs +++ b/BeatSaberMarkupLanguage/TypeHandlers/LocalizedTextMeshProUGUIHandler.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Polyglot; +using BGLib.Polyglot; namespace BeatSaberMarkupLanguage.TypeHandlers { @@ -22,7 +22,7 @@ public class LocalizedTextMeshProUGUIHandler : TypeHandler((localizedText, value) => localizedText.MaintainTextAlignment = Parse.Bool(value)) }, + { "maintainTextAlignment", new Action((localizedText, value) => localizedText.maintainTextAlignment = Parse.Bool(value)) }, }; } } diff --git a/BeatSaberMarkupLanguage/TypeHandlers/RectTransformHandler.cs b/BeatSaberMarkupLanguage/TypeHandlers/RectTransformHandler.cs index 2ea4fd70..74f8dc03 100644 --- a/BeatSaberMarkupLanguage/TypeHandlers/RectTransformHandler.cs +++ b/BeatSaberMarkupLanguage/TypeHandlers/RectTransformHandler.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; +using BGLib.Polyglot; using HMUI; -using Polyglot; using UnityEngine; namespace BeatSaberMarkupLanguage.TypeHandlers diff --git a/BeatSaberMarkupLanguage/Util/LocalizationModelExtensions.cs b/BeatSaberMarkupLanguage/Util/LocalizationModelExtensions.cs new file mode 100644 index 00000000..14070a96 --- /dev/null +++ b/BeatSaberMarkupLanguage/Util/LocalizationModelExtensions.cs @@ -0,0 +1,18 @@ +using System; +using BGLib.Polyglot; +using IPA.Utilities; + +namespace BeatSaberMarkupLanguage.Util +{ + internal static class LocalizationModelExtensions + { + private static readonly FieldAccessor>.Accessor OnChangeLanguageAccessor = FieldAccessor>.GetAccessor("_onChangeLanguage"); + + internal static void RemoveOnLocalizeEvent(this LocalizationModel localizationModel, ILocalize localize) + { + Action onChangeLanguageAction = OnChangeLanguageAccessor(ref localizationModel); + onChangeLanguageAction -= localize.OnLocalize; + OnChangeLanguageAccessor(ref localizationModel) = onChangeLanguageAction; + } + } +} diff --git a/BeatSaberMarkupLanguage/MenuInitAwaiter.cs b/BeatSaberMarkupLanguage/Util/MenuInitAwaiter.cs similarity index 85% rename from BeatSaberMarkupLanguage/MenuInitAwaiter.cs rename to BeatSaberMarkupLanguage/Util/MenuInitAwaiter.cs index 093a845e..29a6430a 100644 --- a/BeatSaberMarkupLanguage/MenuInitAwaiter.cs +++ b/BeatSaberMarkupLanguage/Util/MenuInitAwaiter.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Zenject; -namespace BeatSaberMarkupLanguage +namespace BeatSaberMarkupLanguage.Util { internal class MenuInitAwaiter : IInitializable, IDisposable { @@ -19,9 +19,5 @@ public void Dispose() } internal static Task WaitForMainMenuAsync() => _taskCompletionSource.Task; - - private struct VoidResult - { - } } } diff --git a/BeatSaberMarkupLanguage/Util/VoidResult.cs b/BeatSaberMarkupLanguage/Util/VoidResult.cs new file mode 100644 index 00000000..108e9b6d --- /dev/null +++ b/BeatSaberMarkupLanguage/Util/VoidResult.cs @@ -0,0 +1,6 @@ +namespace BeatSaberMarkupLanguage.Util +{ + internal struct VoidResult + { + } +} diff --git a/BeatSaberMarkupLanguage/manifest.json b/BeatSaberMarkupLanguage/manifest.json index d559c4c4..98c50ddf 100644 --- a/BeatSaberMarkupLanguage/manifest.json +++ b/BeatSaberMarkupLanguage/manifest.json @@ -8,8 +8,8 @@ "An XML based UI system." ], "author": "monkeymanboy", - "gameVersion": "1.32.0", - "version": "1.8.1+dev", + "gameVersion": "1.34.5", + "version": "1.9.0+dev", "dependsOn": { "BSIPA": "^4.3.0" },