1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Allow context menus to have visible spacers

This commit is contained in:
Dean Herbert 2023-11-21 14:24:10 +09:00
parent 3d569850b1
commit 405ab499e9
No known key found for this signature in database
8 changed files with 67 additions and 65 deletions

View File

@ -34,51 +34,51 @@ namespace osu.Game.Tests.Visual.Editing
{ {
new MenuItem("File") new MenuItem("File")
{ {
Items = new[] Items = new OsuMenuItem[]
{ {
new EditorMenuItem("Clear All Notes"), new EditorMenuItem("Clear All Notes"),
new EditorMenuItem("Open Difficulty..."), new EditorMenuItem("Open Difficulty..."),
new EditorMenuItem("Save"), new EditorMenuItem("Save"),
new EditorMenuItem("Create a new Difficulty..."), new EditorMenuItem("Create a new Difficulty..."),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem("Revert to Saved"), new EditorMenuItem("Revert to Saved"),
new EditorMenuItem("Revert to Saved (Full)"), new EditorMenuItem("Revert to Saved (Full)"),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem("Test Beatmap"), new EditorMenuItem("Test Beatmap"),
new EditorMenuItem("Open AiMod"), new EditorMenuItem("Open AiMod"),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem("Upload Beatmap..."), new EditorMenuItem("Upload Beatmap..."),
new EditorMenuItem("Export Package"), new EditorMenuItem("Export Package"),
new EditorMenuItem("Export Map Package"), new EditorMenuItem("Export Map Package"),
new EditorMenuItem("Import from..."), new EditorMenuItem("Import from..."),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem("Open Song Folder"), new EditorMenuItem("Open Song Folder"),
new EditorMenuItem("Open .osu in Notepad"), new EditorMenuItem("Open .osu in Notepad"),
new EditorMenuItem("Open .osb in Notepad"), new EditorMenuItem("Open .osb in Notepad"),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem("Exit"), new EditorMenuItem("Exit"),
} }
}, },
new MenuItem("Timing") new MenuItem("Timing")
{ {
Items = new[] Items = new OsuMenuItem[]
{ {
new EditorMenuItem("Time Signature"), new EditorMenuItem("Time Signature"),
new EditorMenuItem("Metronome Clicks"), new EditorMenuItem("Metronome Clicks"),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem("Add Timing Section"), new EditorMenuItem("Add Timing Section"),
new EditorMenuItem("Add Inheriting Section"), new EditorMenuItem("Add Inheriting Section"),
new EditorMenuItem("Reset Current Section"), new EditorMenuItem("Reset Current Section"),
new EditorMenuItem("Delete Timing Section"), new EditorMenuItem("Delete Timing Section"),
new EditorMenuItem("Resnap Current Section"), new EditorMenuItem("Resnap Current Section"),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem("Timing Setup"), new EditorMenuItem("Timing Setup"),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem("Resnap All Notes", MenuItemType.Destructive), new EditorMenuItem("Resnap All Notes", MenuItemType.Destructive),
new EditorMenuItem("Move all notes in time...", MenuItemType.Destructive), new EditorMenuItem("Move all notes in time...", MenuItemType.Destructive),
new EditorMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive), new EditorMenuItem("Recalculate Slider Lengths", MenuItemType.Destructive),
new EditorMenuItem("Delete All Timing Sections", MenuItemType.Destructive), new EditorMenuItem("Delete All Timing Sections", MenuItemType.Destructive),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem("Set Current Position as Preview Point"), new EditorMenuItem("Set Current Position as Preview Point"),
} }
}, },

View File

@ -6,13 +6,15 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osuTK; using osuTK;
using osuTK.Graphics;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
@ -78,6 +80,9 @@ namespace osu.Game.Graphics.UserInterface
{ {
case StatefulMenuItem stateful: case StatefulMenuItem stateful:
return new DrawableStatefulMenuItem(stateful); return new DrawableStatefulMenuItem(stateful);
case OsuMenuItemSpacer spacer:
return new DrawableSpacer(spacer);
} }
return new DrawableOsuMenuItem(item); return new DrawableOsuMenuItem(item);
@ -89,5 +94,28 @@ namespace osu.Game.Graphics.UserInterface
{ {
Anchor = Direction == Direction.Horizontal ? Anchor.BottomLeft : Anchor.TopRight Anchor = Direction == Direction.Horizontal ? Anchor.BottomLeft : Anchor.TopRight
}; };
protected partial class DrawableSpacer : DrawableOsuMenuItem
{
public DrawableSpacer(MenuItem item)
: base(item)
{
Scale = new Vector2(1, 0.6f);
AddInternal(new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = BackgroundColourHover,
RelativeSizeAxes = Axes.X,
Height = 2f,
Width = 0.8f,
});
}
protected override bool OnHover(HoverEvent e) => true;
protected override bool OnClick(ClickEvent e) => true;
}
} }
} }

