コード例 #1
0
        public void SetLevels(SortMode sortMode, string searchRequest)
        {
            BeatmapLevelSO[] levels = null;
            if (lastPlaylist != null)
            {
                levels = lastPlaylist.songs.Where(x => x.level != null).Select(x => x.level).ToArray();
            }
            else
            {
                levels = _levelCollection.beatmapLevels.Cast <BeatmapLevelSO>().ToArray();
            }

            if (string.IsNullOrEmpty(searchRequest))
            {
                switch (sortMode)
                {
                case SortMode.Newest: { levels = SortLevelsByCreationTime(levels); }; break;

                case SortMode.Difficulty:
                {
                    levels = levels.AsParallel().OrderBy(x => { int index = ScrappedData.Songs.FindIndex(y => x.levelID.StartsWith(y.Hash)); return(index == -1 ? (x.levelID.Length < 32 ? int.MaxValue : int.MaxValue - 1) : index); }).ToArray();
                }; break;
                }
            }
            else
            {
                levels = levels.Where(x => ($"{x.songName} {x.songSubName} {x.levelAuthorName} {x.songAuthorName}".ToLower().Contains(searchRequest))).ToArray();
            }

            _levelListViewController.SetData(CustomHelpers.GetLevelPackWithLevels(levels, lastPlaylist?.playlistTitle ?? "Custom Songs", lastPlaylist?.icon));
            PopDifficultyAndDetails();
        }
コード例 #2
0
        private void DeletePressed()
        {
            IBeatmapLevel level = _detailViewController.selectedDifficultyBeatmap.level;

            _simpleDialog.Init("Delete song", $"Do you really want to delete \"{ level.songName} {level.songSubName}\"?", "Delete", "Cancel",
                               (selectedButton) =>
            {
                freePlayFlowCoordinator.InvokePrivateMethod("DismissViewController", new object[] { _simpleDialog, null, false });
                if (selectedButton == 0)
                {
                    try
                    {
                        var levelsTableView = _levelListViewController.GetPrivateField <LevelPackLevelsTableView>("_levelPackLevelsTableView");

                        List <IPreviewBeatmapLevel> levels = levelsTableView.GetPrivateField <IBeatmapLevelPack>("_pack").beatmapLevelCollection.beatmapLevels.ToList();
                        int selectedIndex = levels.FindIndex(x => x.levelID == _detailViewController.selectedDifficultyBeatmap.level.levelID);

                        SongDownloader.Instance.DeleteSong(new Song(SongLoader.CustomLevels.First(x => x.levelID == _detailViewController.selectedDifficultyBeatmap.level.levelID)));

                        if (selectedIndex > -1)
                        {
                            int removedLevels = levels.RemoveAll(x => x.levelID == _detailViewController.selectedDifficultyBeatmap.level.levelID);
                            Logger.Log("Removed " + removedLevels + " level(s) from song list!");

                            _levelListViewController.SetData(CustomHelpers.GetLevelPackWithLevels(levels.Cast <BeatmapLevelSO>().ToArray(), lastPlaylist?.playlistTitle ?? "Custom Songs", lastPlaylist?.icon));
                            TableView listTableView = levelsTableView.GetPrivateField <TableView>("_tableView");
                            listTableView.ScrollToCellWithIdx(selectedIndex, TableView.ScrollPositionType.Beginning, false);
                            levelsTableView.SetPrivateField("_selectedRow", selectedIndex);
                            listTableView.SelectCellWithIdx(selectedIndex, true);
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Unable to delete song! Exception: " + e);
                    }
                }
            });
            freePlayFlowCoordinator.InvokePrivateMethod("PresentViewController", new object[] { _simpleDialog, null, false });
        }