1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 00:02:54 +08:00

Implement Genre filter

This commit is contained in:
Andrei Zavatski 2020-02-20 17:40:45 +03:00
parent 5a0b93bdb2
commit 6b2ae67eaf
4 changed files with 53 additions and 2 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using osu.Game.Overlays;
using NUnit.Framework;
using osu.Game.Online.API.Requests;
namespace osu.Game.Tests.Visual.Online
{
@ -30,6 +31,12 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Show Rem tag", () => overlay.ShowTag("Rem"));
}
[Test]
public void TestShowGenre()
{
AddStep("Show Anime genre", () => overlay.ShowGenre(BeatmapSearchGenre.Anime));
}
[Test]
public void TestShow()
{

View File

@ -16,15 +16,17 @@ namespace osu.Game.Online.API.Requests
private readonly BeatmapSearchCategory searchCategory;
private readonly DirectSortCriteria sortCriteria;
private readonly SortDirection direction;
private readonly BeatmapSearchGenre genre;
private string directionString => direction == SortDirection.Descending ? @"desc" : @"asc";
public SearchBeatmapSetsRequest(string query, RulesetInfo ruleset, BeatmapSearchCategory searchCategory = BeatmapSearchCategory.Any, DirectSortCriteria sortCriteria = DirectSortCriteria.Ranked, SortDirection direction = SortDirection.Descending)
public SearchBeatmapSetsRequest(string query, RulesetInfo ruleset, BeatmapSearchCategory searchCategory = BeatmapSearchCategory.Any, DirectSortCriteria sortCriteria = DirectSortCriteria.Ranked, SortDirection direction = SortDirection.Descending, BeatmapSearchGenre genre = BeatmapSearchGenre.Any)
{
this.query = string.IsNullOrEmpty(query) ? string.Empty : System.Uri.EscapeDataString(query);
this.ruleset = ruleset;
this.searchCategory = searchCategory;
this.sortCriteria = sortCriteria;
this.direction = direction;
this.genre = genre;
}
protected override WebRequest CreateWebRequest()
@ -36,6 +38,10 @@ namespace osu.Game.Online.API.Requests
req.AddParameter("m", ruleset.ID.Value.ToString());
req.AddParameter("s", searchCategory.ToString().ToLowerInvariant());
if (genre != BeatmapSearchGenre.Any)
req.AddParameter("g", ((int)genre).ToString());
req.AddParameter("sort", $"{sortCriteria.ToString().ToLowerInvariant()}_{directionString}");
return req;
@ -62,4 +68,22 @@ namespace osu.Game.Online.API.Requests
[Description("My Maps")]
Mine,
}
public enum BeatmapSearchGenre
{
Any,
Unspecified,
[Description("Video Game")]
Game,
Anime,
Rock,
Pop,
Other,
Novelty,
[Description("Hip Hop")]
Hiphop = 9,
Electronic
}
}

View File

@ -25,6 +25,8 @@ namespace osu.Game.Overlays.BeatmapListing
public Bindable<BeatmapSearchCategory> Category => categoryFilter.Current;
public Bindable<BeatmapSearchGenre> Genre => genreFilter.Current;
public BeatmapSetInfo BeatmapSet
{
set
@ -43,6 +45,7 @@ namespace osu.Game.Overlays.BeatmapListing
private readonly BeatmapSearchTextBox textBox;
private readonly BeatmapSearchRulesetFilterRow modeFilter;
private readonly BeatmapSearchFilterRow<BeatmapSearchCategory> categoryFilter;
private readonly BeatmapSearchSmallFilterRow<BeatmapSearchGenre> genreFilter;
private readonly Box background;
private readonly UpdateableBeatmapSetCover beatmapCover;
@ -98,6 +101,7 @@ namespace osu.Game.Overlays.BeatmapListing
{
modeFilter = new BeatmapSearchRulesetFilterRow(),
categoryFilter = new BeatmapSearchFilterRow<BeatmapSearchCategory>(@"Categories"),
genreFilter = new BeatmapSearchSmallFilterRow<BeatmapSearchGenre>(@"Genre"),
}
}
}

View File

@ -154,6 +154,7 @@ namespace osu.Game.Overlays
searchSection.Ruleset.BindValueChanged(_ => queueUpdateSearch());
searchSection.Category.BindValueChanged(_ => queueUpdateSearch());
searchSection.Genre.BindValueChanged(_ => queueUpdateSearch());
sortCriteria.BindValueChanged(_ => queueUpdateSearch());
sortDirection.BindValueChanged(_ => queueUpdateSearch());
}
@ -171,11 +172,25 @@ namespace osu.Game.Overlays
Show();
}
public void ShowGenre(BeatmapSearchGenre genre)
{
var currentGenre = searchSection.Genre.Value;
if (currentGenre != genre)
{
setDefaultSearchValues();
searchSection.Genre.Value = genre;
}
Show();
}
private void setDefaultSearchValues()
{
searchSection.Query.Value = string.Empty;
searchSection.Ruleset.Value = new RulesetInfo { Name = @"Any" };
searchSection.Category.Value = BeatmapSearchCategory.Leaderboard;
searchSection.Genre.Value = BeatmapSearchGenre.Any;
}
private ScheduledDelegate queryChangedDebounce;
@ -208,7 +223,8 @@ namespace osu.Game.Overlays
searchSection.Ruleset.Value,
searchSection.Category.Value,
sortControl.Current.Value,
sortControl.SortDirection.Value);
sortControl.SortDirection.Value,
searchSection.Genre.Value);
getSetsRequest.Success += response => Schedule(() => recreatePanels(response));