diff --git a/osu.Game/Localisation/SongSelectStrings.cs b/osu.Game/Localisation/SongSelectStrings.cs index 169f4782a7b7..363effecd632 100644 --- a/osu.Game/Localisation/SongSelectStrings.cs +++ b/osu.Game/Localisation/SongSelectStrings.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Localisation; @@ -149,6 +149,11 @@ public static class SongSelectStrings /// public static LocalisableString RestoreAllHidden => new TranslatableString(getKey(@"restore_all_hidden"), @"Restore all hidden"); + /// + /// "Delete all in group" + /// + public static LocalisableString DeleteAllInGroup => new TranslatableString(getKey(@"delete_all_in_group"), @"Delete all in group"); + /// /// "{0} stars" /// diff --git a/osu.Game/Screens/Select/BeatmapCarousel.cs b/osu.Game/Screens/Select/BeatmapCarousel.cs index 2cf8c7d2d041..3de2a5030b5d 100644 --- a/osu.Game/Screens/Select/BeatmapCarousel.cs +++ b/osu.Game/Screens/Select/BeatmapCarousel.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; @@ -63,6 +63,15 @@ public partial class BeatmapCarousel : Carousel /// public int MatchedBeatmapsCount => Filters.Last().BeatmapItemsCount; + /// + /// Retrieves all beatmap sets which are currently contained within the specified . + /// + /// The group to retrieve beatmap sets for. + public IEnumerable GetBeatmapSetsForGroup(GroupDefinition group) + => grouping.SetItems.Keys + .Where(set => EqualityComparer.Default.Equals(set.Group, group)) + .Select(set => set.BeatmapSet); + protected override float GetSpacingBetweenPanels(CarouselItem top, CarouselItem bottom) { // Group panels do not overlap with any other panel but should overlap with themselves. diff --git a/osu.Game/Screens/Select/BeatmapGroupDeleteDialog.cs b/osu.Game/Screens/Select/BeatmapGroupDeleteDialog.cs new file mode 100644 index 000000000000..dd7ac675f6c3 --- /dev/null +++ b/osu.Game/Screens/Select/BeatmapGroupDeleteDialog.cs @@ -0,0 +1,32 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Game.Beatmaps; +using osu.Game.Overlays.Dialog; + +namespace osu.Game.Screens.Select +{ + public partial class BeatmapGroupDeleteDialog : DeletionDialog + { + private readonly IReadOnlyList beatmapSets; + + public BeatmapGroupDeleteDialog(GroupDefinition group, IReadOnlyList beatmapSets) + { + this.beatmapSets = beatmapSets; + BodyText = group.Title; + } + + [BackgroundDependencyLoader] + private void load(BeatmapManager beatmapManager) + { + DangerousAction = () => + { + foreach (var set in beatmapSets) + beatmapManager.Delete(set); + }; + } + } +} + diff --git a/osu.Game/Screens/Select/ISongSelect.cs b/osu.Game/Screens/Select/ISongSelect.cs index d63f241c80ce..945873b7e392 100644 --- a/osu.Game/Screens/Select/ISongSelect.cs +++ b/osu.Game/Screens/Select/ISongSelect.cs @@ -26,6 +26,12 @@ public interface ISongSelect /// void RestoreAllHidden(BeatmapSetInfo beatmapSet); + /// + /// Requests the user for confirmation to delete all beatmap sets contained within the given group. + /// + /// The group whose contents should be deleted. + void DeleteGroup(GroupDefinition group); + /// /// Opens the manage collections dialog. /// diff --git a/osu.Game/Screens/Select/PanelGroup.cs b/osu.Game/Screens/Select/PanelGroup.cs index 0b3fed927803..098f6e30d87c 100644 --- a/osu.Game/Screens/Select/PanelGroup.cs +++ b/osu.Game/Screens/Select/PanelGroup.cs @@ -17,6 +17,7 @@ using osu.Game.Graphics.Carousel; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using osu.Game.Localisation; using osu.Game.Overlays; using osuTK; using osuTK.Graphics; @@ -38,6 +39,9 @@ public partial class PanelGroup : Panel [Resolved] private OverlayColourProvider colourProvider { get; set; } = null!; + [Resolved] + private ISongSelect? songSelect { get; set; } + [BackgroundDependencyLoader] private void load() { @@ -170,7 +174,15 @@ public override MenuItem[] ContextMenuItems return new MenuItem[] { - new OsuMenuItem(Expanded.Value ? WebCommonStrings.ButtonsCollapse.ToSentence() : WebCommonStrings.ButtonsExpand.ToSentence(), MenuItemType.Highlighted, () => TriggerClick()) + new OsuMenuItem( + Expanded.Value ? WebCommonStrings.ButtonsCollapse.ToSentence() : WebCommonStrings.ButtonsExpand.ToSentence(), + MenuItemType.Highlighted, + () => TriggerClick()), + new OsuMenuItemSpacer(), + new OsuMenuItem( + SongSelectStrings.DeleteAllInGroup, + MenuItemType.Destructive, + () => songSelect?.DeleteGroup((GroupDefinition)Item.Model)) }; } } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 51e814b1a177..631cfdf13a82 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -1246,6 +1246,19 @@ protected IEnumerable CreateCollectionMenuActions(BeatmapInfo beatm public void Delete(BeatmapSetInfo beatmapSet) => dialogOverlay?.Push(new BeatmapDeleteDialog(beatmapSet)); + public void DeleteGroup(GroupDefinition group) + { + if (dialogOverlay == null) + return; + + var beatmapSets = carousel.GetBeatmapSetsForGroup(group).ToArray(); + + if (beatmapSets.Length == 0) + return; + + dialogOverlay.Push(new BeatmapGroupDeleteDialog(group, beatmapSets)); + } + public void RestoreAllHidden(BeatmapSetInfo beatmapSet) { foreach (var b in beatmapSet.Beatmaps)