mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:03:22 +08:00
Add test
This commit is contained in:
parent
e23a75c64a
commit
cfdf710676
@ -16,6 +16,7 @@ using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osu.Game.Tests.Visual;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
@ -85,6 +86,25 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
checkPositions();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSingleControlPointSelection()
|
||||
{
|
||||
moveMouseToControlPoint(0);
|
||||
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
||||
checkControlPointSelected(0, true);
|
||||
checkControlPointSelected(1, false);
|
||||
|
||||
moveMouseToControlPoint(1);
|
||||
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
||||
checkControlPointSelected(0, false);
|
||||
checkControlPointSelected(1, true);
|
||||
|
||||
AddStep("move mouse outside control point", () => InputManager.MoveMouseTo(drawableObject));
|
||||
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
||||
checkControlPointSelected(0, false);
|
||||
checkControlPointSelected(1, false);
|
||||
}
|
||||
|
||||
private void moveHitObject()
|
||||
{
|
||||
AddStep("move hitobject", () =>
|
||||
@ -104,11 +124,24 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
() => Precision.AlmostEquals(blueprint.TailBlueprint.CirclePiece.ScreenSpaceDrawQuad.Centre, drawableObject.TailCircle.ScreenSpaceDrawQuad.Centre));
|
||||
}
|
||||
|
||||
private void moveMouseToControlPoint(int index)
|
||||
{
|
||||
AddStep($"move mouse to control point {index}", () =>
|
||||
{
|
||||
Vector2 position = slider.Position + slider.Path.ControlPoints[index];
|
||||
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);
|
||||
|
||||
private class TestSliderBlueprint : SliderSelectionBlueprint
|
||||
{
|
||||
public new SliderBodyPiece BodyPiece => base.BodyPiece;
|
||||
public new TestSliderCircleBlueprint HeadBlueprint => (TestSliderCircleBlueprint)base.HeadBlueprint;
|
||||
public new TestSliderCircleBlueprint TailBlueprint => (TestSliderCircleBlueprint)base.TailBlueprint;
|
||||
public new PathControlPointVisualiser ControlPointVisualiser => base.ControlPointVisualiser;
|
||||
|
||||
public TestSliderBlueprint(DrawableSlider slider)
|
||||
: base(slider)
|
||||
|
@ -14,9 +14,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
{
|
||||
public Action<Vector2[]> ControlPointsChanged;
|
||||
|
||||
private readonly Slider slider;
|
||||
internal Container<PathControlPointPiece> Pieces { get; }
|
||||
|
||||
private readonly Container<PathControlPointPiece> pieces;
|
||||
private readonly Slider slider;
|
||||
|
||||
public PathControlPointVisualiser(Slider slider)
|
||||
{
|
||||
@ -24,24 +24,24 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
InternalChild = pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both };
|
||||
InternalChild = Pieces = new Container<PathControlPointPiece> { RelativeSizeAxes = Axes.Both };
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
while (slider.Path.ControlPoints.Length > pieces.Count)
|
||||
pieces.Add(new PathControlPointPiece(slider, pieces.Count) { ControlPointsChanged = c => ControlPointsChanged?.Invoke(c) });
|
||||
while (slider.Path.ControlPoints.Length < pieces.Count)
|
||||
pieces.Remove(pieces[pieces.Count - 1]);
|
||||
while (slider.Path.ControlPoints.Length > Pieces.Count)
|
||||
Pieces.Add(new PathControlPointPiece(slider, Pieces.Count) { ControlPointsChanged = c => ControlPointsChanged?.Invoke(c) });
|
||||
while (slider.Path.ControlPoints.Length < Pieces.Count)
|
||||
Pieces.Remove(Pieces[Pieces.Count - 1]);
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
bool anySelected = false;
|
||||
|
||||
foreach (var piece in pieces)
|
||||
foreach (var piece in Pieces)
|
||||
{
|
||||
if (piece.IsHovered)
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
protected readonly SliderBodyPiece BodyPiece;
|
||||
protected readonly SliderCircleSelectionBlueprint HeadBlueprint;
|
||||
protected readonly SliderCircleSelectionBlueprint TailBlueprint;
|
||||
protected readonly PathControlPointVisualiser ControlPointVisualiser;
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private HitObjectComposer composer { get; set; }
|
||||
@ -32,7 +33,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
BodyPiece = new SliderBodyPiece(),
|
||||
HeadBlueprint = CreateCircleSelectionBlueprint(slider, SliderPosition.Start),
|
||||
TailBlueprint = CreateCircleSelectionBlueprint(slider, SliderPosition.End),
|
||||
new PathControlPointVisualiser(sliderObject) { ControlPointsChanged = onNewControlPoints },
|
||||
ControlPointVisualiser = new PathControlPointVisualiser(sliderObject) { ControlPointsChanged = onNewControlPoints },
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ using osu.Game.Rulesets.Edit;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public abstract class SelectionBlueprintTestScene : OsuTestScene
|
||||
public abstract class SelectionBlueprintTestScene : ManualInputManagerTestScene
|
||||
{
|
||||
protected override Container<Drawable> Content => content ?? base.Content;
|
||||
private readonly Container content;
|
||||
|
Loading…
Reference in New Issue
Block a user