From 1367c18d3f2a471c5d8a303990362b181337911d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 14 Jan 2020 15:07:25 +0900 Subject: [PATCH] General refactorings --- .../Online/TestSceneRankingsCountryFilter.cs | 2 +- osu.Game/Overlays/Rankings/CountryFilter.cs | 18 ++- osu.Game/Overlays/Rankings/CountryPill.cs | 117 ++++++++++-------- 3 files changed, 80 insertions(+), 57 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneRankingsCountryFilter.cs b/osu.Game.Tests/Visual/Online/TestSceneRankingsCountryFilter.cs index 3d38710b59..7ac65181f9 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneRankingsCountryFilter.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneRankingsCountryFilter.cs @@ -44,7 +44,7 @@ namespace osu.Game.Tests.Visual.Online { Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, - Country = { BindTarget = countryBindable } + Current = { BindTarget = countryBindable } }, new OsuSpriteText { diff --git a/osu.Game/Overlays/Rankings/CountryFilter.cs b/osu.Game/Overlays/Rankings/CountryFilter.cs index 7cd56100db..2b12457ccc 100644 --- a/osu.Game/Overlays/Rankings/CountryFilter.cs +++ b/osu.Game/Overlays/Rankings/CountryFilter.cs @@ -6,6 +6,7 @@ using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Users; @@ -13,12 +14,18 @@ using osuTK; namespace osu.Game.Overlays.Rankings { - public class CountryFilter : Container + public class CountryFilter : CompositeDrawable, IHasCurrentValue { private const int duration = 200; private const int height = 50; - public readonly Bindable Country = new Bindable(); + private readonly BindableWithCurrent current = new BindableWithCurrent(); + + public Bindable Current + { + get => current.Current; + set => current.Current = value; + } private readonly Box background; private readonly CountryPill countryPill; @@ -27,7 +34,8 @@ namespace osu.Game.Overlays.Rankings public CountryFilter() { RelativeSizeAxes = Axes.X; - Child = content = new Container + + InternalChild = content = new Container { RelativeSizeAxes = Axes.X, Height = height, @@ -59,7 +67,7 @@ namespace osu.Game.Overlays.Rankings Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Alpha = 0, - Country = { BindTarget = Country } + Current = Current } } } @@ -76,7 +84,7 @@ namespace osu.Game.Overlays.Rankings protected override void LoadComplete() { base.LoadComplete(); - Country.BindValueChanged(onCountryChanged, true); + Current.BindValueChanged(onCountryChanged, true); } private void onCountryChanged(ValueChangedEvent country) diff --git a/osu.Game/Overlays/Rankings/CountryPill.cs b/osu.Game/Overlays/Rankings/CountryPill.cs index 65fce3b909..410d316006 100644 --- a/osu.Game/Overlays/Rankings/CountryPill.cs +++ b/osu.Game/Overlays/Rankings/CountryPill.cs @@ -8,6 +8,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; @@ -18,68 +19,80 @@ using osuTK.Graphics; namespace osu.Game.Overlays.Rankings { - public class CountryPill : CircularContainer + public class CountryPill : CompositeDrawable, IHasCurrentValue { private const int duration = 200; + private readonly BindableWithCurrent current = new BindableWithCurrent(); + + public Bindable Current + { + get => current.Current; + set => current.Current = value; + } + + private readonly Container content; private readonly Box background; private readonly UpdateableFlag flag; private readonly OsuSpriteText countryName; - public readonly Bindable Country = new Bindable(); - public CountryPill() { - AutoSizeDuration = duration; - AutoSizeEasing = Easing.OutQuint; - Height = 25; - Masking = true; - Children = new Drawable[] + AutoSizeAxes = Axes.Both; + + InternalChild = content = new CircularContainer { - background = new Box + Height = 25, + AutoSizeDuration = duration, + AutoSizeEasing = Easing.OutQuint, + Masking = true, + Children = new Drawable[] { - RelativeSizeAxes = Axes.Both - }, - new FillFlowContainer - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Y, - AutoSizeAxes = Axes.X, - Margin = new MarginPadding { Horizontal = 10 }, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(8, 0), - Children = new Drawable[] + background = new Box { - new FillFlowContainer + RelativeSizeAxes = Axes.Both + }, + new FillFlowContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + Margin = new MarginPadding { Horizontal = 10 }, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(8, 0), + Children = new Drawable[] { - RelativeSizeAxes = Axes.Y, - AutoSizeAxes = Axes.X, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Direction = FillDirection.Horizontal, - Spacing = new Vector2(3, 0), - Children = new Drawable[] + new FillFlowContainer { - flag = new UpdateableFlag + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(3, 0), + Children = new Drawable[] { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = new Vector2(22, 15) - }, - countryName = new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Font = OsuFont.GetFont(size: 14) + flag = new UpdateableFlag + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(22, 15) + }, + countryName = new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 14) + } } + }, + new CloseButton + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Action = () => Current.Value = null } - }, - new CloseButton - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Action = () => Country.Value = null } } } @@ -95,21 +108,23 @@ namespace osu.Game.Overlays.Rankings protected override void LoadComplete() { base.LoadComplete(); - Country.BindValueChanged(onCountryChanged, true); + Current.BindValueChanged(onCountryChanged, true); } public void Expand() { - ClearTransforms(); - AutoSizeAxes = Axes.X; + content.ClearTransforms(); + content.AutoSizeAxes = Axes.X; + this.FadeIn(duration, Easing.OutQuint); } public void Collapse() { - ClearTransforms(); - AutoSizeAxes = Axes.None; - this.ResizeWidthTo(0, duration, Easing.OutQuint); + content.ClearTransforms(); + content.AutoSizeAxes = Axes.None; + content.ResizeWidthTo(0, duration, Easing.OutQuint); + this.FadeOut(duration, Easing.OutQuint); }