From 7349c023d1b9696559d5190469024544d064204a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 14 Jan 2020 14:01:51 +0900 Subject: [PATCH] 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 @@ namespace osu.Game.Tests.Visual.Online }; 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 @@ namespace osu.Game.Online.API.Requests.Responses 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 osu.Game.Online.API.Requests.Responses; 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 @@ namespace osu.Game.Overlays.Rankings Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.X, - Current = SelectedSpotlight, + Current = Current, Depth = -float.MaxValue }, new FillFlowContainer @@ -84,12 +91,19 @@ namespace osu.Game.Overlays.Rankings 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");