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;
|
2021-04-16 17:01:58 +08:00
|
|
|
using osu.Game.Configuration;
|
2018-11-26 16:40:25 +08:00
|
|
|
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]
|
2020-03-23 09:01:33 +08:00
|
|
|
public class TestSceneIdleTracker : OsuManualInputManagerTestScene
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
2019-06-24 10:09:59 +08:00
|
|
|
private IdleTrackingBox box1;
|
|
|
|
private IdleTrackingBox box2;
|
|
|
|
private IdleTrackingBox box3;
|
|
|
|
private IdleTrackingBox box4;
|
2018-11-26 16:40:25 +08:00
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
private IdleTrackingBox[] boxes;
|
2019-06-24 10:00:00 +08:00
|
|
|
|
2021-04-16 17:01:58 +08:00
|
|
|
public SessionStatics sessionStatics;
|
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
[SetUp]
|
|
|
|
public void SetUp() => Schedule(() =>
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
2021-04-16 17:01:58 +08:00
|
|
|
sessionStatics = new SessionStatics();
|
2019-06-24 10:09:59 +08:00
|
|
|
InputManager.MoveMouseTo(Vector2.Zero);
|
|
|
|
|
2019-06-24 10:10:29 +08:00
|
|
|
Children = boxes = new[]
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
2021-04-16 17:01:58 +08:00
|
|
|
box1 = new IdleTrackingBox(2000, sessionStatics)
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
2019-06-22 23:34:06 +08:00
|
|
|
Name = "TopLeft",
|
2018-11-26 16:40:25 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Red,
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
},
|
2021-04-16 17:01:58 +08:00
|
|
|
box2 = new IdleTrackingBox(4000, sessionStatics)
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
2019-06-22 23:34:06 +08:00
|
|
|
Name = "TopRight",
|
2018-11-26 16:40:25 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Green,
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
},
|
2021-04-16 17:01:58 +08:00
|
|
|
box3 = new IdleTrackingBox(6000, sessionStatics)
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
2019-06-22 23:34:06 +08:00
|
|
|
Name = "BottomLeft",
|
2018-11-26 16:40:25 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Blue,
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
},
|
2021-04-16 17:01:58 +08:00
|
|
|
box4 = new IdleTrackingBox(8000, sessionStatics)
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
2019-06-22 23:34:06 +08:00
|
|
|
Name = "BottomRight",
|
2018-11-26 16:40:25 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.Orange,
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
},
|
|
|
|
};
|
2019-06-24 10:09:59 +08:00
|
|
|
});
|
2018-11-26 16:40:25 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestNudge()
|
|
|
|
{
|
2019-06-22 23:43:24 +08:00
|
|
|
AddStep("move to top left", () => InputManager.MoveMouseTo(box1));
|
2018-11-26 16:40:25 +08:00
|
|
|
|
2019-06-22 23:34:06 +08:00
|
|
|
waitForAllIdle();
|
2018-11-26 16:40:25 +08:00
|
|
|
|
|
|
|
AddStep("nudge mouse", () => InputManager.MoveMouseTo(box1.ScreenSpaceDrawQuad.Centre + new Vector2(1)));
|
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
checkIdleStatus(1, false);
|
|
|
|
checkIdleStatus(2, true);
|
|
|
|
checkIdleStatus(3, true);
|
|
|
|
checkIdleStatus(4, true);
|
2018-11-26 16:40:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMovement()
|
|
|
|
{
|
2019-06-22 23:43:24 +08:00
|
|
|
AddStep("move to top right", () => InputManager.MoveMouseTo(box2));
|
2018-11-26 16:40:25 +08:00
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
checkIdleStatus(1, true);
|
|
|
|
checkIdleStatus(2, false);
|
|
|
|
checkIdleStatus(3, true);
|
|
|
|
checkIdleStatus(4, true);
|
2018-11-26 16:40:25 +08:00
|
|
|
|
2019-06-22 23:43:24 +08:00
|
|
|
AddStep("move to bottom left", () => InputManager.MoveMouseTo(box3));
|
|
|
|
AddStep("move to bottom right", () => InputManager.MoveMouseTo(box4));
|
2018-11-26 16:40:25 +08:00
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
checkIdleStatus(1, true);
|
|
|
|
checkIdleStatus(2, false);
|
|
|
|
checkIdleStatus(3, false);
|
|
|
|
checkIdleStatus(4, false);
|
2018-11-26 16:40:25 +08:00
|
|
|
|
2019-06-22 23:34:06 +08:00
|
|
|
waitForAllIdle();
|
2018-11-26 16:40:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestTimings()
|
|
|
|
{
|
2019-06-22 23:43:24 +08:00
|
|
|
AddStep("move to centre", () => InputManager.MoveMouseTo(Content));
|
2019-06-22 23:34:06 +08:00
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
checkIdleStatus(1, false);
|
|
|
|
checkIdleStatus(2, false);
|
|
|
|
checkIdleStatus(3, false);
|
|
|
|
checkIdleStatus(4, false);
|
2018-11-26 16:40:25 +08:00
|
|
|
|
2019-03-19 16:24:26 +08:00
|
|
|
AddUntilStep("Wait for idle", () => box1.IsIdle);
|
2019-06-22 23:34:06 +08:00
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
checkIdleStatus(1, true);
|
|
|
|
checkIdleStatus(2, false);
|
|
|
|
checkIdleStatus(3, false);
|
|
|
|
checkIdleStatus(4, false);
|
2019-06-22 23:34:06 +08:00
|
|
|
|
2019-03-19 16:24:26 +08:00
|
|
|
AddUntilStep("Wait for idle", () => box2.IsIdle);
|
2019-06-22 23:34:06 +08:00
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
checkIdleStatus(1, true);
|
|
|
|
checkIdleStatus(2, true);
|
|
|
|
checkIdleStatus(3, false);
|
|
|
|
checkIdleStatus(4, false);
|
2019-06-22 23:34:06 +08:00
|
|
|
|
2019-03-19 16:24:26 +08:00
|
|
|
AddUntilStep("Wait for idle", () => box3.IsIdle);
|
2018-11-26 16:40:25 +08:00
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
checkIdleStatus(1, true);
|
|
|
|
checkIdleStatus(2, true);
|
|
|
|
checkIdleStatus(3, true);
|
|
|
|
checkIdleStatus(4, false);
|
2019-06-22 23:34:06 +08:00
|
|
|
|
|
|
|
waitForAllIdle();
|
|
|
|
}
|
|
|
|
|
2021-04-16 17:01:58 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSessionStaticsReset()
|
|
|
|
{
|
|
|
|
AddStep("move to top left", () => InputManager.MoveMouseTo(box1));
|
|
|
|
AddStep("set session statics", () =>
|
|
|
|
{
|
|
|
|
sessionStatics.SetValue(Static.LoginOverlayDisplayed, true);
|
|
|
|
sessionStatics.SetValue(Static.MutedAudioNotificationShownOnce, true);
|
|
|
|
sessionStatics.SetValue(Static.LowBatteryNotificationShownOnce, true);
|
|
|
|
sessionStatics.SetValue(Static.LastHoverSoundPlaybackTime, (double?)1d);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("move away from box1", () => InputManager.MoveMouseTo(box4));
|
|
|
|
AddUntilStep("Wait for idle", () => box1.IsIdle);
|
|
|
|
AddAssert("LoginOverlayDisplayed is default", () => sessionStatics.Get<bool>(Static.LoginOverlayDisplayed) == false);
|
|
|
|
AddAssert("MutedAudioNotificationShownOnce is default", () => sessionStatics.Get<bool>(Static.MutedAudioNotificationShownOnce) == false);
|
|
|
|
AddAssert("LowBatteryNotificationShownOnce is default", () => sessionStatics.Get<bool>(Static.LowBatteryNotificationShownOnce) == false);
|
|
|
|
AddAssert("LastHoverSoundPlaybackTime is default", () => sessionStatics.Get<double?>(Static.LastHoverSoundPlaybackTime) == null);
|
|
|
|
}
|
|
|
|
|
2019-06-24 10:09:59 +08:00
|
|
|
private void checkIdleStatus(int box, bool expectedIdle)
|
2019-06-22 23:34:06 +08:00
|
|
|
{
|
2019-06-24 10:09:59 +08:00
|
|
|
AddAssert($"box {box} is {(expectedIdle ? "idle" : "active")}", () => boxes[box - 1].IsIdle == expectedIdle);
|
2019-06-22 23:34:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void waitForAllIdle()
|
|
|
|
{
|
2021-04-16 17:01:58 +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;
|
|
|
|
|
2021-04-16 17:01:58 +08:00
|
|
|
public IdleTrackingBox(int timeToIdle, SessionStatics statics)
|
2018-11-26 16:40:25 +08:00
|
|
|
{
|
|
|
|
Box box;
|
|
|
|
|
|
|
|
Alpha = 0.6f;
|
|
|
|
Scale = new Vector2(0.6f);
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2021-04-16 17:01:58 +08:00
|
|
|
idleTracker = new GameIdleTracker(timeToIdle, statics),
|
2018-11-26 16:40:25 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|