View File

@ -0,0 +1,13 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
namespace osu.Game.Graphics.UserInterface
{
public class OsuMenuItemSpacer : OsuMenuItem
{
public OsuMenuItemSpacer()
: base(" ")
{
}
}
}

View File

@ -151,23 +151,23 @@ namespace osu.Game.Overlays.SkinEditor
{ {
new MenuItem(CommonStrings.MenuBarFile) new MenuItem(CommonStrings.MenuBarFile)
{ {
Items = new[] Items = new OsuMenuItem[]
{ {
new EditorMenuItem(Web.CommonStrings.ButtonsSave, MenuItemType.Standard, () => Save()), new EditorMenuItem(Web.CommonStrings.ButtonsSave, MenuItemType.Standard, () => Save()),
new EditorMenuItem(CommonStrings.Export, MenuItemType.Standard, () => skins.ExportCurrentSkin()) { Action = { Disabled = !RuntimeInfo.IsDesktop } }, new EditorMenuItem(CommonStrings.Export, MenuItemType.Standard, () => skins.ExportCurrentSkin()) { Action = { Disabled = !RuntimeInfo.IsDesktop } },
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem(CommonStrings.RevertToDefault, MenuItemType.Destructive, () => dialogOverlay?.Push(new RevertConfirmDialog(revert))), new EditorMenuItem(CommonStrings.RevertToDefault, MenuItemType.Destructive, () => dialogOverlay?.Push(new RevertConfirmDialog(revert))),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem(CommonStrings.Exit, MenuItemType.Standard, () => skinEditorOverlay?.Hide()), new EditorMenuItem(CommonStrings.Exit, MenuItemType.Standard, () => skinEditorOverlay?.Hide()),
}, },
}, },
new MenuItem(CommonStrings.MenuBarEdit) new MenuItem(CommonStrings.MenuBarEdit)
{ {
Items = new[] Items = new OsuMenuItem[]
{ {
undoMenuItem = new EditorMenuItem(CommonStrings.Undo, MenuItemType.Standard, Undo), undoMenuItem = new EditorMenuItem(CommonStrings.Undo, MenuItemType.Standard, Undo),
redoMenuItem = new EditorMenuItem(CommonStrings.Redo, MenuItemType.Standard, Redo), redoMenuItem = new EditorMenuItem(CommonStrings.Redo, MenuItemType.Standard, Redo),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
cutMenuItem = new EditorMenuItem(CommonStrings.Cut, MenuItemType.Standard, Cut), cutMenuItem = new EditorMenuItem(CommonStrings.Cut, MenuItemType.Standard, Cut),
copyMenuItem = new EditorMenuItem(CommonStrings.Copy, MenuItemType.Standard, Copy), copyMenuItem = new EditorMenuItem(CommonStrings.Copy, MenuItemType.Standard, Copy),
pasteMenuItem = new EditorMenuItem(CommonStrings.Paste, MenuItemType.Standard, Paste), pasteMenuItem = new EditorMenuItem(CommonStrings.Paste, MenuItemType.Standard, Paste),

View File

@ -14,7 +14,6 @@ using osu.Framework.Utils;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Screens.Edit.Components.Menus;
using osu.Game.Screens.Edit.Compose.Components; using osu.Game.Screens.Edit.Compose.Components;
using osu.Game.Skinning; using osu.Game.Skinning;
using osu.Game.Utils; using osu.Game.Utils;
@ -249,7 +248,7 @@ namespace osu.Game.Overlays.SkinEditor
Items = createAnchorItems((d, o) => ((Drawable)d).Origin == o, applyOrigins).ToArray() Items = createAnchorItems((d, o) => ((Drawable)d).Origin == o, applyOrigins).ToArray()
}; };
yield return new EditorMenuItemSpacer(); yield return new OsuMenuItemSpacer();
yield return new OsuMenuItem("Reset position", MenuItemType.Standard, () => yield return new OsuMenuItem("Reset position", MenuItemType.Standard, () =>
{ {
@ -277,13 +276,13 @@ namespace osu.Game.Overlays.SkinEditor
} }
}); });
yield return new EditorMenuItemSpacer(); yield return new OsuMenuItemSpacer();
yield return new OsuMenuItem("Bring to front", MenuItemType.Standard, () => skinEditor.BringSelectionToFront()); yield return new OsuMenuItem("Bring to front", MenuItemType.Standard, () => skinEditor.BringSelectionToFront());
yield return new OsuMenuItem("Send to back", MenuItemType.Standard, () => skinEditor.SendSelectionToBack()); yield return new OsuMenuItem("Send to back", MenuItemType.Standard, () => skinEditor.SendSelectionToBack());
yield return new EditorMenuItemSpacer(); yield return new OsuMenuItemSpacer();
foreach (var item in base.GetContextMenuItemsForSelection(selection)) foreach (var item in base.GetContextMenuItemsForSelection(selection))
yield return item; yield return item;

View File

@ -4,11 +4,9 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -151,7 +149,7 @@ namespace osu.Game.Screens.Edit.Components.Menus
{ {
switch (item) switch (item)
{ {
case EditorMenuItemSpacer spacer: case OsuMenuItemSpacer spacer:
return new DrawableSpacer(spacer); return new DrawableSpacer(spacer);
case StatefulMenuItem stateful: case StatefulMenuItem stateful:
@ -195,29 +193,6 @@ namespace osu.Game.Screens.Edit.Components.Menus
Foreground.Padding = new MarginPadding { Vertical = 2 }; Foreground.Padding = new MarginPadding { Vertical = 2 };
} }
} }
private partial class DrawableSpacer : DrawableOsuMenuItem
{
public DrawableSpacer(MenuItem item)
: base(item)
{
Scale = new Vector2(1, 0.6f);
AddInternal(new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = BackgroundColourHover,
RelativeSizeAxes = Axes.X,
Height = 2f,
Width = 0.8f,
});
}
protected override bool OnHover(HoverEvent e) => true;
protected override bool OnClick(ClickEvent e) => true;
}
} }
} }
} }

