osu/osu.Game.Tests/Visual/Gameplay/TestSceneKeyCounter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
3.0 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 09:19:50 +00:00
2018-09-15 07:25:37 +00:00
using System.Linq;
2018-03-02 06:34:31 +00:00
using NUnit.Framework;
using osu.Framework.Allocation;
2017-09-18 13:32:49 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-01-09 04:43:44 +00:00
using osu.Framework.Utils;
2017-09-18 13:32:49 +00:00
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osuTK;
2018-11-20 07:51:59 +00:00
using osuTK.Input;
2018-04-13 09:19:50 +00:00
2019-03-24 16:02:36 +00:00
namespace osu.Game.Tests.Visual.Gameplay
2017-09-18 13:32:49 +00:00
{
2018-03-02 06:34:31 +00:00
[TestFixture]
public partial class TestSceneKeyCounter : OsuManualInputManagerTestScene
2017-09-18 13:32:49 +00:00
{
[Cached]
private readonly InputCountController controller;
public TestSceneKeyCounter()
2017-09-18 13:32:49 +00:00
{
Children = new Drawable[]
2017-09-18 13:32:49 +00:00
{
controller = new InputCountController(),
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(72.7f),
Children = new KeyCounterDisplay[]
{
new DefaultKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
},
new ArgonKeyCounterDisplay
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
}
}
}
2017-09-18 13:32:49 +00:00
};
2018-04-13 09:19:50 +00: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-22 17:59:39 +00:00
2017-09-18 13:32:49 +00:00
AddStep("Add random", () =>
{
Key key = (Key)((int)Key.A + RNG.Next(26));
2023-06-27 18:29:27 +00:00
var trigger = new KeyCounterKeyboardTrigger(key);
Add(trigger);
controller.Add(trigger);
2017-09-18 13:32:49 +00:00
});
2018-04-13 09:19:50 +00:00
InputTrigger testTrigger = controller.Triggers.First();
Key testKey = ((KeyCounterKeyboardTrigger)testTrigger).Key;
2018-07-28 20:24:03 +00: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);
2018-09-15 07:25:37 +00:00
void addPressKeyStep() => AddStep($"Press {testKey} key", () => InputManager.Key(testKey));
2017-09-18 13:32:49 +00:00
}
}
}