diff --git a/BSIPA-ModList/Plugin.cs b/BSIPA-ModList/Plugin.cs index d9e7c24e..08a555ab 100644 --- a/BSIPA-ModList/Plugin.cs +++ b/BSIPA-ModList/Plugin.cs @@ -4,6 +4,9 @@ using IPALogger = IPA.Logging.Logger; using BSIPA_ModList.UI; using UnityEngine; using IPA.Logging; +using BSIPA_ModList.UI.ViewControllers; +using System.Collections; +using IPA.Loader; namespace BSIPA_ModList { @@ -21,6 +24,8 @@ namespace BSIPA_ModList Logger.log = logger; IPA.Updating.BeatMods.Updater.ModListPresent = true; + + } public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) @@ -33,7 +38,20 @@ namespace BSIPA_ModList public void OnApplicationStart() { + // Load resources ahead of time + MarkdownView.StartLoadResourcesAsync(); + + SharedCoroutineStarter.instance.StartCoroutine(LoadPluginIcons()); + } + private static IEnumerator LoadPluginIcons() + { + foreach (var p in PluginManager.AllPlugins) + { + yield return null; + Logger.log.Debug($"Loading icon for {p.Metadata.Name}"); + var _ = p.Metadata.GetIcon(); + } } public void OnFixedUpdate() diff --git a/BSIPA-ModList/UI/FloatingNotification.cs b/BSIPA-ModList/UI/FloatingNotification.cs index b331b63e..4bd78d72 100644 --- a/BSIPA-ModList/UI/FloatingNotification.cs +++ b/BSIPA-ModList/UI/FloatingNotification.cs @@ -16,7 +16,7 @@ namespace BSIPA_ModList.UI private Image _loadingBackg; private Image _loadingBar; - private static readonly Vector3 Position = new Vector3(2.3f, 2.3f, 1.35f); + private static readonly Vector3 Position = new Vector3(2.25f, 2.3f, 1.55f); private static readonly Vector3 Rotation = new Vector3(0, 60, 0); private static readonly Vector3 Scale = new Vector3(0.01f, 0.01f, 0.01f); diff --git a/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs b/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs index d7607c25..9a8d4222 100644 --- a/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs +++ b/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs @@ -12,6 +12,7 @@ using System.Reflection; using UnityEngine.EventSystems; using System.Diagnostics; using System.Collections; +using System.IO; namespace BSIPA_ModList.UI.ViewControllers { @@ -86,39 +87,73 @@ namespace BSIPA_ModList.UI.ViewControllers return uri.Substring(3); } + private static Stream ConsolasAssetBundleFontStream => Assembly.GetExecutingAssembly().GetManifestResourceStream("BSIPA_ModList.Bundles.consolas.font"); + + private static AssetBundleCreateRequest _bundleRequest; private static AssetBundle _bundle; private static AssetBundle Bundle { get { + if (_bundle == null && _bundleRequest != null) + throw new InvalidOperationException("Asset bundle is being loaded asynchronously; please wait for that to complete"); if (_bundle == null) - _bundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("BSIPA_ModList.Bundles.consolas.font")); + _bundle = AssetBundle.LoadFromStream(ConsolasAssetBundleFontStream); return _bundle; } } + + private static AssetBundleRequest _consolasRequest; + private static TMP_FontAsset _unsetConsolas; private static TMP_FontAsset _consolas; private static TMP_FontAsset Consolas { get { - if (_consolas == null) - { - _consolas = Bundle?.LoadAsset("CONSOLAS"); - if (_consolas != null) - { - var originalFont = Resources.FindObjectsOfTypeAll().Last(f => f.name == "Teko-Medium SDF No Glow"); - var matCopy = Instantiate(originalFont.material); - matCopy.mainTexture = _consolas.material.mainTexture; - matCopy.mainTextureOffset = _consolas.material.mainTextureOffset; - matCopy.mainTextureScale = _consolas.material.mainTextureScale; - _consolas.material = matCopy; - MaterialReferenceManager.AddFontAsset(_consolas); - } - } + if (_unsetConsolas == null && _consolasRequest != null) + throw new InvalidOperationException("Asset is being loaded asynchronously; please wait for that to complete"); + if (_unsetConsolas == null) + _unsetConsolas = Bundle?.LoadAsset("CONSOLAS"); + if (_consolas == null && _unsetConsolas != null) + _consolas = SetupFont(_unsetConsolas); return _consolas; } } + private static TMP_FontAsset SetupFont(TMP_FontAsset f) + { + var originalFont = Resources.FindObjectsOfTypeAll().Last(f2 => f2.name == "Teko-Medium SDF No Glow"); + var matCopy = Instantiate(originalFont.material); + matCopy.mainTexture = f.material.mainTexture; + matCopy.mainTextureOffset = f.material.mainTextureOffset; + matCopy.mainTextureScale = f.material.mainTextureScale; + f.material = matCopy; + f = Instantiate(f); + MaterialReferenceManager.AddFontAsset(f); + return f; + } + + internal static void StartLoadResourcesAsync() + { + SharedCoroutineStarter.instance.StartCoroutine(LoadResourcesAsync()); + } + private static IEnumerator LoadResourcesAsync() + { + Logger.md.Debug("Starting to load resources"); + + _bundleRequest = AssetBundle.LoadFromStreamAsync(ConsolasAssetBundleFontStream); + yield return _bundleRequest; + _bundle = _bundleRequest.assetBundle; + + Logger.md.Debug("Bundle loaded"); + + _consolasRequest = _bundle.LoadAssetAsync("CONSOLAS"); + yield return _consolasRequest; + _unsetConsolas = _consolasRequest.asset as TMP_FontAsset; + + Logger.md.Debug("Font loaded"); + } + protected void Awake() { if (Consolas == null) diff --git a/BSIPA-ModList/UI/ViewControllers/ModCells.cs b/BSIPA-ModList/UI/ViewControllers/ModCells.cs index 54741014..f51a7c42 100644 --- a/BSIPA-ModList/UI/ViewControllers/ModCells.cs +++ b/BSIPA-ModList/UI/ViewControllers/ModCells.cs @@ -44,7 +44,7 @@ namespace BSIPA_ModList.UI.ViewControllers { var desc = Plugin.Metadata.Manifest.Description; if (string.IsNullOrWhiteSpace(desc)) - desc = "No description"; + desc = "*No description*"; infoView = BeatSaberUI.CreateViewController(); infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext, @@ -87,7 +87,7 @@ namespace BSIPA_ModList.UI.ViewControllers { var desc = Plugin.Manifest.Description; if (string.IsNullOrWhiteSpace(desc)) - desc = "No description"; + desc = "*No description*"; infoView = BeatSaberUI.CreateViewController(); infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), authorText, @@ -109,7 +109,7 @@ namespace BSIPA_ModList.UI.ViewControllers this.list = list; if (string.IsNullOrWhiteSpace(subtext)) - subtext = "Unspecified Author"; + subtext = "Unspecified Author"; icon = Utilities.DefaultLibraryIcon; } @@ -124,7 +124,7 @@ namespace BSIPA_ModList.UI.ViewControllers { var desc = Plugin.Metadata.Manifest.Description; if (string.IsNullOrWhiteSpace(desc)) - desc = "No description"; + desc = "*No description*"; infoView = BeatSaberUI.CreateViewController(); infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext, diff --git a/BSIPA-ModList/UI/ViewControllers/ModListController.cs b/BSIPA-ModList/UI/ViewControllers/ModListController.cs index 8277f049..727a7726 100644 --- a/BSIPA-ModList/UI/ViewControllers/ModListController.cs +++ b/BSIPA-ModList/UI/ViewControllers/ModListController.cs @@ -22,6 +22,8 @@ namespace BSIPA_ModList.UI var cell = base.CellForIdx(idx) as LevelListTableCell; var nameText = cell.GetPrivateField("_songNameText"); nameText.overflowMode = TextOverflowModes.Overflow; + var authorText = cell.GetPrivateField("_authorText"); + authorText.overflowMode = TextOverflowModes.Overflow; return cell; } diff --git a/BSIPA-ModList/manifest.json b/BSIPA-ModList/manifest.json index 94685593..deeb0387 100644 --- a/BSIPA-ModList/manifest.json +++ b/BSIPA-ModList/manifest.json @@ -11,7 +11,7 @@ "gameVersion": "0.13.2", "id": "BSIPA Mod List", "name": "BSIPA Mod List", - "version": "1.2.0", + "version": "1.2.1", "icon": "BSIPA_ModList.Icons.self.png", "dependsOn": { "BSIPA": "^3.12.16", diff --git a/Refs/BeatSaberCustomUI.dll b/Refs/BeatSaberCustomUI.dll index 996e033d..32e70767 100644 Binary files a/Refs/BeatSaberCustomUI.dll and b/Refs/BeatSaberCustomUI.dll differ