You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3 KiB

  1. using IPA;
  2. using UnityEngine.SceneManagement;
  3. using IPALogger = IPA.Logging.Logger;
  4. using BSIPA_ModList.UI;
  5. using UnityEngine;
  6. using IPA.Logging;
  7. using BSIPA_ModList.UI.ViewControllers;
  8. using System.Collections;
  9. using IPA.Loader;
  10. namespace BSIPA_ModList
  11. {
  12. internal static class Logger
  13. {
  14. internal static IPALogger log { get; set; }
  15. internal static IPALogger md => log.GetChildLogger("MarkDown");
  16. }
  17. /// <summary>
  18. /// The main plugin type for the in-game mod list mod.
  19. /// </summary>
  20. internal class Plugin : IBeatSaberPlugin
  21. {
  22. /// <summary>
  23. /// Initializes the plugin with certain parameters. Is only called once.
  24. ///
  25. /// This is called by the plugin loader in BSIPA, and thus must be <see langword="public"/>.
  26. /// </summary>
  27. /// <param name="logger">a logger to initialize the plugin with</param>
  28. public void Init(IPALogger logger)
  29. {
  30. Logger.log = logger;
  31. IPA.Updating.BeatMods.Updater.ModListPresent = true;
  32. // Load resources ahead of time
  33. MarkdownView.StartLoadResourcesAsync();
  34. SharedCoroutineStarter.instance.StartCoroutine(LoadPluginIcons());
  35. }
  36. public void OnActiveSceneChanged(Scene prevScene, Scene nextScene)
  37. {
  38. }
  39. public void OnApplicationQuit()
  40. {
  41. }
  42. public void OnApplicationStart()
  43. {
  44. }
  45. private static IEnumerator LoadPluginIcons()
  46. {
  47. foreach (var p in PluginManager.AllPlugins)
  48. {
  49. yield return null;
  50. Logger.log.Debug($"Loading icon for {p.Metadata.Name}");
  51. var _ = p.Metadata.GetIcon();
  52. }
  53. }
  54. public void OnFixedUpdate()
  55. {
  56. }
  57. public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
  58. {
  59. if (scene.name == "MenuCore")
  60. {
  61. FloatingNotification.Create();
  62. if (ButtonUI.Instance == null)
  63. new GameObject("BSIPA Mod List Object").AddComponent<ButtonUI>().Init();
  64. }
  65. }
  66. public void OnSceneUnloaded(Scene scene)
  67. {
  68. }
  69. public void OnUpdate()
  70. {
  71. }
  72. }
  73. }