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.

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