mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 22:34:09 +08:00
Refactor SearchBeatmapSetsRequest
This commit is contained in:
parent
58903759f1
commit
20b49bea4b
@ -12,24 +12,31 @@ namespace osu.Game.Online.API.Requests
|
|||||||
{
|
{
|
||||||
public class SearchBeatmapSetsRequest : APIRequest<SearchBeatmapSetsResponse>
|
public class SearchBeatmapSetsRequest : APIRequest<SearchBeatmapSetsResponse>
|
||||||
{
|
{
|
||||||
|
public BeatmapSearchCategory SearchCategory { get; set; }
|
||||||
|
|
||||||
|
public DirectSortCriteria SortCriteria { get; set; }
|
||||||
|
|
||||||
|
public SortDirection SortDirection { get; set; }
|
||||||
|
|
||||||
|
public BeatmapSearchGenre Genre { get; set; }
|
||||||
|
|
||||||
|
public BeatmapSearchLanguage Language { get; set; }
|
||||||
|
|
||||||
private readonly string query;
|
private readonly string query;
|
||||||
private readonly RulesetInfo ruleset;
|
private readonly RulesetInfo ruleset;
|
||||||
private readonly BeatmapSearchCategory searchCategory;
|
|
||||||
private readonly DirectSortCriteria sortCriteria;
|
|
||||||
private readonly SortDirection direction;
|
|
||||||
private readonly BeatmapSearchGenre genre;
|
|
||||||
private readonly BeatmapSearchLanguage language;
|
|
||||||
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, BeatmapSearchLanguage language = BeatmapSearchLanguage.Any)
|
private string directionString => SortDirection == SortDirection.Descending ? @"desc" : @"asc";
|
||||||
|
|
||||||
|
public SearchBeatmapSetsRequest(string query, RulesetInfo ruleset)
|
||||||
{
|
{
|
||||||
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;
|
||||||
this.searchCategory = searchCategory;
|
|
||||||
this.sortCriteria = sortCriteria;
|
SearchCategory = BeatmapSearchCategory.Any;
|
||||||
this.direction = direction;
|
SortCriteria = DirectSortCriteria.Ranked;
|
||||||
this.genre = genre;
|
SortDirection = SortDirection.Descending;
|
||||||
this.language = language;
|
Genre = BeatmapSearchGenre.Any;
|
||||||
|
Language = BeatmapSearchLanguage.Any;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override WebRequest CreateWebRequest()
|
protected override WebRequest CreateWebRequest()
|
||||||
@ -40,15 +47,15 @@ namespace osu.Game.Online.API.Requests
|
|||||||
if (ruleset.ID.HasValue)
|
if (ruleset.ID.HasValue)
|
||||||
req.AddParameter("m", ruleset.ID.Value.ToString());
|
req.AddParameter("m", ruleset.ID.Value.ToString());
|
||||||
|
|
||||||
req.AddParameter("s", searchCategory.ToString().ToLowerInvariant());
|
req.AddParameter("s", SearchCategory.ToString().ToLowerInvariant());
|
||||||
|
|
||||||
if (genre != BeatmapSearchGenre.Any)
|
if (Genre != BeatmapSearchGenre.Any)
|
||||||
req.AddParameter("g", ((int)genre).ToString());
|
req.AddParameter("g", ((int)Genre).ToString());
|
||||||
|
|
||||||
if (language != BeatmapSearchLanguage.Any)
|
if (Language != BeatmapSearchLanguage.Any)
|
||||||
req.AddParameter("l", ((int)language).ToString());
|
req.AddParameter("l", ((int)Language).ToString());
|
||||||
|
|
||||||
req.AddParameter("sort", $"{sortCriteria.ToString().ToLowerInvariant()}_{directionString}");
|
req.AddParameter("sort", $"{SortCriteria.ToString().ToLowerInvariant()}_{directionString}");
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
@ -233,14 +233,14 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
currentContent?.FadeColour(Color4.DimGray, 400, Easing.OutQuint);
|
currentContent?.FadeColour(Color4.DimGray, 400, Easing.OutQuint);
|
||||||
|
|
||||||
getSetsRequest = new SearchBeatmapSetsRequest(
|
getSetsRequest = new SearchBeatmapSetsRequest(searchSection.Query.Value, searchSection.Ruleset.Value)
|
||||||
searchSection.Query.Value,
|
{
|
||||||
searchSection.Ruleset.Value,
|
SearchCategory = searchSection.Category.Value,
|
||||||
searchSection.Category.Value,
|
SortCriteria = sortControl.Current.Value,
|
||||||
sortControl.Current.Value,
|
SortDirection = sortControl.SortDirection.Value,
|
||||||
sortControl.SortDirection.Value,
|
Genre = searchSection.Genre.Value,
|
||||||
searchSection.Genre.Value,
|
Language = searchSection.Language.Value,
|
||||||
searchSection.Language.Value);
|
};
|
||||||
|
|
||||||
getSetsRequest.Success += response => Schedule(() => recreatePanels(response));
|
getSetsRequest.Success += response => Schedule(() => recreatePanels(response));
|
||||||
|
|
||||||
|
@ -254,11 +254,11 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
previewTrackManager.StopAnyPlaying(this);
|
previewTrackManager.StopAnyPlaying(this);
|
||||||
|
|
||||||
getSetsRequest = new SearchBeatmapSetsRequest(
|
getSetsRequest = new SearchBeatmapSetsRequest(currentQuery.Value, ((FilterControl)Filter).Ruleset.Value)
|
||||||
currentQuery.Value,
|
{
|
||||||
((FilterControl)Filter).Ruleset.Value,
|
SearchCategory = Filter.DisplayStyleControl.Dropdown.Current.Value,
|
||||||
Filter.DisplayStyleControl.Dropdown.Current.Value,
|
SortCriteria = Filter.Tabs.Current.Value
|
||||||
Filter.Tabs.Current.Value); //todo: sort direction (?)
|
};
|
||||||
|
|
||||||
getSetsRequest.Success += response =>
|
getSetsRequest.Success += response =>
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user