2023-01-16 10:34:59 +00: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.
|
|
|
|
|
|
2023-01-16 11:45:04 +00:00
|
|
|
|
using System.Diagnostics;
|
2023-01-16 10:34:59 +00:00
|
|
|
|
using NUnit.Framework;
|
2023-01-16 11:58:24 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2023-01-16 10:34:59 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-01-16 11:45:04 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-01-16 10:34:59 +00:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Framework.Input.Events;
|
2023-01-16 11:45:04 +00:00
|
|
|
|
using osu.Framework.Input.States;
|
2023-01-16 10:34:59 +00:00
|
|
|
|
using osu.Framework.Testing;
|
2023-01-23 08:07:27 +00:00
|
|
|
|
using osu.Framework.Timing;
|
2023-01-23 08:54:17 +00:00
|
|
|
|
using osu.Framework.Utils;
|
2023-01-23 08:07:27 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2023-01-16 11:58:24 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2023-01-23 08:07:27 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2024-05-13 16:23:40 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
2023-01-23 08:54:17 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.UI.Cursor;
|
2023-03-07 07:28:54 +00:00
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
2023-01-16 10:34:59 +00:00
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
using osuTK;
|
2023-01-16 11:45:04 +00:00
|
|
|
|
using osuTK.Graphics;
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2023-01-25 06:01:05 +00:00
|
|
|
|
public partial class TestSceneOsuTouchInput : OsuManualInputManagerTestScene
|
2023-01-16 10:34:59 +00:00
|
|
|
|
{
|
2023-01-16 11:58:24 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuConfigManager config { get; set; } = null!;
|
|
|
|
|
|
2023-02-13 01:33:09 +00:00
|
|
|
|
private DefaultKeyCounter leftKeyCounter = null!;
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-02-13 01:33:09 +00:00
|
|
|
|
private DefaultKeyCounter rightKeyCounter = null!;
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
private OsuInputManager osuInputManager = null!;
|
|
|
|
|
|
2023-01-23 08:07:27 +00:00
|
|
|
|
private Container mainContent = null!;
|
|
|
|
|
|
2023-01-16 10:34:59 +00:00
|
|
|
|
[SetUpSteps]
|
|
|
|
|
public void SetUpSteps()
|
|
|
|
|
{
|
|
|
|
|
releaseAllTouches();
|
|
|
|
|
|
|
|
|
|
AddStep("Create tests", () =>
|
|
|
|
|
{
|
2023-06-18 15:51:17 +00:00
|
|
|
|
InputTrigger triggerLeft;
|
|
|
|
|
InputTrigger triggerRight;
|
|
|
|
|
|
2023-01-16 11:45:04 +00:00
|
|
|
|
Children = new Drawable[]
|
2023-01-16 10:34:59 +00:00
|
|
|
|
{
|
2023-01-16 11:45:04 +00:00
|
|
|
|
osuInputManager = new OsuInputManager(new OsuRuleset().RulesetInfo)
|
2023-01-16 10:34:59 +00:00
|
|
|
|
{
|
2023-06-18 15:51:17 +00:00
|
|
|
|
Child = mainContent = new Container
|
2023-01-16 10:34:59 +00:00
|
|
|
|
{
|
2023-06-18 15:51:17 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Children = new Drawable[]
|
2023-01-16 11:45:04 +00:00
|
|
|
|
{
|
2023-06-18 15:51:17 +00:00
|
|
|
|
new OsuCursorContainer
|
2023-01-16 11:45:04 +00:00
|
|
|
|
{
|
2023-06-18 15:51:17 +00:00
|
|
|
|
Depth = float.MinValue,
|
2023-01-23 08:54:17 +00:00
|
|
|
|
},
|
2023-06-18 16:26:08 +00:00
|
|
|
|
triggerLeft = new TestActionKeyCounterTrigger(OsuAction.LeftButton)
|
|
|
|
|
{
|
|
|
|
|
Depth = float.MinValue
|
|
|
|
|
},
|
2023-06-18 15:51:17 +00:00
|
|
|
|
triggerRight = new TestActionKeyCounterTrigger(OsuAction.RightButton)
|
2023-06-18 16:26:08 +00:00
|
|
|
|
{
|
|
|
|
|
Depth = float.MinValue
|
|
|
|
|
}
|
2023-01-16 11:45:04 +00:00
|
|
|
|
},
|
2023-06-18 15:51:17 +00:00
|
|
|
|
},
|
2023-01-16 11:45:04 +00:00
|
|
|
|
},
|
|
|
|
|
new TouchVisualiser(),
|
2023-01-16 10:34:59 +00:00
|
|
|
|
};
|
2023-06-16 16:54:19 +00:00
|
|
|
|
|
|
|
|
|
mainContent.AddRange(new[]
|
|
|
|
|
{
|
|
|
|
|
leftKeyCounter = new DefaultKeyCounter(triggerLeft)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
X = -100,
|
|
|
|
|
},
|
|
|
|
|
rightKeyCounter = new DefaultKeyCounter(triggerRight)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
X = 100,
|
|
|
|
|
},
|
|
|
|
|
});
|
2023-01-16 10:34:59 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 08:54:17 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestStreamInputVisual()
|
|
|
|
|
{
|
|
|
|
|
addHitCircleAt(TouchSource.Touch1);
|
|
|
|
|
addHitCircleAt(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
AddRepeatStep("Alternate", () =>
|
|
|
|
|
{
|
|
|
|
|
TouchSource down = i % 2 == 0 ? TouchSource.Touch3 : TouchSource.Touch4;
|
|
|
|
|
TouchSource up = i % 2 == 0 ? TouchSource.Touch4 : TouchSource.Touch3;
|
|
|
|
|
|
|
|
|
|
// sometimes the user will end the previous touch before touching again, sometimes not.
|
|
|
|
|
if (RNG.NextBool())
|
|
|
|
|
{
|
|
|
|
|
InputManager.BeginTouch(new Touch(down, getSanePositionForSource(down)));
|
|
|
|
|
InputManager.EndTouch(new Touch(up, getSanePositionForSource(up)));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
InputManager.EndTouch(new Touch(up, getSanePositionForSource(up)));
|
|
|
|
|
InputManager.BeginTouch(new Touch(down, getSanePositionForSource(down)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}, 100);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 10:34:59 +00:00
|
|
|
|
[Test]
|
2023-11-06 19:43:24 +00:00
|
|
|
|
public void TestSimpleInput([Values] bool disableMouseButtons)
|
2023-01-16 10:34:59 +00:00
|
|
|
|
{
|
2023-11-06 19:43:24 +00:00
|
|
|
|
// OsuSetting.MouseDisableButtons should not affect touch taps
|
|
|
|
|
AddStep($"{(disableMouseButtons ? "disable" : "enable")} mouse buttons", () => config.SetValue(OsuSetting.MouseDisableButtons, disableMouseButtons));
|
|
|
|
|
|
2023-01-16 10:34:59 +00:00
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 0);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
2023-01-16 12:02:37 +00:00
|
|
|
|
checkPosition(TouchSource.Touch1);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 12:02:37 +00:00
|
|
|
|
checkPosition(TouchSource.Touch2);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 12:02:37 +00:00
|
|
|
|
// Subsequent touches should be ignored (except position).
|
2023-01-16 10:34:59 +00:00
|
|
|
|
beginTouch(TouchSource.Touch3);
|
2023-01-16 12:02:37 +00:00
|
|
|
|
checkPosition(TouchSource.Touch3);
|
|
|
|
|
|
2023-01-16 10:34:59 +00:00
|
|
|
|
beginTouch(TouchSource.Touch4);
|
2023-01-16 12:02:37 +00:00
|
|
|
|
checkPosition(TouchSource.Touch4);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-15 07:26:36 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestPositionalTrackingAfterLongDistanceTravelled()
|
|
|
|
|
{
|
|
|
|
|
// When a single touch has already travelled enough distance on screen, it should remain as the positional
|
|
|
|
|
// tracking touch until released (unless a direct touch occurs).
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 0);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
// cover some distance
|
|
|
|
|
beginTouch(TouchSource.Touch1, new Vector2(0));
|
|
|
|
|
beginTouch(TouchSource.Touch1, new Vector2(9999));
|
|
|
|
|
beginTouch(TouchSource.Touch1, new Vector2(0));
|
|
|
|
|
beginTouch(TouchSource.Touch1, new Vector2(9999));
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
2023-03-15 07:38:26 +00:00
|
|
|
|
checkNotPressed(OsuAction.LeftButton);
|
2023-03-15 07:26:36 +00:00
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
// in this case, touch 2 should not become the positional tracking touch.
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
2023-03-21 05:47:20 +00:00
|
|
|
|
|
|
|
|
|
// even if the second touch moves on the screen, the original tracking touch is retained.
|
|
|
|
|
beginTouch(TouchSource.Touch2, new Vector2(0));
|
|
|
|
|
beginTouch(TouchSource.Touch2, new Vector2(9999));
|
|
|
|
|
beginTouch(TouchSource.Touch2, new Vector2(0));
|
|
|
|
|
beginTouch(TouchSource.Touch2, new Vector2(9999));
|
|
|
|
|
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
2023-03-15 07:26:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 12:07:19 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestPositionalInputUpdatesOnlyFromMostRecentTouch()
|
|
|
|
|
{
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1, Vector2.One);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch2);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
|
2023-01-23 08:07:27 +00:00
|
|
|
|
// note that touch1 was never ended, but is no longer valid for touch input due to touch 2 occurring.
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestStreamInput()
|
|
|
|
|
{
|
|
|
|
|
// In this scenario, the user is tapping on the first object in a stream,
|
|
|
|
|
// then using one or two fingers in empty space to continue the stream.
|
|
|
|
|
|
|
|
|
|
addHitCircleAt(TouchSource.Touch1);
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
// The first touch is handled as normal.
|
|
|
|
|
assertKeyCounter(1, 0);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
// The second touch should release the first, and also act as a right button.
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
2023-01-23 08:28:01 +00:00
|
|
|
|
// Importantly, this is different from the simple case because an object was interacted with in the first touch, but not the second touch.
|
|
|
|
|
// left button is automatically released.
|
2023-01-23 08:07:27 +00:00
|
|
|
|
checkNotPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
// Also importantly, the positional part of the second touch is ignored.
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
// In this scenario, a third touch should be allowed, and handled similarly to the second.
|
|
|
|
|
beginTouch(TouchSource.Touch3);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(2, 1);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
// Position is still ignored.
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkNotPressed(OsuAction.RightButton);
|
|
|
|
|
// Position is still ignored.
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
// User continues streaming
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(2, 2);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
// Position is still ignored.
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
// In this mode a maximum of three touches should be supported.
|
|
|
|
|
// A fourth touch should result in no changes anywhere.
|
|
|
|
|
beginTouch(TouchSource.Touch4);
|
|
|
|
|
assertKeyCounter(2, 2);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
endTouch(TouchSource.Touch4);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 08:28:01 +00:00
|
|
|
|
[Test]
|
2023-01-23 08:39:41 +00:00
|
|
|
|
public void TestStreamInputWithInitialTouchDownLeft()
|
2023-01-23 08:28:01 +00:00
|
|
|
|
{
|
|
|
|
|
// In this scenario, the user is wanting to use stream input but we start with one finger still on the screen.
|
2023-01-23 08:39:41 +00:00
|
|
|
|
// That finger is mapped to a left action.
|
2023-01-23 08:28:01 +00:00
|
|
|
|
|
|
|
|
|
addHitCircleAt(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
assertKeyCounter(1, 0);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
2023-01-23 08:39:41 +00:00
|
|
|
|
// hits circle as right action
|
2023-01-23 08:28:01 +00:00
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
assertKeyCounter(1, 1);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch1);
|
|
|
|
|
checkNotPressed(OsuAction.LeftButton);
|
|
|
|
|
|
|
|
|
|
// stream using other two fingers while touch2 tracks
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
assertKeyCounter(2, 1);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
// right button is automatically released
|
|
|
|
|
checkNotPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch3);
|
|
|
|
|
assertKeyCounter(2, 2);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch1);
|
|
|
|
|
checkNotPressed(OsuAction.LeftButton);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
assertKeyCounter(3, 2);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 08:39:41 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestStreamInputWithInitialTouchDownRight()
|
|
|
|
|
{
|
|
|
|
|
// In this scenario, the user is wanting to use stream input but we start with one finger still on the screen.
|
|
|
|
|
// That finger is mapped to a right action.
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
addHitCircleAt(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
// hits circle as left action
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
assertKeyCounter(2, 1);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
// stream using other two fingers while touch1 tracks
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
assertKeyCounter(2, 2);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
// left button is automatically released
|
|
|
|
|
checkNotPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch3);
|
|
|
|
|
assertKeyCounter(3, 2);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch2);
|
|
|
|
|
checkNotPressed(OsuAction.RightButton);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
assertKeyCounter(3, 3);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 08:07:27 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestNonStreamOverlappingDirectTouchesWithRelease()
|
|
|
|
|
{
|
|
|
|
|
// In this scenario, the user is tapping on three circles directly while correctly releasing the first touch.
|
|
|
|
|
// All three should be recognised.
|
|
|
|
|
|
|
|
|
|
addHitCircleAt(TouchSource.Touch1);
|
|
|
|
|
addHitCircleAt(TouchSource.Touch2);
|
|
|
|
|
addHitCircleAt(TouchSource.Touch3);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
assertKeyCounter(1, 0);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
assertKeyCounter(1, 1);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch3);
|
|
|
|
|
assertKeyCounter(2, 1);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestNonStreamOverlappingDirectTouchesWithoutRelease()
|
|
|
|
|
{
|
|
|
|
|
// In this scenario, the user is tapping on three circles directly without releasing any touches.
|
|
|
|
|
// The first two should be recognised, but a third should not (as the user already has two fingers down).
|
|
|
|
|
|
|
|
|
|
addHitCircleAt(TouchSource.Touch1);
|
|
|
|
|
addHitCircleAt(TouchSource.Touch2);
|
|
|
|
|
addHitCircleAt(TouchSource.Touch3);
|
|
|
|
|
|
2023-01-16 12:07:19 +00:00
|
|
|
|
beginTouch(TouchSource.Touch1);
|
2023-01-23 08:07:27 +00:00
|
|
|
|
assertKeyCounter(1, 0);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
2023-01-16 12:07:19 +00:00
|
|
|
|
checkPosition(TouchSource.Touch1);
|
2023-01-23 08:07:27 +00:00
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
assertKeyCounter(1, 1);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch3);
|
|
|
|
|
assertKeyCounter(1, 1);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkPosition(TouchSource.Touch3);
|
2023-01-16 12:07:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 11:58:24 +00:00
|
|
|
|
[Test]
|
2023-01-17 06:07:03 +00:00
|
|
|
|
public void TestMovementWhileDisallowed()
|
|
|
|
|
{
|
|
|
|
|
// aka "autopilot" mod
|
|
|
|
|
|
|
|
|
|
AddStep("Disallow gameplay cursor movement", () => osuInputManager.AllowUserCursorMovement = false);
|
|
|
|
|
|
|
|
|
|
Vector2? positionBefore = null;
|
|
|
|
|
|
|
|
|
|
AddStep("Store cursor position", () => positionBefore = osuInputManager.CurrentState.Mouse.Position);
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 0);
|
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
AddAssert("Cursor position unchanged", () => osuInputManager.CurrentState.Mouse.Position, () => Is.EqualTo(positionBefore));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestActionWhileDisallowed()
|
|
|
|
|
{
|
|
|
|
|
// aka "relax" mod
|
|
|
|
|
|
|
|
|
|
AddStep("Disallow gameplay actions", () => osuInputManager.AllowGameplayInputs = false);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(0, 0);
|
|
|
|
|
checkNotPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPosition(TouchSource.Touch1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestInputWhileMouseButtonsDisabled()
|
2023-01-16 11:58:24 +00:00
|
|
|
|
{
|
2023-11-06 23:13:46 +00:00
|
|
|
|
AddStep("Disable gameplay taps", () => config.SetValue(OsuSetting.TouchDisableGameplayTaps, true));
|
2023-01-16 11:58:24 +00:00
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(0, 0);
|
|
|
|
|
checkNotPressed(OsuAction.LeftButton);
|
2023-01-16 12:02:37 +00:00
|
|
|
|
checkPosition(TouchSource.Touch1);
|
2023-01-16 11:58:24 +00:00
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(0, 0);
|
|
|
|
|
checkNotPressed(OsuAction.LeftButton);
|
|
|
|
|
checkNotPressed(OsuAction.RightButton);
|
2023-01-16 12:02:37 +00:00
|
|
|
|
checkPosition(TouchSource.Touch2);
|
2023-01-16 11:58:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 10:34:59 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestAlternatingInput()
|
|
|
|
|
{
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 0);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
|
{
|
|
|
|
|
endTouch(TouchSource.Touch1);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
checkNotPressed(OsuAction.LeftButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
beginTouch(TouchSource.Touch1);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
endTouch(TouchSource.Touch2);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkNotPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
beginTouch(TouchSource.Touch2);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
|
|
|
|
}
|
2023-01-16 10:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestPressReleaseOrder()
|
|
|
|
|
{
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
beginTouch(TouchSource.Touch3);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
// Touch 3 was ignored, but let's ensure that if 1 or 2 are released, 3 will be handled a second attempt.
|
|
|
|
|
endTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
endTouch(TouchSource.Touch3);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch3);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(2, 1);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestWithDisallowedUserCursor()
|
|
|
|
|
{
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 0);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
// Subsequent touches should be ignored.
|
|
|
|
|
beginTouch(TouchSource.Touch3);
|
|
|
|
|
beginTouch(TouchSource.Touch4);
|
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
checkPressed(OsuAction.LeftButton);
|
|
|
|
|
checkPressed(OsuAction.RightButton);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
|
|
|
|
assertKeyCounter(1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-13 16:23:40 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestTouchJudgedCircle()
|
|
|
|
|
{
|
|
|
|
|
addHitCircleAt(TouchSource.Touch1);
|
|
|
|
|
addHitCircleAt(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
endTouch(TouchSource.Touch1);
|
|
|
|
|
|
|
|
|
|
// Hold the second touch (this becomes the primary touch).
|
|
|
|
|
beginTouch(TouchSource.Touch2);
|
|
|
|
|
|
|
|
|
|
// Touch again on the first circle.
|
|
|
|
|
// Because it's been judged, the cursor should not move here.
|
|
|
|
|
beginTouch(TouchSource.Touch1);
|
|
|
|
|
checkPosition(TouchSource.Touch2);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 08:07:27 +00:00
|
|
|
|
private void addHitCircleAt(TouchSource source)
|
|
|
|
|
{
|
|
|
|
|
AddStep($"Add circle at {source}", () =>
|
|
|
|
|
{
|
|
|
|
|
var hitCircle = new HitCircle();
|
|
|
|
|
|
|
|
|
|
hitCircle.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
|
|
|
|
|
|
|
|
|
mainContent.Add(new DrawableHitCircle(hitCircle)
|
|
|
|
|
{
|
|
|
|
|
Clock = new FramedClock(new ManualClock()),
|
|
|
|
|
Position = mainContent.ToLocalSpace(getSanePositionForSource(source)),
|
2024-05-13 16:23:40 +00:00
|
|
|
|
CheckHittable = (_, _, _) => ClickAction.Hit
|
2023-01-23 08:07:27 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 10:34:59 +00:00
|
|
|
|
private void beginTouch(TouchSource source, Vector2? screenSpacePosition = null) =>
|
2023-01-16 11:45:04 +00:00
|
|
|
|
AddStep($"Begin touch for {source}", () => InputManager.BeginTouch(new Touch(source, screenSpacePosition ??= getSanePositionForSource(source))));
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 11:45:04 +00:00
|
|
|
|
private void endTouch(TouchSource source, Vector2? screenSpacePosition = null) =>
|
|
|
|
|
AddStep($"Release touch for {source}", () => InputManager.EndTouch(new Touch(source, screenSpacePosition ??= getSanePositionForSource(source))));
|
|
|
|
|
|
|
|
|
|
private Vector2 getSanePositionForSource(TouchSource source)
|
|
|
|
|
{
|
|
|
|
|
return new Vector2(
|
|
|
|
|
osuInputManager.ScreenSpaceDrawQuad.Centre.X + osuInputManager.ScreenSpaceDrawQuad.Width * (-1 + (int)source) / 8,
|
|
|
|
|
osuInputManager.ScreenSpaceDrawQuad.Centre.Y - 100
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-01-16 12:02:37 +00:00
|
|
|
|
private void checkPosition(TouchSource touchSource) =>
|
|
|
|
|
AddAssert("Cursor position is correct", () => osuInputManager.CurrentState.Mouse.Position, () => Is.EqualTo(getSanePositionForSource(touchSource)));
|
|
|
|
|
|
2023-01-16 10:34:59 +00:00
|
|
|
|
private void assertKeyCounter(int left, int right)
|
|
|
|
|
{
|
2023-02-17 00:13:45 +00:00
|
|
|
|
AddAssert($"The left key was pressed {left} times", () => leftKeyCounter.CountPresses.Value, () => Is.EqualTo(left));
|
|
|
|
|
AddAssert($"The right key was pressed {right} times", () => rightKeyCounter.CountPresses.Value, () => Is.EqualTo(right));
|
2023-01-16 10:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void releaseAllTouches()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Release all touches", () =>
|
|
|
|
|
{
|
2023-01-16 11:58:24 +00:00
|
|
|
|
config.SetValue(OsuSetting.MouseDisableButtons, false);
|
2023-11-06 23:13:46 +00:00
|
|
|
|
config.SetValue(OsuSetting.TouchDisableGameplayTaps, false);
|
2023-01-16 10:34:59 +00:00
|
|
|
|
foreach (TouchSource source in InputManager.CurrentState.Touch.ActiveSources)
|
|
|
|
|
InputManager.EndTouch(new Touch(source, osuInputManager.ScreenSpaceDrawQuad.Centre));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-16 11:55:53 +00:00
|
|
|
|
private void checkNotPressed(OsuAction action) => AddAssert($"Not pressing {action}", () => !osuInputManager.PressedActions.Contains(action));
|
|
|
|
|
private void checkPressed(OsuAction action) => AddAssert($"Is pressing {action}", () => osuInputManager.PressedActions.Contains(action));
|
2023-01-16 10:34:59 +00:00
|
|
|
|
|
2023-02-22 15:03:44 +00:00
|
|
|
|
public partial class TestActionKeyCounterTrigger : InputTrigger, IKeyBindingHandler<OsuAction>
|
2023-01-16 10:34:59 +00:00
|
|
|
|
{
|
|
|
|
|
public OsuAction Action { get; }
|
|
|
|
|
|
2023-02-13 23:49:57 +00:00
|
|
|
|
public TestActionKeyCounterTrigger(OsuAction action)
|
2023-01-16 10:34:59 +00:00
|
|
|
|
: base(action.ToString())
|
|
|
|
|
{
|
|
|
|
|
Action = action;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Action == Action)
|
|
|
|
|
{
|
2023-02-16 23:15:03 +00:00
|
|
|
|
Activate();
|
2023-01-16 10:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
|
|
|
|
|
{
|
2023-02-13 01:33:09 +00:00
|
|
|
|
if (e.Action == Action)
|
2023-02-16 23:15:03 +00:00
|
|
|
|
Deactivate();
|
2023-01-16 10:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-16 11:45:04 +00:00
|
|
|
|
|
|
|
|
|
public partial class TouchVisualiser : CompositeDrawable
|
|
|
|
|
{
|
2023-01-17 05:56:07 +00:00
|
|
|
|
private readonly Drawable?[] drawableTouches = new Drawable?[TouchState.MAX_TOUCH_COUNT];
|
2023-01-16 11:45:04 +00:00
|
|
|
|
|
|
|
|
|
public TouchVisualiser()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnTouchDown(TouchDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (IsDisposed)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var circle = new Circle
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0.5f,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(20),
|
|
|
|
|
Position = e.Touch.Position,
|
|
|
|
|
Colour = colourFor(e.Touch.Source),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AddInternal(circle);
|
|
|
|
|
drawableTouches[(int)e.Touch.Source] = circle;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnTouchMove(TouchMoveEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (IsDisposed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var circle = drawableTouches[(int)e.Touch.Source];
|
|
|
|
|
|
|
|
|
|
Debug.Assert(circle != null);
|
|
|
|
|
|
|
|
|
|
AddInternal(new FadingCircle(circle));
|
|
|
|
|
circle.Position = e.Touch.Position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnTouchUp(TouchUpEvent e)
|
|
|
|
|
{
|
|
|
|
|
var circle = drawableTouches[(int)e.Touch.Source];
|
2023-01-17 05:56:07 +00:00
|
|
|
|
|
|
|
|
|
Debug.Assert(circle != null);
|
|
|
|
|
|
2023-01-16 11:45:04 +00:00
|
|
|
|
circle.FadeOut(200, Easing.OutQuint).Expire();
|
|
|
|
|
drawableTouches[(int)e.Touch.Source] = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Color4 colourFor(TouchSource source)
|
|
|
|
|
{
|
|
|
|
|
return Color4.FromHsv(new Vector4((float)source / TouchState.MAX_TOUCH_COUNT, 1f, 1f, 1f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private partial class FadingCircle : Circle
|
|
|
|
|
{
|
|
|
|
|
public FadingCircle(Drawable source)
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
Size = source.Size;
|
|
|
|
|
Position = source.Position;
|
|
|
|
|
Colour = source.Colour;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
this.FadeOut(200).Expire();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-16 10:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|