using CustomUI.BeatSaber; using CustomUI.Utilities; using IPA.Loader; using System; using System.Linq; using System.Reflection; using UnityEngine; using VRUI; namespace BSIPA_ModList.UI { internal class ModListFlowCoordinator : FlowCoordinator { private BackButtonNavigationController navigationController; private ModListController modList; #pragma warning disable CS0618 protected override void DidActivate(bool firstActivation, ActivationType activationType) { // thx Caeden if (firstActivation && activationType == ActivationType.AddedToHierarchy) { title = "Installed Mods"; navigationController = BeatSaberUI.CreateViewController(); navigationController.didFinishEvent += backButton_DidFinish; modList = BeatSaberUI.CreateViewController(); modList.Init(this, PluginManager.AllPlugins, PluginLoader.ignoredPlugins, PluginManager.Plugins); PushViewControllerToNavigationController(navigationController, modList); } ProvideInitialViewControllers(navigationController); } #pragma warning restore private delegate void PresentFlowCoordDel(FlowCoordinator self, FlowCoordinator newF, Action finished, bool immediate, bool replaceTop); private static PresentFlowCoordDel presentFlow; public void PresentOn(FlowCoordinator main, Action finished = null, bool immediate = false, bool replaceTop = false) { if (presentFlow == null) { var ty = typeof(FlowCoordinator); var m = ty.GetMethod("PresentFlowCoordinator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); presentFlow = (PresentFlowCoordDel)Delegate.CreateDelegate(typeof(PresentFlowCoordDel), m); } presentFlow(main, this, finished, immediate, replaceTop); } public bool HasSelected { get; private set; } = false; public void SetSelected(VRUIViewController selected, Action callback = null, bool immediate = false) { if (immediate) { Logger.log.Debug("setting selected immediately"); if (HasSelected) { Logger.log.Debug("popping vc"); PopViewController(immediate: true); } Logger.log.Debug("pushing vc"); PushViewController(selected, callback, true); HasSelected = true; } else { Logger.log.Debug("setting selected"); if (HasSelected) { Logger.log.Debug("popping vc"); PopViewController(() => { Logger.log.Debug("pushing vc"); PushViewController(selected, callback, immediate); HasSelected = true; }, immediate); } else { Logger.log.Debug("pushing vc"); PushViewController(selected, callback, immediate); HasSelected = true; } } } public void ClearSelected(Action callback = null, bool immediate = false) { if (HasSelected) PopViewController(callback, immediate); HasSelected = false; } public void PushViewController(VRUIViewController controller, Action callback = null, bool immediate = false) { PushViewControllerToNavigationController(navigationController, controller, callback, immediate); } public void PopViewController(Action callback = null, bool immediate = false) { PopViewControllerFromNavigationController(navigationController, callback, immediate); } private delegate void DismissFlowDel(FlowCoordinator self, FlowCoordinator newF, Action finished, bool immediate); private static DismissFlowDel dismissFlow; private void backButton_DidFinish() { if (dismissFlow == null) { var ty = typeof(FlowCoordinator); var m = ty.GetMethod("DismissFlowCoordinator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); dismissFlow = (DismissFlowDel)Delegate.CreateDelegate(typeof(DismissFlowDel), m); } MainFlowCoordinator mainFlow = Resources.FindObjectsOfTypeAll().First(); dismissFlow(mainFlow, this, null, false); } } }