Skip to content

Commit

Permalink
More input fixes (#414)
Browse files Browse the repository at this point in the history
* Reset axis regardless if active or not, build tool prompts to avoid issues with stationary tools

* Roll mode now on both grip buttons to avoid confusion

* Grip action should hide hand, correct tool dpad prompts to include grip

* Check hand only for active bindings
  • Loading branch information
artumino authored May 26, 2021
1 parent f32b0c2 commit 1a4923a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 25 deletions.
18 changes: 9 additions & 9 deletions NomaiVR/Input/Bindings/oculus_touch.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
}
}
},
{
"path": "/user/hand/right/input/grip",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/default/in/RollMode"
}
}
},
{
"path": "/user/hand/left/input/trigger",
"mode": "button",
Expand Down Expand Up @@ -270,15 +279,6 @@
}
}
},
{
"path": "/user/hand/right/input/y",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/tools/in/use"
}
}
},
{
"path": "/user/hand/right/input/b",
"mode": "button",
Expand Down
9 changes: 9 additions & 0 deletions NomaiVR/Input/Bindings/vive_wands.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
}
}
},
{
"path": "/user/hand/right/input/grip",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/default/in/RollMode"
}
}
},
{
"path": "/user/hand/left/input/trigger",
"mode": "button",
Expand Down
9 changes: 9 additions & 0 deletions NomaiVR/Input/Bindings/wmr-controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
}
}
},
{
"path": "/user/hand/right/input/grip",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/default/in/RollMode"
}
}
},
{
"path": "/user/hand/left/input/trigger",
"mode": "button",
Expand Down
59 changes: 43 additions & 16 deletions NomaiVR/Input/ControllerInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Behaviour : MonoBehaviour

private bool _isLeftDominant;
private bool _isUsingTools;
private bool _isBuildingDefaultToolPrompts = true;
private System.Collections.IEnumerator _executeBaseBindingsChanged;
private System.Collections.IEnumerator _executeBaseBindingsOverriden;
private SteamVR_Input_Sources? _lastToolInputSource;
Expand All @@ -56,6 +57,7 @@ internal void Start()
ReplaceInputs();
SetUpActionInputs();
UpdateHandDominance();
ToolModeBound(null, ModSettings.LeftHandDominant ? SteamVR_Input_Sources.LeftHand : SteamVR_Input_Sources.RightHand, false); //Force update tool prompts

ModSettings.OnConfigChange += OnSettingsChanged;
}
Expand All @@ -75,6 +77,9 @@ internal void UpdateHandDominance()
SteamVR_Actions.inverted.Activate(priority: 1);
else
SteamVR_Actions.inverted.Deactivate();

_isBuildingDefaultToolPrompts = true;
ToolModeBound(null, ModSettings.LeftHandDominant ? SteamVR_Input_Sources.LeftHand : SteamVR_Input_Sources.RightHand, false); //Force update tool prompts
}

internal void OnEnable()
Expand Down Expand Up @@ -136,8 +141,9 @@ private static void SetUpActionInputs()
[AxisIdentifier.CTRLR_RSTICK] = new VRActionInput(new OverridableSteamVRAction(defaultActionSet.Look, invertedActionSet.Look)),
[AxisIdentifier.CTRLR_RSTICKX] = new VRActionInput(new OverridableSteamVRAction(defaultActionSet.Look, invertedActionSet.Look)),
[AxisIdentifier.CTRLR_RSTICKY] = new VRActionInput(new OverridableSteamVRAction(defaultActionSet.Look, invertedActionSet.Look)),
[AxisIdentifier.CTRLR_DPADX] = new VRActionInput(toolsActionSet.DPad, isDynamic: true),
[AxisIdentifier.CTRLR_DPADY] = new VRActionInput(toolsActionSet.DPad, isDynamic: true)
//TODO: For Now we lie about needing to press grip button in hand-held mode, needs to be removed after cockpit changes
[AxisIdentifier.CTRLR_DPADX] = new VRActionInput(toolsActionSet.DPad, holdActionInput: gripActionInput, isDynamic: true),
[AxisIdentifier.CTRLR_DPADY] = new VRActionInput(toolsActionSet.DPad, holdActionInput: gripActionInput, isDynamic: true)
};

otherActions = new VRActionInput[] { gripActionInput };
Expand Down Expand Up @@ -187,7 +193,7 @@ private static void CheckForOppositeHandButtons()
handMappings.Add(true, new Dictionary<string, List<VRActionInput>>());
handMappings.Add(false, new Dictionary<string, List<VRActionInput>>());

