1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 10:03:00 +08:00

Merge pull request #29691 from bdach/hotkeys-in-context-menus

Add hotkey hints to editor menus
This commit is contained in:
Dean Herbert 2024-10-01 19:29:05 +09:00 committed by GitHub
commit 54e68005ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 497 additions and 99 deletions

View File

@ -8,6 +8,7 @@ using osu.Framework.Caching;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Catch.Edit.Blueprints.Components;
@ -172,7 +173,10 @@ namespace osu.Game.Rulesets.Catch.Edit.Blueprints
yield return new OsuMenuItem("Add vertex", MenuItemType.Standard, () =>
{
editablePath.AddVertex(rightMouseDownPosition);
});
})
{
Hotkey = new Hotkey(new KeyCombination(InputKey.Control, InputKey.MouseLeft))
};
}
protected override void Dispose(bool isDisposing)

View File

@ -107,7 +107,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
if (segment.Count == 0)
return;
var first = segment[0];
PathControlPoint first = segment[0];
if (first.Type != PathType.PERFECT_CURVE)
return;
@ -273,10 +273,10 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
if (selectedPieces.Length != 1)
return false;
var selectedPiece = selectedPieces.Single();
var selectedPoint = selectedPiece.ControlPoint;
PathControlPointPiece<T> selectedPiece = selectedPieces.Single();
PathControlPoint selectedPoint = selectedPiece.ControlPoint;
var validTypes = path_types;
PathType?[] validTypes = path_types;
if (selectedPoint == controlPoints[0])
validTypes = validTypes.Where(t => t != null).ToArray();
@ -313,7 +313,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
if (Pieces.All(p => !p.IsSelected.Value))
return false;
var type = path_types[e.Key - Key.Number1];
PathType? type = path_types[e.Key - Key.Number1];
// The first control point can never be inherit type
if (Pieces[0].IsSelected.Value && type == null)
@ -357,7 +357,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
foreach (var p in Pieces.Where(p => p.IsSelected.Value))
{
var pointsInSegment = hitObject.Path.PointsInSegment(p.ControlPoint);
List<PathControlPoint> pointsInSegment = hitObject.Path.PointsInSegment(p.ControlPoint);
int indexInSegment = pointsInSegment.IndexOf(p.ControlPoint);
if (type?.Type == SplineType.PerfectCurve)
@ -412,14 +412,14 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
public void DragInProgress(DragEvent e)
{
Vector2[] oldControlPoints = hitObject.Path.ControlPoints.Select(cp => cp.Position).ToArray();
var oldPosition = hitObject.Position;
Vector2 oldPosition = hitObject.Position;
double oldStartTime = hitObject.StartTime;
if (selectedControlPoints.Contains(hitObject.Path.ControlPoints[0]))
{
// Special handling for selections containing head control point - the position of the hit object changes which means the snapped position and time have to be taken into account
Vector2 newHeadPosition = Parent!.ToScreenSpace(e.MousePosition + (dragStartPositions[0] - dragStartPositions[draggedControlPointIndex]));
var result = positionSnapProvider?.FindSnappedPositionAndTime(newHeadPosition);
SnapResult result = positionSnapProvider?.FindSnappedPositionAndTime(newHeadPosition);
Vector2 movementDelta = Parent!.ToLocalSpace(result?.ScreenSpacePosition ?? newHeadPosition) - hitObject.Position;
@ -428,7 +428,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
for (int i = 1; i < hitObject.Path.ControlPoints.Count; i++)
{
var controlPoint = hitObject.Path.ControlPoints[i];
PathControlPoint controlPoint = hitObject.Path.ControlPoints[i];
// Since control points are relative to the position of the hit object, all points that are _not_ selected
// need to be offset _back_ by the delta corresponding to the movement of the head point.
// All other selected control points (if any) will move together with the head point
@ -439,13 +439,13 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
}
else
{
var result = positionSnapProvider?.FindSnappedPositionAndTime(Parent!.ToScreenSpace(e.MousePosition), SnapType.GlobalGrids);
SnapResult result = positionSnapProvider?.FindSnappedPositionAndTime(Parent!.ToScreenSpace(e.MousePosition), SnapType.GlobalGrids);
Vector2 movementDelta = Parent!.ToLocalSpace(result?.ScreenSpacePosition ?? Parent!.ToScreenSpace(e.MousePosition)) - dragStartPositions[draggedControlPointIndex] - hitObject.Position;
for (int i = 0; i < controlPoints.Count; ++i)
{
var controlPoint = controlPoints[i];
PathControlPoint controlPoint = controlPoints[i];
if (selectedControlPoints.Contains(controlPoint))
controlPoint.Position = dragStartPositions[i] + movementDelta;
}
@ -495,8 +495,10 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
curveTypeItems = new List<MenuItem>();
foreach (PathType? type in path_types)
for (int i = 0; i < path_types.Length; ++i)
{
PathType? type = path_types[i];
// special inherit case
if (type == null)
{
@ -506,7 +508,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
curveTypeItems.Add(new OsuMenuItemSpacer());
}
curveTypeItems.Add(createMenuItemForPathType(type));
curveTypeItems.Add(createMenuItemForPathType(type, InputKey.Number1 + i));
}
if (selectedPieces.Any(piece => piece.ControlPoint.Type?.Type == SplineType.Catmull))
@ -540,7 +542,15 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
return menuItems.ToArray();
CurveTypeMenuItem createMenuItemForPathType(PathType? type) => new CurveTypeMenuItem(type, _ => updatePathTypeOfSelectedPieces(type));
CurveTypeMenuItem createMenuItemForPathType(PathType? type, InputKey? key = null)
{
Hotkey hotkey = default;
if (key != null)
hotkey = new Hotkey(new KeyCombination(InputKey.Alt, key.Value));
return new CurveTypeMenuItem(type, _ => updatePathTypeOfSelectedPieces(type)) { Hotkey = hotkey };
}
}
}

View File

@ -11,6 +11,7 @@ using osu.Framework.Caching;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Audio;
@ -593,8 +594,14 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
changeHandler?.BeginChange();
addControlPoint(lastRightClickPosition);
changeHandler?.EndChange();
}),
new OsuMenuItem("Convert to stream", MenuItemType.Destructive, convertToStream),
})
{
Hotkey = new Hotkey(new KeyCombination(InputKey.Control, InputKey.MouseLeft))
},
new OsuMenuItem("Convert to stream", MenuItemType.Destructive, convertToStream)
{
Hotkey = new Hotkey(new KeyCombination(InputKey.Control, InputKey.Shift, InputKey.F))
},
};
// Always refer to the drawable object's slider body so subsequent movement deltas are calculated with updated positions.

