2020-03-06 20:10:23 +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-03-06 20:10:23 +00:00
|
|
|
using System;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
2021-09-16 13:41:35 +00:00
|
|
|
using osu.Framework.Input.Events;
|
2020-03-06 20:10:23 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Skinning;
|
2020-03-22 22:45:13 +00:00
|
|
|
using osu.Game.Tests.Visual;
|
2020-03-06 20:10:23 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
{
|
2020-03-23 01:01:33 +00:00
|
|
|
public partial class TestSceneHitCircleArea : OsuManualInputManagerTestScene
|
2020-03-06 20:10:23 +00:00
|
|
|
{
|
|
|
|
private HitCircle hitCircle;
|
|
|
|
private DrawableHitCircle drawableHitCircle;
|
|
|
|
private DrawableHitCircle.HitReceptor hitAreaReceptor => drawableHitCircle.HitArea;
|
|
|
|
|
|
|
|
[SetUp]
|
2020-03-22 22:45:13 +00:00
|
|
|
public void SetUp() => Schedule(() =>
|
2020-03-06 20:10:23 +00:00
|
|
|
{
|
2020-03-22 22:45:13 +00:00
|
|
|
hitCircle = new HitCircle
|
2020-03-06 20:10:23 +00:00
|
|
|
{
|
2020-03-22 22:45:13 +00:00
|
|
|
Position = new Vector2(100, 100),
|
|
|
|
StartTime = Time.Current + 500
|
|
|
|
};
|
2020-03-06 20:10:23 +00:00
|
|
|
|
2020-03-22 22:45:13 +00:00
|
|
|
hitCircle.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
2020-03-06 20:10:23 +00:00
|
|
|
|
2022-11-09 07:45:06 +00:00
|
|
|
Child = new SkinProvidingContainer(new TrianglesSkin(null!))
|
2020-03-22 22:45:13 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = drawableHitCircle = new DrawableHitCircle(hitCircle)
|
2020-03-06 20:10:23 +00:00
|
|
|
{
|
2020-03-22 22:45:13 +00:00
|
|
|
Size = new Vector2(100)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2020-03-06 20:10:23 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCircleHitCentre()
|
|
|
|
{
|
|
|
|
AddStep("move mouse to centre", () => InputManager.MoveMouseTo(hitAreaReceptor.ScreenSpaceDrawQuad.Centre));
|
|
|
|
scheduleHit();
|
|
|
|
|
|
|
|
AddAssert("hit registered", () => hitAreaReceptor.HitAction == OsuAction.LeftButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCircleHitLeftEdge()
|
|
|
|
{
|
|
|
|
AddStep("move mouse to left edge", () =>
|
|
|
|
{
|
|
|
|
var drawQuad = hitAreaReceptor.ScreenSpaceDrawQuad;
|
|
|
|
var mousePosition = new Vector2(drawQuad.TopLeft.X, drawQuad.Centre.Y);
|
|
|
|
|
|
|
|
InputManager.MoveMouseTo(mousePosition);
|
|
|
|
});
|
|
|
|
scheduleHit();
|
|
|
|
|
|
|
|
AddAssert("hit registered", () => hitAreaReceptor.HitAction == OsuAction.LeftButton);
|
|
|
|
}
|
|
|
|
|
2020-03-06 21:09:02 +00:00
|
|
|
[TestCase(0.95f, OsuAction.LeftButton)]
|
|
|
|
[TestCase(1.05f, null)]
|
|
|
|
public void TestHitsCloseToEdge(float relativeDistanceFromCentre, OsuAction? expectedAction)
|
2020-03-06 20:10:23 +00:00
|
|
|
{
|
|
|
|
AddStep("move mouse to top left circle edge", () =>
|
|
|
|
{
|
|
|
|
var drawQuad = hitAreaReceptor.ScreenSpaceDrawQuad;
|
|
|
|
// sqrt(2) / 2 = sin(45deg) = cos(45deg)
|
|
|
|
// draw width halved to get radius
|
2020-03-06 21:09:02 +00:00
|
|
|
float correction = relativeDistanceFromCentre * (float)Math.Sqrt(2) / 2 * (drawQuad.Width / 2);
|
2020-03-06 20:10:23 +00:00
|
|
|
var mousePosition = new Vector2(drawQuad.Centre.X - correction, drawQuad.Centre.Y - correction);
|
|
|
|
|
|
|
|
InputManager.MoveMouseTo(mousePosition);
|
|
|
|
});
|
|
|
|
scheduleHit();
|
|
|
|
|
2020-03-06 21:09:02 +00:00
|
|
|
AddAssert($"hit {(expectedAction == null ? "not " : string.Empty)}registered", () => hitAreaReceptor.HitAction == expectedAction);
|
2020-03-06 20:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCircleMissBoundingBoxCorner()
|
|
|
|
{
|
|
|
|
AddStep("move mouse to top left corner of bounding box", () => InputManager.MoveMouseTo(hitAreaReceptor.ScreenSpaceDrawQuad.TopLeft));
|
|
|
|
scheduleHit();
|
|
|
|
|
|
|
|
AddAssert("hit not registered", () => hitAreaReceptor.HitAction == null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void scheduleHit() => AddStep("schedule action", () =>
|
|
|
|
{
|
2021-10-27 04:04:41 +00:00
|
|
|
double delay = hitCircle.StartTime - hitCircle.HitWindows.WindowFor(HitResult.Great) - Time.Current;
|
2021-09-16 13:41:35 +00:00
|
|
|
Scheduler.AddDelayed(() => hitAreaReceptor.OnPressed(new KeyBindingPressEvent<OsuAction>(GetContainingInputManager().CurrentState, OsuAction.LeftButton)), delay);
|
2020-03-06 20:10:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|