Skip to content

Commit

Permalink
Merge pull request #368 from tacchinotacchi/master
Browse files Browse the repository at this point in the history
Added basic sorting functionality
  • Loading branch information
peppy authored Mar 2, 2017
2 parents ffd6560 + 4163569 commit 35c920d
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 23 deletions.
20 changes: 15 additions & 5 deletions osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using System.Collections.Generic;
using osu.Desktop.VisualTests.Platform;
using osu.Framework.Screens.Testing;
using osu.Framework.MathUtils;
using osu.Game.Database;
using osu.Game.Modes;
using osu.Game.Screens.Select;
Expand All @@ -14,6 +16,7 @@ class TestCasePlaySongSelect : TestCase
{
private BeatmapDatabase db, oldDb;
private TestStorage storage;
private PlaySongSelect songSelect;

public override string Name => @"Song Select";
public override string Description => @"with fake data";
Expand All @@ -35,9 +38,15 @@ public override void Reset()

db.Import(sets);
}
Add(new PlaySongSelect());

Add(songSelect = new PlaySongSelect());

AddButton(@"Sort by Artist", delegate { songSelect.Filter.Sort = FilterControl.SortMode.Artist; });
AddButton(@"Sort by Title", delegate { songSelect.Filter.Sort = FilterControl.SortMode.Title; });
AddButton(@"Sort by Author", delegate { songSelect.Filter.Sort = FilterControl.SortMode.Author; });
AddButton(@"Sort by Difficulty", delegate { songSelect.Filter.Sort = FilterControl.SortMode.Difficulty; });
}

