2020-04-13 07:13:14 +00: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 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-04-13 07:13:14 +00:00
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
2021-04-08 09:46:52 +00:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-04-13 07:13:14 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-04-08 09:46:52 +00:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2020-04-13 07:13:14 +00: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 09:48:04 +00:00
|
|
|
namespace osu.Game.Rulesets.Osu.Tests.Editor
|
2020-04-13 07:13:14 +00:00
|
|
|
{
|
2021-04-08 09:46:52 +00:00
|
|
|
public partial class TestScenePathControlPointVisualiser : OsuManualInputManagerTestScene
|
2020-04-13 07:13:14 +00:00
|
|
|
{
|
|
|
|
private Slider slider;
|
2022-11-03 11:25:23 +00:00
|
|
|
private PathControlPointVisualiser<Slider> visualiser;
|
2020-04-13 07:13:14 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
|
|
|
slider = new Slider();
|
|
|
|
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
|
|
|
});
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddOverlappingControlPoints()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
|
|
|
addControlPointStep(new Vector2(200));
|
|
|
|
addControlPointStep(new Vector2(300));
|
|
|
|
addControlPointStep(new Vector2(300));
|
|
|
|
addControlPointStep(new Vector2(500, 300));
|
|
|
|
|
|
|
|
AddAssert("last connection displayed", () =>
|
|
|
|
{
|
2021-08-25 16:42:57 +00:00
|
|
|
var lastConnection = visualiser.Connections.Last(c => c.ControlPoint.Position == new Vector2(300));
|
2020-04-13 07:13:14 +00:00
|
|
|
return lastConnection.DrawWidth > 50;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-08 09:46:52 +00:00
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveTooManyPoints()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
|
|
|
addControlPointStep(new Vector2(200), PathType.Bezier);
|
|
|
|
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");
|
|
|
|
|
|
|
|
assertControlPointPathType(0, PathType.Bezier);
|
|
|
|
assertControlPointPathType(1, PathType.PerfectCurve);
|
2021-04-09 09:03:38 +00:00
|
|
|
assertControlPointPathType(3, PathType.Bezier);
|
2021-04-08 09:46:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveLastThreePoints()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
|
|
|
addControlPointStep(new Vector2(200), PathType.Bezier);
|
|
|
|
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");
|
|
|
|
|
|
|
|
assertControlPointPathType(0, PathType.Bezier);
|
|
|
|
assertControlPointPathType(2, PathType.PerfectCurve);
|
|
|
|
assertControlPointPathType(4, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveLastTwoPoints()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
|
|
|
addControlPointStep(new Vector2(200), PathType.Bezier);
|
|
|
|
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");
|
|
|
|
|
|
|
|
assertControlPointPathType(0, PathType.Bezier);
|
|
|
|
AddAssert("point 3 is not inherited", () => slider.Path.ControlPoints[3].Type != null);
|
|
|
|
}
|
|
|
|
|
2021-04-09 09:03:38 +00:00
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveTooManyPointsLinear()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
|
|
|
addControlPointStep(new Vector2(200), PathType.Linear);
|
|
|
|
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");
|
|
|
|
|
|
|
|
assertControlPointPathType(0, PathType.Linear);
|
|
|
|
assertControlPointPathType(1, PathType.PerfectCurve);
|
|
|
|
assertControlPointPathType(3, PathType.Linear);
|
|
|
|
}
|
|
|
|
|
2021-04-08 10:32:45 +00:00
|
|
|
[Test]
|
|
|
|
public void TestPerfectCurveChangeToBezier()
|
|
|
|
{
|
|
|
|
createVisualiser(true);
|
|
|
|
|
|
|
|
addControlPointStep(new Vector2(200), PathType.Bezier);
|
|
|
|
addControlPointStep(new Vector2(300), PathType.PerfectCurve);
|
|
|
|
addControlPointStep(new Vector2(500, 300));
|
|
|
|
addControlPointStep(new Vector2(700, 200), PathType.Bezier);
|
|
|
|
addControlPointStep(new Vector2(500, 100));
|
|
|
|
|
|
|
|
moveMouseToControlPoint(3);
|
|
|
|
AddStep("select control point", () => visualiser.Pieces[3].IsSelected.Value = true);
|
|
|
|
addContextMenuItemStep("Inherit");
|
|
|
|
|
|
|
|
assertControlPointPathType(0, PathType.Bezier);
|
|
|
|
assertControlPointPathType(1, PathType.Bezier);
|
|
|
|
assertControlPointPathType(3, null);
|
|
|
|
}
|
|
|
|
|
2022-11-03 11:25:23 +00:00
|
|
|
private void createVisualiser(bool allowSelection) => AddStep("create visualiser", () => Child = visualiser = new PathControlPointVisualiser<Slider>(slider, allowSelection)
|
2020-04-13 07:13:14 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
});
|
|
|
|
|
2021-04-08 09:46:52 +00:00
|
|
|
private void addControlPointStep(Vector2 position) => addControlPointStep(position, null);
|
|
|
|
|
|
|
|
private void addControlPointStep(Vector2 position, PathType? type)
|
|
|
|
{
|
|
|
|
AddStep($"add {type} control point at {position}", () =>
|
|
|
|
{
|
|
|
|
slider.Path.ControlPoints.Add(new PathControlPoint(position, type));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void moveMouseToControlPoint(int index)
|
|
|
|
{
|
|
|
|
AddStep($"move mouse to control point {index}", () =>
|
|
|
|
{
|
2021-08-26 04:47:10 +00:00
|
|
|
Vector2 position = slider.Path.ControlPoints[index].Position;
|
2021-04-08 09:46:52 +00:00
|
|
|
InputManager.MoveMouseTo(visualiser.Pieces[0].Parent.ToScreenSpace(position));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void assertControlPointPathType(int controlPointIndex, PathType? type)
|
|
|
|
{
|
2021-08-25 16:42:57 +00:00
|
|
|
AddAssert($"point {controlPointIndex} is {type}", () => slider.Path.ControlPoints[controlPointIndex].Type == type);
|
2021-04-08 09:46:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addContextMenuItemStep(string contextMenuText)
|
|
|
|
{
|
|
|
|
AddStep($"click context menu item \"{contextMenuText}\"", () =>
|
|
|
|
{
|
2022-08-19 17:31:47 +00:00
|
|
|
MenuItem item = visualiser.ContextMenuItems.FirstOrDefault(menuItem => menuItem.Text.Value == "Curve type")?.Items.FirstOrDefault(menuItem => menuItem.Text.Value == contextMenuText);
|
2021-04-08 09:46:52 +00:00
|
|
|
|
|
|
|
item?.Action?.Value();
|
|
|
|
});
|
|
|
|
}
|
2020-04-13 07:13:14 +00:00
|
|
|
}
|
|
|
|
}
|