Add global flip hotkeys

This commit is contained in:
Dean Herbert
2022-01-05 16:46:34 +09:00
parent 13cce50fa7
commit 866ae3472b
8 changed files with 68 additions and 24 deletions

View File

@ -21,7 +21,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
public Func<float, bool> OnRotation;
public Func<Vector2, Anchor, bool> OnScale;
public Func<Direction, bool> OnFlip;
public Func<Direction, bool, bool> OnFlip;
public Func<bool> OnReverse;
public Action OperationStarted;
@ -281,12 +281,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void addXFlipComponents()
{
addButton(FontAwesome.Solid.ArrowsAltH, "Flip horizontally", () => OnFlip?.Invoke(Direction.Horizontal));
addButton(FontAwesome.Solid.ArrowsAltH, "Flip horizontally", () => OnFlip?.Invoke(Direction.Horizontal, false));
}
private void addYFlipComponents()
{
addButton(FontAwesome.Solid.ArrowsAltV, "Flip vertically", () => OnFlip?.Invoke(Direction.Vertical));
addButton(FontAwesome.Solid.ArrowsAltV, "Flip vertically", () => OnFlip?.Invoke(Direction.Vertical, false));
}
private void addButton(IconUsage icon, string tooltip, Action action)

View File

@ -17,6 +17,7 @@ using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Edit;
using osuTK;
using osuTK.Input;
@ -26,7 +27,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary>
/// A component which outlines items and handles movement of selections.
/// </summary>
public abstract class SelectionHandler<T> : CompositeDrawable, IKeyBindingHandler<PlatformAction>, IHasContextMenu
public abstract class SelectionHandler<T> : CompositeDrawable, IKeyBindingHandler<PlatformAction>, IKeyBindingHandler<GlobalAction>, IHasContextMenu
{
/// <summary>
/// The currently selected blueprints.
@ -127,9 +128,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary>
/// Handles the selected items being flipped.
/// </summary>
/// <param name="direction">The direction to flip</param>
/// <param name="direction">The direction to flip.</param>
/// <param name="flipOverOrigin">Whether the flip operation should be global to the playfield's origin or local to the selected pattern.</param>
/// <returns>Whether any items could be flipped.</returns>
public virtual bool HandleFlip(Direction direction) => false;
public virtual bool HandleFlip(Direction direction, bool flipOverOrigin) => false;
/// <summary>
/// Handles the selected items being reversed pattern-wise.
@ -137,6 +139,29 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <returns>Whether any items could be reversed.</returns>
public virtual bool HandleReverse() => false;
public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat)
return false;
switch (e.Action)
{
case GlobalAction.EditorFlipHorizontally:
HandleFlip(Direction.Horizontal, true);
return true;
case GlobalAction.EditorFlipVertically:
HandleFlip(Direction.Vertical, true);
return true;
}
return false;
}
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
{
switch (e.Action)

View File

@ -7,7 +7,6 @@ using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
using osu.Game.Rulesets.Edit;
@ -17,7 +16,7 @@ using osuTK.Input;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
internal class TimelineSelectionHandler : EditorSelectionHandler, IKeyBindingHandler<GlobalAction>
internal class TimelineSelectionHandler : EditorSelectionHandler
{
[Resolved]
private Timeline timeline { get; set; }
@ -27,8 +26,11 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
// for now we always allow movement. snapping is provided by the Timeline's "distance" snap implementation
public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent) => true;
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
// Importantly, we block the base call here.
// Other key operations will be handled by the composer view's SelectionHandler instead.
switch (e.Action)
{
case GlobalAction.EditorNudgeLeft:
@ -43,10 +45,6 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
return false;
}
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
/// <summary>
/// Nudge the current selection by the specified multiple of beat divisor lengths,
/// based on the timing at the first object in the selection.