From f65f030e79ff6756fe11156311e1bceaf95720f0 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 10 Jan 2020 15:48:54 +0300 Subject: [PATCH 01/14] Implement GetSpotlightsRequest --- .../API/Requests/GetSpotlightsRequest.cs | 13 +++++++ .../API/Requests/Responses/APISpotlight.cs | 34 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 osu.Game/Online/API/Requests/GetSpotlightsRequest.cs create mode 100644 osu.Game/Online/API/Requests/Responses/APISpotlight.cs diff --git a/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs b/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs new file mode 100644 index 0000000000..7a6a988c09 --- /dev/null +++ b/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs @@ -0,0 +1,13 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Online.API.Requests +{ + public class GetSpotlightsRequest : APIRequest> + { + protected override string Target => "spotlights"; + } +} diff --git a/osu.Game/Online/API/Requests/Responses/APISpotlight.cs b/osu.Game/Online/API/Requests/Responses/APISpotlight.cs new file mode 100644 index 0000000000..210ef04dac --- /dev/null +++ b/osu.Game/Online/API/Requests/Responses/APISpotlight.cs @@ -0,0 +1,34 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using Newtonsoft.Json; + +namespace osu.Game.Online.API.Requests.Responses +{ + public class APISpotlight + { + [JsonProperty("id")] + public int Id; + + [JsonProperty("name")] + public string Name; + + [JsonProperty("type")] + public string Type; + + [JsonProperty("mode_specific")] + public bool ModeSpecific; + + [JsonProperty(@"start_date")] + public DateTimeOffset StartDate; + + [JsonProperty(@"end_date")] + public DateTimeOffset EndDate; + + [JsonProperty(@"participant_count")] + public int? ParticipiantCount; + + public override string ToString() => Name; + } +} From 08fb68ddfeddb891b2ddc9972544a0bf6f2bff68 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 10 Jan 2020 16:28:52 +0300 Subject: [PATCH 02/14] Fix incorrect return type for spotlight request --- osu.Game/Online/API/Requests/GetSpotlightsRequest.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs b/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs index 7a6a988c09..d5b03e52e2 100644 --- a/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs +++ b/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs @@ -2,12 +2,19 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; +using Newtonsoft.Json; using osu.Game.Online.API.Requests.Responses; namespace osu.Game.Online.API.Requests { - public class GetSpotlightsRequest : APIRequest> + public class GetSpotlightsRequest : APIRequest { protected override string Target => "spotlights"; } + + public class SpotlightsArray + { + [JsonProperty("spotlights")] + public List Spotlights; + } } From d48b161662ec0058d8f1aed526bb5fa1d9d1af50 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 10 Jan 2020 16:33:00 +0300 Subject: [PATCH 03/14] Implement basic SpotlightSelector component --- .../TestSceneRankingsSpotlightSelector.cs | 28 ++++++++ .../Overlays/Rankings/SpotlightSelector.cs | 67 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs create mode 100644 osu.Game/Overlays/Rankings/SpotlightSelector.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs new file mode 100644 index 0000000000..9320213844 --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs @@ -0,0 +1,28 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Game.Overlays.Rankings; + +namespace osu.Game.Tests.Visual.Online +{ + public class TestSceneRankingsSpotlightSelector : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(SpotlightSelector), + }; + + protected override bool UseOnlineAPI => true; + + public TestSceneRankingsSpotlightSelector() + { + SpotlightSelector selector; + + Add(selector = new SpotlightSelector()); + + AddStep("Fetch spotlights", selector.FetchSpotlights); + } + } +} diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs new file mode 100644 index 0000000000..95bcc10631 --- /dev/null +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -0,0 +1,67 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Overlays.Rankings +{ + public class SpotlightSelector : Container + { + private readonly Box background; + private readonly OsuDropdown dropdown; + private readonly DimmedLoadingLayer loading; + + [Resolved] + private IAPIProvider api { get; set; } + + public SpotlightSelector() + { + RelativeSizeAxes = Axes.X; + Height = 200; + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both, + }, + dropdown = new OsuDropdown + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.X, + Width = 0.8f, + Margin = new MarginPadding { Top = 10 } + }, + loading = new DimmedLoadingLayer(), + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + background.Colour = colours.GreySeafoam; + dropdown.AccentColour = colours.GreySeafoamDarker; + } + + public void FetchSpotlights() + { + loading.Show(); + + var request = new GetSpotlightsRequest(); + request.Success += response => + { + dropdown.Items = response.Spotlights; + loading.Hide(); + }; + api.Queue(request); + } + } +} From 474d7e92d92ef7a20dc07ee4a75cb2e62b5bd2e2 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 10 Jan 2020 16:41:17 +0300 Subject: [PATCH 04/14] Fix incorrect dropdown menu height --- osu.Game/Overlays/Rankings/SpotlightSelector.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index 95bcc10631..482db10796 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -16,7 +16,7 @@ namespace osu.Game.Overlays.Rankings public class SpotlightSelector : Container { private readonly Box background; - private readonly OsuDropdown dropdown; + private readonly SpotlightsDropdown dropdown; private readonly DimmedLoadingLayer loading; [Resolved] @@ -32,7 +32,7 @@ public SpotlightSelector() { RelativeSizeAxes = Axes.Both, }, - dropdown = new OsuDropdown + dropdown = new SpotlightsDropdown { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, @@ -63,5 +63,10 @@ public void FetchSpotlights() }; api.Queue(request); } + + private class SpotlightsDropdown : OsuDropdown + { + protected override DropdownMenu CreateMenu() => base.CreateMenu().With(menu => menu.MaxHeight = 400); + } } } From 2e627f4b7c4f52d827941399cf67fce87087ebc3 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 10 Jan 2020 17:30:51 +0300 Subject: [PATCH 05/14] Implement InfoColumn component --- .../Overlays/Rankings/SpotlightSelector.cs | 111 ++++++++++++++++-- 1 file changed, 102 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index 482db10796..66c5f37917 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -2,14 +2,18 @@ // See the LICENCE file in the repository root for full licence text. using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; +using osuTK; +using System; namespace osu.Game.Overlays.Rankings { @@ -22,23 +26,49 @@ public class SpotlightSelector : Container [Resolved] private IAPIProvider api { get; set; } + public readonly Bindable SelectedSpotlight = new Bindable(); + + private readonly InfoCoulmn startDateColumn; + private readonly InfoCoulmn endDateColumn; + public SpotlightSelector() { RelativeSizeAxes = Axes.X; - Height = 200; + Height = 100; Children = new Drawable[] { background = new Box { RelativeSizeAxes = Axes.Both, }, - dropdown = new SpotlightsDropdown + new Container { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - RelativeSizeAxes = Axes.X, - Width = 0.8f, - Margin = new MarginPadding { Top = 10 } + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding { Horizontal = UserProfileOverlay.CONTENT_X_MARGIN, Vertical = 10 }, + Children = new Drawable[] + { + dropdown = new SpotlightsDropdown + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + RelativeSizeAxes = Axes.X, + Current = SelectedSpotlight, + Depth = -float.MaxValue + }, + new FillFlowContainer + { + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(15, 0), + Children = new Drawable[] + { + startDateColumn = new InfoCoulmn(@"Start Date"), + endDateColumn = new InfoCoulmn(@"End Date"), + } + } + } }, loading = new DimmedLoadingLayer(), }; @@ -48,7 +78,12 @@ public SpotlightSelector() private void load(OsuColour colours) { background.Colour = colours.GreySeafoam; - dropdown.AccentColour = colours.GreySeafoamDarker; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + SelectedSpotlight.BindValueChanged(onSelectionChanged); } public void FetchSpotlights() @@ -64,9 +99,67 @@ public void FetchSpotlights() api.Queue(request); } + private void onSelectionChanged(ValueChangedEvent spotlight) + { + startDateColumn.Value = dateToString(spotlight.NewValue.StartDate); + endDateColumn.Value = dateToString(spotlight.NewValue.EndDate); + } + + private string dateToString(DateTimeOffset date) => $"{date.Year}-{date.Month:D2}-{date.Day:D2}"; + + private class InfoCoulmn : FillFlowContainer + { + public string Value + { + set => valueText.Text = value; + } + + private readonly OsuSpriteText valueText; + + public InfoCoulmn(string name) + { + AutoSizeAxes = Axes.Both; + Direction = FillDirection.Vertical; + Children = new Drawable[] + { + new OsuSpriteText + { + Text = name, + Font = OsuFont.GetFont(size: 10), + }, + new Container + { + AutoSizeAxes = Axes.X, + Height = 20, + Child = valueText = new OsuSpriteText + { + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Font = OsuFont.GetFont(size: 18, weight: FontWeight.Light), + } + } + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + valueText.Colour = colours.GreySeafoamLighter; + } + } + private class SpotlightsDropdown : OsuDropdown { - protected override DropdownMenu CreateMenu() => base.CreateMenu().With(menu => menu.MaxHeight = 400); + private DropdownMenu menu; + + protected override DropdownMenu CreateMenu() => menu = base.CreateMenu().With(m => m.MaxHeight = 400); + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + menu.BackgroundColour = colours.Gray1; + AccentColour = colours.GreySeafoamDarker; + } } } } From 9260ea91955fdcf56e4edbbb3770e39ac0eb21a0 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Fri, 10 Jan 2020 20:46:35 +0300 Subject: [PATCH 06/14] Apply suggestions --- .../Online/API/Requests/GetSpotlightsRequest.cs | 4 ++-- .../Online/API/Requests/Responses/APISpotlight.cs | 2 +- osu.Game/Overlays/Rankings/SpotlightSelector.cs | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs b/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs index d5b03e52e2..6fafb3933c 100644 --- a/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs +++ b/osu.Game/Online/API/Requests/GetSpotlightsRequest.cs @@ -7,12 +7,12 @@ namespace osu.Game.Online.API.Requests { - public class GetSpotlightsRequest : APIRequest + public class GetSpotlightsRequest : APIRequest { protected override string Target => "spotlights"; } - public class SpotlightsArray + public class SpotlightsCollection { [JsonProperty("spotlights")] public List Spotlights; diff --git a/osu.Game/Online/API/Requests/Responses/APISpotlight.cs b/osu.Game/Online/API/Requests/Responses/APISpotlight.cs index 210ef04dac..63c47e7812 100644 --- a/osu.Game/Online/API/Requests/Responses/APISpotlight.cs +++ b/osu.Game/Online/API/Requests/Responses/APISpotlight.cs @@ -27,7 +27,7 @@ public class APISpotlight public DateTimeOffset EndDate; [JsonProperty(@"participant_count")] - public int? ParticipiantCount; + public int? ParticipantCount; public override string ToString() => Name; } diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index 66c5f37917..fb61555c20 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -28,8 +28,8 @@ public class SpotlightSelector : Container public readonly Bindable SelectedSpotlight = new Bindable(); - private readonly InfoCoulmn startDateColumn; - private readonly InfoCoulmn endDateColumn; + private readonly InfoColumn startDateColumn; + private readonly InfoColumn endDateColumn; public SpotlightSelector() { @@ -64,8 +64,8 @@ public SpotlightSelector() Spacing = new Vector2(15, 0), Children = new Drawable[] { - startDateColumn = new InfoCoulmn(@"Start Date"), - endDateColumn = new InfoCoulmn(@"End Date"), + startDateColumn = new InfoColumn(@"Start Date"), + endDateColumn = new InfoColumn(@"End Date"), } } } @@ -105,9 +105,9 @@ private void onSelectionChanged(ValueChangedEvent spotlight) endDateColumn.Value = dateToString(spotlight.NewValue.EndDate); } - private string dateToString(DateTimeOffset date) => $"{date.Year}-{date.Month:D2}-{date.Day:D2}"; + private string dateToString(DateTimeOffset date) => date.ToString("yyyy-MM-dd"); - private class InfoCoulmn : FillFlowContainer + private class InfoColumn : FillFlowContainer { public string Value { @@ -116,7 +116,7 @@ public string Value private readonly OsuSpriteText valueText; - public InfoCoulmn(string name) + public InfoColumn(string name) { AutoSizeAxes = Axes.Both; Direction = FillDirection.Vertical; From 90e4def4bd0d782f24b4d987639f33a1388fe621 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 14 Jan 2020 07:07:21 +0300 Subject: [PATCH 07/14] Remove online stuff out of the selector --- .../TestSceneRankingsSpotlightSelector.cs | 18 ++++++-- .../Overlays/Rankings/SpotlightSelector.cs | 45 +++++++------------ 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs index 9320213844..0862b3251a 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays.Rankings; namespace osu.Game.Tests.Visual.Online @@ -14,15 +15,26 @@ public class TestSceneRankingsSpotlightSelector : OsuTestScene typeof(SpotlightSelector), }; - protected override bool UseOnlineAPI => true; - public TestSceneRankingsSpotlightSelector() { SpotlightSelector selector; Add(selector = new SpotlightSelector()); - AddStep("Fetch spotlights", selector.FetchSpotlights); + var spotlights = new APISpotlight[] + { + new APISpotlight { Name = "Spotlight 1" }, + new APISpotlight { Name = "Spotlight 2" }, + new APISpotlight { Name = "Spotlight 3" }, + }; + + AddStep("Load spotlights", () => selector.Spotlights = spotlights); + AddStep("Load info", () => selector.UpdateInfo(new APISpotlight + { + StartDate = DateTimeOffset.Now, + EndDate = DateTimeOffset.Now, + ParticipantCount = 15155151, + }, 18)); } } } diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index fb61555c20..a275f4ed50 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -9,11 +9,10 @@ using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; -using osu.Game.Online.API; -using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; using osuTK; using System; +using System.Collections.Generic; namespace osu.Game.Overlays.Rankings { @@ -21,15 +20,19 @@ public class SpotlightSelector : Container { private readonly Box background; private readonly SpotlightsDropdown dropdown; - private readonly DimmedLoadingLayer loading; - - [Resolved] - private IAPIProvider api { get; set; } public readonly Bindable SelectedSpotlight = new Bindable(); + public IEnumerable Spotlights + { + get => dropdown.Items; + set => dropdown.Items = value; + } + private readonly InfoColumn startDateColumn; private readonly InfoColumn endDateColumn; + private readonly InfoColumn mapCountColumn; + private readonly InfoColumn participants; public SpotlightSelector() { @@ -66,11 +69,12 @@ public SpotlightSelector() { startDateColumn = new InfoColumn(@"Start Date"), endDateColumn = new InfoColumn(@"End Date"), + mapCountColumn = new InfoColumn(@"Map Count"), + participants = new InfoColumn(@"Participants"), } } } }, - loading = new DimmedLoadingLayer(), }; } @@ -80,29 +84,12 @@ private void load(OsuColour colours) background.Colour = colours.GreySeafoam; } - protected override void LoadComplete() + public void UpdateInfo(APISpotlight spotlight, int mapCount) { - base.LoadComplete(); - SelectedSpotlight.BindValueChanged(onSelectionChanged); - } - - public void FetchSpotlights() - { - loading.Show(); - - var request = new GetSpotlightsRequest(); - request.Success += response => - { - dropdown.Items = response.Spotlights; - loading.Hide(); - }; - api.Queue(request); - } - - private void onSelectionChanged(ValueChangedEvent spotlight) - { - startDateColumn.Value = dateToString(spotlight.NewValue.StartDate); - endDateColumn.Value = dateToString(spotlight.NewValue.EndDate); + startDateColumn.Value = dateToString(spotlight.StartDate); + endDateColumn.Value = dateToString(spotlight.EndDate); + mapCountColumn.Value = mapCount.ToString(); + participants.Value = spotlight.ParticipantCount?.ToString("N0"); } private string dateToString(DateTimeOffset date) => date.ToString("yyyy-MM-dd"); From 18ebd309788124c12ae3d5bf8388f97e4822939c Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 14 Jan 2020 07:20:03 +0300 Subject: [PATCH 08/14] CI fix --- .../Visual/Online/TestSceneRankingsSpotlightSelector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs index 0862b3251a..1a62cb6dad 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs @@ -21,7 +21,7 @@ public TestSceneRankingsSpotlightSelector() Add(selector = new SpotlightSelector()); - var spotlights = new APISpotlight[] + var spotlights = new[] { new APISpotlight { Name = "Spotlight 1" }, new APISpotlight { Name = "Spotlight 2" }, From 7349c023d1b9696559d5190469024544d064204a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 14 Jan 2020 14:01:51 +0900 Subject: [PATCH 09/14] Cleanup spotlight selection --- .../TestSceneRankingsSpotlightSelector.cs | 4 +-- .../API/Requests/Responses/APISpotlight.cs | 2 +- .../Overlays/Rankings/SpotlightSelector.cs | 30 ++++++++++++++----- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs index 1a62cb6dad..d714d5fb7d 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs @@ -29,12 +29,12 @@ public TestSceneRankingsSpotlightSelector() }; AddStep("Load spotlights", () => selector.Spotlights = spotlights); - AddStep("Load info", () => selector.UpdateInfo(new APISpotlight + AddStep("Load info", () => selector.Current.Value = new APISpotlight { StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now, ParticipantCount = 15155151, - }, 18)); + }); } } } diff --git a/osu.Game/Online/API/Requests/Responses/APISpotlight.cs b/osu.Game/Online/API/Requests/Responses/APISpotlight.cs index 63c47e7812..2191ed4743 100644 --- a/osu.Game/Online/API/Requests/Responses/APISpotlight.cs +++ b/osu.Game/Online/API/Requests/Responses/APISpotlight.cs @@ -27,7 +27,7 @@ public class APISpotlight public DateTimeOffset EndDate; [JsonProperty(@"participant_count")] - public int? ParticipantCount; + public int ParticipantCount; public override string ToString() => Name; } diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index a275f4ed50..def7469b16 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -13,15 +13,22 @@ using osuTK; using System; using System.Collections.Generic; +using osu.Framework.Graphics.UserInterface; namespace osu.Game.Overlays.Rankings { - public class SpotlightSelector : Container + public class SpotlightSelector : Container, IHasCurrentValue { private readonly Box background; private readonly SpotlightsDropdown dropdown; - public readonly Bindable SelectedSpotlight = new Bindable(); + private readonly BindableWithCurrent current = new BindableWithCurrent(); + + public Bindable Current + { + get => current.Current; + set => current.Current = value; + } public IEnumerable Spotlights { @@ -55,7 +62,7 @@ public SpotlightSelector() Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.X, - Current = SelectedSpotlight, + Current = Current, Depth = -float.MaxValue }, new FillFlowContainer @@ -84,12 +91,19 @@ private void load(OsuColour colours) background.Colour = colours.GreySeafoam; } - public void UpdateInfo(APISpotlight spotlight, int mapCount) + protected override void LoadComplete() { - startDateColumn.Value = dateToString(spotlight.StartDate); - endDateColumn.Value = dateToString(spotlight.EndDate); - mapCountColumn.Value = mapCount.ToString(); - participants.Value = spotlight.ParticipantCount?.ToString("N0"); + base.LoadComplete(); + + Current.BindValueChanged(onCurrentChanged); + } + + private void onCurrentChanged(ValueChangedEvent spotlight) + { + startDateColumn.Value = dateToString(spotlight.NewValue.StartDate); + endDateColumn.Value = dateToString(spotlight.NewValue.EndDate); + // mapCountColumn.Value = spotlight.NewValue.ParticipantCount.ToString(); + participants.Value = spotlight.NewValue.ParticipantCount.ToString(); } private string dateToString(DateTimeOffset date) => date.ToString("yyyy-MM-dd"); From cb1984a3c3f7b23b0c76465be334b89596edbd41 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 14 Jan 2020 14:37:14 +0900 Subject: [PATCH 10/14] Improve test scene data --- .../TestSceneRankingsSpotlightSelector.cs | 66 ++++++++++++++++--- 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs index d714d5fb7d..c3df1f055b 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs @@ -3,6 +3,10 @@ using System; using System.Collections.Generic; +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays.Rankings; @@ -15,25 +19,67 @@ public class TestSceneRankingsSpotlightSelector : OsuTestScene typeof(SpotlightSelector), }; + protected override bool UseOnlineAPI => true; + + [Resolved] + private IAPIProvider api { get; set; } + + private readonly SpotlightSelector selector; + public TestSceneRankingsSpotlightSelector() { - SpotlightSelector selector; - Add(selector = new SpotlightSelector()); + } + [Test] + public void TestLocalSpotlights() + { var spotlights = new[] { - new APISpotlight { Name = "Spotlight 1" }, - new APISpotlight { Name = "Spotlight 2" }, - new APISpotlight { Name = "Spotlight 3" }, + new APISpotlight + { + Name = "Spotlight 1", + StartDate = DateTimeOffset.Now, + EndDate = DateTimeOffset.Now, + ParticipantCount = 100 + }, + new APISpotlight + { + Name = "Spotlight 2", + StartDate = DateTimeOffset.Now, + EndDate = DateTimeOffset.Now, + ParticipantCount = 200 + }, + new APISpotlight + { + Name = "Spotlight 3", + StartDate = DateTimeOffset.Now, + EndDate = DateTimeOffset.Now, + ParticipantCount = 300 + }, }; - AddStep("Load spotlights", () => selector.Spotlights = spotlights); - AddStep("Load info", () => selector.Current.Value = new APISpotlight + AddStep("load spotlights", () => selector.Spotlights = spotlights); + AddStep("change to spotlight 3", () => selector.Current.Value = spotlights[2]); + } + + [Test] + public void TestOnlineSpotlights() + { + List spotlights = null; + + AddStep("retrieve spotlights", () => { - StartDate = DateTimeOffset.Now, - EndDate = DateTimeOffset.Now, - ParticipantCount = 15155151, + var req = new GetSpotlightsRequest(); + req.Success += res => spotlights = res.Spotlights; + + api.Perform(req); + }); + + AddStep("set spotlights", () => + { + if (spotlights != null) + selector.Spotlights = spotlights; }); } } From 05702af9054797578deebf03f3ab654d653035d4 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 14 Jan 2020 14:37:24 +0900 Subject: [PATCH 11/14] Remove map count (not returned by API) --- osu.Game/Overlays/Rankings/SpotlightSelector.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index def7469b16..d6efff626d 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -38,7 +38,6 @@ public IEnumerable Spotlights private readonly InfoColumn startDateColumn; private readonly InfoColumn endDateColumn; - private readonly InfoColumn mapCountColumn; private readonly InfoColumn participants; public SpotlightSelector() @@ -76,7 +75,6 @@ public SpotlightSelector() { startDateColumn = new InfoColumn(@"Start Date"), endDateColumn = new InfoColumn(@"End Date"), - mapCountColumn = new InfoColumn(@"Map Count"), participants = new InfoColumn(@"Participants"), } } @@ -102,7 +100,6 @@ private void onCurrentChanged(ValueChangedEvent spotlight) { startDateColumn.Value = dateToString(spotlight.NewValue.StartDate); endDateColumn.Value = dateToString(spotlight.NewValue.EndDate); - // mapCountColumn.Value = spotlight.NewValue.ParticipantCount.ToString(); participants.Value = spotlight.NewValue.ParticipantCount.ToString(); } From 33993837b7f175421c0b34cbdff0ac0e36d962d2 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 14 Jan 2020 14:41:38 +0900 Subject: [PATCH 12/14] Remove participant count (not returned by API) --- .../Visual/Online/TestSceneRankingsSpotlightSelector.cs | 3 --- osu.Game/Online/API/Requests/Responses/APISpotlight.cs | 3 --- osu.Game/Overlays/Rankings/SpotlightSelector.cs | 3 --- 3 files changed, 9 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs index c3df1f055b..009fe7cc8c 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs @@ -41,21 +41,18 @@ public void TestLocalSpotlights() Name = "Spotlight 1", StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now, - ParticipantCount = 100 }, new APISpotlight { Name = "Spotlight 2", StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now, - ParticipantCount = 200 }, new APISpotlight { Name = "Spotlight 3", StartDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now, - ParticipantCount = 300 }, }; diff --git a/osu.Game/Online/API/Requests/Responses/APISpotlight.cs b/osu.Game/Online/API/Requests/Responses/APISpotlight.cs index 2191ed4743..3a002e57b2 100644 --- a/osu.Game/Online/API/Requests/Responses/APISpotlight.cs +++ b/osu.Game/Online/API/Requests/Responses/APISpotlight.cs @@ -26,9 +26,6 @@ public class APISpotlight [JsonProperty(@"end_date")] public DateTimeOffset EndDate; - [JsonProperty(@"participant_count")] - public int ParticipantCount; - public override string ToString() => Name; } } diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index d6efff626d..c538a80786 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -38,7 +38,6 @@ public IEnumerable Spotlights private readonly InfoColumn startDateColumn; private readonly InfoColumn endDateColumn; - private readonly InfoColumn participants; public SpotlightSelector() { @@ -75,7 +74,6 @@ public SpotlightSelector() { startDateColumn = new InfoColumn(@"Start Date"), endDateColumn = new InfoColumn(@"End Date"), - participants = new InfoColumn(@"Participants"), } } } @@ -100,7 +98,6 @@ private void onCurrentChanged(ValueChangedEvent spotlight) { startDateColumn.Value = dateToString(spotlight.NewValue.StartDate); endDateColumn.Value = dateToString(spotlight.NewValue.EndDate); - participants.Value = spotlight.NewValue.ParticipantCount.ToString(); } private string dateToString(DateTimeOffset date) => date.ToString("yyyy-MM-dd"); From d6bd0b7106b215441348b1192979d9611677abf7 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 14 Jan 2020 14:43:57 +0900 Subject: [PATCH 13/14] Container -> CompositeDrawable --- osu.Game/Overlays/Rankings/SpotlightSelector.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index c538a80786..4da3daa62a 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -17,7 +17,7 @@ namespace osu.Game.Overlays.Rankings { - public class SpotlightSelector : Container, IHasCurrentValue + public class SpotlightSelector : CompositeDrawable, IHasCurrentValue { private readonly Box background; private readonly SpotlightsDropdown dropdown; @@ -43,7 +43,8 @@ public SpotlightSelector() { RelativeSizeAxes = Axes.X; Height = 100; - Children = new Drawable[] + + InternalChildren = new Drawable[] { background = new Box { From 12574111e5375b56ebfae7af839b38d55be427d6 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 3 Feb 2020 19:44:10 +0300 Subject: [PATCH 14/14] Use ColourProvider colours --- .../Online/TestSceneRankingsSpotlightSelector.cs | 4 ++++ osu.Game/Overlays/Rankings/SpotlightSelector.cs | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs index 009fe7cc8c..e46c8a4a71 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsSpotlightSelector.cs @@ -8,6 +8,7 @@ using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Overlays; using osu.Game.Overlays.Rankings; namespace osu.Game.Tests.Visual.Online @@ -21,6 +22,9 @@ public class TestSceneRankingsSpotlightSelector : OsuTestScene protected override bool UseOnlineAPI => true; + [Cached] + private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green); + [Resolved] private IAPIProvider api { get; set; } diff --git a/osu.Game/Overlays/Rankings/SpotlightSelector.cs b/osu.Game/Overlays/Rankings/SpotlightSelector.cs index 4da3daa62a..e34c01113e 100644 --- a/osu.Game/Overlays/Rankings/SpotlightSelector.cs +++ b/osu.Game/Overlays/Rankings/SpotlightSelector.cs @@ -83,9 +83,9 @@ public SpotlightSelector() } [BackgroundDependencyLoader] - private void load(OsuColour colours) + private void load(OverlayColourProvider colourProvider) { - background.Colour = colours.GreySeafoam; + background.Colour = colourProvider.Dark3; } protected override void LoadComplete() @@ -138,9 +138,9 @@ public InfoColumn(string name) } [BackgroundDependencyLoader] - private void load(OsuColour colours) + private void load(OverlayColourProvider colourProvider) { - valueText.Colour = colours.GreySeafoamLighter; + valueText.Colour = colourProvider.Content2; } } @@ -151,10 +151,10 @@ private class SpotlightsDropdown : OsuDropdown protected override DropdownMenu CreateMenu() => menu = base.CreateMenu().With(m => m.MaxHeight = 400); [BackgroundDependencyLoader] - private void load(OsuColour colours) + private void load(OverlayColourProvider colourProvider) { - menu.BackgroundColour = colours.Gray1; - AccentColour = colours.GreySeafoamDarker; + menu.BackgroundColour = colourProvider.Background5; + AccentColour = colourProvider.Background6; } } }