1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 05:02:56 +08:00

Merge pull request #10680 from peppy/editor-flip-keybinds

Add key bindings for flip and reverse patterns
This commit is contained in:
Bartłomiej Dach 2020-11-03 21:17:52 +01:00 committed by GitHub
commit f3d5e7b15a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 13 deletions

View File

@ -41,7 +41,7 @@ namespace osu.Game.Tests.Visual.Editing
AddToggleStep("toggle y", state => selectionBox.CanScaleY = state); AddToggleStep("toggle y", state => selectionBox.CanScaleY = state);
} }
private void handleScale(Vector2 amount, Anchor reference) private bool handleScale(Vector2 amount, Anchor reference)
{ {
if ((reference & Anchor.y1) == 0) if ((reference & Anchor.y1) == 0)
{ {
@ -58,12 +58,15 @@ namespace osu.Game.Tests.Visual.Editing
selectionArea.X += amount.X; selectionArea.X += amount.X;
selectionArea.Width += directionX * amount.X; selectionArea.Width += directionX * amount.X;
} }
return true;
} }
private void handleRotation(float angle) private bool handleRotation(float angle)
{ {
// kinda silly and wrong, but just showing that the drag handles work. // kinda silly and wrong, but just showing that the drag handles work.
selectionArea.Rotation += angle; selectionArea.Rotation += angle;
return true;
} }
} }
} }

View File

@ -7,17 +7,19 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osuTK; using osuTK;
using osuTK.Input;
namespace osu.Game.Screens.Edit.Compose.Components namespace osu.Game.Screens.Edit.Compose.Components
{ {
public class SelectionBox : CompositeDrawable public class SelectionBox : CompositeDrawable
{ {
public Action<float> OnRotation; public Func<float, bool> OnRotation;
public Action<Vector2, Anchor> OnScale; public Func<Vector2, Anchor, bool> OnScale;
public Action<Direction> OnFlip; public Func<Direction, bool> OnFlip;
public Action OnReverse; public Func<bool> OnReverse;
public Action OperationStarted; public Action OperationStarted;
public Action OperationEnded; public Action OperationEnded;
@ -105,6 +107,26 @@ namespace osu.Game.Screens.Edit.Compose.Components
recreate(); recreate();
} }
protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.Repeat || !e.ControlPressed)
return false;
switch (e.Key)
{
case Key.G:
return CanReverse && OnReverse?.Invoke() == true;
case Key.H:
return CanScaleX && OnFlip?.Invoke(Direction.Horizontal) == true;
case Key.J:
return CanScaleY && OnFlip?.Invoke(Direction.Vertical) == true;
}
return base.OnKeyDown(e);
}
private void recreate() private void recreate()
{ {
if (LoadState < LoadState.Loading) if (LoadState < LoadState.Loading)
@ -143,7 +165,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (CanScaleX && CanScaleY) addFullScaleComponents(); if (CanScaleX && CanScaleY) addFullScaleComponents();
if (CanScaleY) addYScaleComponents(); if (CanScaleY) addYScaleComponents();
if (CanRotate) addRotationComponents(); 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() private void addRotationComponents()
@ -178,7 +200,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void addYScaleComponents() 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.TopCentre);
addDragHandle(Anchor.BottomCentre); addDragHandle(Anchor.BottomCentre);
@ -194,7 +216,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void addXScaleComponents() 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.CentreLeft);
addDragHandle(Anchor.CentreRight); addDragHandle(Anchor.CentreRight);

View File

@ -99,10 +99,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
OperationStarted = OnOperationBegan, OperationStarted = OnOperationBegan,
OperationEnded = OnOperationEnded, OperationEnded = OnOperationEnded,
OnRotation = angle => HandleRotation(angle), OnRotation = HandleRotation,
OnScale = (amount, anchor) => HandleScale(amount, anchor), OnScale = HandleScale,
OnFlip = direction => HandleFlip(direction), OnFlip = HandleFlip,
OnReverse = () => HandleReverse(), OnReverse = HandleReverse,
}; };
/// <summary> /// <summary>