mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 14:32:55 +08:00
Migrate SelectionHandler
to use SelectionRotationHandler
This commit is contained in:
parent
21df0e2d60
commit
aec3ca250c
@ -40,7 +40,6 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
|
|
||||||
Quad quad = selectedMovableObjects.Length > 0 ? GeometryUtils.GetSurroundingQuad(selectedMovableObjects) : new Quad();
|
Quad quad = selectedMovableObjects.Length > 0 ? GeometryUtils.GetSurroundingQuad(selectedMovableObjects) : new Quad();
|
||||||
|
|
||||||
SelectionBox.CanRotate = quad.Width > 0 || quad.Height > 0;
|
|
||||||
SelectionBox.CanFlipX = SelectionBox.CanScaleX = quad.Width > 0;
|
SelectionBox.CanFlipX = SelectionBox.CanScaleX = quad.Width > 0;
|
||||||
SelectionBox.CanFlipY = SelectionBox.CanScaleY = quad.Height > 0;
|
SelectionBox.CanFlipY = SelectionBox.CanScaleY = quad.Height > 0;
|
||||||
SelectionBox.CanReverse = EditorBeatmap.SelectedHitObjects.Count > 1 || EditorBeatmap.SelectedHitObjects.Any(s => s is Slider);
|
SelectionBox.CanReverse = EditorBeatmap.SelectedHitObjects.Count > 1 || EditorBeatmap.SelectedHitObjects.Any(s => s is Slider);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
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.Shapes;
|
||||||
@ -22,7 +23,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
private const float button_padding = 5;
|
private const float button_padding = 5;
|
||||||
|
|
||||||
public Func<float, bool>? OnRotation;
|
public SelectionRotationHandler? RotationHandler { get; init; }
|
||||||
public Func<Vector2, Anchor, bool>? OnScale;
|
public Func<Vector2, Anchor, bool>? OnScale;
|
||||||
public Func<Direction, bool, bool>? OnFlip;
|
public Func<Direction, bool, bool>? OnFlip;
|
||||||
public Func<bool>? OnReverse;
|
public Func<bool>? OnReverse;
|
||||||
@ -51,22 +52,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool canRotate;
|
private IBindable<bool> canRotate = new BindableBool();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether rotation support should be enabled.
|
|
||||||
/// </summary>
|
|
||||||
public bool CanRotate
|
|
||||||
{
|
|
||||||
get => canRotate;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (canRotate == value) return;
|
|
||||||
|
|
||||||
canRotate = value;
|
|
||||||
recreate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool canScaleX;
|
private bool canScaleX;
|
||||||
|
|
||||||
@ -161,7 +147,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
private OsuColour colours { get; set; } = null!;
|
private OsuColour colours { get; set; } = null!;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load() => recreate();
|
private void load()
|
||||||
|
{
|
||||||
|
if (RotationHandler != null)
|
||||||
|
canRotate.BindTo(RotationHandler.CanRotate);
|
||||||
|
|
||||||
|
canRotate.BindValueChanged(_ => recreate());
|
||||||
|
recreate();
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnKeyDown(KeyDownEvent e)
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
{
|
{
|
||||||
@ -174,10 +167,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
return CanReverse && reverseButton?.TriggerClick() == true;
|
return CanReverse && reverseButton?.TriggerClick() == true;
|
||||||
|
|
||||||
case Key.Comma:
|
case Key.Comma:
|
||||||
return CanRotate && rotateCounterClockwiseButton?.TriggerClick() == true;
|
return canRotate.Value && rotateCounterClockwiseButton?.TriggerClick() == true;
|
||||||
|
|
||||||
case Key.Period:
|
case Key.Period:
|
||||||
return CanRotate && rotateClockwiseButton?.TriggerClick() == true;
|
return canRotate.Value && rotateClockwiseButton?.TriggerClick() == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.OnKeyDown(e);
|
return base.OnKeyDown(e);
|
||||||
@ -254,14 +247,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
if (CanScaleY) addYScaleComponents();
|
if (CanScaleY) addYScaleComponents();
|
||||||
if (CanFlipX) addXFlipComponents();
|
if (CanFlipX) addXFlipComponents();
|
||||||
if (CanFlipY) addYFlipComponents();
|
if (CanFlipY) addYFlipComponents();
|
||||||
if (CanRotate) addRotationComponents();
|
if (canRotate.Value) addRotationComponents();
|
||||||
if (CanReverse) reverseButton = addButton(FontAwesome.Solid.Backward, "Reverse pattern (Ctrl-G)", () => OnReverse?.Invoke());
|
if (CanReverse) reverseButton = addButton(FontAwesome.Solid.Backward, "Reverse pattern (Ctrl-G)", () => OnReverse?.Invoke());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRotationComponents()
|
private void addRotationComponents()
|
||||||
{
|
{
|
||||||
rotateCounterClockwiseButton = addButton(FontAwesome.Solid.Undo, "Rotate 90 degrees counter-clockwise (Ctrl-<)", () => OnRotation?.Invoke(-90));
|
rotateCounterClockwiseButton = addButton(FontAwesome.Solid.Undo, "Rotate 90 degrees counter-clockwise (Ctrl-<)", () => RotationHandler?.Rotate(-90));
|
||||||
rotateClockwiseButton = addButton(FontAwesome.Solid.Redo, "Rotate 90 degrees clockwise (Ctrl->)", () => OnRotation?.Invoke(90));
|
rotateClockwiseButton = addButton(FontAwesome.Solid.Redo, "Rotate 90 degrees clockwise (Ctrl->)", () => RotationHandler?.Rotate(90));
|
||||||
|
|
||||||
addRotateHandle(Anchor.TopLeft);
|
addRotateHandle(Anchor.TopLeft);
|
||||||
addRotateHandle(Anchor.TopRight);
|
addRotateHandle(Anchor.TopRight);
|
||||||
@ -331,7 +324,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
var handle = new SelectionBoxRotationHandle
|
var handle = new SelectionBoxRotationHandle
|
||||||
{
|
{
|
||||||
Anchor = anchor,
|
Anchor = anchor,
|
||||||
HandleRotate = angle => OnRotation?.Invoke(angle)
|
RotationHandler = RotationHandler
|
||||||
};
|
};
|
||||||
|
|
||||||
handle.OperationStarted += operationStarted;
|
handle.OperationStarted += operationStarted;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.EnumExtensions;
|
using osu.Framework.Extensions.EnumExtensions;
|
||||||
@ -21,7 +22,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
{
|
{
|
||||||
public partial class SelectionBoxRotationHandle : SelectionBoxDragHandle, IHasTooltip
|
public partial class SelectionBoxRotationHandle : SelectionBoxDragHandle, IHasTooltip
|
||||||
{
|
{
|
||||||
public Action<float> HandleRotate { get; set; }
|
[CanBeNull]
|
||||||
|
public SelectionRotationHandler RotationHandler { get; init; }
|
||||||
|
|
||||||
public LocalisableString TooltipText { get; private set; }
|
public LocalisableString TooltipText { get; private set; }
|
||||||
|
|
||||||
@ -63,10 +65,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
protected override bool OnDragStart(DragStartEvent e)
|
protected override bool OnDragStart(DragStartEvent e)
|
||||||
{
|
{
|
||||||
bool handle = base.OnDragStart(e);
|
if (RotationHandler == null) return false;
|
||||||
if (handle)
|
|
||||||
cumulativeRotation.Value = 0;
|
RotationHandler.Begin();
|
||||||
return handle;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDrag(DragEvent e)
|
protected override void OnDrag(DragEvent e)
|
||||||
@ -99,7 +101,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
protected override void OnDragEnd(DragEndEvent e)
|
protected override void OnDragEnd(DragEndEvent e)
|
||||||
{
|
{
|
||||||
base.OnDragEnd(e);
|
RotationHandler?.Commit();
|
||||||
|
UpdateHoverState();
|
||||||
|
|
||||||
cumulativeRotation.Value = null;
|
cumulativeRotation.Value = null;
|
||||||
rawCumulativeRotation = 0;
|
rawCumulativeRotation = 0;
|
||||||
TooltipText = default;
|
TooltipText = default;
|
||||||
@ -116,14 +120,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
private void applyRotation(bool shouldSnap)
|
private void applyRotation(bool shouldSnap)
|
||||||
{
|
{
|
||||||
float oldRotation = cumulativeRotation.Value ?? 0;
|
|
||||||
|
|
||||||
float newRotation = shouldSnap ? snap(rawCumulativeRotation, snap_step) : MathF.Round(rawCumulativeRotation);
|
float newRotation = shouldSnap ? snap(rawCumulativeRotation, snap_step) : MathF.Round(rawCumulativeRotation);
|
||||||
newRotation = (newRotation - 180) % 360 + 180;
|
newRotation = (newRotation - 180) % 360 + 180;
|
||||||
|
|
||||||
cumulativeRotation.Value = newRotation;
|
cumulativeRotation.Value = newRotation;
|
||||||
|
|
||||||
HandleRotate?.Invoke(newRotation - oldRotation);
|
RotationHandler?.Update(newRotation);
|
||||||
TooltipText = shouldSnap ? EditorStrings.RotationSnapped(newRotation) : EditorStrings.RotationUnsnapped(newRotation);
|
TooltipText = shouldSnap ? EditorStrings.RotationSnapped(newRotation) : EditorStrings.RotationUnsnapped(newRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
OperationStarted = OnOperationBegan,
|
OperationStarted = OnOperationBegan,
|
||||||
OperationEnded = OnOperationEnded,
|
OperationEnded = OnOperationEnded,
|
||||||
|
|
||||||
OnRotation = HandleRotation,
|
RotationHandler = RotationHandler,
|
||||||
OnScale = HandleScale,
|
OnScale = HandleScale,
|
||||||
OnFlip = HandleFlip,
|
OnFlip = HandleFlip,
|
||||||
OnReverse = HandleReverse,
|
OnReverse = HandleReverse,
|
||||||
|
@ -16,11 +16,18 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Bindable<bool> CanRotate { get; private set; } = new BindableBool();
|
public Bindable<bool> CanRotate { get; private set; } = new BindableBool();
|
||||||
|
|
||||||
|
public void Rotate(float rotation, Vector2? origin = null)
|
||||||
|
{
|
||||||
|
Begin();
|
||||||
|
Update(rotation, origin);
|
||||||
|
Commit();
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Begin()
|
public virtual void Begin()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Update(float rotation, Vector2 origin)
|
public virtual void Update(float rotation, Vector2? origin = null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user