View File

@ -6,6 +6,7 @@ using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
@ -86,10 +87,22 @@ namespace osu.Game.Rulesets.Taiko.Edit
protected override IEnumerable<MenuItem> GetContextMenuItemsForSelection(IEnumerable<SelectionBlueprint<HitObject>> selection)
{
if (selection.All(s => s.Item is Hit))
yield return new TernaryStateToggleMenuItem("Rim") { State = { BindTarget = selectionRimState } };
{
yield return new TernaryStateToggleMenuItem("Rim")
{
State = { BindTarget = selectionRimState },
Hotkey = new Hotkey(new KeyCombination(InputKey.W), new KeyCombination(InputKey.R)),
};
}
if (selection.All(s => s.Item is TaikoHitObject))
yield return new TernaryStateToggleMenuItem("Strong") { State = { BindTarget = selectionStrongState } };
{
yield return new TernaryStateToggleMenuItem("Strong")
{
State = { BindTarget = selectionStrongState },
Hotkey = new Hotkey(new KeyCombination(InputKey.E)),
};
}
foreach (var item in base.GetContextMenuItemsForSelection(selection))
yield return item;

View File

@ -13,6 +13,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Components.Menus;
using osu.Game.Storyboards;
using osu.Game.Tests.Beatmaps.IO;
using osuTK.Input;
@ -60,7 +61,7 @@ namespace osu.Game.Tests.Visual.Editing
beatmapSetHashBefore = Beatmap.Value.BeatmapSetInfo.Hash;
});
AddStep("click File", () => this.ChildrenOfType<DrawableOsuMenuItem>().First().TriggerClick());
AddStep("click File", () => this.ChildrenOfType<EditorMenuBar.DrawableEditorBarMenuItem>().First().TriggerClick());
if (i == 11)
{
@ -107,7 +108,7 @@ namespace osu.Game.Tests.Visual.Editing
EditorBeatmap.EndChange();
});
AddStep("click File", () => this.ChildrenOfType<DrawableOsuMenuItem>().First().TriggerClick());
AddStep("click File", () => this.ChildrenOfType<EditorMenuBar.DrawableEditorBarMenuItem>().First().TriggerClick());
AddStep("click delete", () => getDeleteMenuItem().TriggerClick());
AddUntilStep("wait for dialog", () => DialogOverlay.CurrentDialog != null);

