Browse Source

ModList now attempts to load all resources on application start

Updated position of the floating notification to match the right screen
Author text in the mod list now overflows instead of getting ellipses
Fixed some formatting for mod cells
pull/46/head
Anairkoen Schno 5 years ago
parent
commit
bce32007de
7 changed files with 76 additions and 21 deletions
  1. +18
    -0
      BSIPA-ModList/Plugin.cs
  2. +1
    -1
      BSIPA-ModList/UI/FloatingNotification.cs
  3. +50
    -15
      BSIPA-ModList/UI/ViewControllers/MarkdownView.cs
  4. +4
    -4
      BSIPA-ModList/UI/ViewControllers/ModCells.cs
  5. +2
    -0
      BSIPA-ModList/UI/ViewControllers/ModListController.cs
  6. +1
    -1
      BSIPA-ModList/manifest.json
  7. BIN
      Refs/BeatSaberCustomUI.dll

+ 18
- 0
BSIPA-ModList/Plugin.cs View File

@ -4,6 +4,9 @@ using IPALogger = IPA.Logging.Logger;
using BSIPA_ModList.UI; using BSIPA_ModList.UI;
using UnityEngine; using UnityEngine;
using IPA.Logging; using IPA.Logging;
using BSIPA_ModList.UI.ViewControllers;
using System.Collections;
using IPA.Loader;
namespace BSIPA_ModList namespace BSIPA_ModList
{ {
@ -21,6 +24,8 @@ namespace BSIPA_ModList
Logger.log = logger; Logger.log = logger;
IPA.Updating.BeatMods.Updater.ModListPresent = true; IPA.Updating.BeatMods.Updater.ModListPresent = true;
} }
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) public void OnActiveSceneChanged(Scene prevScene, Scene nextScene)
@ -33,7 +38,20 @@ namespace BSIPA_ModList
public void OnApplicationStart() 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() public void OnFixedUpdate()


+ 1
- 1
BSIPA-ModList/UI/FloatingNotification.cs View File

@ -16,7 +16,7 @@ namespace BSIPA_ModList.UI
private Image _loadingBackg; private Image _loadingBackg;
private Image _loadingBar; 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 Rotation = new Vector3(0, 60, 0);
private static readonly Vector3 Scale = new Vector3(0.01f, 0.01f, 0.01f); private static readonly Vector3 Scale = new Vector3(0.01f, 0.01f, 0.01f);


+ 50
- 15
BSIPA-ModList/UI/ViewControllers/MarkdownView.cs View File

