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.

122 lines
4.7 KiB

  1. using CustomUI.BeatSaber;
  2. using CustomUI.Utilities;
  3. using IPA.Loader;
  4. using System;
  5. using System.Linq;
  6. using System.Reflection;
  7. using UnityEngine;
  8. using VRUI;
  9. namespace BSIPA_ModList.UI
  10. {
  11. internal class ModListFlowCoordinator : FlowCoordinator
  12. {
  13. private BackButtonNavigationController navigationController;
  14. private ModListController modList;
  15. #pragma warning disable CS0618
  16. protected override void DidActivate(bool firstActivation, ActivationType activationType)
  17. { // thx Caeden
  18. if (firstActivation && activationType == ActivationType.AddedToHierarchy)
  19. {
  20. title = "Installed Mods";
  21. navigationController = BeatSaberUI.CreateViewController<BackButtonNavigationController>();
  22. navigationController.didFinishEvent += backButton_DidFinish;
  23. modList = BeatSaberUI.CreateViewController<ModListController>();
  24. modList.Init(this, PluginManager.AllPlugins, PluginLoader.ignoredPlugins, PluginManager.Plugins);
  25. PushViewControllerToNavigationController(navigationController, modList);
  26. }
  27. ProvideInitialViewControllers(navigationController);
  28. }
  29. #pragma warning restore
  30. private delegate void PresentFlowCoordDel(FlowCoordinator self, FlowCoordinator newF, Action finished, bool immediate, bool replaceTop);
  31. private static PresentFlowCoordDel presentFlow;
  32. public void PresentOn(FlowCoordinator main, Action finished = null, bool immediate = false, bool replaceTop = false)
  33. {
  34. if (presentFlow == null)
  35. {
  36. var ty = typeof(FlowCoordinator);
  37. var m = ty.GetMethod("PresentFlowCoordinator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  38. presentFlow = (PresentFlowCoordDel)Delegate.CreateDelegate(typeof(PresentFlowCoordDel), m);
  39. }
  40. presentFlow(main, this, finished, immediate, replaceTop);
  41. }
  42. public bool HasSelected { get; private set; } = false;
  43. public void SetSelected(VRUIViewController selected, Action callback = null, bool immediate = false)
  44. {
  45. if (immediate)
  46. {
  47. Logger.log.Debug("setting selected immediately");
  48. if (HasSelected)
  49. {
  50. Logger.log.Debug("popping vc");
  51. PopViewController(immediate: true);
  52. }
  53. Logger.log.Debug("pushing vc");
  54. PushViewController(selected, callback, true);
  55. HasSelected = true;
  56. }
  57. else
  58. {
  59. Logger.log.Debug("setting selected");
  60. if (HasSelected)
  61. {
  62. Logger.log.Debug("popping vc");
  63. PopViewController(() =>
  64. {
  65. Logger.log.Debug("pushing vc");
  66. PushViewController(selected, callback, immediate);
  67. HasSelected = true;
  68. }, immediate);
  69. }
  70. else
  71. {
  72. Logger.log.Debug("pushing vc");
  73. PushViewController(selected, callback, immediate);
  74. HasSelected = true;
  75. }
  76. }
  77. }
  78. public void ClearSelected(Action callback = null, bool immediate = false)
  79. {
  80. if (HasSelected) PopViewController(callback, immediate);
  81. HasSelected = false;
  82. }
  83. public void PushViewController(VRUIViewController controller, Action callback = null, bool immediate = false)
  84. {
  85. PushViewControllerToNavigationController(navigationController, controller, callback, immediate);
  86. }
  87. public void PopViewController(Action callback = null, bool immediate = false)
  88. {
  89. PopViewControllerFromNavigationController(navigationController, callback, immediate);
  90. }
  91. private delegate void DismissFlowDel(FlowCoordinator self, FlowCoordinator newF, Action finished, bool immediate);
  92. private static DismissFlowDel dismissFlow;
  93. private void backButton_DidFinish()
  94. {
  95. if (dismissFlow == null)
  96. {
  97. var ty = typeof(FlowCoordinator);
  98. var m = ty.GetMethod("DismissFlowCoordinator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  99. dismissFlow = (DismissFlowDel)Delegate.CreateDelegate(typeof(DismissFlowDel), m);
  100. }
  101. MainFlowCoordinator mainFlow = Resources.FindObjectsOfTypeAll<MainFlowCoordinator>().First();
  102. dismissFlow(mainFlow, this, null, false);
  103. }
  104. }
  105. }