View File

@ -0,0 +1,28 @@
// 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.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneHotkeyDisplay : ThemeComparisonTestScene
{
protected override Drawable CreateContent() => new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Vertical,
Children = new[]
{
new HotkeyDisplay { Hotkey = new Hotkey(new KeyCombination(InputKey.MouseLeft)) },
new HotkeyDisplay { Hotkey = new Hotkey(GlobalAction.EditorDecreaseDistanceSpacing) },
new HotkeyDisplay { Hotkey = new Hotkey(PlatformAction.Save) },
}
};
}
}

View File

@ -3,6 +3,7 @@
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
@ -20,12 +21,13 @@ namespace osu.Game.Graphics.UserInterface
{
public partial class DrawableOsuMenuItem : Menu.DrawableMenuItem
{
public const int MARGIN_HORIZONTAL = 17;
public const int MARGIN_HORIZONTAL = 10;
public const int MARGIN_VERTICAL = 4;
private const int text_size = 17;
private const int transition_length = 80;
public const int TEXT_SIZE = 17;
public const int TRANSITION_LENGTH = 80;
private TextContainer text;
private HotkeyDisplay hotkey;
private HoverClickSounds hoverClickSounds;
public DrawableOsuMenuItem(MenuItem item)
@ -39,32 +41,33 @@ namespace osu.Game.Graphics.UserInterface
BackgroundColour = Color4.Transparent;
BackgroundColourHover = Color4Extensions.FromHex(@"172023");
AddInternal(hotkey = new HotkeyDisplay
{
Alpha = 0,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding { Right = 10, Top = 1 },
});
AddInternal(hoverClickSounds = new HoverClickSounds());
updateTextColour();
updateText();
bool hasSubmenu = Item.Items.Any();
// Only add right chevron if direction of menu items is vertical (i.e. width is relative size, see `DrawableMenuItem.SetFlowDirection()`).
if (hasSubmenu && RelativeSizeAxes == Axes.X)
if (showChevron)
{
AddInternal(new SpriteIcon
{
Margin = new MarginPadding(6),
Margin = new MarginPadding { Horizontal = 10, },
Size = new Vector2(8),
Icon = FontAwesome.Solid.ChevronRight,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
});
text.Padding = new MarginPadding
{
// Add some padding for the chevron above.
Right = 5,
};
}
}
// Only add right chevron if direction of menu items is vertical (i.e. width is relative size, see `DrawableMenuItem.SetFlowDirection()`).
private bool showChevron => Item.Items.Any() && RelativeSizeAxes == Axes.X;
protected override void LoadComplete()
{
base.LoadComplete();
@ -73,9 +76,11 @@ namespace osu.Game.Graphics.UserInterface
FinishTransforms();
}
private void updateTextColour()
private void updateText()
{
switch ((Item as OsuMenuItem)?.Type)
var osuMenuItem = Item as OsuMenuItem;
switch (osuMenuItem?.Type)
{
default:
case MenuItemType.Standard:
@ -90,6 +95,20 @@ namespace osu.Game.Graphics.UserInterface
text.Colour = Color4Extensions.FromHex(@"ffcc22");
break;
}
hotkey.Hotkey = osuMenuItem?.Hotkey ?? default;
hotkey.Alpha = EqualityComparer<Hotkey>.Default.Equals(hotkey.Hotkey, default) ? 0 : 1;
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
// this hack ensures that the menu can auto-size while leaving enough space for the hotkey display.
// the gist of it is that while the hotkey display is not in the text / "content" that determines sizing
// (because it cannot be, because we want the hotkey display to align to the *right* and not the left),
// enough padding to fit the hotkey with _its_ spacing is added as padding of the text to compensate.
text.Padding = new MarginPadding { Right = hotkey.Alpha > 0 || showChevron ? hotkey.DrawWidth + 15 : 0 };
}
protected override bool OnHover(HoverEvent e)
@ -111,13 +130,13 @@ namespace osu.Game.Graphics.UserInterface
if (IsHovered && IsActionable)
{
text.BoldText.FadeIn(transition_length, Easing.OutQuint);
text.NormalText.FadeOut(transition_length, Easing.OutQuint);
text.BoldText.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
text.NormalText.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
}
else
{
text.BoldText.FadeOut(transition_length, Easing.OutQuint);
text.NormalText.FadeIn(transition_length, Easing.OutQuint);
text.BoldText.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
text.NormalText.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
}
}
@ -138,32 +157,53 @@ namespace osu.Game.Graphics.UserInterface
public readonly SpriteText NormalText;
public readonly SpriteText BoldText;
public readonly Container CheckboxContainer;
public TextContainer()
{
Anchor = Anchor.CentreLeft;
Origin = Anchor.CentreLeft;
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
Child = new FillFlowContainer
{
NormalText = new OsuSpriteText
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(10),
Direction = FillDirection.Horizontal,
Padding = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL, },
Children = new Drawable[]
{
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: text_size),
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL },
},
BoldText = new OsuSpriteText
{
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Alpha = 0,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL },
CheckboxContainer = new Container
{
RelativeSizeAxes = Axes.Y,
Width = MARGIN_HORIZONTAL,
},
new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
NormalText = new OsuSpriteText
{
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: TEXT_SIZE),
},
BoldText = new OsuSpriteText
{
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Alpha = 0,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: TEXT_SIZE, weight: FontWeight.Bold),
}
}
},
}
};
}

