From 522f106f746f34a3a80f64ff236704c506103b30 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 14 Oct 2018 00:40:33 +0900 Subject: [PATCH] Add initial version of beatmap card --- .../TestCaseBeatmapPanel.cs | 42 +++++++ .../Components/TournamentBeatmapPanel.cs | 110 ++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 osu.Game.Tournament.Tests/TestCaseBeatmapPanel.cs create mode 100644 osu.Game.Tournament/Components/TournamentBeatmapPanel.cs diff --git a/osu.Game.Tournament.Tests/TestCaseBeatmapPanel.cs b/osu.Game.Tournament.Tests/TestCaseBeatmapPanel.cs new file mode 100644 index 0000000000..8298cbd8ea --- /dev/null +++ b/osu.Game.Tournament.Tests/TestCaseBeatmapPanel.cs @@ -0,0 +1,42 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Beatmaps; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Rulesets; +using osu.Game.Tests.Visual; +using osu.Game.Tournament.Components; + +namespace osu.Game.Tournament.Tests +{ + public class TestCaseBeatmapPanel : OsuTestCase + { + [Resolved] + protected APIAccess API { get; set; } + + [Resolved] + protected RulesetStore Rulesets { get; set; } + + [BackgroundDependencyLoader] + private void load() + { + var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = 1091460 }); + req.Success += success; + API.Queue(req); + } + + private void success(APIBeatmap apiBeatmap) + { + var beatmap = apiBeatmap.ToBeatmap(Rulesets); + Add(new TournamentBeatmapPanel(beatmap) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre + }); + } + } +} diff --git a/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs b/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs new file mode 100644 index 0000000000..5eb597a3c6 --- /dev/null +++ b/osu.Game.Tournament/Components/TournamentBeatmapPanel.cs @@ -0,0 +1,110 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Drawables; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using OpenTK.Graphics; + +namespace osu.Game.Tournament.Components +{ + public class TournamentBeatmapPanel : CompositeDrawable + { + private readonly BeatmapInfo beatmap; + private const float horizontal_padding = 10; + private const float vertical_padding = 5; + + public TournamentBeatmapPanel(BeatmapInfo beatmap) + { + this.beatmap = beatmap; + Width = 400; + Height = 50; + } + + [BackgroundDependencyLoader] + private void load() + { + CornerRadius = 25; + Masking = true; + + AddRangeInternal(new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + }, + new UpdateableBeatmapSetCover + { + RelativeSizeAxes = Axes.Both, + Colour = OsuColour.Gray(0.5f), + BeatmapSet = beatmap.BeatmapSet, + }, + new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Padding = new MarginPadding(vertical_padding), + Direction = FillDirection.Vertical, + Children = new Drawable[] + { + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Text = new LocalisedString(( + $"{beatmap.Metadata.ArtistUnicode} - {beatmap.Metadata.TitleUnicode}", + $"{beatmap.Metadata.Artist} - {beatmap.Metadata.Title}")), + Font = @"Exo2.0-BoldItalic", + }, + new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Padding = new MarginPadding(vertical_padding), + Direction = FillDirection.Horizontal, + Children = new Drawable[] + { + new OsuSpriteText + { + Text = "mapper", + Font = @"Exo2.0-RegularItalic", + Padding = new MarginPadding { Right = 5 }, + TextSize = 14 + }, + new OsuSpriteText + { + Text = beatmap.Metadata.AuthorString, + Font = @"Exo2.0-BoldItalic", + Padding = new MarginPadding { Right = 20 }, + TextSize = 14 + }, + new OsuSpriteText + { + Text = "difficulty", + Font = @"Exo2.0-RegularItalic", + Padding = new MarginPadding { Right = 5 }, + TextSize = 14 + }, + new OsuSpriteText + { + Text = beatmap.Version, + Font = @"Exo2.0-BoldItalic", + TextSize = 14 + }, + } + } + }, + }, + }); + } + } +}