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 @@ public void SelectGroup(BeatmapGroup group, BeatmapPanel panel, bool 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)
{
// The radius of the circle the carousel moves on.

View File

@ -250,9 +250,9 @@ private void load(OsuColour colours)
public enum SortMode
{
Arist,
Artist,
BPM,
Creator,
Author,
DateAdded,
Difficulty,
Length,
@ -263,9 +263,9 @@ public enum SortMode
public enum GroupMode
{
NoGrouping,
Arist,
Artist,
BPM,
Creator,
Author,
DateAdded,
Difficulty,
Length,

View File

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