From d5027cdfbd4418a129687aed5b881c41cc34a823 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 19:46:13 +0300 Subject: [PATCH 1/9] Add `FeaturedInSpotlight` property to API beatmapsets --- .../Visual/Beatmaps/TestSceneBeatmapCard.cs | 17 +++++++++---- .../Online/TestSceneBeatmapSetOverlay.cs | 24 +++++++++++++++++++ .../API/Requests/Responses/APIBeatmapSet.cs | 3 +++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs index 94b693363a..6cb171974a 100644 --- a/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs +++ b/osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs @@ -84,20 +84,26 @@ namespace osu.Game.Tests.Visual.Beatmaps explicitMap.Title = someDifficulties.TitleUnicode = "explicit beatmap"; explicitMap.HasExplicitContent = true; + var spotlightMap = CreateAPIBeatmapSet(Ruleset.Value); + spotlightMap.Title = someDifficulties.TitleUnicode = "spotlight beatmap"; + spotlightMap.FeaturedInSpotlight = true; + var featuredMap = CreateAPIBeatmapSet(Ruleset.Value); featuredMap.Title = someDifficulties.TitleUnicode = "featured artist beatmap"; featuredMap.TrackId = 1; - var explicitFeaturedMap = CreateAPIBeatmapSet(Ruleset.Value); - explicitFeaturedMap.Title = someDifficulties.TitleUnicode = "explicit featured artist"; - explicitFeaturedMap.HasExplicitContent = true; - explicitFeaturedMap.TrackId = 2; + var allBadgesMap = CreateAPIBeatmapSet(Ruleset.Value); + allBadgesMap.Title = someDifficulties.TitleUnicode = "all-badges beatmap"; + allBadgesMap.HasExplicitContent = true; + allBadgesMap.FeaturedInSpotlight = true; + allBadgesMap.TrackId = 2; var longName = CreateAPIBeatmapSet(Ruleset.Value); longName.Title = longName.TitleUnicode = "this track has an incredibly and implausibly long title"; longName.Artist = longName.ArtistUnicode = "and this artist! who would have thunk it. it's really such a long name."; longName.Source = "wow. even the source field has an impossibly long string in it. this really takes the cake, doesn't it?"; longName.HasExplicitContent = true; + longName.FeaturedInSpotlight = true; longName.TrackId = 444; testCases = new[] @@ -108,8 +114,9 @@ namespace osu.Game.Tests.Visual.Beatmaps someDifficulties, manyDifficulties, explicitMap, + spotlightMap, featuredMap, - explicitFeaturedMap, + allBadgesMap, longName }; diff --git a/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs b/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs index f87cca80b0..859727e632 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs @@ -165,6 +165,17 @@ namespace osu.Game.Tests.Visual.Online }); } + [Test] + public void TestSpotlightBeatmap() + { + AddStep("show spotlight map", () => + { + var beatmapSet = getBeatmapSet(); + beatmapSet.FeaturedInSpotlight = true; + overlay.ShowBeatmapSet(beatmapSet); + }); + } + [Test] public void TestFeaturedBeatmap() { @@ -176,6 +187,19 @@ namespace osu.Game.Tests.Visual.Online }); } + [Test] + public void TestAllBadgesBeatmap() + { + AddStep("show map with all badges", () => + { + var beatmapSet = getBeatmapSet(); + beatmapSet.HasExplicitContent = true; + beatmapSet.FeaturedInSpotlight = true; + beatmapSet.TrackId = 1; + overlay.ShowBeatmapSet(beatmapSet); + }); + } + [Test] public void TestHide() { diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index d99c13b977..79c65fa79e 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -42,6 +42,9 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty(@"nsfw")] public bool HasExplicitContent { get; set; } + [JsonProperty(@"spotlight")] + public bool FeaturedInSpotlight { get; set; } + [JsonProperty(@"video")] public bool HasVideo { get; set; } From c8bea6273b484018310d654fd80f3499ea531e91 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 19:46:34 +0300 Subject: [PATCH 2/9] Abstractify beatmap badge logic to own class --- .../Overlays/BeatmapSet/BeatmapBadgePill.cs | 67 +++++++++++++++++++ .../BeatmapSet/ExplicitContentBeatmapPill.cs | 42 ++---------- .../BeatmapSet/FeaturedArtistBeatmapPill.cs | 42 ++---------- 3 files changed, 79 insertions(+), 72 deletions(-) create mode 100644 osu.Game/Overlays/BeatmapSet/BeatmapBadgePill.cs diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapBadgePill.cs b/osu.Game/Overlays/BeatmapSet/BeatmapBadgePill.cs new file mode 100644 index 0000000000..2c5042942c --- /dev/null +++ b/osu.Game/Overlays/BeatmapSet/BeatmapBadgePill.cs @@ -0,0 +1,67 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Extensions.LocalisationExtensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; + +#nullable enable + +namespace osu.Game.Overlays.BeatmapSet +{ + public abstract class BeatmapBadgePill : CompositeDrawable + { + [Resolved] + protected OsuColour Colours { get; private set; } = null!; + + [Resolved(canBeNull: true)] + protected OverlayColourProvider? ColourProvider { get; private set; } + + /// + /// The text displayed on the badge's label. + /// + public abstract LocalisableString BadgeText { get; } + + /// + /// The colour of the badge's label. + /// + public abstract Colour4 BadgeColour { get; } + + // todo: add linking support, to allow redirecting featured artist badge to corresponding track and spotlight badge to wiki page. + + protected BeatmapBadgePill() + { + AutoSizeAxes = Axes.Both; + } + + [BackgroundDependencyLoader(true)] + private void load() + { + InternalChild = new CircularContainer + { + Masking = true, + AutoSizeAxes = Axes.Both, + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = ColourProvider?.Background5 ?? Colours.Gray2, + }, + new OsuSpriteText + { + Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold), + Margin = new MarginPadding { Horizontal = 10, Vertical = 2 }, + Text = BadgeText.ToUpper(), + Colour = BadgeColour, + } + } + }; + } + } +} diff --git a/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapPill.cs b/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapPill.cs index 21d1d1172c..f8530f3a16 100644 --- a/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapPill.cs +++ b/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapPill.cs @@ -1,47 +1,17 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Allocation; -using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; +using osu.Framework.Localisation; using osu.Game.Resources.Localisation.Web; +#nullable enable + namespace osu.Game.Overlays.BeatmapSet { - public class ExplicitContentBeatmapPill : CompositeDrawable + public class ExplicitContentBeatmapPill : BeatmapBadgePill { - public ExplicitContentBeatmapPill() - { - AutoSizeAxes = Axes.Both; - } - - [BackgroundDependencyLoader(true)] - private void load(OsuColour colours, OverlayColourProvider colourProvider) - { - InternalChild = new CircularContainer - { - Masking = true, - AutoSizeAxes = Axes.Both, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = colourProvider?.Background5 ?? colours.Gray2, - }, - new OsuSpriteText - { - Margin = new MarginPadding { Horizontal = 10f, Vertical = 2f }, - Text = BeatmapsetsStrings.NsfwBadgeLabel.ToUpper(), - Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold), - Colour = colours.Orange2 - } - } - }; - } + public override LocalisableString BadgeText => BeatmapsetsStrings.NsfwBadgeLabel; + public override Colour4 BadgeColour => Colours.Orange2; } } diff --git a/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapPill.cs b/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapPill.cs index 1be987cde2..4c29ede12e 100644 --- a/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapPill.cs +++ b/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapPill.cs @@ -1,47 +1,17 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Allocation; -using osu.Framework.Extensions.LocalisationExtensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Shapes; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; +using osu.Framework.Localisation; using osu.Game.Resources.Localisation.Web; +#nullable enable + namespace osu.Game.Overlays.BeatmapSet { - public class FeaturedArtistBeatmapPill : CompositeDrawable + public class FeaturedArtistBeatmapPill : BeatmapBadgePill { - public FeaturedArtistBeatmapPill() - { - AutoSizeAxes = Axes.Both; - } - - [BackgroundDependencyLoader(true)] - private void load(OsuColour colours, OverlayColourProvider colourProvider) - { - InternalChild = new CircularContainer - { - Masking = true, - AutoSizeAxes = Axes.Both, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = colourProvider?.Background5 ?? colours.Gray2, - }, - new OsuSpriteText - { - Margin = new MarginPadding { Horizontal = 10f, Vertical = 2f }, - Text = BeatmapsetsStrings.FeaturedArtistBadgeLabel.ToUpper(), - Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold), - Colour = colours.Blue1 - } - } - }; - } + public override LocalisableString BadgeText => BeatmapsetsStrings.FeaturedArtistBadgeLabel; + public override Colour4 BadgeColour => Colours.Blue1; } } From 56d6cb5764f49eb2aaa98aef0b2ca97b3b88cbd6 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 19:46:50 +0300 Subject: [PATCH 3/9] Add "spotlight" beatmap badge --- .../Overlays/BeatmapSet/SpotlightBeatmapPill.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 osu.Game/Overlays/BeatmapSet/SpotlightBeatmapPill.cs diff --git a/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapPill.cs b/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapPill.cs new file mode 100644 index 0000000000..7376889d7b --- /dev/null +++ b/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapPill.cs @@ -0,0 +1,17 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; +using osu.Framework.Localisation; +using osu.Game.Resources.Localisation.Web; + +#nullable enable + +namespace osu.Game.Overlays.BeatmapSet +{ + public class SpotlightBeatmapPill : BeatmapBadgePill + { + public override LocalisableString BadgeText => BeatmapsetsStrings.SpotlightBadgeLabel; + public override Colour4 BadgeColour => Colours.Pink1; + } +} From 2878a6dcbed331b7f73e5f8eb877fbc73745f7c2 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 19:47:10 +0300 Subject: [PATCH 4/9] Integrate spotlight beatmap badge in info overlay --- .../Overlays/BeatmapSet/BeatmapSetHeaderContent.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs index 8f4089c707..4233cfcb70 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs @@ -39,8 +39,11 @@ namespace osu.Game.Overlays.BeatmapSet private readonly Box coverGradient; private readonly OsuSpriteText title, artist; private readonly AuthorInfo author; + private readonly ExplicitContentBeatmapPill explicitContentPill; + private readonly SpotlightBeatmapPill spotlightPill; private readonly FeaturedArtistBeatmapPill featuredArtistPill; + private readonly FillFlowContainer downloadButtonsContainer; private readonly BeatmapAvailability beatmapAvailability; private readonly BeatmapSetOnlineStatusPill onlineStatusPill; @@ -127,6 +130,13 @@ namespace osu.Game.Overlays.BeatmapSet Margin = new MarginPadding { Left = 5, Bottom = 4 }, // To better lineup with the font }, explicitContentPill = new ExplicitContentBeatmapPill + { + Alpha = 0f, + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Margin = new MarginPadding { Left = 10, Bottom = 4 }, + }, + spotlightPill = new SpotlightBeatmapPill { Alpha = 0f, Anchor = Anchor.BottomLeft, @@ -258,6 +268,7 @@ namespace osu.Game.Overlays.BeatmapSet artist.Text = new RomanisableString(setInfo.NewValue.ArtistUnicode, setInfo.NewValue.Artist); explicitContentPill.Alpha = setInfo.NewValue.HasExplicitContent ? 1 : 0; + spotlightPill.Alpha = setInfo.NewValue.FeaturedInSpotlight ? 1 : 0; featuredArtistPill.Alpha = setInfo.NewValue.TrackId != null ? 1 : 0; onlineStatusPill.FadeIn(500, Easing.OutQuint); From 9bac33ec9f6fb5a7c91f22356a803a50b3954f1e Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 19:47:29 +0300 Subject: [PATCH 5/9] Integrate spotlight beatmap badge in listing cards --- .../Drawables/Cards/BeatmapCardExtra.cs | 30 +++++++++++++---- .../Drawables/Cards/BeatmapCardNormal.cs | 32 ++++++++++++++----- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs index 535f222228..32da23b27d 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs @@ -54,7 +54,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards Height = height; FillFlowContainer leftIconArea = null!; - GridContainer titleContainer = null!; + FillFlowContainer titleBadgeArea = null!; GridContainer artistContainer = null!; Child = content.With(c => @@ -93,7 +93,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards Direction = FillDirection.Vertical, Children = new Drawable[] { - titleContainer = new GridContainer + new GridContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, @@ -108,7 +108,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards }, Content = new[] { - new[] + new Drawable[] { new OsuSpriteText { @@ -117,7 +117,13 @@ namespace osu.Game.Beatmaps.Drawables.Cards RelativeSizeAxes = Axes.X, Truncate = true }, - Empty() + titleBadgeArea = new FillFlowContainer + { + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + } } } }, @@ -244,14 +250,24 @@ namespace osu.Game.Beatmaps.Drawables.Cards if (BeatmapSet.HasStoryboard) leftIconArea.Add(new IconPill(FontAwesome.Solid.Image) { IconSize = new Vector2(20) }); - if (BeatmapSet.HasExplicitContent) + if (BeatmapSet.FeaturedInSpotlight) { - titleContainer.Content[0][1] = new ExplicitContentBeatmapPill + titleBadgeArea.Add(new SpotlightBeatmapPill { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, Margin = new MarginPadding { Left = 5 } - }; + }); + } + + if (BeatmapSet.HasExplicitContent) + { + titleBadgeArea.Add(new ExplicitContentBeatmapPill + { + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight, + Margin = new MarginPadding { Left = 5 } + }); } if (BeatmapSet.TrackId != null) diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs index 08befd5340..fc91c91e3c 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs @@ -55,7 +55,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards Height = height; FillFlowContainer leftIconArea = null!; - GridContainer titleContainer = null!; + FillFlowContainer titleBadgeArea = null!; GridContainer artistContainer = null!; Child = content.With(c => @@ -94,14 +94,14 @@ namespace osu.Game.Beatmaps.Drawables.Cards Direction = FillDirection.Vertical, Children = new Drawable[] { - titleContainer = new GridContainer + new GridContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, ColumnDimensions = new[] { new Dimension(), - new Dimension(GridSizeMode.AutoSize) + new Dimension(GridSizeMode.AutoSize), }, RowDimensions = new[] { @@ -109,7 +109,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards }, Content = new[] { - new[] + new Drawable[] { new OsuSpriteText { @@ -118,7 +118,13 @@ namespace osu.Game.Beatmaps.Drawables.Cards RelativeSizeAxes = Axes.X, Truncate = true }, - Empty() + titleBadgeArea = new FillFlowContainer + { + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight, + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + } } } }, @@ -225,14 +231,24 @@ namespace osu.Game.Beatmaps.Drawables.Cards if (BeatmapSet.HasStoryboard) leftIconArea.Add(new IconPill(FontAwesome.Solid.Image) { IconSize = new Vector2(20) }); - if (BeatmapSet.HasExplicitContent) + if (BeatmapSet.FeaturedInSpotlight) { - titleContainer.Content[0][1] = new ExplicitContentBeatmapPill + titleBadgeArea.Add(new SpotlightBeatmapPill { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, Margin = new MarginPadding { Left = 5 } - }; + }); + } + + if (BeatmapSet.HasExplicitContent) + { + titleBadgeArea.Add(new ExplicitContentBeatmapPill + { + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight, + Margin = new MarginPadding { Left = 5 } + }); } if (BeatmapSet.TrackId != null) From 88ba84ac9cc99c3a60632ca31aed38083a48dc7a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 20:52:38 +0300 Subject: [PATCH 6/9] Replace `Pill` with `Badge` everywhere --- .../Drawables/Cards/BeatmapCardExtra.cs | 6 +++--- .../Drawables/Cards/BeatmapCardNormal.cs | 6 +++--- .../{BeatmapBadgePill.cs => BeatmapBadge.cs} | 4 ++-- .../BeatmapSet/BeatmapSetHeaderContent.cs | 18 +++++++++--------- ...pPill.cs => ExplicitContentBeatmapBadge.cs} | 2 +- ...apPill.cs => FeaturedArtistBeatmapBadge.cs} | 2 +- ...BeatmapPill.cs => SpotlightBeatmapBadge.cs} | 2 +- .../OnlinePlay/DrawableRoomPlaylistItem.cs | 6 +++--- 8 files changed, 23 insertions(+), 23 deletions(-) rename osu.Game/Overlays/BeatmapSet/{BeatmapBadgePill.cs => BeatmapBadge.cs} (95%) rename osu.Game/Overlays/BeatmapSet/{ExplicitContentBeatmapPill.cs => ExplicitContentBeatmapBadge.cs} (88%) rename osu.Game/Overlays/BeatmapSet/{FeaturedArtistBeatmapPill.cs => FeaturedArtistBeatmapBadge.cs} (88%) rename osu.Game/Overlays/BeatmapSet/{SpotlightBeatmapPill.cs => SpotlightBeatmapBadge.cs} (89%) diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs index 32da23b27d..58c1ebee0f 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs @@ -252,7 +252,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards if (BeatmapSet.FeaturedInSpotlight) { - titleBadgeArea.Add(new SpotlightBeatmapPill + titleBadgeArea.Add(new SpotlightBeatmapBadge { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, @@ -262,7 +262,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards if (BeatmapSet.HasExplicitContent) { - titleBadgeArea.Add(new ExplicitContentBeatmapPill + titleBadgeArea.Add(new ExplicitContentBeatmapBadge { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, @@ -272,7 +272,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards if (BeatmapSet.TrackId != null) { - artistContainer.Content[0][1] = new FeaturedArtistBeatmapPill + artistContainer.Content[0][1] = new FeaturedArtistBeatmapBadge { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs index fc91c91e3c..3d7e81de21 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs @@ -233,7 +233,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards if (BeatmapSet.FeaturedInSpotlight) { - titleBadgeArea.Add(new SpotlightBeatmapPill + titleBadgeArea.Add(new SpotlightBeatmapBadge { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, @@ -243,7 +243,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards if (BeatmapSet.HasExplicitContent) { - titleBadgeArea.Add(new ExplicitContentBeatmapPill + titleBadgeArea.Add(new ExplicitContentBeatmapBadge { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, @@ -253,7 +253,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards if (BeatmapSet.TrackId != null) { - artistContainer.Content[0][1] = new FeaturedArtistBeatmapPill + artistContainer.Content[0][1] = new FeaturedArtistBeatmapBadge { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapBadgePill.cs b/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs similarity index 95% rename from osu.Game/Overlays/BeatmapSet/BeatmapBadgePill.cs rename to osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs index 2c5042942c..6a444cc85f 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapBadgePill.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs @@ -14,7 +14,7 @@ using osu.Game.Graphics.Sprites; namespace osu.Game.Overlays.BeatmapSet { - public abstract class BeatmapBadgePill : CompositeDrawable + public abstract class BeatmapBadge : CompositeDrawable { [Resolved] protected OsuColour Colours { get; private set; } = null!; @@ -34,7 +34,7 @@ namespace osu.Game.Overlays.BeatmapSet // todo: add linking support, to allow redirecting featured artist badge to corresponding track and spotlight badge to wiki page. - protected BeatmapBadgePill() + protected BeatmapBadge() { AutoSizeAxes = Axes.Both; } diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs index 4233cfcb70..56efb725cd 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs @@ -40,9 +40,9 @@ namespace osu.Game.Overlays.BeatmapSet private readonly OsuSpriteText title, artist; private readonly AuthorInfo author; - private readonly ExplicitContentBeatmapPill explicitContentPill; - private readonly SpotlightBeatmapPill spotlightPill; - private readonly FeaturedArtistBeatmapPill featuredArtistPill; + private readonly ExplicitContentBeatmapBadge explicitContent; + private readonly SpotlightBeatmapBadge spotlight; + private readonly FeaturedArtistBeatmapBadge featuredArtist; private readonly FillFlowContainer downloadButtonsContainer; private readonly BeatmapAvailability beatmapAvailability; @@ -129,14 +129,14 @@ namespace osu.Game.Overlays.BeatmapSet Origin = Anchor.BottomLeft, Margin = new MarginPadding { Left = 5, Bottom = 4 }, // To better lineup with the font }, - explicitContentPill = new ExplicitContentBeatmapPill + explicitContent = new ExplicitContentBeatmapBadge { Alpha = 0f, Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, Margin = new MarginPadding { Left = 10, Bottom = 4 }, }, - spotlightPill = new SpotlightBeatmapPill + spotlight = new SpotlightBeatmapBadge { Alpha = 0f, Anchor = Anchor.BottomLeft, @@ -156,7 +156,7 @@ namespace osu.Game.Overlays.BeatmapSet { Font = OsuFont.GetFont(size: 20, weight: FontWeight.Medium, italics: true), }, - featuredArtistPill = new FeaturedArtistBeatmapPill + featuredArtist = new FeaturedArtistBeatmapBadge { Alpha = 0f, Anchor = Anchor.BottomLeft, @@ -267,9 +267,9 @@ namespace osu.Game.Overlays.BeatmapSet title.Text = new RomanisableString(setInfo.NewValue.TitleUnicode, setInfo.NewValue.Title); artist.Text = new RomanisableString(setInfo.NewValue.ArtistUnicode, setInfo.NewValue.Artist); - explicitContentPill.Alpha = setInfo.NewValue.HasExplicitContent ? 1 : 0; - spotlightPill.Alpha = setInfo.NewValue.FeaturedInSpotlight ? 1 : 0; - featuredArtistPill.Alpha = setInfo.NewValue.TrackId != null ? 1 : 0; + explicitContent.Alpha = setInfo.NewValue.HasExplicitContent ? 1 : 0; + spotlight.Alpha = setInfo.NewValue.FeaturedInSpotlight ? 1 : 0; + featuredArtist.Alpha = setInfo.NewValue.TrackId != null ? 1 : 0; onlineStatusPill.FadeIn(500, Easing.OutQuint); onlineStatusPill.Status = setInfo.NewValue.Status; diff --git a/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapPill.cs b/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapBadge.cs similarity index 88% rename from osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapPill.cs rename to osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapBadge.cs index f8530f3a16..b78b203a21 100644 --- a/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapPill.cs +++ b/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapBadge.cs @@ -9,7 +9,7 @@ using osu.Game.Resources.Localisation.Web; namespace osu.Game.Overlays.BeatmapSet { - public class ExplicitContentBeatmapPill : BeatmapBadgePill + public class ExplicitContentBeatmapBadge : BeatmapBadge { public override LocalisableString BadgeText => BeatmapsetsStrings.NsfwBadgeLabel; public override Colour4 BadgeColour => Colours.Orange2; diff --git a/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapPill.cs b/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs similarity index 88% rename from osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapPill.cs rename to osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs index 4c29ede12e..b471911217 100644 --- a/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapPill.cs +++ b/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs @@ -9,7 +9,7 @@ using osu.Game.Resources.Localisation.Web; namespace osu.Game.Overlays.BeatmapSet { - public class FeaturedArtistBeatmapPill : BeatmapBadgePill + public class FeaturedArtistBeatmapBadge : BeatmapBadge { public override LocalisableString BadgeText => BeatmapsetsStrings.FeaturedArtistBadgeLabel; public override Colour4 BadgeColour => Colours.Blue1; diff --git a/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapPill.cs b/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs similarity index 89% rename from osu.Game/Overlays/BeatmapSet/SpotlightBeatmapPill.cs rename to osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs index 7376889d7b..caa2043474 100644 --- a/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapPill.cs +++ b/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs @@ -9,7 +9,7 @@ using osu.Game.Resources.Localisation.Web; namespace osu.Game.Overlays.BeatmapSet { - public class SpotlightBeatmapPill : BeatmapBadgePill + public class SpotlightBeatmapBadge : BeatmapBadge { public override LocalisableString BadgeText => BeatmapsetsStrings.SpotlightBadgeLabel; public override Colour4 BadgeColour => Colours.Pink1; diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index 2618e15d31..39853a5c45 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -78,7 +78,7 @@ namespace osu.Game.Screens.OnlinePlay private Container difficultyIconContainer; private LinkFlowContainer beatmapText; private LinkFlowContainer authorText; - private ExplicitContentBeatmapPill explicitContentPill; + private ExplicitContentBeatmapBadge explicitContent; private ModDisplay modDisplay; private FillFlowContainer buttonsFlow; private UpdateableAvatar ownerAvatar; @@ -293,7 +293,7 @@ namespace osu.Game.Screens.OnlinePlay } bool hasExplicitContent = (beatmap?.BeatmapSet as IBeatmapSetOnlineInfo)?.HasExplicitContent == true; - explicitContentPill.Alpha = hasExplicitContent ? 1 : 0; + explicitContent.Alpha = hasExplicitContent ? 1 : 0; modDisplay.Current.Value = requiredMods.ToArray(); @@ -380,7 +380,7 @@ namespace osu.Game.Screens.OnlinePlay Children = new Drawable[] { authorText = new LinkFlowContainer(fontParameters) { AutoSizeAxes = Axes.Both }, - explicitContentPill = new ExplicitContentBeatmapPill + explicitContent = new ExplicitContentBeatmapBadge { Alpha = 0f, Anchor = Anchor.CentreLeft, From 441957e18ee58e4c256002d593b583439921b6cc Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 21:01:29 +0300 Subject: [PATCH 7/9] Convert get-only virtual properties to avoid DI order dependency --- osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs | 26 +++++++++---------- .../BeatmapSet/ExplicitContentBeatmapBadge.cs | 12 ++++++--- .../BeatmapSet/FeaturedArtistBeatmapBadge.cs | 12 ++++++--- .../BeatmapSet/SpotlightBeatmapBadge.cs | 12 ++++++--- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs b/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs index 6a444cc85f..2604a58a2b 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs @@ -16,21 +16,23 @@ namespace osu.Game.Overlays.BeatmapSet { public abstract class BeatmapBadge : CompositeDrawable { - [Resolved] - protected OsuColour Colours { get; private set; } = null!; - - [Resolved(canBeNull: true)] - protected OverlayColourProvider? ColourProvider { get; private set; } - /// /// The text displayed on the badge's label. /// - public abstract LocalisableString BadgeText { get; } + public LocalisableString BadgeText + { + set => badgeLabel.Text = value.ToUpper(); + } /// /// The colour of the badge's label. /// - public abstract Colour4 BadgeColour { get; } + public Colour4 BadgeColour + { + set => badgeLabel.Colour = value; + } + + private OsuSpriteText badgeLabel = null!; // todo: add linking support, to allow redirecting featured artist badge to corresponding track and spotlight badge to wiki page. @@ -40,7 +42,7 @@ namespace osu.Game.Overlays.BeatmapSet } [BackgroundDependencyLoader(true)] - private void load() + private void load(OsuColour colours, OverlayColourProvider? colourProvider) { InternalChild = new CircularContainer { @@ -51,14 +53,12 @@ namespace osu.Game.Overlays.BeatmapSet new Box { RelativeSizeAxes = Axes.Both, - Colour = ColourProvider?.Background5 ?? Colours.Gray2, + Colour = colourProvider?.Background5 ?? colours.Gray2, }, - new OsuSpriteText + badgeLabel = new OsuSpriteText { Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold), Margin = new MarginPadding { Horizontal = 10, Vertical = 2 }, - Text = BadgeText.ToUpper(), - Colour = BadgeColour, } } }; diff --git a/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapBadge.cs b/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapBadge.cs index b78b203a21..2a20d22b61 100644 --- a/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapBadge.cs +++ b/osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapBadge.cs @@ -1,8 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics; -using osu.Framework.Localisation; +using osu.Framework.Allocation; +using osu.Game.Graphics; using osu.Game.Resources.Localisation.Web; #nullable enable @@ -11,7 +11,11 @@ namespace osu.Game.Overlays.BeatmapSet { public class ExplicitContentBeatmapBadge : BeatmapBadge { - public override LocalisableString BadgeText => BeatmapsetsStrings.NsfwBadgeLabel; - public override Colour4 BadgeColour => Colours.Orange2; + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BadgeText = BeatmapsetsStrings.NsfwBadgeLabel; + BadgeColour = colours.Orange2; + } } } diff --git a/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs b/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs index b471911217..230b8b5243 100644 --- a/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs +++ b/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs @@ -1,8 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics; -using osu.Framework.Localisation; +using osu.Framework.Allocation; +using osu.Game.Graphics; using osu.Game.Resources.Localisation.Web; #nullable enable @@ -11,7 +11,11 @@ namespace osu.Game.Overlays.BeatmapSet { public class FeaturedArtistBeatmapBadge : BeatmapBadge { - public override LocalisableString BadgeText => BeatmapsetsStrings.FeaturedArtistBadgeLabel; - public override Colour4 BadgeColour => Colours.Blue1; + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BadgeText = BeatmapsetsStrings.FeaturedArtistBadgeLabel; + BadgeColour = colours.Blue1; + } } } diff --git a/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs b/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs index caa2043474..8bfd623b2e 100644 --- a/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs +++ b/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs @@ -1,8 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Graphics; -using osu.Framework.Localisation; +using osu.Framework.Allocation; +using osu.Game.Graphics; using osu.Game.Resources.Localisation.Web; #nullable enable @@ -11,7 +11,11 @@ namespace osu.Game.Overlays.BeatmapSet { public class SpotlightBeatmapBadge : BeatmapBadge { - public override LocalisableString BadgeText => BeatmapsetsStrings.SpotlightBadgeLabel; - public override Colour4 BadgeColour => Colours.Pink1; + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BadgeText = BeatmapsetsStrings.SpotlightBadgeLabel; + BadgeColour = colours.Pink1; + } } } From 1878578196e157bfb755318d39db742f5e5b74b0 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 21:02:56 +0300 Subject: [PATCH 8/9] Move todo comment to subclasses --- osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs | 2 -- osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs | 1 + osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs b/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs index 2604a58a2b..d19aff3a69 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs @@ -34,8 +34,6 @@ namespace osu.Game.Overlays.BeatmapSet private OsuSpriteText badgeLabel = null!; - // todo: add linking support, to allow redirecting featured artist badge to corresponding track and spotlight badge to wiki page. - protected BeatmapBadge() { AutoSizeAxes = Axes.Both; diff --git a/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs b/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs index 230b8b5243..4f336d85fc 100644 --- a/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs +++ b/osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs @@ -16,6 +16,7 @@ namespace osu.Game.Overlays.BeatmapSet { BadgeText = BeatmapsetsStrings.FeaturedArtistBadgeLabel; BadgeColour = colours.Blue1; + // todo: add linking support to allow redirecting featured artist badge to corresponding track. } } } diff --git a/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs b/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs index 8bfd623b2e..3204f79b21 100644 --- a/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs +++ b/osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs @@ -16,6 +16,7 @@ namespace osu.Game.Overlays.BeatmapSet { BadgeText = BeatmapsetsStrings.SpotlightBadgeLabel; BadgeColour = colours.Pink1; + // todo: add linking support to allow redirecting spotlight badge to https://osu.ppy.sh/wiki/en/Beatmap_Spotlights. } } } From 4bb06873d53d4459268e13305788cb9996d373ec Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 21:54:52 +0300 Subject: [PATCH 9/9] Move badge hierarchy declaration to constructor for safer access --- osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs b/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs index d19aff3a69..a75fc8e888 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs @@ -32,26 +32,22 @@ namespace osu.Game.Overlays.BeatmapSet set => badgeLabel.Colour = value; } - private OsuSpriteText badgeLabel = null!; + private readonly Box background; + private readonly OsuSpriteText badgeLabel; protected BeatmapBadge() { AutoSizeAxes = Axes.Both; - } - [BackgroundDependencyLoader(true)] - private void load(OsuColour colours, OverlayColourProvider? colourProvider) - { InternalChild = new CircularContainer { Masking = true, AutoSizeAxes = Axes.Both, Children = new Drawable[] { - new Box + background = new Box { RelativeSizeAxes = Axes.Both, - Colour = colourProvider?.Background5 ?? colours.Gray2, }, badgeLabel = new OsuSpriteText { @@ -61,5 +57,11 @@ namespace osu.Game.Overlays.BeatmapSet } }; } + + [BackgroundDependencyLoader(true)] + private void load(OsuColour colours, OverlayColourProvider? colourProvider) + { + background.Colour = colourProvider?.Background5 ?? colours.Gray2; + } } }