Skip to content

Commit

Permalink
Add ability to download beatmaps from context menu of beatmap cards
Browse files Browse the repository at this point in the history
Closes ppy#31151 I guess?
  • Loading branch information
peppy committed Jan 10, 2025
1 parent 0509623 commit b82b3cf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
19 changes: 16 additions & 3 deletions osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
Expand All @@ -24,6 +25,8 @@ public abstract partial class BeatmapCard : OsuClickableContainer, IHasContextMe

protected const float WIDTH = 345;

public CollapsibleButtonContainer ButtonContainer { get; set; } = null!;

public IBindable<bool> Expanded { get; }

public readonly APIBeatmapSet BeatmapSet;
Expand Down Expand Up @@ -103,9 +106,19 @@ public static BeatmapCard Create(APIBeatmapSet beatmapSet, BeatmapCardSize size,
}
}

public MenuItem[] ContextMenuItems => new MenuItem[]
public MenuItem[] ContextMenuItems
{
new OsuMenuItem(ContextMenuStrings.ViewBeatmap, MenuItemType.Highlighted, Action),
};
get
{
var menuItems = new List<MenuItem>();

if (ButtonContainer.DownloadButton.Enabled.Value)
menuItems.Add(new OsuMenuItem(ContextMenuStrings.DownloadBeatmap, MenuItemType.Highlighted, () => ButtonContainer.DownloadButton.TriggerClick()));

menuItems.Add(new OsuMenuItem(ContextMenuStrings.ViewBeatmap, MenuItemType.Standard, Action));

return menuItems.ToArray();
}
}
}
}
5 changes: 2 additions & 3 deletions osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public partial class BeatmapCardExtra : BeatmapCard
private readonly BeatmapCardContent content;

private BeatmapCardThumbnail thumbnail = null!;
private CollapsibleButtonContainer buttonContainer = null!;

private GridContainer statisticsContainer = null!;

Expand Down Expand Up @@ -74,7 +73,7 @@ private void load(BeatmapSetOverlay? beatmapSetOverlay)
Spacing = new Vector2(1)
}
},
buttonContainer = new CollapsibleButtonContainer(BeatmapSet)
ButtonContainer = new CollapsibleButtonContainer(BeatmapSet)
{
X = height - CORNER_RADIUS,
Width = WIDTH - height + CORNER_RADIUS,
Expand Down Expand Up @@ -318,7 +317,7 @@ protected override void UpdateState()

bool showDetails = IsHovered || Expanded.Value;

buttonContainer.ShowDetails.Value = showDetails;
ButtonContainer.ShowDetails.Value = showDetails;
thumbnail.Dimmed.Value = showDetails;
}
}
Expand Down
8 changes: 3 additions & 5 deletions osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNano.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override float Width
base.Width = value;

if (LoadState >= LoadState.Ready)
buttonContainer.Width = value;
ButtonContainer.Width = value;
}
}

Expand All @@ -38,8 +38,6 @@ public override float Width
[Cached]
private readonly BeatmapCardContent content;

private CollapsibleButtonContainer buttonContainer = null!;

private FillFlowContainer idleBottomContent = null!;
private BeatmapCardDownloadProgressBar downloadProgressBar = null!;

Expand All @@ -66,7 +64,7 @@ private void load()
Height = height,
Children = new Drawable[]
{
buttonContainer = new CollapsibleButtonContainer(BeatmapSet)
ButtonContainer = new CollapsibleButtonContainer(BeatmapSet)
{
Width = Width,
FavouriteState = { BindTarget = FavouriteState },
Expand Down Expand Up @@ -163,7 +161,7 @@ protected override void UpdateState()

bool showDetails = IsHovered;

buttonContainer.ShowDetails.Value = showDetails;
ButtonContainer.ShowDetails.Value = showDetails;
}
}
}
5 changes: 2 additions & 3 deletions osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public partial class BeatmapCardNormal : BeatmapCard
private readonly BeatmapCardContent content;

private BeatmapCardThumbnail thumbnail = null!;
private CollapsibleButtonContainer buttonContainer = null!;

private FillFlowContainer<BeatmapCardStatistic> statisticsContainer = null!;

Expand Down Expand Up @@ -75,7 +74,7 @@ private void load()
Spacing = new Vector2(1)
}
},
buttonContainer = new CollapsibleButtonContainer(BeatmapSet)
ButtonContainer = new CollapsibleButtonContainer(BeatmapSet)
{
X = HEIGHT - CORNER_RADIUS,
Width = WIDTH - HEIGHT + CORNER_RADIUS,
Expand Down Expand Up @@ -286,7 +285,7 @@ protected override void UpdateState()

bool showDetails = IsHovered || Expanded.Value;

buttonContainer.ShowDetails.Value = showDetails;
ButtonContainer.ShowDetails.Value = showDetails;
thumbnail.Dimmed.Value = showDetails;

statisticsContainer.FadeTo(showDetails ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public partial class CollapsibleButtonContainer : Container

private readonly BeatmapDownloadTracker downloadTracker;

public DownloadButton DownloadButton { get; private set; }

private float buttonsExpandedWidth;

public float ButtonsExpandedWidth
Expand Down Expand Up @@ -108,7 +110,7 @@ public CollapsibleButtonContainer(APIBeatmapSet beatmapSet)
RelativeSizeAxes = Axes.Both,
Height = 0.48f,
},
new DownloadButton(beatmapSet)
DownloadButton = new DownloadButton(beatmapSet)
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Expand Down
5 changes: 5 additions & 0 deletions osu.Game/Localisation/ContextMenuStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public static class ContextMenuStrings
/// </summary>
public static LocalisableString ViewProfile => new TranslatableString(getKey(@"view_profile"), @"View profile");

/// <summary>
/// "Download beatmap"
/// </summary>
public static LocalisableString DownloadBeatmap => new TranslatableString(getKey(@"download_beatmap"), @"Download beatmap");

/// <summary>
/// "View beatmap"
/// </summary>
Expand Down

0 comments on commit b82b3cf

Please sign in to comment.