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
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-09-15 15:25:37 +08:00
|
|
|
|
using System.Linq;
|
2018-03-02 14:34:31 +08:00
|
|
|
|
using NUnit.Framework;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
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;
|
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
|
|
|
|
{
|
2019-05-15 03:37:25 +08:00
|
|
|
|
public TestSceneKeyCounter()
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2023-02-13 09:33:09 +08:00
|
|
|
|
DefaultKeyCounter testCounter;
|
2019-09-12 14:41:53 +08:00
|
|
|
|
|
2023-02-13 09:33:09 +08:00
|
|
|
|
KeyCounterDisplay kc = new DefaultKeyCounterDisplay
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2023-02-13 09:33:09 +08:00
|
|
|
|
Children = new[]
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2023-02-13 09:33:09 +08:00
|
|
|
|
testCounter = new DefaultKeyCounter(new KeyCounterKeyboard(Key.X)),
|
|
|
|
|
new DefaultKeyCounter(new KeyCounterKeyboard(Key.X)),
|
|
|
|
|
new DefaultKeyCounter(new KeyCounterMouse(MouseButton.Left)),
|
|
|
|
|
new DefaultKeyCounter(new KeyCounterMouse(MouseButton.Right)),
|
2017-09-18 21:32:49 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-18 21:32:49 +08:00
|
|
|
|
AddStep("Add random", () =>
|
|
|
|
|
{
|
|
|
|
|
Key key = (Key)((int)Key.A + RNG.Next(26));
|
2023-02-13 09:33:09 +08:00
|
|
|
|
kc.Add(kc.CreateKeyCounter(new KeyCounterKeyboard(key)));
|
2017-09-18 21:32:49 +08:00
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-02-13 09:33:09 +08:00
|
|
|
|
Key testKey = ((KeyCounterKeyboard)kc.Children.First().CounterTrigger).Key;
|
2018-09-15 15:25:37 +08:00
|
|
|
|
|
2020-03-03 08:47:25 +08:00
|
|
|
|
void addPressKeyStep()
|
2018-07-29 04:24:03 +08:00
|
|
|
|
{
|
2020-11-05 22:41:56 +08:00
|
|
|
|
AddStep($"Press {testKey} key", () => InputManager.Key(testKey));
|
2020-03-03 08:47:25 +08:00
|
|
|
|
}
|
2018-07-29 04:24:03 +08:00
|
|
|
|
|
2020-03-03 08:47:25 +08:00
|
|
|
|
addPressKeyStep();
|
2019-09-12 14:41:53 +08:00
|
|
|
|
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses == 1);
|
2020-03-03 08:47:25 +08:00
|
|
|
|
addPressKeyStep();
|
2019-09-12 14:41:53 +08:00
|
|
|
|
AddAssert($"Check {testKey} counter after keypress", () => testCounter.CountPresses == 2);
|
2020-03-06 17:00:07 +08:00
|
|
|
|
AddStep("Disable counting", () => testCounter.IsCounting = false);
|
2020-03-03 08:47:25 +08:00
|
|
|
|
addPressKeyStep();
|
|
|
|
|
AddAssert($"Check {testKey} count has not changed", () => testCounter.CountPresses == 2);
|
2018-09-15 15:25:37 +08:00
|
|
|
|
|
2017-09-18 21:32:49 +08:00
|
|
|
|
Add(kc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|