1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 04:02:59 +08:00

Prefer composite over inheritance for drawable parts

This commit is contained in:
ekrctb 2021-09-09 12:51:21 +09:00
parent 210640af09
commit 52bb02baed
4 changed files with 69 additions and 52 deletions

View File

@ -1,32 +0,0 @@
// 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 JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osuTK.Graphics;
namespace osu.Game.Overlays.BeatmapSet
{
public class BeatmapSetBadgePill : CircularContainer
{
public BeatmapSetBadgePill()
{
AutoSizeAxes = Axes.Both;
Masking = true;
}
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] OsuColour colours, [CanBeNull] OverlayColourProvider colourProvider)
{
Add(new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider?.Background5 ?? colours?.Gray2 ?? Color4.DarkGray,
});
}
}
}

View File

@ -0,0 +1,45 @@
// 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 JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osuTK.Graphics;
namespace osu.Game.Overlays.BeatmapSet
{
public class BeatmapSetBadgePillContainer : CircularContainer
{
protected override Container<Drawable> Content => contentContainer;
private readonly Box background;
private readonly Container contentContainer;
public BeatmapSetBadgePillContainer()
{
Masking = true;
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
contentContainer = new Container
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 10f, Vertical = 2f },
}
};
}
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] OsuColour colours, [CanBeNull] OverlayColourProvider colourProvider)
{
background.Colour = colourProvider?.Background5 ?? colours?.Gray2 ?? Color4.DarkGray;
}
}
}

View File

@ -1,27 +1,29 @@
// 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.Allocation;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.BeatmapSet
{
public class ExplicitContentBeatmapPill : BeatmapSetBadgePill
public class ExplicitContentBeatmapPill : CompositeDrawable
{
[BackgroundDependencyLoader]
private void load()
public ExplicitContentBeatmapPill()
{
Add(new OsuSpriteText
AutoSizeAxes = Axes.Both;
InternalChild = new BeatmapSetBadgePillContainer
{
Margin = new MarginPadding { Horizontal = 10f, Vertical = 2f },
Text = BeatmapsetsStrings.NsfwBadgeLabel.ToUpper(),
Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold),
Colour = OverlayColourProvider.Orange.Colour2,
});
Child = new OsuSpriteText
{
Text = BeatmapsetsStrings.NsfwBadgeLabel.ToUpper(),
Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold),
Colour = OverlayColourProvider.Orange.Colour2,
}
};
}
}
}

View File

@ -1,27 +1,29 @@
// 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.Allocation;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Overlays.BeatmapSet
{
public class FeaturedArtistBeatmapPill : BeatmapSetBadgePill
public class FeaturedArtistBeatmapPill : CompositeDrawable
{
[BackgroundDependencyLoader]
private void load()
public FeaturedArtistBeatmapPill()
{
Add(new OsuSpriteText
AutoSizeAxes = Axes.Both;
InternalChild = new BeatmapSetBadgePillContainer
{
Margin = new MarginPadding { Horizontal = 10f, Vertical = 2f },
Text = BeatmapsetsStrings.FeaturedArtistBadgeLabel.ToUpper(),
Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold),
Colour = OverlayColourProvider.Blue.Colour1
});
Child = new OsuSpriteText
{
Text = BeatmapsetsStrings.FeaturedArtistBadgeLabel.ToUpper(),
Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold),
Colour = OverlayColourProvider.Blue.Colour1
}
};
}
}
}