protected override void Dispose(bool isDisposing)
{
if (oldDb != null)
Expand All @@ -59,9 +68,10 @@ private BeatmapSetInfo createTestBeatmapSet(int i)
Metadata = new BeatmapMetadata
{
OnlineBeatmapSetID = 1234 + i,
Artist = "MONACA",
Title = "Black Song",
Author = "Some Guy",
// Create random metadata, then we can check if sorting works based on these
Artist = "MONACA " + RNG.Next(0, 9),
Title = "Black Song " + RNG.Next(0, 9),
Author = "Some Guy " + RNG.Next(0, 9),
},
Beatmaps = new List<BeatmapInfo>(new[]
{
Expand Down
1 change: 0 additions & 1 deletion osu.Game.Modes.Osu/Objects/HitCircle.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE


namespace osu.Game.Modes.Osu.Objects
{
public class HitCircle : OsuHitObject
Expand Down
5 changes: 4 additions & 1 deletion osu.Game.Modes.Osu/Objects/SliderTick.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace osu.Game.Modes.Osu.Objects
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

namespace osu.Game.Modes.Osu.Objects
{
public class SliderTick : OsuHitObject
{
Expand Down
1 change: 0 additions & 1 deletion osu.Game.Modes.Osu/Objects/Spinner.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE


namespace osu.Game.Modes.Osu.Objects
{
public class Spinner : OsuHitObject
Expand Down
1 change: 0 additions & 1 deletion osu.Game.Modes.Osu/OsuScore.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE


namespace osu.Game.Modes.Osu
{
class OsuScore : Score
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Database/BeatmapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public bool Equals(BeatmapInfo other)
return ID == other?.ID;
}

public bool AudioEquals(BeatmapInfo other) => other != null &&
public bool AudioEquals(BeatmapInfo other) => other != null && BeatmapSet != null && other.BeatmapSet != null &&
BeatmapSet.Path == other.BeatmapSet.Path &&
(Metadata ?? BeatmapSet.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSet.Metadata).AudioFile;
}
Expand Down
5 changes: 4 additions & 1 deletion osu.Game/Graphics/UserInterface/FocusedTextBox.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using OpenTK.Graphics;
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Input;
using System;
Expand Down
1 change: 0 additions & 1 deletion osu.Game/Modes/Objects/HitObjectParser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE


namespace osu.Game.Modes.Objects
{
public abstract class HitObjectParser
Expand Down
1 change: 0 additions & 1 deletion osu.Game/Modes/Objects/NullHitObjectParser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE


namespace osu.Game.Modes.Objects
{
/// <summary>
Expand Down
1 change: 0 additions & 1 deletion osu.Game/Modes/Score.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE


namespace osu.Game.Modes
{
public class Score
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Modes/UI/HealthDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System;
using osu.Framework.Allocation;
Expand Down
1 change: 0 additions & 1 deletion osu.Game/Online/API/IOnlineComponent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE


namespace osu.Game.Online.API
{
public interface IOnlineComponent
Expand Down
53 changes: 53 additions & 0 deletions osu.Game/Screens/Select/CarouselContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public void SelectGroup(BeatmapGroup group, BeatmapPanel panel, bool animated =
if (SelectedGroup != null && SelectedGroup != group && SelectedGroup.State != BeatmapGroupState.Hidden)
SelectedGroup.State = BeatmapGroupState.Collapsed;

group.State = BeatmapGroupState.Expanded;
SelectedGroup = group;
panel.State = PanelSelectedState.Selected;
SelectedPanel = panel;
Expand All @@ -191,6 +192,58 @@ 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) => string.Compare(x.BeatmapSet.Metadata.Artist, y.BeatmapSet.Metadata.Artist));
break;
case FilterControl.SortMode.Title:
groups.Sort((x, y) => string.Compare(x.BeatmapSet.Metadata.Title, y.BeatmapSet.Metadata.Title));
break;
case FilterControl.SortMode.Author:
groups.Sort((x, y) => string.Compare(x.BeatmapSet.Metadata.Author, y.BeatmapSet.Metadata.Author));
break;
case FilterControl.SortMode.Difficulty:
groups.Sort((x, y) =>
{
float xAverage=0, yAverage=0;
int counter=0;
foreach (BeatmapInfo set in x.BeatmapSet.Beatmaps) {
xAverage += set.StarDifficulty;
counter++;
}
xAverage /= counter;
counter = 0;
foreach (BeatmapInfo set in y.BeatmapSet.Beatmaps) {
yAverage += set.StarDifficulty;
counter++;
}
yAverage /= counter;
if (xAverage > yAverage)
return 1;
else
return -1;
});
break;
default:
throw new NotImplementedException();
}
scrollableContent.Clear(false);
lifetime.Clear();
foreach (BeatmapGroup group in groups)
{
group.Header.Depth = -scrollableContent.Children.Count();
scrollableContent.Add(group.Header);

foreach (BeatmapPanel panel in group.BeatmapPanels)
{
panel.Depth = -scrollableContent.Children.Count();
scrollableContent.Add(panel);
}
}
SelectGroup(groups.FirstOrDefault(), groups.First().BeatmapPanels.FirstOrDefault());
}

private static float offsetX(float dist, float halfHeight)
{
// The radius of the circle the carousel moves on.
Expand Down
21 changes: 16 additions & 5 deletions osu.Game/Screens/Select/FilterControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ public class FilterControl : Container
public Action FilterChanged;

public string Search => searchTextBox.Text;
public SortMode Sort { get; private set; } = SortMode.Title;
private SortMode sort = SortMode.Title;
public SortMode Sort {
get { return sort; }
set {
if (sort != value)
{
sort = value;
FilterChanged?.Invoke();
}
}
}

public Action Exit;

private SearchTextBox searchTextBox;
Expand Down Expand Up @@ -251,9 +262,9 @@ private void load(OsuColour colours)

public enum SortMode
{
Arist,
Artist,
BPM,
Creator,
Author,
DateAdded,
Difficulty,
Length,
Expand All @@ -264,9 +275,9 @@ public enum SortMode
public enum GroupMode
{
NoGrouping,
Arist,
Artist,
BPM,
Creator,
Author,
DateAdded,
Difficulty,
Length,
Expand Down
19 changes: 18 additions & 1 deletion osu.Game/Screens/Select/PlaySongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,22 @@ public class PlaySongSelect : OsuScreen

OsuScreen player;

FilterControl filter;
private FilterControl filter;
public FilterControl Filter
{
get
{
return filter;
}
private set
{
if (filter != value)
{
filter = value;
filterChanged();
}
}
}

[BackgroundDependencyLoader(permitNulls: true)]
private void load(BeatmapDatabase beatmaps, AudioManager audio, DialogOverlay dialog, Framework.Game game,
Expand Down Expand Up @@ -164,6 +179,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;
Expand Down Expand Up @@ -375,6 +391,7 @@ private void addBeatmapSets(Framework.Game game, CancellationToken token)
if (token.IsCancellationRequested) return;
addBeatmapSet(beatmapSet, game);
}
filterChanged();
}

protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
Expand Down
1 change: 0 additions & 1 deletion osu.Game/Users/User.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <[email protected]>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE


namespace osu.Game.Users
{
public class User
Expand Down

0 comments on commit 35c920d

Please sign in to comment.