Selaa lähdekoodia

Add sort by playcount.

Stephen Damm 6 vuotta sitten
vanhempi
commit
97393e8654

+ 1 - 0
SongBrowserPlugin/DataAccess/SongBrowserSettings.cs

@@ -14,6 +14,7 @@ namespace SongBrowserPlugin.DataAccess
         Favorites,
         Original,
         Newest,
+        PlayCount,
     }
 
     [Serializable]

+ 15 - 2
SongBrowserPlugin/SongBrowserModel.cs

@@ -101,7 +101,7 @@ namespace SongBrowserPlugin
             // Update song Infos
             this.UpdateSongInfos(gameplayMode);
                                 
-            this.ProcessSongList();                       
+            this.ProcessSongList(gameplayMode);                       
         }
 
         /// <summary>
@@ -123,7 +123,7 @@ namespace SongBrowserPlugin
         /// <summary>
         /// Sort the song list based on the settings.
         /// </summary>
-        private void ProcessSongList()
+        private void ProcessSongList(GameplayMode gameplayMode)
         {
             _log.Trace("ProcessSongList()");
 
@@ -158,6 +158,8 @@ namespace SongBrowserPlugin
                 }
             }*/
 
+            PlayerDynamicData playerData = GameDataModel.instance.gameDynamicData.GetCurrentPlayerDynamicData();
+
             Stopwatch stopwatch = Stopwatch.StartNew();
 
             switch (_settings.sortMode)
@@ -195,6 +197,17 @@ namespace SongBrowserPlugin
                         .ThenBy(x => x.songName)
                         .ToList();
                     break;
+                case SongSortMode.PlayCount:
+                    _log.Info("Sorting song list by playcount");
+                    // Build a map of levelId to sum of all playcounts and sort.
+                    IEnumerable<LevelDifficulty> difficultyIterator = Enum.GetValues(typeof(LevelDifficulty)).Cast<LevelDifficulty>();
+                    Dictionary<string, int> _levelIdToPlayCount = _originalSongs.ToDictionary(x => x.levelID, x => difficultyIterator.Sum(difficulty => playerData.GetPlayerLevelStatsData(x.levelID, difficulty, gameplayMode).playCount));
+                    _sortedSongs = _originalSongs
+                        .AsQueryable()
+                        .OrderByDescending(x => _levelIdToPlayCount[x.levelID])
+                        .ThenBy(x => x.songName)
+                        .ToList();
+                    break;
                 case SongSortMode.Default:
                 default:
                     _log.Info("Sorting song list as default (songName)");

+ 1 - 0
SongBrowserPlugin/UI/SongBrowserUI.cs

@@ -146,6 +146,7 @@ namespace SongBrowserPlugin.UI
                     UIBuilder.CreateSortButton(rect, "PlayButton", "Author", 3, "AllDirectionsIcon", 34f, 74.5f, 16f, 5f, SongSortMode.Author, onSortButtonClickEvent),
                     UIBuilder.CreateSortButton(rect, "PlayButton", "Original", 3, "AllDirectionsIcon", 18f, 74.5f, 16f, 5f, SongSortMode.Original, onSortButtonClickEvent),
                     UIBuilder.CreateSortButton(rect, "PlayButton", "Newest", 3, "AllDirectionsIcon", 2f, 74.5f, 16f, 5f, SongSortMode.Newest, onSortButtonClickEvent),
+                    UIBuilder.CreateSortButton(rect, "PlayButton", "Playcount", 3, "AllDirectionsIcon", -14f, 74.5f, 16f, 5f, SongSortMode.PlayCount, onSortButtonClickEvent),
                 };
 
                 // Creaate Add to Favorites Button