From 441957e18ee58e4c256002d593b583439921b6cc Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 14 May 2022 21:01:29 +0300 Subject: [PATCH] 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; + } } }