1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 18:12:56 +08:00

Implement Language filter

This commit is contained in:
Andrei Zavatski 2020-02-20 17:56:49 +03:00
parent 6b2ae67eaf
commit 063a53017e
4 changed files with 49 additions and 2 deletions

View File

@ -37,6 +37,12 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Show Anime genre", () => overlay.ShowGenre(BeatmapSearchGenre.Anime)); AddStep("Show Anime genre", () => overlay.ShowGenre(BeatmapSearchGenre.Anime));
} }
[Test]
public void TestShowLanguage()
{
AddStep("Show Japanese language", () => overlay.ShowLanguage(BeatmapSearchLanguage.Japanese));
}
[Test] [Test]
public void TestShow() public void TestShow()
{ {

View File

@ -17,9 +17,10 @@ namespace osu.Game.Online.API.Requests
private readonly DirectSortCriteria sortCriteria; private readonly DirectSortCriteria sortCriteria;
private readonly SortDirection direction; private readonly SortDirection direction;
private readonly BeatmapSearchGenre genre; private readonly BeatmapSearchGenre genre;
private readonly BeatmapSearchLanguage language;
private string directionString => direction == SortDirection.Descending ? @"desc" : @"asc"; 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, BeatmapSearchGenre genre = BeatmapSearchGenre.Any) public SearchBeatmapSetsRequest(string query, RulesetInfo ruleset, BeatmapSearchCategory searchCategory = BeatmapSearchCategory.Any, DirectSortCriteria sortCriteria = DirectSortCriteria.Ranked, SortDirection direction = SortDirection.Descending, BeatmapSearchGenre genre = BeatmapSearchGenre.Any, BeatmapSearchLanguage language = BeatmapSearchLanguage.Any)
{ {
this.query = string.IsNullOrEmpty(query) ? string.Empty : System.Uri.EscapeDataString(query); this.query = string.IsNullOrEmpty(query) ? string.Empty : System.Uri.EscapeDataString(query);
this.ruleset = ruleset; this.ruleset = ruleset;
@ -27,6 +28,7 @@ namespace osu.Game.Online.API.Requests
this.sortCriteria = sortCriteria; this.sortCriteria = sortCriteria;
this.direction = direction; this.direction = direction;
this.genre = genre; this.genre = genre;
this.language = language;
} }
protected override WebRequest CreateWebRequest() protected override WebRequest CreateWebRequest()
@ -42,6 +44,9 @@ namespace osu.Game.Online.API.Requests
if (genre != BeatmapSearchGenre.Any) if (genre != BeatmapSearchGenre.Any)
req.AddParameter("g", ((int)genre).ToString()); req.AddParameter("g", ((int)genre).ToString());
if (language != BeatmapSearchLanguage.Any)
req.AddParameter("l", ((int)language).ToString());
req.AddParameter("sort", $"{sortCriteria.ToString().ToLowerInvariant()}_{directionString}"); req.AddParameter("sort", $"{sortCriteria.ToString().ToLowerInvariant()}_{directionString}");
return req; return req;
@ -86,4 +91,20 @@ namespace osu.Game.Online.API.Requests
Hiphop = 9, Hiphop = 9,
Electronic Electronic
} }
public enum BeatmapSearchLanguage
{
Any,
English = 2,
Chilnese = 4,
French = 7,
German,
Italian = 11,
Japanese = 3,
Korean = 6,
Spanish = 10,
Swedish = 9,
Instrumantal = 5,
Other = 1
}
} }

View File

