Skip to content

Commit

Permalink
Merge pull request #1940 from andy840119/implement-beatmap-covre
Browse files Browse the repository at this point in the history
Implement the drawable to show the beatmap cover and some basic info.
  • Loading branch information
andy840119 authored Apr 16, 2023
2 parents 691679d + 15f5182 commit 86f1032
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
37 changes: 37 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneBeatmapCoverInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) andy840119 <[email protected]>. 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); });
}
}
121 changes: 121 additions & 0 deletions osu.Game.Rulesets.Karaoke/UI/Components/BeatmapCoverInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (c) andy840119 <[email protected]>. 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<WorkingBeatmap> 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<WorkingBeatmap> beatmap, LargeTextureStore textures)
{
sprite.Texture = beatmap.Value?.Background ?? textures.Get(fallback_texture_name);
}
}
}

0 comments on commit 86f1032

Please sign in to comment.