Use new SpotlightSelector in RankingsHeader

This commit is contained in:
Andrei Zavatski 2020-02-05 11:21:23 +03:00
parent e119040d5d
commit a3fd952f74
3 changed files with 16 additions and 76 deletions

View File

@ -5,6 +5,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Rankings; using osu.Game.Overlays.Rankings;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -37,20 +38,20 @@ public TestSceneRankingsHeader()
Ruleset = { BindTarget = ruleset }, Ruleset = { BindTarget = ruleset },
Spotlights = new[] Spotlights = new[]
{ {
new Spotlight new APISpotlight
{ {
Id = 1, Id = 1,
Text = "Spotlight 1" Name = "Spotlight 1"
}, },
new Spotlight new APISpotlight
{ {
Id = 2, Id = 2,
Text = "Spotlight 2" Name = "Spotlight 2"
}, },
new Spotlight new APISpotlight
{ {
Id = 3, Id = 3,
Text = "Spotlight 3" Name = "Spotlight 3"
} }
} }
}); });

View File

@ -8,21 +8,20 @@
using osu.Game.Users; using osu.Game.Users;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Game.Online.API.Requests.Responses;
using osu.Framework.Allocation;
namespace osu.Game.Overlays.Rankings namespace osu.Game.Overlays.Rankings
{ {
public class RankingsOverlayHeader : TabControlOverlayHeader<RankingsScope> public class RankingsOverlayHeader : TabControlOverlayHeader<RankingsScope>
{ {
public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>(); public readonly Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
public readonly Bindable<Spotlight> Spotlight = new Bindable<Spotlight>(); public readonly Bindable<APISpotlight> Spotlight = new Bindable<APISpotlight>();
public readonly Bindable<Country> Country = new Bindable<Country>(); public readonly Bindable<Country> Country = new Bindable<Country>();
public IEnumerable<Spotlight> Spotlights public IEnumerable<APISpotlight> Spotlights
{ {
get => spotlightsContainer.Spotlights; get => spotlightSelector.Spotlights;
set => spotlightsContainer.Spotlights = value; set => spotlightSelector.Spotlights = value;
} }
protected override ScreenTitle CreateTitle() => new RankingsTitle protected override ScreenTitle CreateTitle() => new RankingsTitle
@ -35,7 +34,7 @@ public IEnumerable<Spotlight> Spotlights
Current = Ruleset Current = Ruleset
}; };
private SpotlightsContainer spotlightsContainer; private SpotlightSelector spotlightSelector;
protected override Drawable CreateContent() => new FillFlowContainer protected override Drawable CreateContent() => new FillFlowContainer
{ {
@ -48,9 +47,9 @@ public IEnumerable<Spotlight> Spotlights
{ {
Current = Country Current = Country
}, },
spotlightsContainer = new SpotlightsContainer spotlightSelector = new SpotlightSelector
{ {
Spotlight = { BindTarget = Spotlight } Current = { BindTarget = Spotlight }
} }
} }
}; };
@ -62,7 +61,7 @@ protected override void LoadComplete()
} }
private void onCurrentChanged(ValueChangedEvent<RankingsScope> scope) => private void onCurrentChanged(ValueChangedEvent<RankingsScope> scope) =>
spotlightsContainer.FadeTo(scope.NewValue == RankingsScope.Spotlights ? 1 : 0, 200, Easing.OutQuint); spotlightSelector.FadeTo(scope.NewValue == RankingsScope.Spotlights ? 1 : 0, 200, Easing.OutQuint);
private class RankingsTitle : ScreenTitle private class RankingsTitle : ScreenTitle
{ {
@ -81,48 +80,6 @@ protected override void LoadComplete()
protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/rankings"); protected override Drawable CreateIcon() => new ScreenTitleTextureIcon(@"Icons/rankings");
} }
private class SpotlightsContainer : CompositeDrawable
{
public readonly Bindable<Spotlight> Spotlight = new Bindable<Spotlight>();
public IEnumerable<Spotlight> Spotlights
{
get => dropdown.Items;
set => dropdown.Items = value;
}
private readonly OsuDropdown<Spotlight> dropdown;
private readonly Box background;
public SpotlightsContainer()
{
Height = 100;
RelativeSizeAxes = Axes.X;
InternalChildren = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
dropdown = new OsuDropdown<Spotlight>
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
Width = 0.8f,
Current = Spotlight,
Y = 20,
}
};
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
background.Colour = colourProvider.Dark3;
}
}
} }
public enum RankingsScope public enum RankingsScope

View File

@ -1,18 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Newtonsoft.Json;
namespace osu.Game.Overlays.Rankings
{
public class Spotlight
{
[JsonProperty("id")]
public int Id;
[JsonProperty("text")]
public string Text;
public override string ToString() => Text;
}
}