View File

@ -46,12 +46,11 @@ namespace osu.Game.Graphics.UserInterface
state = menuItem.State.GetBoundCopy();
Add(stateIcon = new SpriteIcon
CheckboxContainer.Add(stateIcon = new SpriteIcon
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(10),
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL },
AlwaysPresent = true,
});
}
@ -62,14 +61,6 @@ namespace osu.Game.Graphics.UserInterface
state.BindValueChanged(updateState, true);
}
protected override void Update()
{
base.Update();
// Todo: This is bad. This can maybe be done better with a refactor of DrawableOsuMenuItem.
stateIcon.X = BoldText.DrawWidth + 10;
}
private void updateState(ValueChangedEvent<object> state)
{
var icon = menuItem.GetIconForState(state.NewValue);

View File

@ -0,0 +1,59 @@
// 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.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Platform;
using osu.Game.Input;
using osu.Game.Input.Bindings;
namespace osu.Game.Graphics.UserInterface
{
public readonly record struct Hotkey
{
public KeyCombination[]? KeyCombinations { get; init; }
public GlobalAction? GlobalAction { get; init; }
public PlatformAction? PlatformAction { get; init; }
public Hotkey(params KeyCombination[] keyCombinations)
{
KeyCombinations = keyCombinations;
}
public Hotkey(GlobalAction globalAction)
{
GlobalAction = globalAction;
}
public Hotkey(PlatformAction platformAction)
{
PlatformAction = platformAction;
}
public IEnumerable<string> ResolveKeyCombination(ReadableKeyCombinationProvider keyCombinationProvider, RealmKeyBindingStore keyBindingStore, GameHost gameHost)
{
var result = new List<string>();
if (KeyCombinations != null)
{
result.AddRange(KeyCombinations.Select(keyCombinationProvider.GetReadableString));
}
if (GlobalAction != null)
{
result.AddRange(keyBindingStore.GetReadableKeyCombinationsFor(GlobalAction.Value));
}
if (PlatformAction != null)
{
var action = PlatformAction.Value;
var bindings = gameHost.PlatformKeyBindings.Where(kb => (PlatformAction)kb.Action == action);
result.AddRange(bindings.Select(b => keyCombinationProvider.GetReadableString(b.KeyCombination)));
}
return result;
}
}
}

View File

@ -0,0 +1,110 @@
// 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.
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Platform;
using osu.Game.Graphics.Sprites;
using osu.Game.Input;
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
public partial class HotkeyDisplay : CompositeDrawable
{
private Hotkey hotkey;
public Hotkey Hotkey
{
get => hotkey;
set
{
if (EqualityComparer<Hotkey>.Default.Equals(hotkey, value))
return;
hotkey = value;
if (IsLoaded)
updateState();
}
}
private FillFlowContainer flow = null!;
[Resolved]
private ReadableKeyCombinationProvider readableKeyCombinationProvider { get; set; } = null!;
[Resolved]
private RealmKeyBindingStore realmKeyBindingStore { get; set; } = null!;
[Resolved]
private GameHost gameHost { get; set; } = null!;
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
InternalChild = flow = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5)
};
updateState();
}
protected override void LoadComplete()
{
base.LoadComplete();
updateState();
}
private void updateState()
{
flow.Clear();
foreach (string h in hotkey.ResolveKeyCombination(readableKeyCombinationProvider, realmKeyBindingStore, gameHost))
flow.Add(new HotkeyBox(h));
}
private partial class HotkeyBox : CompositeDrawable
{
private readonly string hotkey;
public HotkeyBox(string hotkey)
{
this.hotkey = hotkey;
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider? colourProvider, OsuColour colours)
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 3;
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider?.Background6 ?? Colour4.Black.Opacity(0.7f),
},
new OsuSpriteText
{
Margin = new MarginPadding { Horizontal = 5, Bottom = 1, },
Text = hotkey.ToUpperInvariant(),
Font = OsuFont.Default.With(size: 12, weight: FontWeight.Bold),
Colour = colourProvider?.Light1 ?? colours.GrayA,
}
};
}
}
}
}

