1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +08:00

Add context menu to beatmap set header

This commit is contained in:
Dean Herbert 2017-08-30 20:41:41 +09:00
parent 2742fe46cf
commit 07da29ea1c
4 changed files with 37 additions and 6 deletions

View File

@ -23,6 +23,8 @@ namespace osu.Game.Beatmaps.Drawables
/// </summary>
public Action<BeatmapInfo> StartRequested;
public Action<WorkingBeatmap> DeleteRequested;
public BeatmapSetHeader Header;
private BeatmapGroupState state;
@ -66,6 +68,7 @@ namespace osu.Game.Beatmaps.Drawables
Header = new BeatmapSetHeader(beatmap)
{
GainedSelection = headerGainedSelection,
DeleteRequested = b => DeleteRequested(b),
RelativeSizeAxes = Axes.X,
};

View File

@ -9,16 +9,22 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Graphics.Sprites;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Beatmaps.Drawables
{
public class BeatmapSetHeader : Panel
public class BeatmapSetHeader : Panel, IHasContextMenu
{
public Action<BeatmapSetHeader> GainedSelection;
public Action<WorkingBeatmap> DeleteRequested;
private readonly SpriteText title;
private readonly SpriteText artist;
@ -148,5 +154,20 @@ namespace osu.Game.Beatmaps.Drawables
foreach (var p in panels)
difficultyIcons.Add(new DifficultyIcon(p.Beatmap));
}
public MenuItem[] ContextMenuItems
{
get
{
List<MenuItem> items = new List<MenuItem>();
if (State == PanelSelectedState.NotSelected)
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => State = PanelSelectedState.Selected));
items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => DeleteRequested?.Invoke(beatmap)));
return items.ToArray();
}
}
}
}

View File

@ -140,6 +140,8 @@ namespace osu.Game.Screens.Select
public Action StartRequested;
public Action<WorkingBeatmap> DeleteRequested;
public void SelectNext(int direction = 1, bool skipDifficulties = true)
{
if (groups.All(g => g.State == BeatmapGroupState.Hidden))
@ -305,6 +307,7 @@ namespace osu.Game.Screens.Select
{
SelectionChanged = (g, p) => selectGroup(g, p),
StartRequested = b => StartRequested?.Invoke(),
DeleteRequested = b => DeleteRequested?.Invoke(b),
State = BeatmapGroupState.Collapsed
};
}

View File

@ -106,6 +106,7 @@ namespace osu.Game.Screens.Select
Origin = Anchor.CentreRight,
SelectionChanged = carouselSelectionChanged,
BeatmapsChanged = carouselBeatmapsLoaded,
DeleteRequested = b => promptDelete(b),
StartRequested = () => carouselRaisedStart(),
});
Add(FilterControl = new FilterControl
@ -163,7 +164,7 @@ namespace osu.Game.Screens.Select
Footer.AddButton(@"random", colours.Green, triggerRandom, Key.F2);
Footer.AddButton(@"options", colours.Blue, BeatmapOptions.ToggleVisibility, Key.F3);
BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, promptDelete, Key.Number4, float.MaxValue);
BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, () => promptDelete(Beatmap), Key.Number4, float.MaxValue);
}
if (manager == null)
@ -389,10 +390,12 @@ namespace osu.Game.Screens.Select
Beatmap.SetDefault();
}
private void promptDelete()
private void promptDelete(WorkingBeatmap beatmap)
{
if (Beatmap != null && !Beatmap.IsDefault)
dialogOverlay?.Push(new BeatmapDeleteDialog(Beatmap));
if (beatmap == null)
return;
dialogOverlay?.Push(new BeatmapDeleteDialog(beatmap));
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
@ -408,7 +411,8 @@ namespace osu.Game.Screens.Select
case Key.Delete:
if (state.Keyboard.ShiftPressed)
{
promptDelete();
if (!Beatmap.IsDefault)
promptDelete(Beatmap);
return true;
}
break;