From f7f4f5e1552e2d52a88c5754685b6262e498a2a4 Mon Sep 17 00:00:00 2001 From: DrabWeb Date: Wed, 7 Jun 2017 10:40:18 -0300 Subject: [PATCH] Request sorting, fix VS Code's "refactoring" --- .../Online/API/Requests/GetBeatmapSetsRequest.cs | 13 +++++++++++-- osu.Game/Overlays/Direct/FilterControl.cs | 2 +- osu.Game/Overlays/DirectOverlay.cs | 11 ++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetBeatmapSetsRequest.cs b/osu.Game/Online/API/Requests/GetBeatmapSetsRequest.cs index ce5c9f0939..536da0cc1c 100644 --- a/osu.Game/Online/API/Requests/GetBeatmapSetsRequest.cs +++ b/osu.Game/Online/API/Requests/GetBeatmapSetsRequest.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using osu.Game.Database; +using osu.Game.Overlays; +using osu.Game.Overlays.Direct; namespace osu.Game.Online.API.Requests { @@ -12,14 +14,21 @@ namespace osu.Game.Online.API.Requests { private readonly string query; private readonly RankStatus rankStatus; + private readonly DirectSortCriteria sortCriteria; + private readonly SortDirection direction; + private string directionString => direction == SortDirection.Descending ? @"desc" : @"asc"; - public GetBeatmapSetsRequest(string query, RankStatus rankStatus = RankStatus.Any) + public GetBeatmapSetsRequest(string query, RankStatus rankStatus = RankStatus.Any, DirectSortCriteria sortCriteria = DirectSortCriteria.Ranked, SortDirection direction = SortDirection.Descending) { this.query = System.Uri.EscapeDataString(query); this.rankStatus = rankStatus; + this.sortCriteria = sortCriteria; + this.direction = direction; + + System.Console.WriteLine(Target); } - protected override string Target => $@"beatmapsets/search?q={query}&s={(int)rankStatus}"; + protected override string Target => $@"beatmapsets/search?q={query}&s={(int)rankStatus}&sort={sortCriteria.ToString().ToLower()}_{directionString}"; } public class GetBeatmapSetsResponse : BeatmapMetadata diff --git a/osu.Game/Overlays/Direct/FilterControl.cs b/osu.Game/Overlays/Direct/FilterControl.cs index ac9b7b1a1e..31727e2adc 100644 --- a/osu.Game/Overlays/Direct/FilterControl.cs +++ b/osu.Game/Overlays/Direct/FilterControl.cs @@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Direct private FillFlowContainer modeButtons; protected override Color4 BackgroundColour => OsuColour.FromHex(@"384552"); - protected override DirectSortCriteria DefaultTab => DirectSortCriteria.Title; + protected override DirectSortCriteria DefaultTab => DirectSortCriteria.Ranked; protected override Drawable CreateSupplementaryControls() { modeButtons = new FillFlowContainer diff --git a/osu.Game/Overlays/DirectOverlay.cs b/osu.Game/Overlays/DirectOverlay.cs index c7c8a1f0ed..c1ef6930b2 100644 --- a/osu.Game/Overlays/DirectOverlay.cs +++ b/osu.Game/Overlays/DirectOverlay.cs @@ -16,9 +16,9 @@ using osu.Game.Overlays.Direct; using osu.Game.Overlays.SearchableList; using OpenTK.Graphics; -namespace osu.Game.Overlaysi +namespace osu.Game.Overlays { - public class DirectOverlay : SearchableListOverlay + public class DirectOverlay : SearchableListOverlay { private const float panel_padding = 10f; @@ -29,12 +29,12 @@ namespace osu.Game.Overlaysi private readonly OsuSpriteText resultCountsText; private readonly FillFlowContainer panels; - protected override Color4 BackgroundColour => OsuColour.FromHexi(@"485e74"); + protected override Color4 BackgroundColour => OsuColour.FromHex(@"485e74"); protected override Color4 TrianglesColourLight => OsuColour.FromHex(@"465b71"); protected override Color4 TrianglesColourDark => OsuColour.FromHex(@"3f5265"); protected override SearchableListHeader CreateHeader() => new Header(); - protected override SearchableListFilterControl CreateFilterControl() => new FilterControl(); + protected override SearchableListFilterControl CreateFilterControl() => new FilterControl(); private IEnumerable beatmapSets; public IEnumerable BeatmapSets @@ -117,6 +117,7 @@ namespace osu.Game.Overlaysi Header.Tabs.Current.ValueChanged += tab => { if (tab != DirectTab.Search) Filter.Search.Text = string.Empty; }; Filter.Search.Current.ValueChanged += text => { if (text != string.Empty) Header.Tabs.Current.Value = DirectTab.Search; }; Filter.Search.OnCommit = (sender, text) => updateSets(); + Filter.Tabs.Current.ValueChanged += sortCriteria => updateSets(); Filter.DisplayStyleControl.DisplayStyle.ValueChanged += recreatePanels; Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += rankStatus => updateSets(); @@ -162,7 +163,7 @@ namespace osu.Game.Overlaysi if (api == null || Filter.Search.Text == string.Empty) return; - getSetsRequest = new GetBeatmapSetsRequest(Filter.Search.Text, Filter.DisplayStyleControl.Dropdown.Current.Value); + getSetsRequest = new GetBeatmapSetsRequest(Filter.Search.Text, Filter.DisplayStyleControl.Dropdown.Current.Value, Filter.Tabs.Current.Value); //todo: sort direction getSetsRequest.Success += r => BeatmapSets = r?.Select(response => response.ToSetInfo(rulesets)); api.Queue(getSetsRequest); }