From 6bbbbd8f969612653666d197d74798e9b3cf3f2a Mon Sep 17 00:00:00 2001 From: Alex Amadori Date: Sat, 18 Feb 2017 15:11:40 +0100 Subject: [PATCH] Implemented sorting in TestCasePlaySong --- .../Tests/TestCasePlaySongSelect.cs | 25 ++++++++++++++++--- osu.Game/Screens/Select/CarouselContainer.cs | 7 +++--- osu.Game/Screens/Select/FilterControl.cs | 10 +++++++- osu.Game/Screens/Select/PlaySongSelect.cs | 6 ++++- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs b/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs index 47fac4d339..009d7b8830 100644 --- a/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs +++ b/osu.Desktop.VisualTests/Tests/TestCasePlaySongSelect.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // 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.GameModes.Testing; @@ -14,10 +15,17 @@ namespace osu.Desktop.VisualTests.Tests { private BeatmapDatabase db, oldDb; private TestStorage storage; + private Random rnd = new Random(); + private PlaySongSelect SongSelect = new PlaySongSelect(); public override string Name => @"Song Select"; public override string Description => @"with fake data"; + public Action OnArtist; + public Action OnTitle; + public Action OnAuthor; + public Action OnDifficulty; + public override void Reset() { base.Reset(); @@ -35,6 +43,16 @@ namespace osu.Desktop.VisualTests.Tests db.Import(sets); } + OnArtist = () => SongSelect.Filter.Sort = FilterControl.SortMode.Artist; + OnTitle = () => SongSelect.Filter.Sort = FilterControl.SortMode.Title; + OnAuthor = () => SongSelect.Filter.Sort = FilterControl.SortMode.Author; + OnDifficulty = () => SongSelect.Filter.Sort = FilterControl.SortMode.Difficulty; + + AddButton(@"Sort by Artist", OnArtist); + AddButton(@"Sort by Artist", OnTitle); + AddButton(@"Sort by Artist", OnAuthor); + AddButton(@"Sort by Artist", OnDifficulty); + Add(new PlaySongSelect()); } @@ -59,9 +77,10 @@ namespace osu.Desktop.VisualTests.Tests 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 " + rnd.Next(0, 9), + Title = "Black Song " + rnd.Next(0, 9), + Author = "Some Guy " + rnd.Next(0, 9), }, Beatmaps = new List(new[] { diff --git a/osu.Game/Screens/Select/CarouselContainer.cs b/osu.Game/Screens/Select/CarouselContainer.cs index a121d4b3eb..8a346543ba 100644 --- a/osu.Game/Screens/Select/CarouselContainer.cs +++ b/osu.Game/Screens/Select/CarouselContainer.cs @@ -199,13 +199,12 @@ namespace osu.Game.Screens.Select case FilterControl.SortMode.Difficulty: groups.Sort((x, y) => { - // TODO: replace with star rating once implemented + /*TODO: replace with star rating once implemented + * Assumes BeatmapSets not to be grouped - or to be by difficulty, + * otherwise this sorting makes little sense - or does it? */ 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; }); diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index e4af7b8d02..c660ce48f0 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -21,7 +21,15 @@ namespace osu.Game.Screens.Select 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 { + sort = value; + FilterChanged?.Invoke(); + } + } + public Action Exit; private SearchTextBox searchTextBox; diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index edd3880a36..82a93c70d2 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -54,8 +54,12 @@ namespace osu.Game.Screens.Select private Footer footer; + private FilterControl filter; + public FilterControl Filter { + get; private set; + } + Player player; - FilterControl filter; private void start() {