Convert get-only virtual properties to avoid DI order dependency

This commit is contained in:
Salman Ahmed
2022-05-14 21:01:29 +03:00
parent 88ba84ac9c
commit 441957e18e
4 changed files with 37 additions and 25 deletions

View File

@ -16,21 +16,23 @@ namespace osu.Game.Overlays.BeatmapSet
{ {
public abstract class BeatmapBadge : CompositeDrawable public abstract class BeatmapBadge : CompositeDrawable
{ {
[Resolved]
protected OsuColour Colours { get; private set; } = null!;
[Resolved(canBeNull: true)]
protected OverlayColourProvider? ColourProvider { get; private set; }
/// <summary> /// <summary>
/// The text displayed on the badge's label. /// The text displayed on the badge's label.
/// </summary> /// </summary>
public abstract LocalisableString BadgeText { get; } public LocalisableString BadgeText
{
set => badgeLabel.Text = value.ToUpper();
}
/// <summary> /// <summary>
/// The colour of the badge's label. /// The colour of the badge's label.
/// </summary> /// </summary>
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. // 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)] [BackgroundDependencyLoader(true)]
private void load() private void load(OsuColour colours, OverlayColourProvider? colourProvider)
{ {
InternalChild = new CircularContainer InternalChild = new CircularContainer
{ {
@ -51,14 +53,12 @@ namespace osu.Game.Overlays.BeatmapSet
new Box new Box
{ {
RelativeSizeAxes = Axes.Both, 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), Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold),
Margin = new MarginPadding { Horizontal = 10, Vertical = 2 }, Margin = new MarginPadding { Horizontal = 10, Vertical = 2 },
Text = BadgeText.ToUpper(),
Colour = BadgeColour,
} }
} }
}; };

View File

@ -1,8 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics; using osu.Framework.Allocation;
using osu.Framework.Localisation; using osu.Game.Graphics;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
#nullable enable #nullable enable
@ -11,7 +11,11 @@ namespace osu.Game.Overlays.BeatmapSet
{ {
public class ExplicitContentBeatmapBadge : BeatmapBadge public class ExplicitContentBeatmapBadge : BeatmapBadge
{ {
public override LocalisableString BadgeText => BeatmapsetsStrings.NsfwBadgeLabel; [BackgroundDependencyLoader]
public override Colour4 BadgeColour => Colours.Orange2; private void load(OsuColour colours)
{
BadgeText = BeatmapsetsStrings.NsfwBadgeLabel;
BadgeColour = colours.Orange2;
}
} }
} }

View File

@ -1,8 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics; using osu.Framework.Allocation;
using osu.Framework.Localisation; using osu.Game.Graphics;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
#nullable enable #nullable enable
@ -11,7 +11,11 @@ namespace osu.Game.Overlays.BeatmapSet
{ {
public class FeaturedArtistBeatmapBadge : BeatmapBadge public class FeaturedArtistBeatmapBadge : BeatmapBadge
{ {
public override LocalisableString BadgeText => BeatmapsetsStrings.FeaturedArtistBadgeLabel; [BackgroundDependencyLoader]
public override Colour4 BadgeColour => Colours.Blue1; private void load(OsuColour colours)
{
BadgeText = BeatmapsetsStrings.FeaturedArtistBadgeLabel;
BadgeColour = colours.Blue1;
}
} }
} }

View File

@ -1,8 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics; using osu.Framework.Allocation;
using osu.Framework.Localisation; using osu.Game.Graphics;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
#nullable enable #nullable enable
@ -11,7 +11,11 @@ namespace osu.Game.Overlays.BeatmapSet
{ {
public class SpotlightBeatmapBadge : BeatmapBadge public class SpotlightBeatmapBadge : BeatmapBadge
{ {
public override LocalisableString BadgeText => BeatmapsetsStrings.SpotlightBadgeLabel; [BackgroundDependencyLoader]
public override Colour4 BadgeColour => Colours.Pink1; private void load(OsuColour colours)
{
BadgeText = BeatmapsetsStrings.SpotlightBadgeLabel;
BadgeColour = colours.Pink1;
}
} }
} }