@ -27,6 +27,8 @@ namespace osu.Game.Overlays.BeatmapListing
public Bindable<BeatmapSearchGenre> Genre => genreFilter.Current; public Bindable<BeatmapSearchGenre> Genre => genreFilter.Current;
public Bindable<BeatmapSearchLanguage> Language => languageFilter.Current;
public BeatmapSetInfo BeatmapSet public BeatmapSetInfo BeatmapSet
{ {
set set
@ -46,6 +48,7 @@ namespace osu.Game.Overlays.BeatmapListing
private readonly BeatmapSearchRulesetFilterRow modeFilter; private readonly BeatmapSearchRulesetFilterRow modeFilter;
private readonly BeatmapSearchFilterRow<BeatmapSearchCategory> categoryFilter; private readonly BeatmapSearchFilterRow<BeatmapSearchCategory> categoryFilter;
private readonly BeatmapSearchSmallFilterRow<BeatmapSearchGenre> genreFilter; private readonly BeatmapSearchSmallFilterRow<BeatmapSearchGenre> genreFilter;
private readonly BeatmapSearchSmallFilterRow<BeatmapSearchLanguage> languageFilter;
private readonly Box background; private readonly Box background;
private readonly UpdateableBeatmapSetCover beatmapCover; private readonly UpdateableBeatmapSetCover beatmapCover;
@ -102,6 +105,7 @@ namespace osu.Game.Overlays.BeatmapListing
modeFilter = new BeatmapSearchRulesetFilterRow(), modeFilter = new BeatmapSearchRulesetFilterRow(),
categoryFilter = new BeatmapSearchFilterRow<BeatmapSearchCategory>(@"Categories"), categoryFilter = new BeatmapSearchFilterRow<BeatmapSearchCategory>(@"Categories"),
genreFilter = new BeatmapSearchSmallFilterRow<BeatmapSearchGenre>(@"Genre"), genreFilter = new BeatmapSearchSmallFilterRow<BeatmapSearchGenre>(@"Genre"),
languageFilter = new BeatmapSearchSmallFilterRow<BeatmapSearchLanguage>(@"Language"),
} }
} }
} }

View File

@ -155,6 +155,7 @@ namespace osu.Game.Overlays
searchSection.Ruleset.BindValueChanged(_ => queueUpdateSearch()); searchSection.Ruleset.BindValueChanged(_ => queueUpdateSearch());
searchSection.Category.BindValueChanged(_ => queueUpdateSearch()); searchSection.Category.BindValueChanged(_ => queueUpdateSearch());
searchSection.Genre.BindValueChanged(_ => queueUpdateSearch()); searchSection.Genre.BindValueChanged(_ => queueUpdateSearch());
searchSection.Language.BindValueChanged(_ => queueUpdateSearch());
sortCriteria.BindValueChanged(_ => queueUpdateSearch()); sortCriteria.BindValueChanged(_ => queueUpdateSearch());
sortDirection.BindValueChanged(_ => queueUpdateSearch()); sortDirection.BindValueChanged(_ => queueUpdateSearch());
} }
@ -185,12 +186,26 @@ namespace osu.Game.Overlays
Show(); Show();
} }
public void ShowLanguage(BeatmapSearchLanguage language)
{
var currentLanguage = searchSection.Language.Value;
if (currentLanguage != language)
{
setDefaultSearchValues();
searchSection.Language.Value = language;
}
Show();
}
private void setDefaultSearchValues() private void setDefaultSearchValues()
{ {
searchSection.Query.Value = string.Empty; searchSection.Query.Value = string.Empty;
searchSection.Ruleset.Value = new RulesetInfo { Name = @"Any" }; searchSection.Ruleset.Value = new RulesetInfo { Name = @"Any" };
searchSection.Category.Value = BeatmapSearchCategory.Leaderboard; searchSection.Category.Value = BeatmapSearchCategory.Leaderboard;
searchSection.Genre.Value = BeatmapSearchGenre.Any; searchSection.Genre.Value = BeatmapSearchGenre.Any;
searchSection.Language.Value = BeatmapSearchLanguage.Any;
} }
private ScheduledDelegate queryChangedDebounce; private ScheduledDelegate queryChangedDebounce;
@ -224,7 +239,8 @@ namespace osu.Game.Overlays
searchSection.Category.Value, searchSection.Category.Value,
sortControl.Current.Value, sortControl.Current.Value,
sortControl.SortDirection.Value, sortControl.SortDirection.Value,
searchSection.Genre.Value); searchSection.Genre.Value,
searchSection.Language.Value);
getSetsRequest.Success += response => Schedule(() => recreatePanels(response)); getSetsRequest.Success += response => Schedule(() => recreatePanels(response));