Example #1
0
        private void DismissFilterFlowCoordinator()
        {
            _freePlayFlowCoordinator.InvokeMethod("DismissFlowCoordinator", _filterFlowCoordinator, null, false);
            ButtonPanel.instance.ShowPanel();

            // instead of applying filters inside the filter flow coordinator, apply the filters when the flow coordinator is dismissed
            // that way, we don't get the unity complaining about the LevelSelectionNavigationController being not active
            if (SongBrowserTweaks.Initialized && FilterList.AnyApplied)
            {
                SongBrowserTweaks.ApplyFilters();
            }
            else if (_levelsToApply != null)
            {
                // NOTE: levels should already be sorted
                LevelSelectionNavigationController.SetData(
                    _levelsToApply,
                    true,
                    LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"),
                    LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView"),
                    null);
                _levelsToApply = null;

                if (_uiAdditions != null)
                {
                    _uiAdditions.RefreshPageButtons();
                }
            }
        }
        private void LevelPackSelected(LevelPacksViewController viewController, IBeatmapLevelPack levelPack)
        {
            var previousPack = _lastPack;

            if (levelPack.packName != FilteredSongsPackName)
            {
                _lastPack = levelPack;
            }

            if (SongBrowserTweaks.ModLoaded && SongBrowserTweaks.Initialized)
            {
                // on the new version of SongBrowser, selecting the same level pack should have no changes to what is shown
                // unless it is an OST song pack (which we then clear the filter)
                IPreviewBeatmapLevel[] levels = levelPack.beatmapLevelCollection.beatmapLevels;
                if (previousPack != levelPack || (levels.Length > 0 && !(levels[0] is CustomPreviewBeatmapLevel)))
                {
                    if (_filterViewController != null)
                    {
                        _filterViewController.UnapplyFilters(false);
                    }
                    SongBrowserTweaks.FiltersUnapplied();
                }
            }
            else
            {
                UnapplyFilters();
            }
        }
Example #3
0
        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;
            }

            // unapply filters before leaving the screen
            if (FilterList.AnyApplied == true)
            {
                UnapplyFilters();

                SongBrowserTweaks.FiltersUnapplied();
            }

            _freePlayFlowCoordinator = null;
        }
        private void FilterViewControllerFiltersUnapplied()
        {
            LevelsViewController.SetData(_lastPack);

            if (!SongBrowserTweaks.ModLoaded)
            {
                FilterButton.SetButtonText(FilterButtonText);
                FilterButton.SetButtonTextSize(3f);

                // if the clear button is shown, then that was pressed to clear filters
                // therefore, it should currently be highlighted
                if ((ClearButton as NoTransitionsButton).selectionState == NoTransitionsButton.SelectionState.Highlighted)
                {
                    ClearButton.SetButtonText(ClearFilterButtonHighlightedText);
                }
                else
                {
                    ClearButton.SetButtonText(ClearFilterButtonText);
                }
            }
            else
            {
                SongBrowserTweaks.FiltersUnapplied();
            }
        }
