Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,6 @@ public void Initialize()
RegisterActions(_cfg);
}

private void OnNextPreviousPerformed(InputAction.CallbackContext ctx)
{
if (ctx.control.device is Keyboard)
{
//TODO repeat rate
var keyboard = ctx.control.device as Keyboard;
DispatchFromCallback(Event.From(new NavigationEvent
{
type = NavigationEvent.Type.Move,
direction = keyboard.shiftKey.isPressed ? NavigationEvent.Direction.Previous : NavigationEvent.Direction.Next,
timestamp = _currentTime,
eventSource = EventSource.Keyboard,
}));
}
}

public void Shutdown()
{
UnregisterActions(_cfg);
Expand Down Expand Up @@ -143,13 +127,19 @@ public void Update()
_seenMouseEvents = false;
}

//TODO: Refactor as there is no need for having almost the same implementation in the IM and ISX?
private void DirectionNavigation(DiscreteTime currentTime)
{
//TODO: Refactor as there is no need for having almost the same implementation in the IM and ISX?
var(move, axesButtonWerePressed) = ReadCurrentNavigationMoveVector();

var direction = NavigationEvent.DetermineMoveDirection(move);

// Checks for next/previous directions if no movement was detected
if (direction == NavigationEvent.Direction.None)
{
direction = ReadNextPreviousDirection();
axesButtonWerePressed = _nextPreviousAction.WasPressedThisFrame();
}

if (direction == NavigationEvent.Direction.None)
{
repeatHelper.Reset();
Expand All @@ -163,14 +153,32 @@ private void DirectionNavigation(DiscreteTime currentTime)
type = NavigationEvent.Type.Move,
direction = direction,
timestamp = currentTime,
eventSource = GetEventSource(_moveAction.action.activeControl.device),
eventSource = GetEventSource(GetActiveDeviceFromDirection(direction)),
playerId = kDefaultPlayerId,
eventModifiers = _eventModifiers
}));
}
}
}

private InputDevice GetActiveDeviceFromDirection(NavigationEvent.Direction direction)
{
switch (direction)
{
case NavigationEvent.Direction.Left:
case NavigationEvent.Direction.Up:
case NavigationEvent.Direction.Right:
case NavigationEvent.Direction.Down:
return _moveAction.action.activeControl.device;
case NavigationEvent.Direction.Next:
case NavigationEvent.Direction.Previous:
return _nextPreviousAction.activeControl.device;
case NavigationEvent.Direction.None:
default:
return Keyboard.current;
}
}

private (Vector2, bool) ReadCurrentNavigationMoveVector()
{
var move = _moveAction.action.ReadValue<Vector2>();
Expand All @@ -179,9 +187,28 @@ private void DirectionNavigation(DiscreteTime currentTime)
return (move, axisWasPressed);
}

private NavigationEvent.Direction ReadNextPreviousDirection()
{
if (_nextPreviousAction.IsPressed())
{
//TODO: For now it only deals with Keyboard, needs to deal with other devices if we can add bindings
// for Gamepad, etc
//TODO: An alternative could be to have an action for next and for previous since shortcut support does
// not work properly
if (_nextPreviousAction.activeControl.device is Keyboard)
{
var keyboard = _nextPreviousAction.activeControl.device as Keyboard;
// Return direction based on whether shift is pressed or not
return keyboard.shiftKey.isPressed ? NavigationEvent.Direction.Previous : NavigationEvent.Direction.Next;
}
}

return NavigationEvent.Direction.None;
}

private static int SortEvents(Event a, Event b)
{
return Event.Compare(a, b);
return Event.CompareType(a, b);
}

public void OnFocusChanged(bool focus)
Expand Down Expand Up @@ -492,20 +519,16 @@ private void OnScrollWheelPerformed(InputAction.CallbackContext ctx)

private void RegisterNextPreviousAction()
{
_nextPreviousAction = new InputAction(name: "nextPreviousAction");
_nextPreviousAction = new InputAction(name: "nextPreviousAction", type: InputActionType.Button);
// TODO add more default bindings, or make them configurable
_nextPreviousAction.AddBinding("<Keyboard>/tab");
if (_nextPreviousAction != null)
_nextPreviousAction.performed += OnNextPreviousPerformed;

_nextPreviousAction.Enable();
}

private void UnregisterNextPreviousAction()
{
if (_nextPreviousAction != null)
{
_nextPreviousAction.performed -= OnNextPreviousPerformed;
_nextPreviousAction.Disable();
_nextPreviousAction = null;
}
Expand Down