View File

@ -109,7 +109,7 @@ namespace osu.Game.Graphics.UserInterface
Colour = BackgroundColourHover,
RelativeSizeAxes = Axes.X,
Height = 2f,
Width = 0.8f,
Width = 0.9f,
});
}

View File

@ -11,6 +11,8 @@ namespace osu.Game.Graphics.UserInterface
{
public readonly MenuItemType Type;
public Hotkey Hotkey { get; init; }
public OsuMenuItem(LocalisableString text, MenuItemType type = MenuItemType.Standard)
: this(text, type, null)
{

View File

@ -409,6 +409,7 @@ namespace osu.Game
KeyBindingStore = new RealmKeyBindingStore(realm, keyCombinationProvider);
KeyBindingStore.Register(globalBindings, RulesetStore.AvailableRulesets);
dependencies.Cache(KeyBindingStore);
dependencies.Cache(globalBindings);

View File

@ -363,7 +363,7 @@ namespace osu.Game.Rulesets.Edit
if (e.ControlPressed || e.AltPressed || e.SuperPressed)
return false;
if (checkLeftToggleFromKey(e.Key, out int leftIndex))
if (checkToolboxMappingFromKey(e.Key, out int leftIndex))
{
var item = toolboxCollection.Items.ElementAtOrDefault(leftIndex);
@ -375,7 +375,7 @@ namespace osu.Game.Rulesets.Edit
}
}
if (checkRightToggleFromKey(e.Key, out int rightIndex))
if (checkToggleMappingFromKey(e.Key, out int rightIndex))
{
var item = e.ShiftPressed
? sampleBankTogglesCollection.ElementAtOrDefault(rightIndex)
@ -391,7 +391,7 @@ namespace osu.Game.Rulesets.Edit
return base.OnKeyDown(e);
}
private bool checkLeftToggleFromKey(Key key, out int index)
private bool checkToolboxMappingFromKey(Key key, out int index)
{
if (key < Key.Number1 || key > Key.Number9)
{
@ -403,7 +403,7 @@ namespace osu.Game.Rulesets.Edit
return true;
}
private bool checkRightToggleFromKey(Key key, out int index)
private bool checkToggleMappingFromKey(Key key, out int index)
{
switch (key)
{

View File

@ -7,7 +7,10 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK;
@ -78,8 +81,11 @@ namespace osu.Game.Screens.Edit.Components.Menus
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item) => new DrawableEditorBarMenuItem(item);
private partial class DrawableEditorBarMenuItem : DrawableOsuMenuItem
internal partial class DrawableEditorBarMenuItem : DrawableMenuItem
{
private HoverClickSounds hoverClickSounds = null!;
private TextContainer text = null!;
public DrawableEditorBarMenuItem(MenuItem item)
: base(item)
{
@ -92,6 +98,8 @@ namespace osu.Game.Screens.Edit.Components.Menus
BackgroundColour = colourProvider.Background2;
ForegroundColourHover = colourProvider.Content1;
BackgroundColourHover = colourProvider.Background1;
AddInternal(hoverClickSounds = new HoverClickSounds());
}
protected override void LoadComplete()
@ -100,6 +108,36 @@ namespace osu.Game.Screens.Edit.Components.Menus
Foreground.Anchor = Anchor.CentreLeft;
Foreground.Origin = Anchor.CentreLeft;
Item.Action.BindDisabledChanged(_ => updateState(), true);
}
protected override bool OnHover(HoverEvent e)
{
updateState();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateState();
base.OnHoverLost(e);
}
private void updateState()
{
hoverClickSounds.Enabled.Value = IsActionable;
Alpha = IsActionable ? 1 : 0.2f;
if (IsHovered && IsActionable)
{
text.BoldText.FadeIn(DrawableOsuMenuItem.TRANSITION_LENGTH, Easing.OutQuint);
text.NormalText.FadeOut(DrawableOsuMenuItem.TRANSITION_LENGTH, Easing.OutQuint);
}
else
{
text.BoldText.FadeOut(DrawableOsuMenuItem.TRANSITION_LENGTH, Easing.OutQuint);
text.NormalText.FadeIn(DrawableOsuMenuItem.TRANSITION_LENGTH, Easing.OutQuint);
}
}
protected override void UpdateBackgroundColour()
@ -118,16 +156,56 @@ namespace osu.Game.Screens.Edit.Components.Menus
base.UpdateForegroundColour();
}
protected override DrawableOsuMenuItem.TextContainer CreateTextContainer() => new TextContainer();
protected sealed override Drawable CreateContent() => text = new TextContainer();
}
private new partial class TextContainer : DrawableOsuMenuItem.TextContainer
private partial class TextContainer : Container, IHasText
{
public LocalisableString Text
{
public TextContainer()
get => NormalText.Text;
set
{
NormalText.Font = OsuFont.TorusAlternate;
BoldText.Font = OsuFont.TorusAlternate.With(weight: FontWeight.Bold);
NormalText.Text = value;
BoldText.Text = value;
}
}
public readonly SpriteText NormalText;
public readonly SpriteText BoldText;
public TextContainer()
{
AutoSizeAxes = Axes.Both;
Child = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 17, Vertical = DrawableOsuMenuItem.MARGIN_VERTICAL, },
Children = new Drawable[]
{
NormalText = new OsuSpriteText
{
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: DrawableOsuMenuItem.TEXT_SIZE),
},
BoldText = new OsuSpriteText
{
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
Alpha = 0,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: DrawableOsuMenuItem.TEXT_SIZE, weight: FontWeight.Bold),
}
}
};
}
}
private partial class SubMenu : OsuMenu

