mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 15:43:22 +08:00
Merge pull request #19865 from OliBomby/fix-slider-flip
Fix flipping a slider sometimes changing the curve type from "Perfect" to "Bezier"
This commit is contained in:
commit
513ba69f6f
@ -12,6 +12,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Osu.Edit;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
@ -55,9 +56,9 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
||||
{
|
||||
ControlPoints =
|
||||
{
|
||||
new PathControlPoint(Vector2.Zero),
|
||||
new PathControlPoint(OsuPlayfield.BASE_SIZE * 2 / 5),
|
||||
new PathControlPoint(OsuPlayfield.BASE_SIZE * 3 / 5)
|
||||
new PathControlPoint(Vector2.Zero, PathType.PerfectCurve),
|
||||
new PathControlPoint(new Vector2(136, 205)),
|
||||
new PathControlPoint(new Vector2(-4, 226))
|
||||
}
|
||||
}
|
||||
}));
|
||||
@ -99,8 +100,8 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
||||
AddStep("move mouse to new point location", () =>
|
||||
{
|
||||
var firstPiece = this.ChildrenOfType<PathControlPointPiece>().Single(piece => piece.ControlPoint == slider.Path.ControlPoints[0]);
|
||||
var secondPiece = this.ChildrenOfType<PathControlPointPiece>().Single(piece => piece.ControlPoint == slider.Path.ControlPoints[1]);
|
||||
InputManager.MoveMouseTo((firstPiece.ScreenSpaceDrawQuad.Centre + secondPiece.ScreenSpaceDrawQuad.Centre) / 2);
|
||||
var pos = slider.Path.PositionAt(0.25d) + slider.Position;
|
||||
InputManager.MoveMouseTo(firstPiece.Parent.ToScreenSpace(pos));
|
||||
});
|
||||
AddStep("move slider end", () =>
|
||||
{
|
||||
@ -175,6 +176,23 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
||||
assertSliderSnapped(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRotatingSliderRetainsPerfectControlPointType()
|
||||
{
|
||||
OsuSelectionHandler selectionHandler;
|
||||
|
||||
AddAssert("first control point perfect", () => slider.Path.ControlPoints[0].Type == PathType.PerfectCurve);
|
||||
|
||||
AddStep("select slider", () => EditorBeatmap.SelectedHitObjects.Add(slider));
|
||||
AddStep("rotate 90 degrees ccw", () =>
|
||||
{
|
||||
selectionHandler = this.ChildrenOfType<OsuSelectionHandler>().Single();
|
||||
selectionHandler.HandleRotation(-90);
|
||||
});
|
||||
|
||||
AddAssert("first control point still perfect", () => slider.Path.ControlPoints[0].Type == PathType.PerfectCurve);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFlippingSliderDoesNotSnap()
|
||||
{
|
||||
@ -200,6 +218,23 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
||||
assertSliderSnapped(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFlippingSliderRetainsPerfectControlPointType()
|
||||
{
|
||||
OsuSelectionHandler selectionHandler;
|
||||
|
||||
AddAssert("first control point perfect", () => slider.Path.ControlPoints[0].Type == PathType.PerfectCurve);
|
||||
|
||||
AddStep("select slider", () => EditorBeatmap.SelectedHitObjects.Add(slider));
|
||||
AddStep("flip slider horizontally", () =>
|
||||
{
|
||||
selectionHandler = this.ChildrenOfType<OsuSelectionHandler>().Single();
|
||||
selectionHandler.OnPressed(new KeyBindingPressEvent<GlobalAction>(InputManager.CurrentState, GlobalAction.EditorFlipVertically));
|
||||
});
|
||||
|
||||
AddAssert("first control point still perfect", () => slider.Path.ControlPoints[0].Type == PathType.PerfectCurve);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReversingSliderDoesNotSnap()
|
||||
{
|
||||
|
@ -127,13 +127,16 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
didFlip = true;
|
||||
|
||||
foreach (var point in slider.Path.ControlPoints)
|
||||
{
|
||||
point.Position = new Vector2(
|
||||
(direction == Direction.Horizontal ? -1 : 1) * point.Position.X,
|
||||
(direction == Direction.Vertical ? -1 : 1) * point.Position.Y
|
||||
);
|
||||
}
|
||||
var controlPoints = slider.Path.ControlPoints.Select(p =>
|
||||
new PathControlPoint(new Vector2(
|
||||
(direction == Direction.Horizontal ? -1 : 1) * p.Position.X,
|
||||
(direction == Direction.Vertical ? -1 : 1) * p.Position.Y
|
||||
), p.Type)).ToArray();
|
||||
|
||||
// Importantly, update as a single operation so automatic adjustment of control points to different
|
||||
// curve types does not unexpectedly trigger and change the slider's shape.
|
||||
slider.Path.ControlPoints.Clear();
|
||||
slider.Path.ControlPoints.AddRange(controlPoints);
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,8 +186,13 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
|
||||
if (h is IHasPath path)
|
||||
{
|
||||
foreach (var point in path.Path.ControlPoints)
|
||||
point.Position = RotatePointAroundOrigin(point.Position, Vector2.Zero, delta);
|
||||
var controlPoints = path.Path.ControlPoints.Select(p =>
|
||||
new PathControlPoint(RotatePointAroundOrigin(p.Position, Vector2.Zero, delta), p.Type)).ToArray();
|
||||
|
||||
// Importantly, update as a single operation so automatic adjustment of control points to different
|
||||
// curve types does not unexpectedly trigger and change the slider's shape.
|
||||
path.Path.ControlPoints.Clear();
|
||||
path.Path.ControlPoints.AddRange(controlPoints);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user