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.

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