View File

@ -8,6 +8,7 @@ using Humanizer;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
using osu.Game.Audio;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.UserInterface;
@ -350,19 +351,69 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
if (SelectedBlueprints.All(b => b.Item is IHasComboInformation))
{
yield return new TernaryStateToggleMenuItem("New combo") { State = { BindTarget = SelectionNewComboState } };
yield return new TernaryStateToggleMenuItem("New combo")
{
State = { BindTarget = SelectionNewComboState },
Hotkey = new Hotkey(new KeyCombination(InputKey.Q))
};
}
yield return new OsuMenuItem("Sample")
yield return new OsuMenuItem("Sample") { Items = getSampleSubmenuItems().ToArray(), };
yield return new OsuMenuItem("Bank") { Items = getBankSubmenuItems().ToArray(), };
}
private IEnumerable<MenuItem> getSampleSubmenuItems()
{
var whistle = SelectionSampleStates[HitSampleInfo.HIT_WHISTLE];
yield return new TernaryStateToggleMenuItem(whistle.Description)
{
Items = SelectionSampleStates.Select(kvp =>
new TernaryStateToggleMenuItem(kvp.Value.Description) { State = { BindTarget = kvp.Value } }).ToArray()
State = { BindTarget = whistle },
Hotkey = new Hotkey(new KeyCombination(InputKey.W))
};
yield return new OsuMenuItem("Bank")
var finish = SelectionSampleStates[HitSampleInfo.HIT_FINISH];
yield return new TernaryStateToggleMenuItem(finish.Description)
{
Items = SelectionBankStates.Select(kvp =>
new TernaryStateToggleMenuItem(kvp.Value.Description) { State = { BindTarget = kvp.Value } }).ToArray()
State = { BindTarget = finish },
Hotkey = new Hotkey(new KeyCombination(InputKey.E))
};
var clap = SelectionSampleStates[HitSampleInfo.HIT_CLAP];
yield return new TernaryStateToggleMenuItem(clap.Description)
{
State = { BindTarget = clap },
Hotkey = new Hotkey(new KeyCombination(InputKey.R))
};
}
private IEnumerable<MenuItem> getBankSubmenuItems()
{
var auto = SelectionBankStates[HIT_BANK_AUTO];
yield return new TernaryStateToggleMenuItem(auto.Description)
{
State = { BindTarget = auto },
Hotkey = new Hotkey(new KeyCombination(InputKey.Shift, InputKey.Q))
};
var normal = SelectionBankStates[HitSampleInfo.BANK_NORMAL];
yield return new TernaryStateToggleMenuItem(normal.Description)
{
State = { BindTarget = normal },
Hotkey = new Hotkey(new KeyCombination(InputKey.Shift, InputKey.W))
};
var soft = SelectionBankStates[HitSampleInfo.BANK_SOFT];
yield return new TernaryStateToggleMenuItem(soft.Description)
{
State = { BindTarget = soft },
Hotkey = new Hotkey(new KeyCombination(InputKey.Shift, InputKey.E))
};
var drum = SelectionBankStates[HitSampleInfo.BANK_DRUM];
yield return new TernaryStateToggleMenuItem(drum.Description)
{
State = { BindTarget = drum },
Hotkey = new Hotkey(new KeyCombination(InputKey.Shift, InputKey.R))
};
}

