Skip to content

Commit

Permalink
Convert get-only virtual properties to avoid DI order dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed May 14, 2022
1 parent 88ba84a commit 441957e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
26 changes: 13 additions & 13 deletions osu.Game/Overlays/BeatmapSet/BeatmapBadge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/// <summary>
/// The text displayed on the badge's label.
/// </summary>
public abstract LocalisableString BadgeText { get; }
public LocalisableString BadgeText
{
set => badgeLabel.Text = value.ToUpper();
}

/// <summary>
/// The colour of the badge's label.
/// </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.

Expand All @@ -40,7 +42,7 @@ protected BeatmapBadge()
}

[BackgroundDependencyLoader(true)]
private void load()
private void load(OsuColour colours, OverlayColourProvider? colourProvider)
{
InternalChild = new CircularContainer
{
Expand All @@ -51,14 +53,12 @@ private void load()
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,
}
}
};
Expand Down
12 changes: 8 additions & 4 deletions osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapBadge.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// 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.

using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Allocation;
using osu.Game.Graphics;
using osu.Game.Resources.Localisation.Web;

#nullable enable
Expand All @@ -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;
}
}
}
12 changes: 8 additions & 4 deletions osu.Game/Overlays/BeatmapSet/FeaturedArtistBeatmapBadge.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// 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.

using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Allocation;
using osu.Game.Graphics;
using osu.Game.Resources.Localisation.Web;

#nullable enable
Expand All @@ -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;
}
}
}
12 changes: 8 additions & 4 deletions osu.Game/Overlays/BeatmapSet/SpotlightBeatmapBadge.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// 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.

using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Allocation;
using osu.Game.Graphics;
using osu.Game.Resources.Localisation.Web;

#nullable enable
Expand All @@ -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;
}
}
}

0 comments on commit 441957e

Please sign in to comment.