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-04-13 17:19:50 +08:00
|
|
|
|
|
2018-09-15 15:25:37 +08:00
|
|
|
|
using System.Linq;
|
2018-03-02 14:34:31 +08:00
|
|
|
|
using NUnit.Framework;
|
2023-06-15 03:13:35 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2023-06-15 03:13:35 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-01-09 12:43:44 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2023-03-07 15:28:54 +08:00
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
2023-02-16 06:18:02 +08:00
|
|
|
|
using osuTK;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2018-03-02 14:34:31 +08:00
|
|
|
|
[TestFixture]
|
2020-03-23 09:01:33 +08:00
|
|
|
|
public partial class TestSceneKeyCounter : OsuManualInputManagerTestScene
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2023-06-15 03:13:35 +08:00
|
|
|
|
[Cached]
|
2023-06-27 01:27:42 +08:00
|
|
|
|
private readonly InputCountController controller;
|
2023-06-15 03:13:35 +08:00
|
|
|
|
|
2019-05-15 03:37:25 +08:00
|
|
|
|
public TestSceneKeyCounter()
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2023-06-15 03:13:35 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2023-06-27 01:27:42 +08:00
|
|
|
|
controller = new InputCountController(),
|
2023-06-15 03:13:35 +08:00
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(72.7f),
|
2023-06-15 18:02:30 +08:00
|
|
|
|
Children = new KeyCounterDisplay[]
|
2023-06-15 03:13:35 +08:00
|
|
|
|
{
|
2023-06-15 18:02:30 +08:00
|
|
|
|
new DefaultKeyCounterDisplay
|
2023-06-15 03:13:35 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
new ArgonKeyCounterDisplay
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-18 21:32:49 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-06-27 15:35:59 +08:00
|
|
|
|
var inputTriggers = new InputTrigger[]
|
2023-04-06 03:34:36 +08:00
|
|
|
|
{
|
|
|
|
|
new KeyCounterKeyboardTrigger(Key.X),
|
|
|
|
|
new KeyCounterKeyboardTrigger(Key.X),
|
|
|
|
|
new KeyCounterMouseTrigger(MouseButton.Left),
|
|
|
|
|
new KeyCounterMouseTrigger(MouseButton.Right),
|
2023-06-27 15:35:59 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AddRange(inputTriggers);
|
|
|
|
|
controller.AddRange(inputTriggers);
|
2023-02-23 01:59:39 +08:00
|
|
|
|
|
2017-09-18 21:32:49 +08:00
|
|
|
|
AddStep("Add random", () =>
|
|
|
|
|
{
|
|
|
|
|
Key key = (Key)((int)Key.A + RNG.Next(26));
|
2023-06-28 02:29:27 +08:00
|
|
|
|
var trigger = new KeyCounterKeyboardTrigger(key);
|
|
|
|
|
Add(trigger);
|
|
|
|
|
controller.Add(trigger);
|
2017-09-18 21:32:49 +08:00
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-06-15 18:02:30 +08:00
|
|
|
|
InputTrigger testTrigger = controller.Triggers.First();
|
|
|
|
|
Key testKey = ((KeyCounterKeyboardTrigger)testTrigger).Key;
|
2018-07-29 04:24:03 +08:00
|
|
|
|
|
2020-03-03 08:47:25 +08:00
|
|
|
|
addPressKeyStep();
|
2023-06-15 18:02:30 +08:00
|
|
|
|
AddAssert($"Check {testKey} counter after keypress", () => testTrigger.ActivationCount.Value == 1);
|
2020-03-03 08:47:25 +08:00
|
|
|
|
addPressKeyStep();
|
2023-06-15 18:02:30 +08:00
|
|
|
|
AddAssert($"Check {testKey} counter after keypress", () => testTrigger.ActivationCount.Value == 2);
|
2023-06-15 03:13:35 +08:00
|
|
|
|
AddStep("Disable counting", () => controller.IsCounting.Value = false);
|
2020-03-03 08:47:25 +08:00
|
|
|
|
addPressKeyStep();
|
2023-06-15 18:02:30 +08:00
|
|
|
|
AddAssert($"Check {testKey} count has not changed", () => testTrigger.ActivationCount.Value == 2);
|
2018-09-15 15:25:37 +08:00
|
|
|
|
|
2023-04-25 20:37:17 +08:00
|
|
|
|
void addPressKeyStep() => AddStep($"Press {testKey} key", () => InputManager.Key(testKey));
|
2017-09-18 21:32:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|