mirror of
https://github.com/ppy/osu
synced 2024-12-25 16:22:23 +00:00
Make osu! touch input aware of the distance travelled of a non-direct touch
This commit is contained in:
parent
0a19b1e9cf
commit
6c4f596a9a
@ -150,6 +150,34 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
assertKeyCounter(1, 1);
|
||||
}
|
||||
|
||||
[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);
|
||||
checkPressed(OsuAction.LeftButton);
|
||||
checkPressed(OsuAction.RightButton);
|
||||
// in this case, touch 2 should not become the positional tracking touch.
|
||||
checkPosition(TouchSource.Touch1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPositionalInputUpdatesOnlyFromMostRecentTouch()
|
||||
{
|
||||
|
@ -97,8 +97,8 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
return;
|
||||
}
|
||||
|
||||
// ..or if the current position tracking touch was not a direct touch (this one is debatable and may be change in the future, but it's the simplest way to handle)
|
||||
if (!positionTrackingTouch.DirectTouch)
|
||||
// ..or if the current position tracking touch was not a direct touch (and didn't travel across the screen too far).
|
||||
if (!positionTrackingTouch.DirectTouch && positionTrackingTouch.DistanceTravelled < 200)
|
||||
{
|
||||
positionTrackingTouch = newTouch;
|
||||
return;
|
||||
@ -117,6 +117,12 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
|
||||
private void handleTouchMovement(TouchEvent touchEvent)
|
||||
{
|
||||
if (touchEvent is TouchMoveEvent moveEvent)
|
||||
{
|
||||
var trackedTouch = trackedTouches.Single(t => t.Source == touchEvent.Touch.Source);
|
||||
trackedTouch.DistanceTravelled += moveEvent.Delta.Length;
|
||||
}
|
||||
|
||||
// Movement should only be tracked for the most recent touch.
|
||||
if (touchEvent.Touch.Source != positionTrackingTouch?.Source)
|
||||
return;
|
||||
@ -148,8 +154,16 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
|
||||
public OsuAction? Action;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the touch was on a hit circle receptor.
|
||||
/// </summary>
|
||||
public readonly bool DirectTouch;
|
||||
|
||||
/// <summary>
|
||||
/// The total distance on screen travelled by this touch.
|
||||
/// </summary>
|
||||
public double DistanceTravelled;
|
||||
|
||||
public TrackedTouch(TouchSource source, OsuAction? action, bool directTouch)
|
||||
{
|
||||
Source = source;
|
||||
|
Loading…
Reference in New Issue
Block a user