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.

85 lines
2.5 KiB

  1. using CustomUI.BeatSaber;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using UnityEngine;
  9. using UnityEngine.SceneManagement;
  10. using UnityEngine.UI;
  11. namespace BSIPA_ModList.UI
  12. {
  13. internal class ButtonUI : MonoBehaviour
  14. {
  15. private const string ControllerPanel = "MainMenuViewController/SmallButtons";
  16. private const string CopyButton = "CreditsButton";
  17. internal static ButtonUI Instance;
  18. public void Awake()
  19. {
  20. DontDestroyOnLoad(gameObject);
  21. SceneManager.activeSceneChanged += this.SceneManager_activeSceneChanged;
  22. }
  23. private void SceneManager_activeSceneChanged(Scene from, Scene to)
  24. {
  25. if (to.name == "EmptyTransition")
  26. {
  27. if (Instance != null)
  28. {
  29. Instance.StopAllCoroutines();
  30. Destroy(Instance.gameObject);
  31. menuFlow = null;
  32. }
  33. Instance = null;
  34. }
  35. }
  36. public void Init()
  37. {
  38. Instance = this;
  39. Logger.log.Debug("UI Awake");
  40. StartCoroutine(AddModListButton());
  41. }
  42. private static ModListFlowCoordinator menuFlow;
  43. private static readonly WaitUntil _bottomPanelExists = new WaitUntil(() => GameObject.Find(ControllerPanel) != null);
  44. private static RectTransform panel;
  45. private static HoverHint hintText;
  46. private static Button button;
  47. private static IEnumerator AddModListButton()
  48. {
  49. yield return _bottomPanelExists;
  50. Logger.log.Debug("Adding button to main menu");
  51. lock (Instance)
  52. {
  53. if (menuFlow == null)
  54. menuFlow = new GameObject("BSIPA Mod List Flow Controller").AddComponent<ModListFlowCoordinator>();
  55. if (panel == null)
  56. panel = GameObject.Find(ControllerPanel).transform as RectTransform;
  57. if (button == null)
  58. {
  59. button = BeatSaberUI.CreateUIButton(panel, CopyButton, () =>
  60. {
  61. menuFlow.Present();
  62. }, "Mod List");
  63. panel.Find(CopyButton).SetAsLastSibling();
  64. hintText = BeatSaberUI.AddHintText(button.transform as RectTransform, "View and control updates for installed mods");
  65. }
  66. yield break;
  67. }
  68. }
  69. }
  70. }