2020-04-20 08:35:00 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-04-20 08:35:00 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-09-16 17:26:12 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2020-04-20 08:35:00 +08:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Difficulty;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
|
|
|
{
|
|
|
|
[HeadlessTest]
|
|
|
|
public class TestSceneKeyBindings : OsuManualInputManagerTestScene
|
|
|
|
{
|
|
|
|
private readonly ActionReceiver receiver;
|
|
|
|
|
|
|
|
public TestSceneKeyBindings()
|
|
|
|
{
|
|
|
|
Add(new TestKeyBindingContainer
|
|
|
|
{
|
|
|
|
Child = receiver = new ActionReceiver()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDefaultsWhenNotDatabased()
|
|
|
|
{
|
2020-11-05 22:41:56 +08:00
|
|
|
AddStep("fire key", () => InputManager.Key(Key.A));
|
2020-04-20 08:35:00 +08:00
|
|
|
|
|
|
|
AddAssert("received key", () => receiver.ReceivedAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestRuleset : Ruleset
|
|
|
|
{
|
|
|
|
public override IEnumerable<Mod> GetModsFor(ModType type) =>
|
|
|
|
throw new System.NotImplementedException();
|
|
|
|
|
|
|
|
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) =>
|
|
|
|
throw new System.NotImplementedException();
|
|
|
|
|
|
|
|
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) =>
|
|
|
|
throw new System.NotImplementedException();
|
|
|
|
|
2021-11-15 17:19:23 +08:00
|
|
|
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) =>
|
2020-04-20 08:35:00 +08:00
|
|
|
throw new System.NotImplementedException();
|
|
|
|
|
|
|
|
public override IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0)
|
|
|
|
{
|
|
|
|
return new[]
|
|
|
|
{
|
|
|
|
new KeyBinding(InputKey.A, TestAction.Down),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string Description => "test";
|
|
|
|
public override string ShortName => "test";
|
|
|
|
}
|
|
|
|
|
|
|
|
private enum TestAction
|
|
|
|
{
|
|
|
|
Down,
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestKeyBindingContainer : DatabasedKeyBindingContainer<TestAction>
|
|
|
|
{
|
|
|
|
public TestKeyBindingContainer()
|
|
|
|
: base(new TestRuleset().RulesetInfo, 0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class ActionReceiver : CompositeDrawable, IKeyBindingHandler<TestAction>
|
|
|
|
{
|
|
|
|
public bool ReceivedAction;
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
public bool OnPressed(KeyBindingPressEvent<TestAction> e)
|
2020-04-20 08:35:00 +08:00
|
|
|
{
|
2021-11-18 11:36:52 +08:00
|
|
|
if (e.Repeat)
|
|
|
|
return false;
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
ReceivedAction = e.Action == TestAction.Down;
|
2020-04-20 08:35:00 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
public void OnReleased(KeyBindingReleaseEvent<TestAction> e)
|
2020-04-20 08:35:00 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|