View File

@ -1,13 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
namespace osu.Game.Screens.Edit.Components.Menus
{
public class EditorMenuItemSpacer : EditorMenuItem
{
public EditorMenuItemSpacer()
: base(" ")
{
}
}
}

View File

@ -321,7 +321,7 @@ namespace osu.Game.Screens.Edit
{ {
undoMenuItem = new EditorMenuItem(CommonStrings.Undo, MenuItemType.Standard, Undo), undoMenuItem = new EditorMenuItem(CommonStrings.Undo, MenuItemType.Standard, Undo),
redoMenuItem = new EditorMenuItem(CommonStrings.Redo, MenuItemType.Standard, Redo), redoMenuItem = new EditorMenuItem(CommonStrings.Redo, MenuItemType.Standard, Redo),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
cutMenuItem = new EditorMenuItem(CommonStrings.Cut, MenuItemType.Standard, Cut), cutMenuItem = new EditorMenuItem(CommonStrings.Cut, MenuItemType.Standard, Cut),
copyMenuItem = new EditorMenuItem(CommonStrings.Copy, MenuItemType.Standard, Copy), copyMenuItem = new EditorMenuItem(CommonStrings.Copy, MenuItemType.Standard, Copy),
pasteMenuItem = new EditorMenuItem(CommonStrings.Paste, MenuItemType.Standard, Paste), pasteMenuItem = new EditorMenuItem(CommonStrings.Paste, MenuItemType.Standard, Paste),
@ -1005,12 +1005,12 @@ namespace osu.Game.Screens.Edit
{ {
createDifficultyCreationMenu(), createDifficultyCreationMenu(),
createDifficultySwitchMenu(), createDifficultySwitchMenu(),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem(EditorStrings.DeleteDifficulty, MenuItemType.Standard, deleteDifficulty) { Action = { Disabled = Beatmap.Value.BeatmapSetInfo.Beatmaps.Count < 2 } }, new EditorMenuItem(EditorStrings.DeleteDifficulty, MenuItemType.Standard, deleteDifficulty) { Action = { Disabled = Beatmap.Value.BeatmapSetInfo.Beatmaps.Count < 2 } },
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem(WebCommonStrings.ButtonsSave, MenuItemType.Standard, () => Save()), new EditorMenuItem(WebCommonStrings.ButtonsSave, MenuItemType.Standard, () => Save()),
createExportMenu(), createExportMenu(),
new EditorMenuItemSpacer(), new OsuMenuItemSpacer(),
new EditorMenuItem(CommonStrings.Exit, MenuItemType.Standard, this.Exit) new EditorMenuItem(CommonStrings.Exit, MenuItemType.Standard, this.Exit)
}; };
@ -1130,7 +1130,7 @@ namespace osu.Game.Screens.Edit
foreach (var rulesetBeatmaps in groupedOrderedBeatmaps) foreach (var rulesetBeatmaps in groupedOrderedBeatmaps)
{ {
if (difficultyItems.Count > 0) if (difficultyItems.Count > 0)
difficultyItems.Add(new EditorMenuItemSpacer()); difficultyItems.Add(new OsuMenuItemSpacer());
foreach (var beatmap in rulesetBeatmaps) foreach (var beatmap in rulesetBeatmaps)
{ {