Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        internal PlaylistDataManager(AnnotatedBeatmapLevelCollectionsViewController annotatedBeatmapLevelCollectionsViewController, LevelPackDetailViewController levelPackDetailViewController, LevelFilteringNavigationController levelFilteringNavigationController,
                                     List <ILevelCollectionUpdater> levelCollectionUpdaters, List <ILevelCollectionsTableUpdater> levelCollectionsTableUpdaters, List <IPreviewBeatmapLevelUpdater> previewBeatmapLevelUpdaters)
        {
            this.annotatedBeatmapLevelCollectionsViewController = annotatedBeatmapLevelCollectionsViewController;
            this.levelPackDetailViewController      = levelPackDetailViewController;
            this.levelFilteringNavigationController = levelFilteringNavigationController;

            this.levelCollectionUpdaters       = levelCollectionUpdaters;
            this.levelCollectionsTableUpdaters = levelCollectionsTableUpdaters;
            this.previewBeatmapLevelUpdaters   = previewBeatmapLevelUpdaters;

            emptyBeatmapLevelPack = new BeatmapLevelPack(CustomLevelLoader.kCustomLevelPackPrefixId + "CustomLevels", "Custom Levels", "Custom Levels", BeatSaberMarkupLanguage.Utilities.ImageResources.BlankSprite, new BeatmapLevelCollection(new IPreviewBeatmapLevel[0]));
        }
        private void FilterViewControllerSetFilteredSongs(IPreviewBeatmapLevel[] levels)
        {
            // filter application should be handled by FilterViewController calling stuff in SongBrowserTweaks
            if (SongBrowserTweaks.Initialized)
            {
                return;
            }

            BeatmapLevelPack levelPack = new BeatmapLevelPack("", FilteredSongsPackName, LevelsViewController.levelPack.coverImage, new BeatmapLevelCollection(levels));

            LevelsViewController.SetData(levelPack);

            FilterButton.SetButtonText(FilterButtonAppliedText);
            FilterButton.SetButtonTextSize(2.3f);

            ClearButton.SetButtonText(ClearFilterButtonAppliedText);
        }
        /// <summary>
        /// Sort the song list based on the settings.
        /// </summary>
        public void ProcessSongList(LevelPackLevelsViewController levelsViewController)
        {
            Logger.Trace("ProcessSongList()");

            List <IPreviewBeatmapLevel> unsortedSongs = null;
            List <IPreviewBeatmapLevel> filteredSongs = null;
            List <IPreviewBeatmapLevel> sortedSongs   = null;

            // Abort
            if (levelsViewController.levelPack == null)
            {
                Logger.Debug("Cannot process songs yet, no level pack selected...");
                return;
            }

            // fetch unsorted songs.
            // playlists always use customsongs
            if (this._settings.filterMode == SongFilterMode.Playlist && this.CurrentPlaylist != null)
            {
                unsortedSongs = null;
            }
            else
            {
                Logger.Debug("Using songs from level pack: {0}", levelsViewController.levelPack.packID);
                unsortedSongs = levelsViewController.levelPack.beatmapLevelCollection.beatmapLevels.ToList();
            }

            // filter
            Logger.Debug($"Starting filtering songs by {_settings.filterMode}");
            Stopwatch stopwatch = Stopwatch.StartNew();

            switch (_settings.filterMode)
            {
            case SongFilterMode.Favorites:
                filteredSongs = FilterFavorites();
                break;

            case SongFilterMode.Search:
                filteredSongs = FilterSearch(unsortedSongs);
                break;

            case SongFilterMode.Playlist:
                filteredSongs = FilterPlaylist();
                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(levelsViewController.levelPack) : 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();

            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.Difficulty:
                sortedSongs = SortDifficulty(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 = levelsViewController.levelPack.packName;

            if (!packName.EndsWith("*") && _settings.filterMode != SongFilterMode.None)
            {
                packName += "*";
            }
            BeatmapLevelPack levelPack = new BeatmapLevelPack(SongBrowserModel.FilteredSongsPackId, packName, levelsViewController.levelPack.coverImage, new BeatmapLevelCollection(sortedSongs.ToArray()));

            levelsViewController.SetData(levelPack);

            //_sortedSongs.ForEach(x => Logger.Debug(x.levelID));
        }
        /// <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));
        }
        /// <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.GetField <LevelCollectionNavigationController, LevelSelectionNavigationController>("_levelCollectionNavigationController");
            var _showPlayerStatsInDetailView          = navController.GetField <bool, LevelSelectionNavigationController>("_showPlayerStatsInDetailView");
            var _hidePracticeButton           = navController.GetField <bool, LevelSelectionNavigationController>("_hidePracticeButton");
            var _actionButtonText             = navController.GetField <string, LevelSelectionNavigationController>("_actionButtonText");
            var _allowedBeatmapDifficultyMask = navController.GetField <BeatmapDifficultyMask, LevelSelectionNavigationController>("_allowedBeatmapDifficultyMask");
            var _notAllowedCharacteristics    = navController.GetField <BeatmapCharacteristicSO[], LevelSelectionNavigationController>("_notAllowedCharacteristics");

            Logger.Debug("Calling lcnvc.SetData...");
            lcnvc.SetData(levelPack,
                          true,
                          _showPlayerStatsInDetailView,
                          !_hidePracticeButton,
                          _actionButtonText,
                          null,
                          _allowedBeatmapDifficultyMask,
                          _notAllowedCharacteristics);

            //_sortedSongs.ForEach(x => Logger.Debug(x.levelID));
        }