From 207ccc4756474cea1a57b056f5404593433089d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 17 Oct 2021 14:15:36 +0200 Subject: [PATCH 1/4] Add test scene for beatmapset online status pill display --- .../TestSceneBeatmapSetOnlineStatusPill.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs new file mode 100644 index 0000000000..7bbf3c629b --- /dev/null +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs @@ -0,0 +1,32 @@ +// 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.Linq; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Drawables; +using osu.Game.Tests.Visual.UserInterface; +using osuTK; + +namespace osu.Game.Tests.Visual.Beatmaps +{ + public class TestSceneBeatmapSetOnlineStatusPill : ThemeComparisonTestScene + { + protected override Drawable CreateContent() => new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 10), + ChildrenEnumerable = Enum.GetValues(typeof(BeatmapSetOnlineStatus)).Cast().Select(status => new BeatmapSetOnlineStatusPill + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Status = status + }) + }; + } +} From 5ab3337a105a104074e1b019ea93bae329021402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 17 Oct 2021 14:42:04 +0200 Subject: [PATCH 2/4] Update beatmap set status pill appearance --- .../Drawables/BeatmapSetOnlineStatusPill.cs | 46 ++++++++++++++----- osu.Game/Graphics/OsuColour.cs | 36 +++++++++++++++ .../BeatmapSet/BeatmapSetHeaderContent.cs | 1 - 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs index ffc010b3a3..bc8af90069 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs @@ -1,6 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable enable + +using osu.Framework.Allocation; using osu.Framework.Extensions; using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics; @@ -8,15 +11,13 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Overlays; using osuTK.Graphics; namespace osu.Game.Beatmaps.Drawables { public class BeatmapSetOnlineStatusPill : CircularContainer { - private readonly OsuSpriteText statusText; - private readonly Box background; - private BeatmapSetOnlineStatus status; public BeatmapSetOnlineStatus Status @@ -29,8 +30,8 @@ namespace osu.Game.Beatmaps.Drawables status = value; - Alpha = value == BeatmapSetOnlineStatus.None ? 0 : 1; - statusText.Text = value.GetLocalisableDescription().ToUpper(); + if (IsLoaded) + updateState(); } } @@ -46,11 +47,14 @@ namespace osu.Game.Beatmaps.Drawables set => statusText.Padding = value; } - public Color4 BackgroundColour - { - get => background.Colour; - set => background.Colour = value; - } + private readonly OsuSpriteText statusText; + private readonly Box background; + + [Resolved] + private OsuColour colours { get; set; } = null!; + + [Resolved(CanBeNull = true)] + private OverlayColourProvider? colourProvider { get; set; } public BeatmapSetOnlineStatusPill() { @@ -63,7 +67,6 @@ namespace osu.Game.Beatmaps.Drawables { RelativeSizeAxes = Axes.Both, Colour = Color4.Black, - Alpha = 0.5f, }, statusText = new OsuSpriteText { @@ -74,6 +77,27 @@ namespace osu.Game.Beatmaps.Drawables }; Status = BeatmapSetOnlineStatus.None; + TextPadding = new MarginPadding { Horizontal = 5, Bottom = 1 }; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + updateState(); + } + + private void updateState() + { + Alpha = Status == BeatmapSetOnlineStatus.None ? 0 : 1; + + statusText.Text = Status.GetLocalisableDescription().ToUpper(); + + if (colourProvider != null) + statusText.Colour = status == BeatmapSetOnlineStatus.Graveyard ? colourProvider.Background1 : colourProvider.Background3; + else + statusText.Colour = status == BeatmapSetOnlineStatus.Graveyard ? colours.GreySeafoamLight : Color4.Black; + + background.Colour = OsuColour.ForBeatmapSetOnlineStatus(Status) ?? colourProvider?.Light1 ?? colours.GreySeafoamLighter; } } } diff --git a/osu.Game/Graphics/OsuColour.cs b/osu.Game/Graphics/OsuColour.cs index 40d163635a..3aa4dbf1d8 100644 --- a/osu.Game/Graphics/OsuColour.cs +++ b/osu.Game/Graphics/OsuColour.cs @@ -118,6 +118,42 @@ namespace osu.Game.Graphics } } + /// + /// Retrieves a colour for the given . + /// A value indicates that a "background" shade from the local + /// (or another fallback colour) should be used. + /// + /// + /// Sourced from web: https://github.com/ppy/osu-web/blob/007eebb1916ed5cb6a7866d82d8011b1060a945e/resources/assets/less/layout.less#L36-L50 + /// + public static Color4? ForBeatmapSetOnlineStatus(BeatmapSetOnlineStatus status) + { + switch (status) + { + case BeatmapSetOnlineStatus.Ranked: + case BeatmapSetOnlineStatus.Approved: + return Color4Extensions.FromHex(@"b3ff66"); + + case BeatmapSetOnlineStatus.Loved: + return Color4Extensions.FromHex(@"ff66ab"); + + case BeatmapSetOnlineStatus.Qualified: + return Color4Extensions.FromHex(@"66ccff"); + + case BeatmapSetOnlineStatus.Pending: + return Color4Extensions.FromHex(@"ffd966"); + + case BeatmapSetOnlineStatus.WIP: + return Color4Extensions.FromHex(@"ff9966"); + + case BeatmapSetOnlineStatus.Graveyard: + return Color4.Black; + + default: + return null; + } + } + /// /// Returns a foreground text colour that is supposed to contrast well with /// the supplied . diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs index c1029923f7..df88b06879 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs @@ -220,7 +220,6 @@ namespace osu.Game.Overlays.BeatmapSet private void load(OverlayColourProvider colourProvider) { coverGradient.Colour = ColourInfo.GradientVertical(colourProvider.Background6.Opacity(0.3f), colourProvider.Background6.Opacity(0.8f)); - onlineStatusPill.BackgroundColour = colourProvider.Background6; State.BindValueChanged(_ => updateDownloadButtons()); From feedd53a53d86945fe0460b73abd135f16474e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 17 Oct 2021 14:55:52 +0200 Subject: [PATCH 3/4] Add support for setting fixed size of status pill --- .../TestSceneBeatmapSetOnlineStatusPill.cs | 16 ++++++++++++ .../Drawables/BeatmapSetOnlineStatusPill.cs | 25 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs index 7bbf3c629b..2d61385269 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs @@ -2,11 +2,16 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Linq; +using NUnit.Framework; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables; +using osu.Game.Overlays; using osu.Game.Tests.Visual.UserInterface; using osuTK; @@ -28,5 +33,16 @@ namespace osu.Game.Tests.Visual.Beatmaps Status = status }) }; + + private IEnumerable statusPills => this.ChildrenOfType(); + + [Test] + public void TestFixedWidth() + { + AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red)); + + AddStep("set fixed width", () => statusPills.ForEach(pill => pill.FixedWidth = 90)); + AddStep("unset fixed width", () => statusPills.ForEach(pill => pill.FixedWidth = null)); + } } } diff --git a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs index bc8af90069..848bab6394 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs @@ -47,6 +47,31 @@ namespace osu.Game.Beatmaps.Drawables set => statusText.Padding = value; } + private float? fixedWidth; + + /// + /// When set to a non- value, the pill will be forcibly sized to the given width. + /// When set to a value, the pill will autosize to its contents. + /// + public float? FixedWidth + { + get => fixedWidth; + set + { + fixedWidth = value; + + if (fixedWidth == null) + { + AutoSizeAxes = Axes.Both; + } + else + { + AutoSizeAxes = Axes.Y; + Width = fixedWidth.Value; + } + } + } + private readonly OsuSpriteText statusText; private readonly Box background; From 6802e9ec109c34309529a10b950038e54cc62015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 25 Oct 2021 20:20:40 +0200 Subject: [PATCH 4/4] Remove `FixedWidth` and add `AutoSizeAxes` specs to all usages --- .../TestSceneBeatmapSetOnlineStatusPill.cs | 9 +++++-- .../Drawables/BeatmapSetOnlineStatusPill.cs | 26 ------------------- .../BeatmapListing/Panels/GridBeatmapPanel.cs | 1 + .../BeatmapListing/Panels/ListBeatmapPanel.cs | 1 + .../BeatmapSet/BeatmapSetHeaderContent.cs | 1 + osu.Game/Screens/Select/BeatmapInfoWedge.cs | 1 + .../Select/Carousel/SetPanelContent.cs | 1 + 7 files changed, 12 insertions(+), 28 deletions(-) diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs index 2d61385269..c48b63ac89 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapSetOnlineStatusPill.cs @@ -28,6 +28,7 @@ namespace osu.Game.Tests.Visual.Beatmaps Spacing = new Vector2(0, 10), ChildrenEnumerable = Enum.GetValues(typeof(BeatmapSetOnlineStatus)).Cast().Select(status => new BeatmapSetOnlineStatusPill { + AutoSizeAxes = Axes.Both, Anchor = Anchor.Centre, Origin = Anchor.Centre, Status = status @@ -41,8 +42,12 @@ namespace osu.Game.Tests.Visual.Beatmaps { AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red)); - AddStep("set fixed width", () => statusPills.ForEach(pill => pill.FixedWidth = 90)); - AddStep("unset fixed width", () => statusPills.ForEach(pill => pill.FixedWidth = null)); + AddStep("set fixed width", () => statusPills.ForEach(pill => + { + pill.AutoSizeAxes = Axes.Y; + pill.Width = 90; + })); + AddStep("unset fixed width", () => statusPills.ForEach(pill => pill.AutoSizeAxes = Axes.Both)); } } } diff --git a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs index 848bab6394..ec098f4ca2 100644 --- a/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs +++ b/osu.Game/Beatmaps/Drawables/BeatmapSetOnlineStatusPill.cs @@ -47,31 +47,6 @@ namespace osu.Game.Beatmaps.Drawables set => statusText.Padding = value; } - private float? fixedWidth; - - /// - /// When set to a non- value, the pill will be forcibly sized to the given width. - /// When set to a value, the pill will autosize to its contents. - /// - public float? FixedWidth - { - get => fixedWidth; - set - { - fixedWidth = value; - - if (fixedWidth == null) - { - AutoSizeAxes = Axes.Both; - } - else - { - AutoSizeAxes = Axes.Y; - Width = fixedWidth.Value; - } - } - } - private readonly OsuSpriteText statusText; private readonly Box background; @@ -83,7 +58,6 @@ namespace osu.Game.Beatmaps.Drawables public BeatmapSetOnlineStatusPill() { - AutoSizeAxes = Axes.Both; Masking = true; Children = new Drawable[] diff --git a/osu.Game/Overlays/BeatmapListing/Panels/GridBeatmapPanel.cs b/osu.Game/Overlays/BeatmapListing/Panels/GridBeatmapPanel.cs index c078127353..4a0fa59c31 100644 --- a/osu.Game/Overlays/BeatmapListing/Panels/GridBeatmapPanel.cs +++ b/osu.Game/Overlays/BeatmapListing/Panels/GridBeatmapPanel.cs @@ -243,6 +243,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels statusContainer.Add(new BeatmapSetOnlineStatusPill { + AutoSizeAxes = Axes.Both, TextSize = 12, TextPadding = new MarginPadding { Horizontal = 10, Vertical = 5 }, Status = SetInfo.OnlineInfo?.Status ?? BeatmapSetOnlineStatus.None, diff --git a/osu.Game/Overlays/BeatmapListing/Panels/ListBeatmapPanel.cs b/osu.Game/Overlays/BeatmapListing/Panels/ListBeatmapPanel.cs index 5011749c5f..63d651f9de 100644 --- a/osu.Game/Overlays/BeatmapListing/Panels/ListBeatmapPanel.cs +++ b/osu.Game/Overlays/BeatmapListing/Panels/ListBeatmapPanel.cs @@ -257,6 +257,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels statusContainer.Add(new BeatmapSetOnlineStatusPill { + AutoSizeAxes = Axes.Both, TextSize = 12, TextPadding = new MarginPadding { Horizontal = 10, Vertical = 4 }, Status = SetInfo.OnlineInfo?.Status ?? BeatmapSetOnlineStatus.None, diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs index df88b06879..6f85846720 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs @@ -198,6 +198,7 @@ namespace osu.Game.Overlays.BeatmapSet { onlineStatusPill = new BeatmapSetOnlineStatusPill { + AutoSizeAxes = Axes.Both, Anchor = Anchor.TopRight, Origin = Anchor.TopRight, TextSize = 14, diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index ac191a38f2..2de72beaad 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -257,6 +257,7 @@ namespace osu.Game.Screens.Select }, StatusPill = new BeatmapSetOnlineStatusPill { + AutoSizeAxes = Axes.Both, Anchor = Anchor.TopRight, Origin = Anchor.TopRight, Shear = -wedged_container_shear, diff --git a/osu.Game/Screens/Select/Carousel/SetPanelContent.cs b/osu.Game/Screens/Select/Carousel/SetPanelContent.cs index 9fb640ba1a..f2054677b0 100644 --- a/osu.Game/Screens/Select/Carousel/SetPanelContent.cs +++ b/osu.Game/Screens/Select/Carousel/SetPanelContent.cs @@ -60,6 +60,7 @@ namespace osu.Game.Screens.Select.Carousel { new BeatmapSetOnlineStatusPill { + AutoSizeAxes = Axes.Both, Origin = Anchor.CentreLeft, Anchor = Anchor.CentreLeft, Margin = new MarginPadding { Right = 5 },