From 83c004bbdefa4cc9bf4eb9dcfff7d91bcaf8187c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 3 Nov 2020 21:10:31 +0900 Subject: [PATCH] Add key bindings for flip and reverse patterns --- .../Edit/Compose/Components/SelectionBox.cs | 36 +++++++++++++++---- .../Compose/Components/SelectionHandler.cs | 8 ++--- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs index b753c45cca..6367dd6b9b 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionBox.cs @@ -7,17 +7,19 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; +using osu.Framework.Input.Events; using osu.Game.Graphics; using osuTK; +using osuTK.Input; namespace osu.Game.Screens.Edit.Compose.Components { public class SelectionBox : CompositeDrawable { - public Action OnRotation; - public Action OnScale; - public Action OnFlip; - public Action OnReverse; + public Func OnRotation; + public Func OnScale; + public Func OnFlip; + public Func OnReverse; public Action OperationStarted; public Action OperationEnded; @@ -105,6 +107,26 @@ namespace osu.Game.Screens.Edit.Compose.Components recreate(); } + protected override bool OnKeyDown(KeyDownEvent e) + { + if (e.Repeat || !e.ControlPressed) + return false; + + switch (e.Key) + { + case Key.G: + return OnReverse?.Invoke() == true; + + case Key.H: + return OnFlip?.Invoke(Direction.Horizontal) == true; + + case Key.J: + return OnFlip?.Invoke(Direction.Vertical) == true; + } + + return base.OnKeyDown(e); + } + private void recreate() { if (LoadState < LoadState.Loading) @@ -143,7 +165,7 @@ namespace osu.Game.Screens.Edit.Compose.Components if (CanScaleX && CanScaleY) addFullScaleComponents(); if (CanScaleY) addYScaleComponents(); if (CanRotate) addRotationComponents(); - if (CanReverse) addButton(FontAwesome.Solid.Backward, "Reverse pattern", () => OnReverse?.Invoke()); + if (CanReverse) addButton(FontAwesome.Solid.Backward, "Reverse pattern (Ctrl-G)", () => OnReverse?.Invoke()); } private void addRotationComponents() @@ -178,7 +200,7 @@ namespace osu.Game.Screens.Edit.Compose.Components private void addYScaleComponents() { - addButton(FontAwesome.Solid.ArrowsAltV, "Flip vertically", () => OnFlip?.Invoke(Direction.Vertical)); + addButton(FontAwesome.Solid.ArrowsAltV, "Flip vertically (Ctrl-J)", () => OnFlip?.Invoke(Direction.Vertical)); addDragHandle(Anchor.TopCentre); addDragHandle(Anchor.BottomCentre); @@ -194,7 +216,7 @@ namespace osu.Game.Screens.Edit.Compose.Components private void addXScaleComponents() { - addButton(FontAwesome.Solid.ArrowsAltH, "Flip horizontally", () => OnFlip?.Invoke(Direction.Horizontal)); + addButton(FontAwesome.Solid.ArrowsAltH, "Flip horizontally (Ctrl-H)", () => OnFlip?.Invoke(Direction.Horizontal)); addDragHandle(Anchor.CentreLeft); addDragHandle(Anchor.CentreRight); diff --git a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs index c2441b31a9..406ca07185 100644 --- a/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs +++ b/osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs @@ -99,10 +99,10 @@ namespace osu.Game.Screens.Edit.Compose.Components OperationStarted = OnOperationBegan, OperationEnded = OnOperationEnded, - OnRotation = angle => HandleRotation(angle), - OnScale = (amount, anchor) => HandleScale(amount, anchor), - OnFlip = direction => HandleFlip(direction), - OnReverse = () => HandleReverse(), + OnRotation = HandleRotation, + OnScale = HandleScale, + OnFlip = HandleFlip, + OnReverse = HandleReverse, }; ///