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-11-26 16:40:25 +08:00
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Input;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Components
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2019-05-15 03:37:25 +08:00
|
|
|
public class TestSceneIdleTracker : ManualInputManagerTestScene
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
|
|
|
private readonly IdleTrackingBox box1;
|
|
|
|
private readonly IdleTrackingBox box2;
|
|
|
|
private readonly IdleTrackingBox box3;
|
|
|
|
private readonly IdleTrackingBox box4;
|
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
public TestSceneIdleTracker()
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
box1 = new IdleTrackingBox(1000)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Red,
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
},
|
|
|
|
box2 = new IdleTrackingBox(2000)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Green,
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
},
|
|
|
|
box3 = new IdleTrackingBox(3000)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Blue,
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
},
|
|
|
|
box4 = new IdleTrackingBox(4000)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Orange,
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNudge()
|
|
|
|
{
|
|
|
|
AddStep("move mouse to top left", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre));
|
|
|
|
|
2019-03-19 16:24:26 +08:00
|
|
|
AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle);
|
2018-11-26 16:40:25 +08:00
|
|
|
|
|
|
|
AddStep("nudge mouse", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre + new Vector2(1)));
|
|
|
|
|
|
|
|
AddAssert("check not idle", () => !box1.IsIdle);
|
|
|
|
AddAssert("check idle", () => box2.IsIdle);
|
|
|
|
AddAssert("check idle", () => box3.IsIdle);
|
|
|
|
AddAssert("check idle", () => box4.IsIdle);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMovement()
|
|
|
|
{
|
|
|
|
AddStep("move mouse", () => InputManager.MoveMouseTo(box2.ScreenSpaceDrawQuad.Centre));
|
|
|
|
|
|
|
|
AddAssert("check not idle", () => box1.IsIdle);
|
|
|
|
AddAssert("check not idle", () => !box2.IsIdle);
|
|
|
|
AddAssert("check idle", () => box3.IsIdle);
|
|
|
|
AddAssert("check idle", () => box4.IsIdle);
|
|
|
|
|
|
|
|
AddStep("move mouse", () => InputManager.MoveMouseTo(box3.ScreenSpaceDrawQuad.Centre));
|
|
|
|
AddStep("move mouse", () => InputManager.MoveMouseTo(box4.ScreenSpaceDrawQuad.Centre));
|
|
|
|
|
|
|
|
AddAssert("check not idle", () => box1.IsIdle);
|
|
|
|
AddAssert("check not idle", () => !box2.IsIdle);
|
|
|
|
AddAssert("check idle", () => !box3.IsIdle);
|
|
|
|
AddAssert("check idle", () => !box4.IsIdle);
|
|
|
|
|
2019-03-19 16:24:26 +08:00
|
|
|
AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle);
|
2018-11-26 16:40:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestTimings()
|
|
|
|
{
|
|
|
|
AddStep("move mouse", () => InputManager.MoveMouseTo(ScreenSpaceDrawQuad.Centre));
|
|
|
|
|
|
|
|
AddAssert("check not idle", () => !box1.IsIdle && !box2.IsIdle && !box3.IsIdle && !box4.IsIdle);
|
2019-03-19 16:24:26 +08:00
|
|
|
AddUntilStep("Wait for idle", () => box1.IsIdle);
|
2018-11-26 16:40:25 +08:00
|
|
|
AddAssert("check not idle", () => !box2.IsIdle && !box3.IsIdle && !box4.IsIdle);
|
2019-03-19 16:24:26 +08:00
|
|
|
AddUntilStep("Wait for idle", () => box2.IsIdle);
|
2018-11-26 16:40:25 +08:00
|
|
|
AddAssert("check not idle", () => !box3.IsIdle && !box4.IsIdle);
|
2019-03-19 16:24:26 +08:00
|
|
|
AddUntilStep("Wait for idle", () => box3.IsIdle);
|
2018-11-26 16:40:25 +08:00
|
|
|
|
2019-03-19 16:24:26 +08:00
|
|
|
AddUntilStep("Wait for all idle", () => box1.IsIdle && box2.IsIdle && box3.IsIdle && box4.IsIdle);
|
2018-11-26 16:40:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private class IdleTrackingBox : CompositeDrawable
|
|
|
|
{
|
|
|
|
private readonly IdleTracker idleTracker;
|
|
|
|
|
|
|
|
public bool IsIdle => idleTracker.IsIdle.Value;
|
|
|
|
|
|
|
|
public IdleTrackingBox(double timeToIdle)
|
|
|
|
{
|
|
|
|
Box box;
|
|
|
|
|
|
|
|
Alpha = 0.6f;
|
|
|
|
Scale = new Vector2(0.6f);
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
idleTracker = new IdleTracker(timeToIdle),
|
|
|
|
box = new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.White,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-02-22 19:13:38 +08:00
|
|
|
idleTracker.IsIdle.BindValueChanged(idle => box.Colour = idle.NewValue ? Color4.White : Color4.Black, true);
|
2018-11-26 16:40:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|