1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Cleanup spotlight selection

This commit is contained in:
smoogipoo 2020-01-14 14:01:51 +09:00
parent 18ebd30978
commit 7349c023d1
3 changed files with 25 additions and 11 deletions

View File

@ -29,12 +29,12 @@ namespace osu.Game.Tests.Visual.Online
}; };
AddStep("Load spotlights", () => selector.Spotlights = spotlights); AddStep("Load spotlights", () => selector.Spotlights = spotlights);
AddStep("Load info", () => selector.UpdateInfo(new APISpotlight AddStep("Load info", () => selector.Current.Value = new APISpotlight
{ {
StartDate = DateTimeOffset.Now, StartDate = DateTimeOffset.Now,
EndDate = DateTimeOffset.Now, EndDate = DateTimeOffset.Now,
ParticipantCount = 15155151, ParticipantCount = 15155151,
}, 18)); });
} }
} }
} }

View File

@ -27,7 +27,7 @@ namespace osu.Game.Online.API.Requests.Responses
public DateTimeOffset EndDate; public DateTimeOffset EndDate;
[JsonProperty(@"participant_count")] [JsonProperty(@"participant_count")]
public int? ParticipantCount; public int ParticipantCount;
public override string ToString() => Name; public override string ToString() => Name;
} }

View File

@ -13,15 +13,22 @@ using osu.Game.Online.API.Requests.Responses;
using osuTK; using osuTK;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Overlays.Rankings namespace osu.Game.Overlays.Rankings
{ {
public class SpotlightSelector : Container public class SpotlightSelector : Container, IHasCurrentValue<APISpotlight>
{ {
private readonly Box background; private readonly Box background;
private readonly SpotlightsDropdown dropdown; private readonly SpotlightsDropdown dropdown;
public readonly Bindable<APISpotlight> SelectedSpotlight = new Bindable<APISpotlight>(); private readonly BindableWithCurrent<APISpotlight> current = new BindableWithCurrent<APISpotlight>();
public Bindable<APISpotlight> Current
{
get => current.Current;
set => current.Current = value;
}
public IEnumerable<APISpotlight> Spotlights public IEnumerable<APISpotlight> Spotlights
{ {
@ -55,7 +62,7 @@ namespace osu.Game.Overlays.Rankings
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Current = SelectedSpotlight, Current = Current,
Depth = -float.MaxValue Depth = -float.MaxValue
}, },
new FillFlowContainer new FillFlowContainer
@ -84,12 +91,19 @@ namespace osu.Game.Overlays.Rankings
background.Colour = colours.GreySeafoam; background.Colour = colours.GreySeafoam;
} }
public void UpdateInfo(APISpotlight spotlight, int mapCount) protected override void LoadComplete()
{ {
startDateColumn.Value = dateToString(spotlight.StartDate); base.LoadComplete();
endDateColumn.Value = dateToString(spotlight.EndDate);
mapCountColumn.Value = mapCount.ToString(); Current.BindValueChanged(onCurrentChanged);
participants.Value = spotlight.ParticipantCount?.ToString("N0"); }
private void onCurrentChanged(ValueChangedEvent<APISpotlight> 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"); private string dateToString(DateTimeOffset date) => date.ToString("yyyy-MM-dd");