IEnumerator GetBeatSaverDownloaderButtons()
        {
            Logger.log.Info("BeatSaverDownloader mod found. Attempting to replace button behaviour and positions.");

            int     tries;
            Vector2 newButtonSize = new Vector2(20f, 6f);

            for (tries = 10; tries > 0; --tries)
            {
                if (BeatSaverDownloaderTweaks.Init(newButtonSize))
                {
                    CreateFilterButton(new Vector2(-12f, 36.75f), newButtonSize, "CreditsButton");
                    CreateClearButton(new Vector2(8f, 36.75f), newButtonSize, "CreditsButton");

                    break;
                }

                yield return(new WaitForSeconds(0.5f));
            }

            if (tries <= 0)
            {
                Logger.log.Warn("BeatSaverDownloader buttons were not found. Creating new buttons, which may overlap with other UI elements.");
                CreateSearchButton(DefaultSearchButtonPosition, DefaultButtonSize);
                CreateFilterButton(DefaultFilterButtonPosition, DefaultButtonSize);
                CreateClearButton(DefaultClearButtonPosition, DefaultButtonSize);
            }

            ToggleButtonsActive(false);
        }
        private void OnFreePlayFlowCoordinatorFinished(FlowCoordinator unused)
        {
            if (_freePlayFlowCoordinator is SoloFreePlayFlowCoordinator)
            {
                (_freePlayFlowCoordinator as SoloFreePlayFlowCoordinator).didFinishEvent -= OnFreePlayFlowCoordinatorFinished;
            }
            else if (_freePlayFlowCoordinator is PartyFreePlayFlowCoordinator)
            {
                (_freePlayFlowCoordinator as PartyFreePlayFlowCoordinator).didFinishEvent -= OnFreePlayFlowCoordinatorFinished;
            }
            else if (_freePlayFlowCoordinator is CampaignFlowCoordinator)
            {
                (_freePlayFlowCoordinator as CampaignFlowCoordinator).didFinishEvent -= OnFreePlayFlowCoordinatorFinished;
            }

            ToggleButtonsActive(false);
            BeatSaverDownloaderTweaks.HideTopButtons();

            // unapply filters before leaving the screen
            if (_filterViewController?.IsFilterApplied == true)
            {
                UnapplyFilters();

                SongBrowserTweaks.FiltersUnapplied();
            }

            _freePlayFlowCoordinator = null;
        }
        private void OnModeSelection(FreePlayMode mode)
        {
            if (SongBrowserTweaks.ModLoaded && !SongBrowserTweaks.Initialized && mode != FreePlayMode.Campaign)
            {
                StartCoroutine(GetSongBrowserButtons());
            }

            if (mode == FreePlayMode.Solo)
            {
                _freePlayFlowCoordinator = FindObjectOfType <SoloFreePlayFlowCoordinator>();
                (_freePlayFlowCoordinator as SoloFreePlayFlowCoordinator).didFinishEvent += OnFreePlayFlowCoordinatorFinished;

                ToggleButtonsActive(true);
                BeatSaverDownloaderTweaks.SetTopButtons(false);
            }
            else if (mode == FreePlayMode.Party)
            {
                _freePlayFlowCoordinator = FindObjectOfType <PartyFreePlayFlowCoordinator>();
                (_freePlayFlowCoordinator as PartyFreePlayFlowCoordinator).didFinishEvent += OnFreePlayFlowCoordinatorFinished;

                ToggleButtonsActive(true);
                BeatSaverDownloaderTweaks.SetTopButtons(false);
            }
            else if (mode == FreePlayMode.Campaign)
            {
                _freePlayFlowCoordinator = FindObjectOfType <CampaignFlowCoordinator>();
                (_freePlayFlowCoordinator as CampaignFlowCoordinator).didFinishEvent += OnFreePlayFlowCoordinatorFinished;

                ToggleButtonsActive(false);
                BeatSaverDownloaderTweaks.HideTopButtons();
            }

            SongBrowserTweaks.OnModeSelection();
        }
        public void ToggleButtonsActive(bool active)
        {
            if (SearchButton != null)
            {
                SearchButton.gameObject.SetActive(active);
            }
            if (FilterButton != null)
            {
                FilterButton.gameObject.SetActive(active);
            }
            if (ClearButton != null)
            {
                ClearButton.gameObject.SetActive(active);
            }

            if (!active)
            {
                BeatSaverDownloaderTweaks.HideTopButtons();
            }
        }