1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 00:53:22 +08:00

Add collection context menu to room playlist items

This commit is contained in:
Salman Ahmed 2022-07-08 01:40:11 +03:00
parent a94fb62be3
commit 1d0f2e359a

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
@ -15,11 +16,13 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Collections;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
@ -38,7 +41,7 @@ using osuTK.Graphics;
namespace osu.Game.Screens.OnlinePlay
{
public class DrawableRoomPlaylistItem : OsuRearrangeableListItem<PlaylistItem>
public class DrawableRoomPlaylistItem : OsuRearrangeableListItem<PlaylistItem>, IHasContextMenu
{
public const float HEIGHT = 50;
@ -90,6 +93,8 @@ namespace osu.Game.Screens.OnlinePlay
private PanelBackground panelBackground;
private FillFlowContainer mainFillFlow;
private BeatmapDownloadTracker downloadTracker;
[Resolved]
private RulesetStore rulesets { get; set; }
@ -102,6 +107,12 @@ namespace osu.Game.Screens.OnlinePlay
[Resolved]
private BeatmapLookupCache beatmapLookupCache { get; set; }
[Resolved(CanBeNull = true)]
private CollectionManager collectionManager { get; set; }
[Resolved(CanBeNull = true)]
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
protected override bool ShouldBeConsideredForInput(Drawable child) => AllowReordering || AllowDeletion || !AllowSelection || SelectedItem.Value == Model;
public DrawableRoomPlaylistItem(PlaylistItem item)
@ -304,6 +315,15 @@ namespace osu.Game.Screens.OnlinePlay
difficultyIconContainer.FadeInFromZero(500, Easing.OutQuint);
mainFillFlow.FadeInFromZero(500, Easing.OutQuint);
downloadTracker?.RemoveAndDisposeImmediately();
if (beatmap != null)
{
Debug.Assert(beatmap.BeatmapSet != null);
downloadTracker = new BeatmapDownloadTracker(beatmap.BeatmapSet);
AddInternal(downloadTracker);
}
}
protected override Drawable CreateContent()
@ -433,7 +453,7 @@ namespace osu.Game.Screens.OnlinePlay
}
}
},
}
},
};
}
@ -470,6 +490,30 @@ namespace osu.Game.Screens.OnlinePlay
return true;
}
public MenuItem[] ContextMenuItems
{
get
{
List<MenuItem> items = new List<MenuItem>();
if (beatmap != null && collectionManager != null)
{
if (downloadTracker.State.Value == DownloadState.LocallyAvailable)
{
var collectionItems = collectionManager.Collections.Select(c => new CollectionToggleMenuItem(c, beatmap)).Cast<OsuMenuItem>().ToList();
if (manageCollectionsDialog != null)
collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show));
items.Add(new OsuMenuItem("Collections") { Items = collectionItems });
}
else
items.Add(new OsuMenuItem("Download to add to collection") { Action = { Disabled = true } });
}
return items.ToArray();
}
}
public class PlaylistEditButton : GrayButton
{
public PlaylistEditButton()