foreach (var button in buttonActions.Values.Union(axisActions.Values).Union(otherActions).Where(x => !x.Dynamic && !String.IsNullOrEmpty(x.Source)))
foreach (var button in buttonActions.Values.Union(axisActions.Values).Where(x => !x.Dynamic && x.Active && !String.IsNullOrEmpty(x.Source)))
{
//Dynamic buttons are always escluded from this and should default to HideHand = false
//permanent buttons without duplicates on the other hand should default to HideHand = true
Expand Down Expand Up @@ -385,9 +391,8 @@ private void OnToolUseChange(SteamVR_Action_Boolean fromAction, SteamVR_Input_So
private IEnumerator<WaitForEndOfFrame> ResetAllUnboundAxes()
{
yield return new WaitForEndOfFrame();
foreach (var axis in axisActions.Keys)
if (!axisActions[axis].Active)
SimulateInput(axis, 0.0f);
foreach (var axis in _axes.Keys.ToArray())
_axes[axis] = 0.0f;
_executeBaseBindingsOverriden = null;
}

Expand Down Expand Up @@ -474,14 +479,26 @@ private static SteamVR_Action_Vector2.ChangeHandler CreateDoubleAxisHandler(Axis
private void EnterToolMode(SteamVR_Input_Sources inputSource)
{
//Enables the tools override for the proper hand and change affected prompts
_isBuildingDefaultToolPrompts = false;
SteamVR_Actions.tools.Activate(priority: 2, activateForSource: inputSource);
}

private IEnumerator<WaitForEndOfFrame> _executeProcessToolModeBound;
private void ToolModeBound(SteamVR_Action_Boolean action, SteamVR_Input_Sources inputSource, bool newValue)
{
if (newValue)
if (_executeProcessToolModeBound != null)
StopCoroutine(_executeProcessToolModeBound);
StartCoroutine(_executeProcessToolModeBound = ProcessToolModeBound(newValue, inputSource));
}

private IEnumerator<WaitForEndOfFrame> ProcessToolModeBound(bool bound, SteamVR_Input_Sources inputSource)
{
yield return new WaitForEndOfFrame();

//Update screen prompts only when all controls are bound
if (bound)
{
if (_lastToolInputSource != inputSource)
if(_lastToolInputSource != inputSource)
{
foreach (var vrActionInput in toolsActions)
{
Expand All @@ -491,20 +508,30 @@ private void ToolModeBound(SteamVR_Action_Boolean action, SteamVR_Input_Sources
InputPrompts.Behaviour.UpdatePrompts(toolsActions);
_lastToolInputSource = inputSource;
}

if (_isBuildingDefaultToolPrompts)
{
_isBuildingDefaultToolPrompts = false;
SteamVR_Actions.tools.Deactivate(SteamVR_Input_Sources.LeftHand);
SteamVR_Actions.tools.Deactivate(SteamVR_Input_Sources.RightHand);
}
}
else if(_isBuildingDefaultToolPrompts)
{
//Restores mainhand prompts, an ugly hack to avoid issues with OpenVR...
var dominantHand = !ModSettings.LeftHandDominant ? SteamVR_Input_Sources.RightHand : SteamVR_Input_Sources.LeftHand;
SteamVR_Actions.tools.Activate(dominantHand, priority: 2);
}

_executeProcessToolModeBound = null;
}

private void ExitToolMode()
{
var dominantHandSource = ModSettings.LeftHandDominant ? SteamVR_Input_Sources.LeftHand : SteamVR_Input_Sources.RightHand;
var nonDominantHand = !ModSettings.LeftHandDominant ? SteamVR_Input_Sources.LeftHand : SteamVR_Input_Sources.RightHand;

//De-Activates the tools action-set (stops overriting same buttons)
SteamVR_Actions.tools.Deactivate(nonDominantHand);

//Restores mainhand prompts, a bit of a hack...
SteamVR_Actions.tools.Activate(dominantHandSource, priority: 2);
SteamVR_Actions.tools.Deactivate(dominantHandSource);
_isBuildingDefaultToolPrompts = true;
SteamVR_Actions.tools.Deactivate(SteamVR_Input_Sources.LeftHand);
SteamVR_Actions.tools.Deactivate(SteamVR_Input_Sources.RightHand);
}

internal void Update()
Expand Down

0 comments on commit 1a4923a

Please sign in to comment.