2019-01-24 16:43:03 +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.
|
2018-10-25 17:48:11 +08:00
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2019-10-01 18:33:24 +08:00
|
|
|
using NUnit.Framework;
|
2020-01-09 12:43:44 +08:00
|
|
|
using osu.Framework.Utils;
|
2018-10-25 17:48:11 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2018-11-01 14:38:19 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-10-25 17:48:11 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2019-10-01 18:33:24 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components;
|
2018-11-07 15:08:56 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders;
|
|
|
|
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
|
2018-10-25 17:48:11 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
|
|
using osu.Game.Tests.Visual;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
2019-10-31 15:51:58 +08:00
|
|
|
using osuTK.Input;
|
2018-10-25 17:48:11 +08:00
|
|
|
|
2020-09-25 17:48:04 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Tests.Editor
|
2018-10-25 17:48:11 +08:00
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneSliderSelectionBlueprint : SelectionBlueprintTestScene
|
2018-10-25 17:48:11 +08:00
|
|
|
{
|
2019-10-01 18:33:24 +08:00
|
|
|
private Slider slider;
|
|
|
|
private DrawableSlider drawableObject;
|
|
|
|
private TestSliderBlueprint blueprint;
|
2018-10-25 17:48:11 +08:00
|
|
|
|
2019-10-01 18:33:24 +08:00
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
2018-10-25 17:48:11 +08:00
|
|
|
{
|
2019-10-01 18:33:24 +08:00
|
|
|
Clear();
|
|
|
|
|
|
|
|
slider = new Slider
|
2018-10-25 17:48:11 +08:00
|
|
|
{
|
|
|
|
Position = new Vector2(256, 192),
|
2018-11-01 14:38:19 +08:00
|
|
|
Path = new SliderPath(PathType.Bezier, new[]
|
2018-10-25 17:48:11 +08:00
|
|
|
{
|
|
|
|
Vector2.Zero,
|
|
|
|
new Vector2(150, 150),
|
|
|
|
new Vector2(300, 0)
|
2018-11-01 14:38:19 +08:00
|
|
|
})
|
2018-10-25 17:48:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 });
|
|
|
|
|
|
|
|
Add(drawableObject = new DrawableSlider(slider));
|
2021-05-13 18:53:32 +08:00
|
|
|
AddBlueprint(blueprint = new TestSliderBlueprint(slider), drawableObject);
|
2019-10-01 18:33:24 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestInitialState()
|
|
|
|
{
|
|
|
|
checkPositions();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMoveHitObject()
|
|
|
|
{
|
|
|
|
moveHitObject();
|
|
|
|
checkPositions();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMoveAfterApplyingDefaults()
|
|
|
|
{
|
|
|
|
AddStep("apply defaults", () => slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 }));
|
|
|
|
moveHitObject();
|
|
|
|
checkPositions();
|
|
|
|
}
|
|
|
|
|
2019-10-21 15:15:41 +08:00
|
|
|
[Test]
|
|
|
|
public void TestStackedHitObject()
|
|
|
|
{
|
|
|
|
AddStep("set stacking", () => slider.StackHeight = 5);
|
|
|
|
checkPositions();
|
|
|
|
}
|
|
|
|
|
2019-10-31 15:51:58 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSingleControlPointSelection()
|
|
|
|
{
|
|
|
|
moveMouseToControlPoint(0);
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
checkControlPointSelected(0, true);
|
|
|
|
checkControlPointSelected(1, false);
|
2019-10-31 16:25:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSingleControlPointDeselectionViaOtherControlPoint()
|
|
|
|
{
|
|
|
|
moveMouseToControlPoint(0);
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
2019-10-31 15:51:58 +08:00
|
|
|
|
|
|
|
moveMouseToControlPoint(1);
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
checkControlPointSelected(0, false);
|
|
|
|
checkControlPointSelected(1, true);
|
2019-10-31 16:25:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestSingleControlPointDeselectionViaClickOutside()
|
|
|
|
{
|
|
|
|
moveMouseToControlPoint(0);
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
|
|
|
|
AddStep("move mouse outside control point", () => InputManager.MoveMouseTo(drawableObject));
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
checkControlPointSelected(0, false);
|
|
|
|
checkControlPointSelected(1, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMultipleControlPointSelection()
|
|
|
|
{
|
|
|
|
moveMouseToControlPoint(0);
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
moveMouseToControlPoint(1);
|
|
|
|
AddStep("ctrl + click", () =>
|
|
|
|
{
|
|
|
|
InputManager.PressKey(Key.ControlLeft);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
InputManager.ReleaseKey(Key.ControlLeft);
|
|
|
|
});
|
|
|
|
checkControlPointSelected(0, true);
|
|
|
|
checkControlPointSelected(1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMultipleControlPointDeselectionViaOtherControlPoint()
|
|
|
|
{
|
|
|
|
moveMouseToControlPoint(0);
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
moveMouseToControlPoint(1);
|
|
|
|
AddStep("ctrl + click", () =>
|
|
|
|
{
|
|
|
|
InputManager.PressKey(Key.ControlLeft);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
InputManager.ReleaseKey(Key.ControlLeft);
|
|
|
|
});
|
|
|
|
|
|
|
|
moveMouseToControlPoint(2);
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
checkControlPointSelected(0, false);
|
|
|
|
checkControlPointSelected(1, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMultipleControlPointDeselectionViaClickOutside()
|
|
|
|
{
|
|
|
|
moveMouseToControlPoint(0);
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
moveMouseToControlPoint(1);
|
|
|
|
AddStep("ctrl + click", () =>
|
|
|
|
{
|
|
|
|
InputManager.PressKey(Key.ControlLeft);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
InputManager.ReleaseKey(Key.ControlLeft);
|
|
|
|
});
|
2019-10-31 15:51:58 +08:00
|
|
|
|
|
|
|
AddStep("move mouse outside control point", () => InputManager.MoveMouseTo(drawableObject));
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
checkControlPointSelected(0, false);
|
|
|
|
checkControlPointSelected(1, false);
|
|
|
|
}
|
|
|
|
|
2019-10-01 18:33:24 +08:00
|
|
|
private void moveHitObject()
|
|
|
|
{
|
|
|
|
AddStep("move hitobject", () =>
|
|
|
|
{
|
|
|
|
slider.Position = new Vector2(300, 225);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkPositions()
|
|
|
|
{
|
2019-10-21 15:15:41 +08:00
|
|
|
AddAssert("body positioned correctly", () => blueprint.BodyPiece.Position == slider.StackedPosition);
|
2019-10-01 18:33:24 +08:00
|
|
|
|
|
|
|
AddAssert("head positioned correctly",
|
2021-05-18 13:19:11 +08:00
|
|
|
() => Precision.AlmostEquals(blueprint.HeadOverlay.CirclePiece.ScreenSpaceDrawQuad.Centre, drawableObject.HeadCircle.ScreenSpaceDrawQuad.Centre));
|
2019-10-01 18:33:24 +08:00
|
|
|
|
|
|
|
AddAssert("tail positioned correctly",
|
2021-05-18 13:19:11 +08:00
|
|
|
() => Precision.AlmostEquals(blueprint.TailOverlay.CirclePiece.ScreenSpaceDrawQuad.Centre, drawableObject.TailCircle.ScreenSpaceDrawQuad.Centre));
|
2018-10-25 17:48:11 +08:00
|
|
|
}
|
|
|
|
|
2019-10-31 15:51:58 +08:00
|
|
|
private void moveMouseToControlPoint(int index)
|
|
|
|
{
|
|
|
|
AddStep($"move mouse to control point {index}", () =>
|
|
|
|
{
|
2021-08-26 00:42:57 +08:00
|
|
|
Vector2 position = slider.Position + slider.Path.ControlPoints[index].Position;
|
2019-10-31 15:51:58 +08:00
|
|
|
InputManager.MoveMouseTo(drawableObject.Parent.ToScreenSpace(position));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkControlPointSelected(int index, bool selected)
|
|
|
|
=> AddAssert($"control point {index} {(selected ? "selected" : "not selected")}", () => blueprint.ControlPointVisualiser.Pieces[index].IsSelected.Value == selected);
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
private partial class TestSliderBlueprint : SliderSelectionBlueprint
|
2019-10-01 18:33:24 +08:00
|
|
|
{
|
|
|
|
public new SliderBodyPiece BodyPiece => base.BodyPiece;
|
2021-05-18 13:19:11 +08:00
|
|
|
public new TestSliderCircleOverlay HeadOverlay => (TestSliderCircleOverlay)base.HeadOverlay;
|
|
|
|
public new TestSliderCircleOverlay TailOverlay => (TestSliderCircleOverlay)base.TailOverlay;
|
2019-10-31 15:51:58 +08:00
|
|
|
public new PathControlPointVisualiser ControlPointVisualiser => base.ControlPointVisualiser;
|
2019-10-01 18:33:24 +08:00
|
|
|
|
2021-05-13 18:53:32 +08:00
|
|
|
public TestSliderBlueprint(Slider slider)
|
2019-10-01 18:33:24 +08:00
|
|
|
: base(slider)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-18 13:19:11 +08:00
|
|
|
protected override SliderCircleOverlay CreateCircleOverlay(Slider slider, SliderPosition position) => new TestSliderCircleOverlay(slider, position);
|
2019-10-01 18:33:24 +08:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
private partial class TestSliderCircleOverlay : SliderCircleOverlay
|
2019-10-01 18:33:24 +08:00
|
|
|
{
|
|
|
|
public new HitCirclePiece CirclePiece => base.CirclePiece;
|
|
|
|
|
2021-05-18 13:19:11 +08:00
|
|
|
public TestSliderCircleOverlay(Slider slider, SliderPosition position)
|
2019-10-01 18:33:24 +08:00
|
|
|
: base(slider, position)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2018-10-25 17:48:11 +08:00
|
|
|
}
|
|
|
|
}
|