-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1940 from andy840119/implement-beatmap-covre
Implement the drawable to show the beatmap cover and some basic info.
- Loading branch information
Showing
2 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneBeatmapCoverInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
121
osu.Game.Rulesets.Karaoke/UI/Components/BeatmapCoverInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |