2020-04-13 15:13:14 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-04-13 15:13:14 +08:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
2021-04-08 17:46:52 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-04-13 15:13:14 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-04-08 17:46:52 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2020-04-13 15:13:14 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
using osuTK;
|
|
|
|
|
2020-09-25 17:48:04 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Tests.Editor
|
2020-04-13 15:13:14 +08:00
|
|
|
{
|
2021-04-08 17:46:52 +08:00
|
|
|
public partial class TestScenePathControlPointVisualiser : OsuManualInputManagerTestScene
|
2020-04-13 15:13:14 +08:00
|
|
|
{
|
|
|
|
private Slider slider;
|
2022-11-03 19:25:23 +08:00
|
|
|
private PathControlPointVisualiser<Slider> visualiser;
|
2020-04-13 15:13:14 +08:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
|
|
|
slider = new Slider();
|
|
|
|
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
|
|
|
});
|
|
|
|
|
2021-04-08 17:46:52 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveTooManyPoints()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
addControlPointStep(new Vector2(200), PathType.BEZIER);
|
2021-04-08 17:46:52 +08:00
|
|
|
addControlPointStep(new Vector2(300));
|
|
|
|
addControlPointStep(new Vector2(500, 300));
|
|
|
|
addControlPointStep(new Vector2(700, 200));
|
|
|
|
addControlPointStep(new Vector2(500, 100));
|
|
|
|
|
|
|
|
// Must be both hovering and selecting the control point for the context menu to work.
|
|
|
|
moveMouseToControlPoint(1);
|
|
|
|
AddStep("select control point", () => visualiser.Pieces[1].IsSelected.Value = true);
|
|
|
|
addContextMenuItemStep("Perfect curve");
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
assertControlPointPathType(0, PathType.BEZIER);
|
2023-11-13 15:24:09 +08:00
|
|
|
assertControlPointPathType(1, PathType.PERFECT_CURVE);
|
2023-11-08 18:43:54 +08:00
|
|
|
assertControlPointPathType(3, PathType.BEZIER);
|
2021-04-08 17:46:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveLastThreePoints()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
addControlPointStep(new Vector2(200), PathType.BEZIER);
|
2021-04-08 17:46:52 +08:00
|
|
|
addControlPointStep(new Vector2(300));
|
|
|
|
addControlPointStep(new Vector2(500, 300));
|
|
|
|
addControlPointStep(new Vector2(700, 200));
|
|
|
|
addControlPointStep(new Vector2(500, 100));
|
|
|
|
|
|
|
|
moveMouseToControlPoint(2);
|
|
|
|
AddStep("select control point", () => visualiser.Pieces[2].IsSelected.Value = true);
|
|
|
|
addContextMenuItemStep("Perfect curve");
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
assertControlPointPathType(0, PathType.BEZIER);
|
2023-11-13 15:24:09 +08:00
|
|
|
assertControlPointPathType(2, PathType.PERFECT_CURVE);
|
2021-04-08 17:46:52 +08:00
|
|
|
assertControlPointPathType(4, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveLastTwoPoints()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
addControlPointStep(new Vector2(200), PathType.BEZIER);
|
2021-04-08 17:46:52 +08:00
|
|
|
addControlPointStep(new Vector2(300));
|
|
|
|
addControlPointStep(new Vector2(500, 300));
|
|
|
|
addControlPointStep(new Vector2(700, 200));
|
|
|
|
addControlPointStep(new Vector2(500, 100));
|
|
|
|
|
|
|
|
moveMouseToControlPoint(3);
|
|
|
|
AddStep("select control point", () => visualiser.Pieces[3].IsSelected.Value = true);
|
|
|
|
addContextMenuItemStep("Perfect curve");
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
assertControlPointPathType(0, PathType.BEZIER);
|
2021-04-08 17:46:52 +08:00
|
|
|
AddAssert("point 3 is not inherited", () => slider.Path.ControlPoints[3].Type != null);
|
|
|
|
}
|
|
|
|
|
2021-04-09 17:03:38 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveTooManyPointsLinear()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
addControlPointStep(new Vector2(200), PathType.LINEAR);
|
2021-04-09 17:03:38 +08:00
|
|
|
addControlPointStep(new Vector2(300));
|
|
|
|
addControlPointStep(new Vector2(500, 300));
|
|
|
|
addControlPointStep(new Vector2(700, 200));
|
|
|
|
addControlPointStep(new Vector2(500, 100));
|
|
|
|
|
|
|
|
// Must be both hovering and selecting the control point for the context menu to work.
|
|
|
|
moveMouseToControlPoint(1);
|
|
|
|
AddStep("select control point", () => visualiser.Pieces[1].IsSelected.Value = true);
|
|
|
|
addContextMenuItemStep("Perfect curve");
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
assertControlPointPathType(0, PathType.LINEAR);
|
2023-11-13 15:24:09 +08:00
|
|
|
assertControlPointPathType(1, PathType.PERFECT_CURVE);
|
2023-11-08 18:43:54 +08:00
|
|
|
assertControlPointPathType(3, PathType.LINEAR);
|
2021-04-09 17:03:38 +08:00
|
|
|
}
|
|
|
|
|
2021-04-08 18:32:45 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveChangeToBezier()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
addControlPointStep(new Vector2(200), PathType.BEZIER);
|
2023-11-13 15:24:09 +08:00
|
|
|
addControlPointStep(new Vector2(300), PathType.PERFECT_CURVE);
|
2021-04-08 18:32:45 +08:00
|
|
|
addControlPointStep(new Vector2(500, 300));
|
2023-11-08 18:43:54 +08:00
|
|
|
addControlPointStep(new Vector2(700, 200), PathType.BEZIER);
|
2021-04-08 18:32:45 +08:00
|
|
|
addControlPointStep(new Vector2(500, 100));
|
|
|
|
|
|
|
|
moveMouseToControlPoint(3);
|
|
|
|
AddStep("select control point", () => visualiser.Pieces[3].IsSelected.Value = true);
|
|
|
|
addContextMenuItemStep("Inherit");
|
|
|
|
|
2023-11-08 18:43:54 +08:00
|
|
|
assertControlPointPathType(0, PathType.BEZIER);
|
|
|
|
assertControlPointPathType(1, PathType.BEZIER);
|
2021-04-08 18:32:45 +08:00
|
|
|
assertControlPointPathType(3, null);
|
|
|
|
}
|
|
|
|
|
2023-11-20 14:53:25 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCatmullAvailableIffSelectionContainsCatmull()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
|
|
|
addControlPointStep(new Vector2(200), PathType.CATMULL);
|
|
|
|
addControlPointStep(new Vector2(300));
|
|
|
|
addControlPointStep(new Vector2(500, 300));
|
|
|
|
addControlPointStep(new Vector2(700, 200));
|
|
|
|
addControlPointStep(new Vector2(500, 100));
|
|
|
|
|
|
|
|
moveMouseToControlPoint(2);
|
|
|
|
AddStep("select first and third control point", () =>
|
|
|
|
{
|
|
|
|
visualiser.Pieces[0].IsSelected.Value = true;
|
|
|
|
visualiser.Pieces[2].IsSelected.Value = true;
|
|
|
|
});
|
|
|
|
addContextMenuItemStep("Catmull");
|
|
|
|
|
|
|
|
assertControlPointPathType(0, PathType.CATMULL);
|
|
|
|
assertControlPointPathType(2, PathType.CATMULL);
|
|
|
|
assertControlPointPathType(4, null);
|
|
|
|
}
|
|
|
|
|
2024-03-31 08:23:05 +08:00
|
|
|
[Test]
|
|
|
|
public void TestStackingUpdatesPointsPosition()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
2024-04-01 00:39:19 +08:00
|
|
|
Vector2[] points =
|
|
|
|
[
|
2024-03-31 08:23:05 +08:00
|
|
|
new Vector2(200),
|
|
|
|
new Vector2(300),
|
|
|
|
new Vector2(500, 300),
|
|
|
|
new Vector2(700, 200),
|
|
|
|
new Vector2(500, 100)
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach (var point in points) addControlPointStep(point);
|
|
|
|
|
|
|
|
AddStep("apply stacking", () => slider.StackHeightBindable.Value += 1);
|
|
|
|
|
|
|
|
for (int i = 0; i < points.Length; i++)
|
|
|
|
addAssertPointPositionChanged(points, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addAssertPointPositionChanged(Vector2[] points, int index)
|
|
|
|
{
|
|
|
|
AddAssert($"Point at {points.ElementAt(index)} changed",
|
|
|
|
() => visualiser.Pieces[index].Position,
|
|
|
|
() => !Is.EqualTo(points.ElementAt(index))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-03 19:25:23 +08:00
|
|
|
private void createVisualiser(bool allowSelection) => AddStep("create visualiser", () => Child = visualiser = new PathControlPointVisualiser<Slider>(slider, allowSelection)
|
2020-04-13 15:13:14 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
});
|
|
|
|
|
2021-04-08 17:46:52 +08:00
|
|
|
private void addControlPointStep(Vector2 position) => addControlPointStep(position, null);
|
|
|
|
|
|
|
|
private void addControlPointStep(Vector2 position, PathType? type)
|
|
|
|
{
|
2023-11-20 14:53:25 +08:00
|
|
|
AddStep($"add {type?.Type} control point at {position}", () =>
|
2021-04-08 17:46:52 +08:00
|
|
|
{
|
|
|
|
slider.Path.ControlPoints.Add(new PathControlPoint(position, type));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void moveMouseToControlPoint(int index)
|
|
|
|
{
|
|
|
|
AddStep($"move mouse to control point {index}", () =>
|
|
|
|
{
|
2021-08-26 12:47:10 +08:00
|
|
|
Vector2 position = slider.Path.ControlPoints[index].Position;
|
2023-10-17 16:40:44 +08:00
|
|
|
InputManager.MoveMouseTo(visualiser.Pieces[0].Parent!.ToScreenSpace(position));
|
2021-04-08 17:46:52 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void assertControlPointPathType(int controlPointIndex, PathType? type)
|
|
|
|
{
|
2021-08-26 00:42:57 +08:00
|
|
|
AddAssert($"point {controlPointIndex} is {type}", () => slider.Path.ControlPoints[controlPointIndex].Type == type);
|
2021-04-08 17:46:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addContextMenuItemStep(string contextMenuText)
|
|
|
|
{
|
|
|
|
AddStep($"click context menu item \"{contextMenuText}\"", () =>
|
|
|
|
{
|
2024-02-02 18:48:13 +08:00
|
|
|
MenuItem item = visualiser.ContextMenuItems!.FirstOrDefault(menuItem => menuItem.Text.Value == "Curve type")?.Items.FirstOrDefault(menuItem => menuItem.Text.Value == contextMenuText);
|
2021-04-08 17:46:52 +08:00
|
|
|
|
2023-06-25 01:04:05 +08:00
|
|
|
item?.Action.Value?.Invoke();
|
2021-04-08 17:46:52 +08:00
|
|
|
});
|
|
|
|
}
|
2020-04-13 15:13:14 +08:00
|
|
|
}
|
|
|
|
}
|