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.

119 lines
4.6 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. if (HasSelected)
  54. PopViewController(immediate: true);
  55. PushViewController(selected, callback, true);
  56. HasSelected = true;
  57. }
  58. else
  59. {
  60. if (HasSelected)
  61. PopViewController(() =>
  62. {
  63. PushViewController(selected, callback, immediate);
  64. HasSelected = true;
  65. }, immediate);
  66. else
  67. {
  68. PushViewController(selected, callback, immediate);
  69. HasSelected = true;
  70. }
  71. }
  72. }
  73. public void ClearSelected(Action callback = null, bool immediate = false)
  74. {
  75. if (HasSelected) PopViewController(callback, immediate);
  76. HasSelected = false;
  77. }
  78. public void PushViewController(VRUIViewController controller, Action callback = null, bool immediate = false)
  79. {
  80. PushViewControllerToNavigationController(navigationController, controller, callback, immediate);
  81. }
  82. public void PopViewController(Action callback = null, bool immediate = false)
  83. {
  84. PopViewControllerFromNavigationController(navigationController, callback, immediate);
  85. }
  86. private delegate void DismissFlowDel(FlowCoordinator self, FlowCoordinator newF, Action finished, bool immediate);
  87. private static DismissFlowDel dismissFlow;
  88. private void backButton_DidFinish()
  89. {
  90. if (dismissFlow == null)
  91. {
  92. var ty = typeof(FlowCoordinator);
  93. var m = ty.GetMethod("DismissFlowCoordinator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  94. dismissFlow = (DismissFlowDel)Delegate.CreateDelegate(typeof(DismissFlowDel), m);
  95. }
  96. MainFlowCoordinator mainFlow = Resources.FindObjectsOfTypeAll<MainFlowCoordinator>().First();
  97. dismissFlow(mainFlow, this, null, false);
  98. }
  99. }
  100. }