View File

@ -415,7 +415,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (SelectedBlueprints.Count == 1)
items.AddRange(SelectedBlueprints[0].ContextMenuItems);
items.Add(new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, DeleteSelected));
items.Add(new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, DeleteSelected)
{
Hotkey = new Hotkey { PlatformAction = PlatformAction.Delete, KeyCombinations = [new KeyCombination(InputKey.Shift, InputKey.MouseRight), new KeyCombination(InputKey.MouseMiddle)] }
});
return items.ToArray();
}

View File

@ -362,13 +362,13 @@ namespace osu.Game.Screens.Edit
{
Items = new[]
{
undoMenuItem = new EditorMenuItem(CommonStrings.Undo, MenuItemType.Standard, Undo),
redoMenuItem = new EditorMenuItem(CommonStrings.Redo, MenuItemType.Standard, Redo),
undoMenuItem = new EditorMenuItem(CommonStrings.Undo, MenuItemType.Standard, Undo) { Hotkey = new Hotkey(PlatformAction.Undo) },
redoMenuItem = new EditorMenuItem(CommonStrings.Redo, MenuItemType.Standard, Redo) { Hotkey = new Hotkey(PlatformAction.Redo) },
new OsuMenuItemSpacer(),
cutMenuItem = new EditorMenuItem(CommonStrings.Cut, MenuItemType.Standard, Cut),
copyMenuItem = new EditorMenuItem(CommonStrings.Copy, MenuItemType.Standard, Copy),
pasteMenuItem = new EditorMenuItem(CommonStrings.Paste, MenuItemType.Standard, Paste),
cloneMenuItem = new EditorMenuItem(CommonStrings.Clone, MenuItemType.Standard, Clone),
cutMenuItem = new EditorMenuItem(CommonStrings.Cut, MenuItemType.Standard, Cut) { Hotkey = new Hotkey(PlatformAction.Cut) },
copyMenuItem = new EditorMenuItem(CommonStrings.Copy, MenuItemType.Standard, Copy) { Hotkey = new Hotkey(PlatformAction.Copy) },
pasteMenuItem = new EditorMenuItem(CommonStrings.Paste, MenuItemType.Standard, Paste) { Hotkey = new Hotkey(PlatformAction.Paste) },
cloneMenuItem = new EditorMenuItem(CommonStrings.Clone, MenuItemType.Standard, Clone) { Hotkey = new Hotkey(GlobalAction.EditorCloneSelection) },
}
},
new MenuItem(CommonStrings.MenuBarView)
@ -1194,7 +1194,7 @@ namespace osu.Game.Screens.Edit
yield return new EditorMenuItem(EditorStrings.DeleteDifficulty, MenuItemType.Standard, deleteDifficulty) { Action = { Disabled = Beatmap.Value.BeatmapSetInfo.Beatmaps.Count < 2 } };
yield return new OsuMenuItemSpacer();
var save = new EditorMenuItem(WebCommonStrings.ButtonsSave, MenuItemType.Standard, () => attemptMutationOperation(Save));
var save = new EditorMenuItem(WebCommonStrings.ButtonsSave, MenuItemType.Standard, () => attemptMutationOperation(Save)) { Hotkey = new Hotkey(PlatformAction.Save) };
saveRelatedMenuItems.Add(save);
yield return save;