فهرست منبع

Sort by difficulty available. (Songs with Easy show up first, then
Normal, etc).

Stephen Damm 6 سال پیش
والد
کامیت
7816e95dd0

+ 1 - 0
SongBrowserPlugin/DataAccess/SongBrowserSettings.cs

@@ -15,6 +15,7 @@ namespace SongBrowserPlugin.DataAccess
         Original,
         Newest,
         PlayCount,
+        Difficulty,
         Random,
         Search
     }

+ 53 - 0
SongBrowserPlugin/SongBrowserModel.cs

@@ -471,6 +471,9 @@ namespace SongBrowserPlugin
                 case SongSortMode.PlayCount:
                     SortPlayCount(songList, _currentGamePlayMode);
                     break;
+                case SongSortMode.Difficulty:
+                    SortDifficulty(songList);
+                    break;
                 case SongSortMode.Random:
                     SortRandom(songList);
                     break;
@@ -570,6 +573,56 @@ namespace SongBrowserPlugin
                 .ToList();
         }
 
+        private void SortDifficulty(List<StandardLevelSO> levels)
+        {
+            _log.Info("Sorting song list by random");
+
+            System.Random rnd = new System.Random(Guid.NewGuid().GetHashCode());
+
+            Dictionary<LevelDifficulty, int> difficultyWeights = new Dictionary<LevelDifficulty, int>
+            {
+                [LevelDifficulty.Easy] = int.MaxValue - 4,
+                [LevelDifficulty.Normal] = int.MaxValue - 3,
+                [LevelDifficulty.Hard] = int.MaxValue - 2,
+                [LevelDifficulty.Expert] = int.MaxValue - 1,
+                [LevelDifficulty.ExpertPlus] = int.MaxValue,
+            };
+
+            IEnumerable<LevelDifficulty> difficultyIterator = Enum.GetValues(typeof(LevelDifficulty)).Cast<LevelDifficulty>();
+            Dictionary<string, int>  levelIdToDifficultyValue = new Dictionary<string, int>();
+            foreach (var level in levels)
+            {
+                if (!levelIdToDifficultyValue.ContainsKey(level.levelID))
+                {
+                    // Skip folders
+                    if (level.levelID.StartsWith("Folder_"))
+                    {
+                        levelIdToDifficultyValue.Add(level.levelID, 0);
+                    }
+                    else
+                    {
+                        int difficultyValue = 0;
+                        foreach (LevelDifficulty difficulty in difficultyIterator)
+                        {
+                            IStandardLevelDifficultyBeatmap beatmap = level.GetDifficultyLevel(difficulty);
+                            if (beatmap != null)
+                            {
+                                difficultyValue += difficultyWeights[difficulty];
+                                break;
+                            }
+                        }
+                        levelIdToDifficultyValue.Add(level.levelID, difficultyValue);
+                    }
+                }
+            }
+
+            _sortedSongs = levels
+                .AsQueryable()
+                .OrderBy(x => levelIdToDifficultyValue[x.levelID])
+                .ThenBy(x => x.songName)
+                .ToList();
+        }
+
         private void SortRandom(List<StandardLevelSO> levels)
         {
             _log.Info("Sorting song list by random");

+ 3 - 3
SongBrowserPlugin/UI/SongBrowserUI.cs

@@ -165,17 +165,17 @@ namespace SongBrowserPlugin.UI
 
                 string[] buttonNames = new string[]
                 {
-                    "Favorite", "Song", "Author", "Original", "Newest", "Plays", "Random", "Search"
+                    "Favorite", "Song", "Author", "Original", "Newest", "Plays", "Difficult", "Random", "Search"
                 };
 
                 SongSortMode[] sortModes = new SongSortMode[]
                 {
-                    SongSortMode.Favorites, SongSortMode.Default, SongSortMode.Author, SongSortMode.Original, SongSortMode.Newest, SongSortMode.PlayCount, SongSortMode.Random, SongSortMode.Search
+                    SongSortMode.Favorites, SongSortMode.Default, SongSortMode.Author, SongSortMode.Original, SongSortMode.Newest, SongSortMode.PlayCount, SongSortMode.Difficulty, SongSortMode.Random, SongSortMode.Search
                 };
 
                 System.Action<SongSortMode>[] onClickEvents = new Action<SongSortMode>[]
                 {
-                    onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSearchButtonClickEvent
+                    onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSortButtonClickEvent, onSearchButtonClickEvent
                 };
 
                 _sortButtonGroup = new List<SongSortButton>();