Implemented basic sorting logic

This commit is contained in:
Alex Amadori
2017-02-17 17:41:53 +01:00
parent ecb840e26f
commit 7dcbefd50f
3 changed files with 44 additions and 4 deletions

View File

@ -184,6 +184,44 @@ namespace osu.Game.Screens.Select
ScrollTo(selectedY, animated); ScrollTo(selectedY, animated);
} }
public void Sort(FilterControl.SortMode mode) {
switch (mode) {
case FilterControl.SortMode.Artist:
groups.Sort((x, y) =>
{
return string.Compare(x.BeatmapSet.Metadata.Artist, y.BeatmapSet.Metadata.Artist);
});
break;
case FilterControl.SortMode.Title:
groups.Sort((x, y) =>
{
return string.Compare(x.BeatmapSet.Metadata.Title, y.BeatmapSet.Metadata.Title);
});
break;
case FilterControl.SortMode.Author:
groups.Sort((x, y) =>
{
return string.Compare(x.BeatmapSet.Metadata.Author, y.BeatmapSet.Metadata.Author);
});
break;
case FilterControl.SortMode.Difficulty:
groups.Sort((x, y) =>
{
if (x.BeatmapSet.Beatmaps.First().BaseDifficulty.OverallDifficulty >
y.BeatmapSet.Beatmaps.First().BaseDifficulty.OverallDifficulty)
return 1;
else if (Equals(x.BeatmapSet.Beatmaps.First().BaseDifficulty.OverallDifficulty,
y.BeatmapSet.Beatmaps.First().BaseDifficulty.OverallDifficulty))
return 0;
else
return -1;
});
break;
default:
throw new NotImplementedException();
}
}
private static float offsetX(float dist, float halfHeight) private static float offsetX(float dist, float halfHeight)
{ {
// The radius of the circle the carousel moves on. // The radius of the circle the carousel moves on.

View File

@ -250,9 +250,9 @@ namespace osu.Game.Screens.Select
public enum SortMode public enum SortMode
{ {
Arist, Artist,
BPM, BPM,
Creator, Author,
DateAdded, DateAdded,
Difficulty, Difficulty,
Length, Length,
@ -263,9 +263,9 @@ namespace osu.Game.Screens.Select
public enum GroupMode public enum GroupMode
{ {
NoGrouping, NoGrouping,
Arist, Artist,
BPM, BPM,
Creator, Author,
DateAdded, DateAdded,
Difficulty, Difficulty,
Length, Length,

View File

@ -174,6 +174,7 @@ namespace osu.Game.Screens.Select
filterTask = null; filterTask = null;
var search = filter.Search; var search = filter.Search;
BeatmapGroup newSelection = null; BeatmapGroup newSelection = null;
carousel.Sort(filter.Sort);
foreach (var beatmapGroup in carousel) foreach (var beatmapGroup in carousel)
{ {
var set = beatmapGroup.BeatmapSet; var set = beatmapGroup.BeatmapSet;
@ -373,6 +374,7 @@ namespace osu.Game.Screens.Select
if (token.IsCancellationRequested) return; if (token.IsCancellationRequested) return;
addBeatmapSet(beatmapSet, game); addBeatmapSet(beatmapSet, game);
} }
filterChanged();
} }
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)