/// <summary> /// Constructor. Acquire all necessary BeatSaberUi elements. /// </summary> /// <param name="flowCoordinator"></param> public BeatSaberUIController(FlowCoordinator flowCoordinator) { Logger.Debug("Collecting all BeatSaberUI Elements..."); LevelSelectionFlowCoordinator = flowCoordinator; // gather flow coordinator elements LevelSelectionNavigationController = LevelSelectionFlowCoordinator.GetPrivateField <LevelSelectionNavigationController>("levelSelectionNavigationController"); Logger.Debug("Acquired LevelSelectionNavigationController [{0}]", LevelSelectionNavigationController.GetInstanceID()); LevelFilteringNavigationController = LevelSelectionNavigationController.GetPrivateField <LevelFilteringNavigationController>("_levelFilteringNavigationController"); Logger.Debug("Acquired LevelFilteringNavigationController [{0}]", LevelFilteringNavigationController.GetInstanceID()); LevelCollectionNavigationController = LevelSelectionNavigationController.GetPrivateField <LevelCollectionNavigationController>("_levelCollectionNavigationController"); Logger.Debug("Acquired LevelCollectionNavigationController [{0}]", LevelCollectionNavigationController.GetInstanceID()); LevelCollectionViewController = LevelCollectionNavigationController.GetPrivateField <LevelCollectionViewController>("_levelCollectionViewController"); Logger.Debug("Acquired LevelPackLevelsViewController [{0}]", LevelCollectionViewController.GetInstanceID()); LevelDetailViewController = LevelCollectionNavigationController.GetPrivateField <StandardLevelDetailViewController>("_levelDetailViewController"); Logger.Debug("Acquired StandardLevelDetailViewController [{0}]", LevelDetailViewController.GetInstanceID()); LevelCollectionTableView = this.LevelCollectionViewController.GetPrivateField <LevelCollectionTableView>("_levelCollectionTableView"); Logger.Debug("Acquired LevelPackLevelsTableView [{0}]", LevelCollectionTableView.GetInstanceID()); StandardLevelDetailView = LevelDetailViewController.GetPrivateField <StandardLevelDetailView>("_standardLevelDetailView"); Logger.Debug("Acquired StandardLevelDetailView [{0}]", StandardLevelDetailView.GetInstanceID()); BeatmapCharacteristicSelectionViewController = StandardLevelDetailView.GetPrivateField <BeatmapCharacteristicSegmentedControlController>("_beatmapCharacteristicSegmentedControlController"); Logger.Debug("Acquired BeatmapCharacteristicSegmentedControlController [{0}]", BeatmapCharacteristicSelectionViewController.GetInstanceID()); LevelDifficultyViewController = StandardLevelDetailView.GetPrivateField <BeatmapDifficultySegmentedControlController>("_beatmapDifficultySegmentedControlController"); Logger.Debug("Acquired BeatmapDifficultySegmentedControlController [{0}]", LevelDifficultyViewController.GetInstanceID()); LevelCollectionTableViewTransform = LevelCollectionTableView.transform as RectTransform; Logger.Debug("Acquired TableViewRectTransform from LevelPackLevelsTableView [{0}]", LevelCollectionTableViewTransform.GetInstanceID()); AnnotatedBeatmapLevelCollectionsViewController = LevelFilteringNavigationController.GetPrivateField <AnnotatedBeatmapLevelCollectionsViewController>("_annotatedBeatmapLevelCollectionsViewController"); Logger.Debug("Acquired AnnotatedBeatmapLevelCollectionsViewController from LevelFilteringNavigationController [{0}]", AnnotatedBeatmapLevelCollectionsViewController.GetInstanceID()); TableView tableView = LevelCollectionTableView.GetPrivateField <TableView>("_tableView"); TableViewPageUpButton = tableView.GetPrivateField <Button>("_pageUpButton"); TableViewPageDownButton = tableView.GetPrivateField <Button>("_pageDownButton"); Logger.Debug("Acquired Page Up and Down buttons..."); ActionButtons = StandardLevelDetailView.GetComponentsInChildren <RectTransform>().First(x => x.name == "ActionButtons"); Logger.Debug("Acquired ActionButtons [{0}]", ActionButtons.GetInstanceID()); ScreenSystem = Resources.FindObjectsOfTypeAll <ScreenSystem>().Last(); Logger.Debug("Acquired ScreenSystem [{0}]", ScreenSystem.GetInstanceID()); SimpleDialogPromptViewControllerPrefab = Resources.FindObjectsOfTypeAll <SimpleDialogPromptViewController>().Last(); Logger.Debug("Acquired SimpleDialogPromptViewControllerPrefab [{0}]", SimpleDialogPromptViewControllerPrefab.GetInstanceID()); BeatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().Last(); Logger.Debug("Acquired BeatmapLevelsModel [{0}]", BeatmapLevelsModel); }
/// <summary> /// Constructor. Acquire all necessary BeatSaberUi elements. /// </summary> /// <param name="flowCoordinator"></param> public BeatSaberUIController(FlowCoordinator flowCoordinator) { Logger.Debug("Collecting all BeatSaberUI Elements..."); LevelSelectionFlowCoordinator = flowCoordinator; // gather flow coordinator elements LevelSelectionNavigationController = LevelSelectionFlowCoordinator.GetPrivateField <LevelSelectionNavigationController>("_levelSelectionNavigationController"); Logger.Debug("Acquired LevelSelectionNavigationController [{0}]", LevelSelectionNavigationController.GetInstanceID()); // this is loaded late but available early, grab globally. LevelFilteringNavigationController = Resources.FindObjectsOfTypeAll <LevelFilteringNavigationController>().First(); //LevelSelectionFlowCoordinator.GetPrivateField<LevelFilteringNavigationController>("_levelFilteringNavigationController"); Logger.Debug("Acquired LevelFilteringNavigationController [{0}]", LevelFilteringNavigationController.GetInstanceID()); // grab nav controller elements LevelCollectionViewController = LevelSelectionNavigationController.GetPrivateField <LevelCollectionViewController>("_levelCollectionViewController"); Logger.Debug("Acquired LevelPackLevelsViewController [{0}]", LevelCollectionViewController.GetInstanceID()); LevelDetailViewController = LevelSelectionNavigationController.GetPrivateField <StandardLevelDetailViewController>("_levelDetailViewController"); Logger.Debug("Acquired StandardLevelDetailViewController [{0}]", LevelDetailViewController.GetInstanceID()); // grab level collection view controller elements LevelCollectionTableView = this.LevelCollectionViewController.GetPrivateField <LevelCollectionTableView>("_levelCollectionTableView"); Logger.Debug("Acquired LevelPackLevelsTableView [{0}]", LevelCollectionTableView.GetInstanceID()); // grab letel detail view StandardLevelDetailView = LevelDetailViewController.GetPrivateField <StandardLevelDetailView>("_standardLevelDetailView"); Logger.Debug("Acquired StandardLevelDetailView [{0}]", StandardLevelDetailView.GetInstanceID()); BeatmapCharacteristicSelectionViewController = Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSegmentedControlController>().First(); Logger.Debug("Acquired BeatmapCharacteristicSegmentedControlController [{0}]", BeatmapCharacteristicSelectionViewController.GetInstanceID()); LevelDifficultyViewController = StandardLevelDetailView.GetPrivateField <BeatmapDifficultySegmentedControlController>("_beatmapDifficultySegmentedControlController"); Logger.Debug("Acquired BeatmapDifficultySegmentedControlController [{0}]", LevelDifficultyViewController.GetInstanceID()); LevelCollectionTableViewTransform = LevelCollectionTableView.transform as RectTransform; Logger.Debug("Acquired TableViewRectTransform from LevelPackLevelsTableView [{0}]", LevelCollectionTableViewTransform.GetInstanceID()); TableView tableView = LevelCollectionTableView.GetPrivateField <TableView>("_tableView"); TableViewPageUpButton = tableView.GetPrivateField <Button>("_pageUpButton"); TableViewPageDownButton = tableView.GetPrivateField <Button>("_pageDownButton"); Logger.Debug("Acquired Page Up and Down buttons..."); PlayContainer = StandardLevelDetailView.GetComponentsInChildren <RectTransform>().First(x => x.name == "PlayContainer"); PlayButtons = PlayContainer.GetComponentsInChildren <RectTransform>().First(x => x.name == "PlayButtons"); PlayButton = Resources.FindObjectsOfTypeAll <Button>().First(x => x.name == "PlayButton"); PracticeButton = PlayButtons.GetComponentsInChildren <Button>().First(x => x.name == "PracticeButton"); SimpleDialogPromptViewControllerPrefab = Resources.FindObjectsOfTypeAll <SimpleDialogPromptViewController>().First(); BeatmapLevelsModel = Resources.FindObjectsOfTypeAll <BeatmapLevelsModel>().First(); }
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 ApplyQuickFilterPressed(QuickFilter quickFilter) { FilterList.ApplyQuickFilter(quickFilter); IPreviewBeatmapLevel[] unfilteredLevels = null; if (_lastPack == null) { _lastPack = LevelSelectionNavigationController.GetPrivateField <IBeatmapLevelPack>("_levelPack"); } if (_lastPack == null) { unfilteredLevels = _levelCollectionTableView.GetPrivateField <IPreviewBeatmapLevel[]>("_previewBeatmapLevels"); } else { unfilteredLevels = _lastPack.beatmapLevelCollection.beatmapLevels; } if (unfilteredLevels == null) { Logger.log.Warn("Unable to apply quick filter (could not find songs to filter)"); return; } _filteredLevelPack.SetupFromUnfilteredLevels(unfilteredLevels); LevelSelectionNavigationController.SetData( _filteredLevelPack, true, LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"), LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView")); ButtonPanel.instance.SetFilterStatus(true); }
private void SortButtonPressed() { if (_lastPack == null) { _lastPack = LevelSelectionNavigationController.GetPrivateField <IBeatmapLevelPack>("_levelPack"); } if (FilterList.AnyApplied) { _filteredLevelPack.SetupFromUnfilteredLevels(_lastPack.beatmapLevelCollection.beatmapLevels, _lastPack.coverImage, false); LevelSelectionNavigationController.SetData(_filteredLevelPack, true, LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"), LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView")); } else { if (_lastPack != null && _lastPack is IBeatmapLevelPack beatmapLevelPack) { LevelSelectionNavigationController.SetData( _sortedLevelsLevelPack.SetupFromLevelPack(beatmapLevelPack), true, LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"), LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView")); } else { var lastLevels = _levelCollectionTableView.GetPrivateField <IPreviewBeatmapLevel[]>("_previewBeatmapLevels"); if (lastLevels != null) { // if using default sort on a playlist, just show it as a playlist instead of creating a new level pack if (SongSortModule.IsDefaultSort) { LevelSelectionNavigationController.SetData( new BeatmapLevelCollection(lastLevels), LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"), LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView"), null); } else { LevelSelectionNavigationController.SetData( _sortedLevelsLevelPack.SetupFromLevels(lastLevels), true, LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"), LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView")); } } else { Logger.log.Warn("Unable to find songs to sort"); } } } }
private void ConfirmDeleteButtonPressed(CustomBeatmapLevel level) { // scrolling back to the previous position is done by SongListUIAdditions // just need to deal with setting up the current pack here var currentPack = LevelSelectionNavigationController.GetPrivateField <IBeatmapLevelPack>("_levelPack", typeof(LevelSelectionNavigationController)); // if the current list of levels does not belong to a level pack, just provide the same levels minus the deleted song if (currentPack == null) { IPreviewBeatmapLevel[] levels = _levelCollectionTableView.GetPrivateField <IPreviewBeatmapLevel[]>("_previewBeatmapLevels", typeof(LevelCollectionTableView)); BeatmapLevelCollection replacementLevels = new BeatmapLevelCollection(levels.Where(x => x.levelID != level.levelID).ToArray()); Loader.Instance.DeleteSong(level.customLevelPath); LevelSelectionNavigationController.SetData( replacementLevels, LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView", typeof(LevelSelectionNavigationController)), LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView", typeof(LevelSelectionNavigationController)), null); } // check if the current level pack is this mod's filtered/sorted level pack // if it is, just remove the song from the level pack and show it again else if (currentPack.packID == FilteredLevelsLevelPack.PackID || currentPack.packID.Contains(SortedLevelsLevelPack.PackIDSuffix)) { // remove the song from the pack var replacementPack = new BeatmapLevelPack( currentPack.packID, currentPack.packName, currentPack.shortPackName, currentPack.coverImage, new BeatmapLevelCollection(currentPack.beatmapLevelCollection.beatmapLevels.Where(x => x.levelID != level.levelID).ToArray())); try { _isDeletingSongInModOwnedLevelPack = true; Loader.Instance.DeleteSong(level.customLevelPath); } finally { _isDeletingSongInModOwnedLevelPack = false; } LevelSelectionNavigationController.SetData( replacementPack, true, LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView", typeof(LevelSelectionNavigationController)), LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView", typeof(LevelSelectionNavigationController))); } // if the current level pack is not from this mod, just delete // SongCore should automatically reload the pack else { Loader.Instance.DeleteSong(level.customLevelPath); } }
public void ClearButtonPressed() { if (FilterList.AnyApplied) { UnapplyFilters(); } else { return; } if (SongBrowserTweaks.Initialized) { Logger.log.Debug("'Clear Filter' button pressed."); return; } if (_lastPack == null) { var levelCollectionsViewController = Resources.FindObjectsOfTypeAll <AnnotatedBeatmapLevelCollectionsViewController>().FirstOrDefault(); if (levelCollectionsViewController != null) { _lastPack = levelCollectionsViewController.selectedAnnotatedBeatmapLevelCollection; } } if (_lastPack != null) { if (SongSortModule.IsDefaultSort) { LevelSelectionNavigationController.SetData(_lastPack, true, LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"), LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView"), null); } else { LevelSelectionNavigationController.SetData(_sortedLevelsLevelPack.SetupFromLevelCollection(_lastPack), true, LevelSelectionNavigationController.GetPrivateField <bool>("_showPlayerStatsInDetailView"), LevelSelectionNavigationController.GetPrivateField <bool>("_showPracticeButtonInDetailView")); } } else { Logger.log.Warn("Unable to find the last level pack"); } if (ButtonPanel.IsSingletonAvailable && ButtonPanel.instance.Initialized) { ButtonPanel.instance.SetFilterStatus(false); } }
/// <summary> /// Get the currently selected level pack within the LevelPackLevelViewController hierarchy. /// </summary> /// <returns></returns> private IBeatmapLevelPack GetCurrentSelectedLevelPack() { if (LevelSelectionNavigationController == null) { return(null); } var pack = LevelSelectionNavigationController.GetPrivateField <IBeatmapLevelPack>("_levelPack"); return(pack); }
public void FilterButtonPressed() { if (_filterFlowCoordinator == null) { _filterFlowCoordinator = BeatSaberUI.CreateFlowCoordinator <FilterFlowCoordinator>(); _filterFlowCoordinator.name = "FilterFlowCoordinator"; _filterFlowCoordinator.BackButtonPressed += DismissFilterFlowCoordinator; _filterFlowCoordinator.FilterApplied += FilterFlowCoordinatorSetFilteredSongs; _filterFlowCoordinator.FiltersUnapplied += FilterFlowCoordinatorFiltersUnapplied; } if (_lastPack == null) { var levelPack = LevelSelectionNavigationController.GetPrivateField <IBeatmapLevelPack>("_levelPack"); if (levelPack != null && levelPack.packID != FilteredLevelsLevelPack.PackID && !levelPack.packID.Contains(SortedLevelsLevelPack.PackIDSuffix)) { _lastPack = levelPack; Logger.log.Debug($"Storing '{levelPack.packName}' (id = '{levelPack.packID}') level pack as last pack"); } else { var levelCollectionsViewController = Resources.FindObjectsOfTypeAll <AnnotatedBeatmapLevelCollectionsViewController>().FirstOrDefault(); if (levelCollectionsViewController != null) { _lastPack = levelCollectionsViewController.selectedAnnotatedBeatmapLevelCollection; } if (_lastPack == null) { Logger.log.Error("Unable to find currently selected level pack for filtering. Will not display FilterFlowCoordinator"); return; } else { Logger.log.Debug($"Storing '{_lastPack.collectionName}' level collection as last pack"); } } } IPreviewBeatmapLevel[] levels = _lastPack.beatmapLevelCollection.beatmapLevels; _filterFlowCoordinator.Activate(_freePlayFlowCoordinator, levels); if (!ButtonPanel.IsSingletonAvailable || !ButtonPanel.instance.Initialized) { Logger.log.Debug("'Filter' button pressed."); } }
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(); } }
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."); } }
public void SearchButtonPressed() { if (_searchFlowCoordinator == null) { _searchFlowCoordinator = BeatSaberUI.CreateFlowCoordinator <SearchFlowCoordinator>(); _searchFlowCoordinator.name = "EnhancedSearchFlowCoordinator"; _searchFlowCoordinator.BackButtonPressed += DismissSearchFlowCoordinator; _searchFlowCoordinator.SongSelected += SelectSongFromSearchResult; } IBeatmapLevelPack levelPack = LevelSelectionNavigationController.GetPrivateField <IBeatmapLevelPack>("_levelPack"); _searchFlowCoordinator.Activate(_freePlayFlowCoordinator, levelPack); if (!ButtonPanel.IsSingletonAvailable || !ButtonPanel.instance.Initialized) { Logger.log.Debug("'Search' button pressed."); } }
/// <summary> /// Sort the song list based on the settings. /// </summary> public void ProcessSongList(IBeatmapLevelPack selectedLevelPack, LevelCollectionViewController levelCollectionViewController, LevelSelectionNavigationController navController) { Logger.Trace("ProcessSongList()"); List <IPreviewBeatmapLevel> unsortedSongs = null; List <IPreviewBeatmapLevel> filteredSongs = null; List <IPreviewBeatmapLevel> sortedSongs = null; // Abort if (selectedLevelPack == null) { Logger.Debug("Cannot process songs yet, no level pack selected..."); return; } Logger.Debug("Using songs from level pack: {0}", selectedLevelPack.packID); unsortedSongs = selectedLevelPack.beatmapLevelCollection.beatmapLevels.ToList(); // filter Logger.Debug($"Starting filtering songs by {_settings.filterMode}"); Stopwatch stopwatch = Stopwatch.StartNew(); switch (_settings.filterMode) { case SongFilterMode.Favorites: filteredSongs = FilterFavorites(unsortedSongs); break; case SongFilterMode.Search: filteredSongs = FilterSearch(unsortedSongs); break; case SongFilterMode.Ranked: filteredSongs = FilterRanked(unsortedSongs, true, false); break; case SongFilterMode.Unranked: filteredSongs = FilterRanked(unsortedSongs, false, true); break; case SongFilterMode.Custom: Logger.Info("Song filter mode set to custom. Deferring filter behaviour to another mod."); filteredSongs = CustomFilterHandler != null?CustomFilterHandler.Invoke(selectedLevelPack) : unsortedSongs; break; case SongFilterMode.None: default: Logger.Info("No song filter selected..."); filteredSongs = unsortedSongs; break; } stopwatch.Stop(); Logger.Info("Filtering songs took {0}ms", stopwatch.ElapsedMilliseconds); // sort Logger.Debug("Starting to sort songs..."); stopwatch = Stopwatch.StartNew(); SortWasMissingData = false; switch (_settings.sortMode) { case SongSortMode.Original: sortedSongs = SortOriginal(filteredSongs); break; case SongSortMode.Newest: sortedSongs = SortNewest(filteredSongs); break; case SongSortMode.Author: sortedSongs = SortAuthor(filteredSongs); break; case SongSortMode.UpVotes: sortedSongs = SortUpVotes(filteredSongs); break; case SongSortMode.PlayCount: sortedSongs = SortBeatSaverPlayCount(filteredSongs); break; case SongSortMode.Rating: sortedSongs = SortBeatSaverRating(filteredSongs); break; case SongSortMode.Heat: sortedSongs = SortBeatSaverHeat(filteredSongs); break; case SongSortMode.YourPlayCount: sortedSongs = SortPlayCount(filteredSongs); break; case SongSortMode.PP: sortedSongs = SortPerformancePoints(filteredSongs); break; case SongSortMode.Stars: sortedSongs = SortStars(filteredSongs); break; case SongSortMode.Random: sortedSongs = SortRandom(filteredSongs); break; case SongSortMode.Default: default: sortedSongs = SortSongName(filteredSongs); break; } if (this.Settings.invertSortResults && _settings.sortMode != SongSortMode.Random) { sortedSongs.Reverse(); } stopwatch.Stop(); Logger.Info("Sorting songs took {0}ms", stopwatch.ElapsedMilliseconds); // Asterisk the pack name so it is identifable as filtered. var packName = selectedLevelPack.packName; if (!packName.EndsWith("*") && _settings.filterMode != SongFilterMode.None) { packName += "*"; } BeatmapLevelPack levelPack = new BeatmapLevelPack(SongBrowserModel.FilteredSongsPackId, packName, selectedLevelPack.shortPackName, selectedLevelPack.coverImage, new BeatmapLevelCollection(sortedSongs.ToArray())); GameObject _noDataGO = levelCollectionViewController.GetPrivateField <GameObject>("_noDataInfoGO"); //string _headerText = tableView.GetPrivateField<string>("_headerText"); //Sprite _headerSprite = tableView.GetPrivateField<Sprite>("_headerSprite"); bool _showPlayerStatsInDetailView = navController.GetPrivateField <bool>("_showPlayerStatsInDetailView"); bool _showPracticeButtonInDetailView = navController.GetPrivateField <bool>("_showPracticeButtonInDetailView"); navController.SetData(levelPack, true, _showPlayerStatsInDetailView, _showPracticeButtonInDetailView, _noDataGO); //_sortedSongs.ForEach(x => Logger.Debug(x.levelID)); }
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; 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 if (_isDeletingSongInModOwnedLevelPack) { 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) { if (levelPack is IBeatmapLevelPack beatmapLevelPack2) { _sortedLevelsLevelPack.SetupFromLevelPack(beatmapLevelPack2); } else { _sortedLevelsLevelPack.SetupFromLevels(levelPack.beatmapLevelCollection.beatmapLevels); } // 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 StartCoroutine(UIUtilities.DelayedAction(() => 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) { StartCoroutine(UIUtilities.DelayedAction(_uiAdditions.RefreshPageButtons)); } }
/// <summary> /// Sort the song list based on the settings. /// </summary> public void ProcessSongList(IAnnotatedBeatmapLevelCollection selectedBeatmapCollection, LevelSelectionNavigationController navController) { Logger.Trace("ProcessSongList()"); List <IPreviewBeatmapLevel> unsortedSongs = null; List <IPreviewBeatmapLevel> filteredSongs = null; List <IPreviewBeatmapLevel> sortedSongs = null; // Abort if (selectedBeatmapCollection == null) { Logger.Debug("Cannot process songs yet, no level collection selected..."); return; } Logger.Debug($"Using songs from level collection: {selectedBeatmapCollection.collectionName} [num={selectedBeatmapCollection.beatmapLevelCollection.beatmapLevels.Length}"); unsortedSongs = selectedBeatmapCollection.beatmapLevelCollection.beatmapLevels.ToList(); // filter Logger.Debug($"Starting filtering songs by {_settings.filterMode}"); Stopwatch stopwatch = Stopwatch.StartNew(); switch (_settings.filterMode) { case SongFilterMode.Favorites: filteredSongs = FilterFavorites(unsortedSongs); break; case SongFilterMode.Search: filteredSongs = FilterSearch(unsortedSongs); break; case SongFilterMode.Ranked: filteredSongs = FilterRanked(unsortedSongs, true, false); break; case SongFilterMode.Unranked: filteredSongs = FilterRanked(unsortedSongs, false, true); break; case SongFilterMode.Custom: Logger.Info("Song filter mode set to custom. Deferring filter behaviour to another mod."); filteredSongs = CustomFilterHandler != null?CustomFilterHandler.Invoke(selectedBeatmapCollection) : unsortedSongs; break; case SongFilterMode.None: default: Logger.Info("No song filter selected..."); filteredSongs = unsortedSongs; break; } stopwatch.Stop(); Logger.Info("Filtering songs took {0}ms", stopwatch.ElapsedMilliseconds); // sort Logger.Debug($"Starting to sort songs by {_settings.sortMode}"); stopwatch = Stopwatch.StartNew(); SortWasMissingData = false; switch (_settings.sortMode) { case SongSortMode.Original: sortedSongs = SortOriginal(filteredSongs); break; case SongSortMode.Newest: sortedSongs = SortNewest(filteredSongs); break; case SongSortMode.Author: sortedSongs = SortAuthor(filteredSongs); break; case SongSortMode.UpVotes: sortedSongs = SortUpVotes(filteredSongs); break; case SongSortMode.PlayCount: sortedSongs = SortBeatSaverPlayCount(filteredSongs); break; case SongSortMode.Rating: sortedSongs = SortBeatSaverRating(filteredSongs); break; case SongSortMode.Heat: sortedSongs = SortBeatSaverHeat(filteredSongs); break; case SongSortMode.YourPlayCount: sortedSongs = SortPlayCount(filteredSongs); break; case SongSortMode.PP: sortedSongs = SortPerformancePoints(filteredSongs); break; case SongSortMode.Stars: sortedSongs = SortStars(filteredSongs); break; case SongSortMode.Random: sortedSongs = SortRandom(filteredSongs); break; case SongSortMode.Custom: sortedSongs = CustomSortHandler != null?CustomSortHandler.Invoke(filteredSongs) : filteredSongs; break; case SongSortMode.Default: default: sortedSongs = SortSongName(filteredSongs); break; } if (this.Settings.invertSortResults && _settings.sortMode != SongSortMode.Random) { sortedSongs.Reverse(); } stopwatch.Stop(); Logger.Info("Sorting songs took {0}ms", stopwatch.ElapsedMilliseconds); // Still hacking in a custom level pack // Asterisk the pack name so it is identifable as filtered. var packName = selectedBeatmapCollection.collectionName; if (packName == null) { packName = ""; } if (!packName.EndsWith("*") && _settings.filterMode != SongFilterMode.None) { packName += "*"; } // Some level categories have a null cover image, supply something, it won't show it anyway var coverImage = selectedBeatmapCollection.coverImage; if (coverImage == null) { coverImage = BeatSaberMarkupLanguage.Utilities.ImageResources.BlankSprite; } Logger.Debug("Creating filtered level pack..."); BeatmapLevelPack levelPack = new BeatmapLevelPack(SongBrowserModel.FilteredSongsCollectionName, packName, selectedBeatmapCollection.collectionName, coverImage, new BeatmapLevelCollection(sortedSongs.ToArray())); /* * public virtual void SetData( * IAnnotatedBeatmapLevelCollection annotatedBeatmapLevelCollection, * bool showPackHeader, bool showPlayerStats, bool showPracticeButton, * string actionButtonText, * GameObject noDataInfoPrefab, BeatmapDifficultyMask allowedBeatmapDifficultyMask, BeatmapCharacteristicSO[] notAllowedCharacteristics); */ Logger.Debug("Acquiring necessary fields to call SetData(pack)..."); LevelCollectionNavigationController lcnvc = navController.GetPrivateField <LevelCollectionNavigationController>("_levelCollectionNavigationController"); var _showPlayerStatsInDetailView = navController.GetPrivateField <bool>("_showPlayerStatsInDetailView"); var _hidePracticeButton = navController.GetPrivateField <bool>("_hidePracticeButton"); var _actionButtonText = navController.GetPrivateField <string>("_actionButtonText"); var _allowedBeatmapDifficultyMask = navController.GetPrivateField <BeatmapDifficultyMask>("_allowedBeatmapDifficultyMask"); var _notAllowedCharacteristics = navController.GetPrivateField <BeatmapCharacteristicSO[]>("_notAllowedCharacteristics"); Logger.Debug("Calling lcnvc.SetData..."); lcnvc.SetData(levelPack, true, _showPlayerStatsInDetailView, !_hidePracticeButton, _actionButtonText, null, _allowedBeatmapDifficultyMask, _notAllowedCharacteristics); //_sortedSongs.ForEach(x => Logger.Debug(x.levelID)); }