Example #5
0
        private void FilterFlowCoordinatorFiltersUnapplied()
        {
            if (SongBrowserTweaks.ModLoaded)
            {
                SongBrowserTweaks.FiltersUnapplied();
            }
            else
            {
                if (_lastPack != null)
                {
                    if (!SongSortModule.IsDefaultSort)
                    {
                        _levelsToApply = _sortedLevelsLevelPack.SetupFromLevelCollection(_lastPack);
                    }
                    else
                    {
                        _levelsToApply = _lastPack;
                    }
                }
                else        // this should never happen (_lastPack should always be defined by this point)
                {
                    Logger.log.Warn("Unable to unapply filters (could not find previous level pack)");
                }

                ButtonPanel.instance.SetFilterStatus(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();
        }
Example #8
0
        private IEnumerator GetSongBrowserButtons()
        {
            if (SongBrowserTweaks.ModLoaded && !SongBrowserTweaks.IsModAvailable)
            {
                Logger.log.Error($"Unable to initialize this mod to work with SongBrowser (SongBrowser v{SongBrowserTweaks.ValidVersionRange.ToString().Replace("^", "")} or above is required)");
                yield break;
            }

            Logger.log.Info("SongBrowser mod found. Attempting to modify button behaviour.");

            int tries;

            for (tries = 10; tries > 0; --tries)
            {
                if (SongBrowserTweaks.Init())
                {
                    break;
                }

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

            if (tries <= 0)
            {
                Logger.log.Warn("SongBrowser buttons could not be found. Creating default buttons panel");
                InitializeAdditionalScreens();
            }
        }
Example #9
0
        private void ApplySearchFilter(string searchQuery)
        {
            if (string.IsNullOrEmpty(searchQuery))
            {
                _freePlayFlowCoordinator.InvokeMethod("DismissFlowCoordinator", _searchFlowCoordinator, null, false);
                return;
            }

            SearchFilter filter = FilterList.SearchFilter;

            if (filter == null)
            {
                // this should never happen
                Logger.log.Error("Unable to apply search filter (SearchFilter object doesn't exist)");
                return;
            }

            filter.QueryStagingValue        = searchQuery;
            filter.SplitQueryStagingValue   = PluginConfig.SplitQueryByWords;
            filter.SongFieldsStagingValue   = PluginConfig.SongFieldsToSearch;
            filter.StripSymbolsStagingValue = PluginConfig.StripSymbols;
            filter.ApplyStagingValues();

            if (_filterFlowCoordinator != null)
            {
                _filterFlowCoordinator.RefreshUI();
            }

            _freePlayFlowCoordinator.InvokeMethod("DismissFlowCoordinator", _searchFlowCoordinator, null, false);

            if (SongBrowserTweaks.Initialized)
            {
                SongBrowserTweaks.ApplyFilters();
            }
            else
            {
                ButtonPanel.instance.SetFilterStatus(true);
                ButtonPanel.instance.ShowPanel();

                _filteredLevelPack.SetupFromUnfilteredLevels(_lastPack.beatmapLevelCollection.beatmapLevels, _lastPack.coverImage, false);
                LevelSelectionNavigationController.SetData(
                    _filteredLevelPack,
                    true,
                    LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"),
                    LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView"));

                _uiAdditions.RefreshPageButtons();
            }
        }
Example #10
0
        public void SearchButtonPressed()
        {
            if (_searchFlowCoordinator == null)
            {
                _searchFlowCoordinator      = BeatSaberUI.CreateFlowCoordinator <SearchFlowCoordinator>();
                _searchFlowCoordinator.name = "EnhancedSearchFlowCoordinator";

                _searchFlowCoordinator.BackButtonPressed         += DismissSearchFlowCoordinator;
                _searchFlowCoordinator.SongSelected              += SelectSongFromSearchResult;
                _searchFlowCoordinator.SearchFilterButtonPressed += ApplySearchFilter;
            }

            IAnnotatedBeatmapLevelCollection levelPack;

            if (SongBrowserTweaks.Initialized)
            {
                if (SongBrowserTweaks.IsFilterApplied())
                {
                    levelPack = LevelSelectionNavigationController.GetPrivateField <IBeatmapLevelPack>("_levelPack", typeof(LevelSelectionNavigationController));
                }
                // technically, the _lastPack doesn't actually contain the pack being shown
                // (since SongBrowser always overrides the selected pack with its own pack to handle sorting/filtering)
                // but any non-filtered level pack is going to contain the same levels anyways
                // and i'll need the true level pack ID for word storage caching
                else
                {
                    levelPack = _lastPack;
                }
            }
            else if (FilterList.AnyApplied)
            {
                levelPack = _filteredLevelPack;
            }
            else
            {
                levelPack = _lastPack;
            }

            _searchFlowCoordinator.Activate(_freePlayFlowCoordinator, levelPack);

            if (!ButtonPanel.IsSingletonAvailable || !ButtonPanel.instance.Initialized)
            {
                Logger.log.Debug("'Search' button pressed.");
            }
        }
Example #11
0
        private void OnModeSelection(FreePlayMode mode)
        {
            if (mode == FreePlayMode.Solo)
            {
                Logger.log.Debug("Selected solo free play mode");
                _freePlayFlowCoordinator = FindObjectOfType <SoloFreePlayFlowCoordinator>();
                (_freePlayFlowCoordinator as SoloFreePlayFlowCoordinator).didFinishEvent += OnFreePlayFlowCoordinatorFinished;

                PrepareLevelPackSelectedEvent();
                if (!SongBrowserTweaks.ModLoaded)
                {
                    UnityCoroutineHelper.StartDelayedAction(SelectSavedLevelPack);
                }
                else if (!SongBrowserTweaks.Initialized)
                {
                    StartCoroutine(GetSongBrowserButtons());
                }
            }
            else if (mode == FreePlayMode.Party)
            {
                Logger.log.Debug("Selected party free play mode");
                _freePlayFlowCoordinator = FindObjectOfType <PartyFreePlayFlowCoordinator>();
                (_freePlayFlowCoordinator as PartyFreePlayFlowCoordinator).didFinishEvent += OnFreePlayFlowCoordinatorFinished;

                PrepareLevelPackSelectedEvent();
                if (!SongBrowserTweaks.ModLoaded)
                {
                    UnityCoroutineHelper.StartDelayedAction(SelectSavedLevelPack);
                }
                else if (!SongBrowserTweaks.Initialized)
                {
                    StartCoroutine(GetSongBrowserButtons());
                }
            }
            else if (mode == FreePlayMode.Campaign)
            {
                Logger.log.Debug("Selected campaign play mode");
                _freePlayFlowCoordinator = FindObjectOfType <CampaignFlowCoordinator>();
                (_freePlayFlowCoordinator as CampaignFlowCoordinator).didFinishEvent += OnFreePlayFlowCoordinatorFinished;
            }

            // UIState in SongBrowser is always reset to Main, so we need to disable the filter button
            SongBrowserTweaks.DisableOtherFiltersButton();
        }
Example #12
0
        private void OnModeSelection(FreePlayMode mode)
        {
            if (mode == FreePlayMode.Solo)
            {
                _freePlayFlowCoordinator = FindObjectOfType <SoloFreePlayFlowCoordinator>();
                (_freePlayFlowCoordinator as SoloFreePlayFlowCoordinator).didFinishEvent += OnFreePlayFlowCoordinatorFinished;

                if (!SongBrowserTweaks.ModLoaded)
                {
                    PrepareLevelPackSelectedEvent();
                    StartCoroutine(UIUtilities.DelayedAction(SelectSavedLevelPack));
                }
                else if (!SongBrowserTweaks.Initialized)
                {
                    StartCoroutine(GetSongBrowserButtons());
                }
            }
            else if (mode == FreePlayMode.Party)
            {
                _freePlayFlowCoordinator = FindObjectOfType <PartyFreePlayFlowCoordinator>();
                (_freePlayFlowCoordinator as PartyFreePlayFlowCoordinator).didFinishEvent += OnFreePlayFlowCoordinatorFinished;

                if (!SongBrowserTweaks.ModLoaded)
                {
                    PrepareLevelPackSelectedEvent();
                    StartCoroutine(UIUtilities.DelayedAction(SelectSavedLevelPack));
                }
                else if (!SongBrowserTweaks.Initialized)
                {
                    StartCoroutine(GetSongBrowserButtons());
                }
            }
            else if (mode == FreePlayMode.Campaign)
            {
                _freePlayFlowCoordinator = FindObjectOfType <CampaignFlowCoordinator>();
                (_freePlayFlowCoordinator as CampaignFlowCoordinator).didFinishEvent += OnFreePlayFlowCoordinatorFinished;
            }

            SongBrowserTweaks.OnModeSelection();
        }
Example #13
0
        public void SetActiveWordStorageFromLevelPack(IAnnotatedBeatmapLevelCollection levelCollection)
        {
            WordCountStorage  storage;
            IBeatmapLevelPack levelPack      = levelCollection as IBeatmapLevelPack;
            string            collectionName = levelCollection.collectionName;
            bool storageWasCached;

            if (levelPack != null)
            {
                storageWasCached = _cache.TryGetValue(levelPack.packID, out storage);
            }
            else
            {
                storageWasCached = _cache.TryGetValue(collectionName.Replace(SortedLevelsLevelPack.PackIDSuffix, ""), out storage);
            }

            if (!storageWasCached)
            {
                storage = new WordCountStorage(levelCollection);

                // never cache filtered/built-in favorites level packs
                // NOTE: ESAF filtered level pack should already be sorted (will never have sorted level pack suffix)
                if (levelPack != null &&
                    levelPack.packID != FilteredLevelsLevelPack.PackID &&
                    !SongBrowserTweaks.IsFilterApplied())
                {
                    _cache[levelPack.packID] = storage;
                }
                else if (collectionName != FilteredLevelsLevelPack.CollectionName &&
                         collectionName != BuiltInFavouritesPackCollectionName &&
                         collectionName != BuiltInFavouritesPackCollectionName + SortedLevelsLevelPack.PackIDSuffix &&
                         collectionName != SortedLevelsLevelPack.PackIDSuffix)
                {
                    _cache[collectionName.Replace(SortedLevelsLevelPack.PackIDSuffix, "")] = storage;
                }
            }

            _activeWordStorage = storage;
        }
Example #14
0
        private IEnumerator GetSongBrowserButtons()
        {
            Logger.log.Info("SongBrowser mod found. Attempting to modify button behaviour.");

            int tries;

            for (tries = 10; tries > 0; --tries)
            {
                if (SongBrowserTweaks.Init())
                {
                    break;
                }

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

            if (tries <= 0)
            {
                Logger.log.Warn("SongBrowser buttons could not be found. Creating default buttons panel");
                InitializeButtonPanel();
            }
        }
        IEnumerator GetSongBrowserButtons()
        {
            Logger.log.Info("SongBrowser mod found. Attempting to modify button behaviour.");

            int tries;

            for (tries = 10; tries > 0; --tries)
            {
                if (SongBrowserTweaks.Init())
                {
                    break;
                }

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

            if (tries <= 0)
            {
                Logger.log.Warn("SongBrowser buttons were not found. Creating new buttons, which may overlap with other UI elements.");
                CreateSearchButton(DefaultSearchButtonPosition, DefaultButtonSize);
                CreateFilterButton(DefaultFilterButtonPosition, DefaultButtonSize);
                CreateClearButton(DefaultClearButtonPosition, DefaultButtonSize);
            }
        }
Example #16
0
        private void LevelPackSelected(LevelFilteringNavigationController navController, IAnnotatedBeatmapLevelCollection levelPack, GameObject noDataInfoPrefab, BeatmapCharacteristicSO preferredCharacteristic)
        {
            // ignore the first select event that's fired immediately after the user select the free play mode
            // this is done so we can select the saved last pack later
            // when the saved pack is selected, it will then call this function again for sorting/storing
            if (_isSelectingInitialLevelPack)
            {
                _lastPack = levelPack;
                _isSelectingInitialLevelPack = false;

                if (levelPack is IBeatmapLevelPack beatmapLevelPack)
                {
                    Logger.log.Debug($"Storing '{beatmapLevelPack.packName}' (id = '{beatmapLevelPack.packID}') level pack as initial pack");
                }
                else
                {
                    Logger.log.Debug($"Storing '{levelPack.collectionName}' level collection as initial pack");
                }

                return;
            }
            // in ConfirmDeleteButtonClicked, the call to SongCore.Loader.Instance.DeleteSong will reload the level packs
            // which causes the custom level pack to be re-selected. but, if filters are applied or level pack is sorted,
            // we want to reshow our own filtered/sorted level pack and not reset our UI, so we don't have to handle this event
            // this code is kinda smelly tbh, but can't do anything about it unless there are changes to SongCore
            else if (_isDeletingSongInModOwnedLevelPack)
            {
                return;
            }
            // when SongBrowser is enabled, we only need to store the pack for the WordPredictionEngine when using the search feature
            else if (SongBrowserTweaks.Initialized)
            {
                _lastPack = levelPack;
                SongBrowserTweaks.DisableOtherFiltersButton();
                return;
            }

            if (levelPack.collectionName != FilteredLevelsLevelPack.CollectionName)
            {
                _lastPack = levelPack;

                // store level pack to PluginConfig
                var tabBarVC    = LevelFilteringNavigationController.GetPrivateField <TabBarViewController>("_tabBarViewController");
                var tabBarItems = tabBarVC.GetPrivateField <TabBarViewController.TabBarItem[]>("_items");

                string lastLevelPackString = tabBarItems[tabBarVC.selectedCellNumber].title + PluginConfig.LastLevelPackIDSeparator;
                if (levelPack is IBeatmapLevelPack beatmapLevelPack)
                {
                    lastLevelPackString += beatmapLevelPack.packID;
                    Logger.log.Debug($"Storing '{beatmapLevelPack.packName}' (id = '{beatmapLevelPack.packID}') level pack as last pack");
                }
                else
                {
                    lastLevelPackString += levelPack.collectionName;
                    Logger.log.Debug($"Storing '{levelPack.collectionName}' level collection as last pack");
                }
                PluginConfig.LastLevelPackID = lastLevelPackString;

                // reapply sort mode
                if (!SongSortModule.IsDefaultSort)
                {
                    _sortedLevelsLevelPack.SetupFromLevelCollection(levelPack);

                    // since the level selection navigation controller shows a level pack using the same event that calls this function
                    // and it technically isn't a guarantee that this function will run after it is set,
                    // delay setting our level pack
                    UnityCoroutineHelper.StartDelayedAction(() =>
                                                            LevelSelectionNavigationController.SetData(
                                                                _sortedLevelsLevelPack,
                                                                true,
                                                                LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"),
                                                                LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView")));
                }
            }

            // SongBrowser can now apply filters to OST levels and switch between different level packs
            // so our old behaviour of cancelling the filters is no longer needed
            // that being said, without SongBrowser, we are still going to cancel filters upon switching level packs
            // because i'd rather the player have to go into the FilterViewController,
            // so that it can check if all the beatmap details have been loaded
            if (FilterList.AnyApplied)
            {
                Logger.log.Debug("Another level pack has been selected, unapplying filters");
            }
            UnapplyFilters();

            if (_uiAdditions != null)
            {
                UnityCoroutineHelper.StartDelayedAction(_uiAdditions.RefreshPageButtons);
            }
        }