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.

127 lines
5.0 KiB

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