Skip to content

Commit

Permalink
Modified UITests.UI_CanDriveUIFromGamepad with IsKeyboardNavigationEv…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
benoitalain committed Jan 9, 2025
1 parent 426157a commit ffd26de
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions Assets/Tests/InputSystem/Plugins/UITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2911,10 +2911,13 @@ public IEnumerator UI_CanDriveUIFromGamepad()
Assert.That(scene.leftChildReceiver.events,
EventSequence(
OneEvent("type", EventType.Move),
OneEvent("device", gamepad),
OneEvent("moveDir", MoveDirection.Right),
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
Assert.That(scene.rightChildReceiver.events, Is.Empty);

Assert.That(scene.uiModule.IsNonKeyboardNavigationEvent(scene.leftChildReceiver.events[0].data));

scene.leftChildReceiver.events.Clear();

// Move left.
Expand All @@ -2924,6 +2927,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
Assert.That(scene.leftChildReceiver.events,
EventSequence(
OneEvent("type", EventType.Move),
OneEvent("device", gamepad),
OneEvent("moveDir", MoveDirection.Left),
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
Assert.That(scene.rightChildReceiver.events, Is.Empty);
Expand All @@ -2937,6 +2941,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
Assert.That(scene.leftChildReceiver.events,
EventSequence(
OneEvent("type", EventType.Move),
OneEvent("device", gamepad),
OneEvent("moveDir", MoveDirection.Up),
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
Assert.That(scene.rightChildReceiver.events, Is.Empty);
Expand All @@ -2950,6 +2955,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
Assert.That(scene.leftChildReceiver.events,
EventSequence(
OneEvent("type", EventType.Move),
OneEvent("device", gamepad),
OneEvent("moveDir", MoveDirection.Down),
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
Assert.That(scene.rightChildReceiver.events, Is.Empty);
Expand All @@ -2964,6 +2970,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
Assert.That(scene.leftChildReceiver.events,
EventSequence(
OneEvent("type", EventType.Move),
OneEvent("device", gamepad),
OneEvent("moveDir", MoveDirection.Down),
OneEvent("moveVector", gamepad.leftStick.ReadValue())));

Expand All @@ -2977,6 +2984,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
Assert.That(scene.leftChildReceiver.events,
EventSequence(
OneEvent("type", EventType.Move),
OneEvent("device", gamepad),
OneEvent("moveDir", MoveDirection.Down),
OneEvent("moveVector", gamepad.leftStick.ReadValue())));

Expand All @@ -2986,7 +2994,11 @@ public IEnumerator UI_CanDriveUIFromGamepad()
PressAndRelease(gamepad.buttonSouth);
yield return null;

Assert.That(scene.leftChildReceiver.events, EventSequence(OneEvent("type", EventType.Submit)));
Assert.That(scene.leftChildReceiver.events,
EventSequence(
OneEvent("type", EventType.Submit),
OneEvent("device", gamepad)
));
Assert.That(scene.rightChildReceiver.events, Is.Empty);

scene.leftChildReceiver.events.Clear();
Expand All @@ -2995,7 +3007,11 @@ public IEnumerator UI_CanDriveUIFromGamepad()
PressAndRelease(gamepad.buttonEast);
yield return null;

Assert.That(scene.leftChildReceiver.events, EventSequence(OneEvent("type", EventType.Cancel)));
Assert.That(scene.leftChildReceiver.events,
EventSequence(
OneEvent("type", EventType.Cancel),
OneEvent("device", gamepad)
));
Assert.That(scene.rightChildReceiver.events, Is.Empty);

scene.leftChildReceiver.events.Clear();
Expand Down Expand Up @@ -4463,6 +4479,7 @@ public struct Event
public BaseEventData data { get; }
public AxisEventData axisData => (AxisEventData)data;
public ExtendedPointerEventData pointerData => (ExtendedPointerEventData)data;
public INavigationEventData navigationData => (INavigationEventData)data;

public Event(EventType type, BaseEventData data)
{
Expand Down Expand Up @@ -4521,12 +4538,12 @@ public void OnMove(AxisEventData eventData)

public void OnSubmit(BaseEventData eventData)
{
events.Add(new Event(EventType.Submit, null));
events.Add(new Event(EventType.Submit, CloneSubmitCancelEventData(eventData)));
}

public void OnCancel(BaseEventData eventData)
{
events.Add(new Event(EventType.Cancel, null));
events.Add(new Event(EventType.Cancel, CloneSubmitCancelEventData(eventData)));
}

public void OnSelect(BaseEventData eventData)
Expand Down Expand Up @@ -4579,11 +4596,20 @@ private static AxisEventData CloneAxisEventData(AxisEventData eventData)
{
return new ExtendedAxisEventData(EventSystem.current)
{
device = (eventData as ExtendedAxisEventData)?.device,
moveVector = eventData.moveVector,
moveDir = eventData.moveDir
};
}

private static ExtendedSubmitCancelEventData CloneSubmitCancelEventData(BaseEventData eventData)
{
return new ExtendedSubmitCancelEventData(EventSystem.current)
{
device = (eventData as ExtendedSubmitCancelEventData)?.device
};
}

private static ExtendedPointerEventData ClonePointerEventData(PointerEventData eventData)
{
// InputSystemUIInputModule should only be sending ExtendedPointEventData.
Expand Down

0 comments on commit ffd26de

Please sign in to comment.