1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 06:27:27 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneKeyCounter.cs

139 lines
5.4 KiB
C#
Raw Normal View History

// 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-04-13 17:19:50 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
2018-04-13 17:19:50 +08:00
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
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
2018-04-13 17:19:50 +08:00
{
[TestFixture]
2022-11-24 13:32:20 +08:00
public partial class TestSceneKeyCounter : OsuManualInputManagerTestScene
2018-04-13 17:19:50 +08:00
{
[Cached]
private readonly InputCountController controller;
public TestSceneKeyCounter()
2018-04-13 17:19:50 +08:00
{
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
controller = new InputCountController(),
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(20),
Children = new Drawable[]
{
new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
},
new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Scale = new Vector2(1, -1)
},
new ArgonKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
},
new ArgonKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Scale = new Vector2(1, -1)
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Spacing = new Vector2(20),
Children = new Drawable[]
{
new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Rotation = -90,
},
new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Rotation = 90,
},
new ArgonKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Rotation = -90,
},
new ArgonKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Rotation = 90,
},
}
},
}
}
2018-04-13 17:19:50 +08:00
};
var inputTriggers = new InputTrigger[]
{
new KeyCounterKeyboardTrigger(Key.X),
new KeyCounterKeyboardTrigger(Key.X),
new KeyCounterMouseTrigger(MouseButton.Left),
new KeyCounterMouseTrigger(MouseButton.Right),
};
AddRange(inputTriggers);
controller.AddRange(inputTriggers);
2023-02-23 01:59:39 +08:00
2018-04-13 17:19:50 +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);
2018-04-13 17:19:50 +08:00
});
InputTrigger testTrigger = controller.Triggers.First();
Key testKey = ((KeyCounterKeyboardTrigger)testTrigger).Key;
2018-07-29 04:24:03 +08:00
addPressKeyStep();
AddAssert($"Check {testKey} counter after keypress", () => testTrigger.ActivationCount.Value == 1);
addPressKeyStep();
AddAssert($"Check {testKey} counter after keypress", () => testTrigger.ActivationCount.Value == 2);
AddStep("Disable counting", () => controller.IsCounting.Value = false);
addPressKeyStep();
AddAssert($"Check {testKey} count has not changed", () => testTrigger.ActivationCount.Value == 2);
AddStep("Enable counting", () => controller.IsCounting.Value = true);
addPressKeyStep(100);
addPressKeyStep(1000);
2018-09-15 15:25:37 +08:00
void addPressKeyStep(int repeat = 1) => AddStep($"Press {testKey} key {repeat} times", () =>
{
for (int i = 0; i < repeat; i++)
InputManager.Key(testKey);
});
2018-04-13 17:19:50 +08:00
}
}
}