diff --git a/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneBeatmapCoverInfo.cs b/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneBeatmapCoverInfo.cs new file mode 100644 index 000000000..f522882c8 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneBeatmapCoverInfo.cs @@ -0,0 +1,37 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Overlays; +using osu.Game.Rulesets.Karaoke.UI.Components; +using osu.Game.Tests.Visual; +using osuTK; + +namespace osu.Game.Rulesets.Karaoke.Tests.UI; + +public partial class TestSceneBeatmapCoverInfo : OsuTestScene +{ + [Cached] + private readonly OverlayColourProvider colourProvider = new(OverlayColourScheme.Pink); + + private readonly BeatmapCoverInfo beatmapCoverInfo; + + public TestSceneBeatmapCoverInfo() + { + Add(beatmapCoverInfo = new BeatmapCoverInfo + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre + }); + } + + [Test] + public void TestSize() + { + AddStep("Small size", () => { beatmapCoverInfo.Size = new Vector2(200); }); + AddStep("Medium size", () => { beatmapCoverInfo.Size = new Vector2(300); }); + AddStep("Large size", () => { beatmapCoverInfo.Size = new Vector2(400); }); + } +} diff --git a/osu.Game.Rulesets.Karaoke/UI/Components/BeatmapCoverInfo.cs b/osu.Game.Rulesets.Karaoke/UI/Components/BeatmapCoverInfo.cs new file mode 100644 index 000000000..1ac5fe69f --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/UI/Components/BeatmapCoverInfo.cs @@ -0,0 +1,121 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Framework.Localisation; +using osu.Game.Beatmaps; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Overlays; +using osu.Game.Resources.Localisation.Web; + +namespace osu.Game.Rulesets.Karaoke.UI.Components; + +public partial class BeatmapCoverInfo : CompositeDrawable +{ + public BeatmapCoverInfo() + { + Masking = true; + CornerRadius = 10; + } + + [BackgroundDependencyLoader] + private void load(IBindable beatmap, OverlayColourProvider colourProvider) + { + var metadata = beatmap.Value.Metadata; + + InternalChildren = new Drawable[] + { + new BeatmapCover + { + RelativeSizeAxes = Axes.Both, + }, + new Box + { + Colour = colourProvider.Background6, + Alpha = 0.6f, + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + RelativeSizeAxes = Axes.X, + Height = 64, + }, + new FillFlowContainer + { + Anchor = Anchor.BottomCentre, + Origin = Anchor.BottomCentre, + RelativeSizeAxes = Axes.X, + Height = 64, + Padding = new MarginPadding + { + Horizontal = 10, + }, + Direction = FillDirection.Vertical, + Children = new Drawable[] + { + new OsuSpriteText + { + Text = new RomanisableString(metadata.TitleUnicode, metadata.Title), + Font = OsuFont.Default.With(size: 22.5f, weight: FontWeight.SemiBold), + RelativeSizeAxes = Axes.X, + Truncate = true + }, + new OsuSpriteText + { + Text = createArtistText(metadata), + Font = OsuFont.Default.With(size: 17.5f, weight: FontWeight.SemiBold), + RelativeSizeAxes = Axes.X, + Truncate = true + }, + new LinkFlowContainer(s => + { + s.Shadow = false; + s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold); + }).With(d => + { + d.AutoSizeAxes = Axes.Both; + d.Margin = new MarginPadding { Top = 2 }; + d.AddText("mapped by ", t => t.Colour = colourProvider.Content2); + d.AddUserLink(metadata.Author); + }), + } + }, + }; + } + + private static LocalisableString createArtistText(IBeatmapMetadataInfo beatmapMetadata) + { + var romanisableArtist = new RomanisableString(beatmapMetadata.ArtistUnicode, beatmapMetadata.Artist); + return BeatmapsetsStrings.ShowDetailsByArtist(romanisableArtist); + } + + private partial class BeatmapCover : CompositeDrawable + { + private const string fallback_texture_name = @"Backgrounds/bg1"; + + private readonly Sprite sprite; + + public BeatmapCover() + { + AddInternal(sprite = new Sprite + { + RelativeSizeAxes = Axes.Both, + FillMode = FillMode.Fill, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }); + } + + [BackgroundDependencyLoader] + private void load(IBindable beatmap, LargeTextureStore textures) + { + sprite.Texture = beatmap.Value?.Background ?? textures.Get(fallback_texture_name); + } + } +}