@ -12,6 +12,7 @@ using System.Reflection;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using System.Diagnostics; using System.Diagnostics;
using System.Collections; using System.Collections;
using System.IO;
namespace BSIPA_ModList.UI.ViewControllers namespace BSIPA_ModList.UI.ViewControllers
{ {
@ -86,39 +87,73 @@ namespace BSIPA_ModList.UI.ViewControllers
return uri.Substring(3); 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;
private static AssetBundle Bundle private static AssetBundle Bundle
{ {
get get
{ {
if (_bundle == null && _bundleRequest != null)
throw new InvalidOperationException("Asset bundle is being loaded asynchronously; please wait for that to complete");
if (_bundle == null) if (_bundle == null)
_bundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("BSIPA_ModList.Bundles.consolas.font"));
_bundle = AssetBundle.LoadFromStream(ConsolasAssetBundleFontStream);
return _bundle; return _bundle;
} }
} }
private static AssetBundleRequest _consolasRequest;
private static TMP_FontAsset _unsetConsolas;
private static TMP_FontAsset _consolas; private static TMP_FontAsset _consolas;
private static TMP_FontAsset Consolas private static TMP_FontAsset Consolas
{ {
get get
{ {
if (_consolas == null)
{
_consolas = Bundle?.LoadAsset<TMP_FontAsset>("CONSOLAS");
if (_consolas != null)
{
var originalFont = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().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<TMP_FontAsset>("CONSOLAS");
if (_consolas == null && _unsetConsolas != null)
_consolas = SetupFont(_unsetConsolas);
return _consolas; return _consolas;
} }
} }
private static TMP_FontAsset SetupFont(TMP_FontAsset f)
{
var originalFont = Resources.FindObjectsOfTypeAll<TMP_FontAsset>().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<TMP_FontAsset>("CONSOLAS");
yield return _consolasRequest;
_unsetConsolas = _consolasRequest.asset as TMP_FontAsset;
Logger.md.Debug("Font loaded");
}
protected void Awake() protected void Awake()
{ {
if (Consolas == null) if (Consolas == null)


+ 4
- 4
BSIPA-ModList/UI/ViewControllers/ModCells.cs View File

@ -44,7 +44,7 @@ namespace BSIPA_ModList.UI.ViewControllers
{ {
var desc = Plugin.Metadata.Manifest.Description; var desc = Plugin.Metadata.Manifest.Description;
if (string.IsNullOrWhiteSpace(desc)) if (string.IsNullOrWhiteSpace(desc))
desc = "<color=#BFBFBF><i>No description</i>";
desc = "*No description*";
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>(); infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext, 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; var desc = Plugin.Manifest.Description;
if (string.IsNullOrWhiteSpace(desc)) if (string.IsNullOrWhiteSpace(desc))
desc = "<color=#BFBFBF><i>No description</i>";
desc = "*No description*";
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>(); infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), authorText, infoView.Init(icon, Plugin.Name, "v" + Plugin.Version.ToString(), authorText,
@ -109,7 +109,7 @@ namespace BSIPA_ModList.UI.ViewControllers
this.list = list; this.list = list;
if (string.IsNullOrWhiteSpace(subtext)) if (string.IsNullOrWhiteSpace(subtext))
subtext = "<color=#BFBFBF><i>Unspecified Author</i>";
subtext = "<color=#BFBFBF><i>Unspecified Author</i></color>";
icon = Utilities.DefaultLibraryIcon; icon = Utilities.DefaultLibraryIcon;
} }
@ -124,7 +124,7 @@ namespace BSIPA_ModList.UI.ViewControllers
{ {
var desc = Plugin.Metadata.Manifest.Description; var desc = Plugin.Metadata.Manifest.Description;
if (string.IsNullOrWhiteSpace(desc)) if (string.IsNullOrWhiteSpace(desc))
desc = "<color=#BFBFBF><i>No description</i>";
desc = "*No description*";
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>(); infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext, infoView.Init(icon, Plugin.Metadata.Name, "v" + Plugin.Metadata.Version.ToString(), subtext,


+ 2
- 0
BSIPA-ModList/UI/ViewControllers/ModListController.cs View File

@ -22,6 +22,8 @@ namespace BSIPA_ModList.UI
var cell = base.CellForIdx(idx) as LevelListTableCell; var cell = base.CellForIdx(idx) as LevelListTableCell;
var nameText = cell.GetPrivateField<TextMeshProUGUI>("_songNameText"); var nameText = cell.GetPrivateField<TextMeshProUGUI>("_songNameText");
nameText.overflowMode = TextOverflowModes.Overflow; nameText.overflowMode = TextOverflowModes.Overflow;
var authorText = cell.GetPrivateField<TextMeshProUGUI>("_authorText");
authorText.overflowMode = TextOverflowModes.Overflow;
return cell; return cell;
} }


+ 1
- 1
BSIPA-ModList/manifest.json View File

@ -11,7 +11,7 @@
"gameVersion": "0.13.2", "gameVersion": "0.13.2",
"id": "BSIPA Mod List", "id": "BSIPA Mod List",
"name": "BSIPA Mod List", "name": "BSIPA Mod List",
"version": "1.2.0",
"version": "1.2.1",
"icon": "BSIPA_ModList.Icons.self.png", "icon": "BSIPA_ModList.Icons.self.png",
"dependsOn": { "dependsOn": {
"BSIPA": "^3.12.16", "BSIPA": "^3.12.16",


BIN
Refs/BeatSaberCustomUI.dll View File


Loading…
Cancel
Save