diff --git a/PerformanceCalculatorGUI/Components/BeatmapCard.cs b/PerformanceCalculatorGUI/Components/BeatmapCard.cs new file mode 100644 index 0000000..1b1620a --- /dev/null +++ b/PerformanceCalculatorGUI/Components/BeatmapCard.cs @@ -0,0 +1,96 @@ +using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; +using osu.Framework.Input.Events; +using osu.Framework.Platform; +using osu.Game.Beatmaps; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays; + +namespace PerformanceCalculatorGUI.Components +{ + internal class BeatmapCard : OsuClickableContainer + { + private readonly ProcessorWorkingBeatmap beatmap; + + [Resolved(canBeNull: true)] + private OverlayColourProvider colourProvider { get; set; } + + [Resolved] + private OsuColour colours { get; set; } + + [Resolved] + private LargeTextureStore textures { get; set; } + + public BeatmapCard(ProcessorWorkingBeatmap beatmap) : base(HoverSampleSet.Button) + { + this.beatmap = beatmap; + RelativeSizeAxes = Axes.X; + Height = 40; + CornerRadius = ExtendedLabelledTextBox.CORNER_RADIUS; + } + + [BackgroundDependencyLoader] + private void load(GameHost host) + { + Masking = true; + BorderColour = colourProvider?.Light1 ?? colours.GreyVioletLighter; + + AddRange(new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colourProvider?.Background5 ?? colours.Gray1 + }, + new BufferedContainer + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.3f, + Children = new Drawable[] + { + new Sprite + { + RelativeSizeAxes = Axes.Both, + Texture = textures.Get($"https://assets.ppy.sh/beatmaps/{beatmap.BeatmapSetInfo.OnlineID}/covers/cover.jpg"), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + FillMode = FillMode.Fill + } + } + }, + new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold), + Shadow = false, + Text = beatmap.Metadata.GetDisplayTitle(), + Margin = new MarginPadding(10) + } + }); + + Action = () => { host.OpenUrlExternally($"https://osu.ppy.sh/beatmaps/{beatmap.BeatmapInfo.OnlineID}"); }; + } + + protected override bool OnHover(HoverEvent e) + { + BorderThickness = 2; + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + BorderThickness = 0; + base.OnHoverLost(e); + } + } +} diff --git a/PerformanceCalculatorGUI/Screens/BeatmapLeaderboardScreen.cs b/PerformanceCalculatorGUI/Screens/BeatmapLeaderboardScreen.cs index c4b0ab7..d8f3129 100644 --- a/PerformanceCalculatorGUI/Screens/BeatmapLeaderboardScreen.cs +++ b/PerformanceCalculatorGUI/Screens/BeatmapLeaderboardScreen.cs @@ -12,7 +12,6 @@ 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.Logging; using osu.Game.Graphics.Containers; @@ -26,7 +25,6 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; using osu.Game.Users; using osu.Game.Utils; -using osuTK; using PerformanceCalculatorGUI.Components; using PerformanceCalculatorGUI.Configuration; @@ -38,9 +36,13 @@ namespace PerformanceCalculatorGUI.Screens private StatefulButton calculationButton; private VerboseLoadingLayer loadingLayer; + private GridContainer layout; + private OsuScrollContainer scrollContainer; private ScoreTable scoreTable; - private BufferedContainer background; + private Box background; + private Container beatmapPanelContainer; + private BeatmapCard beatmapPanel; private CancellationTokenSource calculationCancellatonToken; @@ -84,11 +86,11 @@ namespace PerformanceCalculatorGUI.Screens { InternalChildren = new Drawable[] { - new GridContainer + layout = new GridContainer { RelativeSizeAxes = Axes.Both, ColumnDimensions = new[] { new Dimension() }, - RowDimensions = new[] { new Dimension(GridSizeMode.Absolute, 40), new Dimension() }, + RowDimensions = new[] { new Dimension(GridSizeMode.Absolute, 40), new Dimension(GridSizeMode.Absolute), new Dimension() }, Content = new[] { new Drawable[] @@ -132,13 +134,29 @@ namespace PerformanceCalculatorGUI.Screens }, new Drawable[] { - new OsuScrollContainer + beatmapPanelContainer = new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y + } + }, + new Drawable[] + { + scrollContainer = new OsuScrollContainer { RelativeSizeAxes = Axes.Both, - Child = scoreTable = new ScoreTable + Children = new Drawable[] { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colourProvider.Background5 + }, + scoreTable = new ScoreTable + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + } } } } @@ -180,7 +198,15 @@ namespace PerformanceCalculatorGUI.Screens var working = ProcessorWorkingBeatmap.FromFileOrId(beatmapIdTextBox.Current.Value, cachePath: configManager.GetBindable(Settings.CachePath).Value); - Schedule(() => loadBackground(working.BeatmapInfo?.BeatmapSet?.OnlineID.ToString())); + Schedule(() => + { + if (beatmapPanel != null) + beatmapPanelContainer.Remove(beatmapPanel); + + beatmapPanelContainer.Add(beatmapPanel = new BeatmapCard(working)); + + layout.RowDimensions = new[] { new Dimension(GridSizeMode.Absolute, 40), new Dimension(GridSizeMode.AutoSize), new Dimension() }; + }); var random = false; @@ -237,47 +263,6 @@ namespace PerformanceCalculatorGUI.Screens }, token); } - private void loadBackground(string beatmapId) - { - if (background is not null) - { - RemoveInternal(background); - } - - if (!string.IsNullOrEmpty(beatmapId)) - { - LoadComponentAsync(background = new BufferedContainer - { - RelativeSizeAxes = Axes.Both, - Depth = 99, - BlurSigma = new Vector2(6), - Children = new Drawable[] - { - new Sprite - { - RelativeSizeAxes = Axes.Both, - Texture = textures.Get($"https://assets.ppy.sh/beatmaps/{beatmapId}/covers/cover.jpg"), - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - FillMode = FillMode.Fill - }, - new Box - { - RelativeSizeAxes = Axes.Both, - Colour = colourProvider.Background6, - Alpha = 0.9f - }, - } - }).ContinueWith(_ => - { - Schedule(() => - { - AddInternal(background); - }); - }); - } - } - private List generateRandomScores(ProcessorWorkingBeatmap working) { var scores = new List();