Merge pull request #8976 from druiz17/FixMenuOutOfView

Fixed menu out of view with HMD and Xbox controller
This commit is contained in:
Brad Hefta-Gaub 2016-11-10 18:49:34 -08:00 committed by GitHub
commit a90a0fe8ba
2 changed files with 57 additions and 17 deletions

View file

@ -4,12 +4,12 @@
{ "from": "GamePad.LY", "filters": { "type": "deadZone", "min": 0.05 }, "to": "Actions.TranslateZ" },
{ "from": "GamePad.LX", "filters": { "type": "deadZone", "min": 0.05 }, "to": "Actions.TranslateX" },
{ "from": "GamePad.LT", "to": "Standard.LTClick",
{ "from": "GamePad.LT", "to": "Standard.LTClick",
"peek": true,
"filters": [ { "type": "hysteresis", "min": 0.85, "max": 0.9 } ]
},
{ "from": "GamePad.LT", "to": "Standard.LT" },
{ "from": "GamePad.LB", "to": "Standard.LB" },
{ "from": "GamePad.LT", "to": "Standard.LT" },
{ "from": "GamePad.LB", "to": "Standard.LB" },
{ "from": "GamePad.LS", "to": "Standard.LS" },
@ -27,34 +27,34 @@
{ "from": "GamePad.RX", "to": "Actions.Yaw" },
{ "from": "GamePad.RY",
"to": "Actions.VERTICAL_UP",
"filters":
{ "from": "GamePad.RY",
"to": "Actions.VERTICAL_UP",
"filters":
[
{ "type": "deadZone", "min": 0.95 },
"invert"
]
},
},
{ "from": "GamePad.RT", "to": "Standard.RTClick",
{ "from": "GamePad.RT", "to": "Standard.RTClick",
"peek": true,
"filters": [ { "type": "hysteresis", "min": 0.85, "max": 0.9 } ]
},
{ "from": "GamePad.RT", "to": "Standard.RT" },
{ "from": "GamePad.RB", "to": "Standard.RB" },
{ "from": "GamePad.RT", "to": "Standard.RT" },
{ "from": "GamePad.RB", "to": "Standard.RB" },
{ "from": "GamePad.RS", "to": "Standard.RS" },
{ "from": "GamePad.Start", "to": "Actions.CycleCamera" },
{ "from": "GamePad.Back", "to": "Actions.ContextMenu" },
{ "from": "GamePad.Back", "to": "Standard.Start" },
{ "from": "GamePad.DU", "to": "Standard.DU" },
{ "from": "GamePad.DD", "to": "Standard.DD" },
{ "from": "GamePad.DD", "to": "Standard.DD" },
{ "from": "GamePad.DL", "to": "Standard.DL" },
{ "from": "GamePad.DR", "to": "Standard.DR" },
{ "from": "GamePad.DR", "to": "Standard.DR" },
{ "from": [ "GamePad.Y" ], "to": "Standard.RightPrimaryThumb", "peek": true },
{ "from": "GamePad.A", "to": "Standard.A" },
{ "from": "GamePad.B", "to": "Standard.B" },
{ "from": "GamePad.A", "to": "Standard.A" },
{ "from": "GamePad.B", "to": "Standard.B" },
{ "from": "GamePad.X", "to": "Standard.X" },
{ "from": "GamePad.Y", "to": "Standard.Y" }
]

View file

@ -203,6 +203,32 @@ function overlayFromWorldPoint(point) {
return { x: horizontalPixels, y: verticalPixels };
}
var gamePad = Controller.findDevice("GamePad");
function activeHudPoint2dGamePad() {
if (!HMD.active) {
return;
}
var headPosition = MyAvatar.getHeadPosition();
var headDirection = Quat.getUp(Quat.multiply(MyAvatar.headOrientation, Quat.angleAxis(-90, { x: 1, y: 0, z: 0 })));
var hudPoint3d = calculateRayUICollisionPoint(headPosition, headDirection);
if (!hudPoint3d) {
if (Menu.isOptionChecked("Overlays")) { // With our hud resetting strategy, hudPoint3d should be valid here
print('Controller is parallel to HUD'); // so let us know that our assumptions are wrong.
}
return;
}
var hudPoint2d = overlayFromWorldPoint(hudPoint3d);
// We don't know yet if we'll want to make the cursor or laser visble, but we need to move it to see if
// it's pointing at a QML tool (aka system overlay).
setReticlePosition(hudPoint2d);
return hudPoint2d;
}
function activeHudPoint2d(activeHand) { // if controller is valid, update reticle position and answer 2d point. Otherwise falsey.
var controllerPose = getControllerWorldLocation(activeHand, true); // note: this will return head pose if hand pose is invalid (third eye)
if (!controllerPose.valid) {
@ -210,7 +236,7 @@ function activeHudPoint2d(activeHand) { // if controller is valid, update reticl
}
var controllerPosition = controllerPose.position;
var controllerDirection = Quat.getUp(controllerPose.rotation);
var hudPoint3d = calculateRayUICollisionPoint(controllerPosition, controllerDirection);
if (!hudPoint3d) {
if (Menu.isOptionChecked("Overlays")) { // With our hud resetting strategy, hudPoint3d should be valid here
@ -405,7 +431,7 @@ clickMapping.from(rightTrigger.full).when(isPointingAtOverlayStartedNonFullTrigg
clickMapping.from(leftTrigger.full).when(isPointingAtOverlayStartedNonFullTrigger(leftTrigger)).to(Controller.Actions.ReticleClick);
// The following is essentially like Left and Right versions of
// clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(Controller.Actions.ContextMenu);
// except that we first update the reticle position from the appropriate hand position, before invoking the ContextMenu.
// except that we first update the reticle position from the appropriate hand position, before invoking the .
var wantsMenu = 0;
clickMapping.from(function () { return wantsMenu; }).to(Controller.Actions.ContextMenu);
clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(function (clicked) {
@ -420,6 +446,13 @@ clickMapping.from(Controller.Standard.LeftSecondaryThumb).peek().to(function (cl
}
wantsMenu = clicked;
});
clickMapping.from(Controller.Standard.Start).peek().to(function (clicked) {
if (clicked) {
activeHudPoint2dGamePad();
}
wantsMenu = clicked;
});
clickMapping.from(Controller.Hardware.Keyboard.RightMouseClicked).peek().to(function () {
// Allow the reticle depth to be set correctly:
// Wait a tick for the context menu to be displayed, and then simulate a (non-hand-controller) mouse move
@ -472,13 +505,16 @@ function update() {
expireMouseCursor();
clearSystemLaser();
}
updateSeeking(true);
if (!handControllerLockOut.expired(now)) {
return off(); // Let them use mouse in peace.
}
if (!Menu.isOptionChecked("First Person")) {
return off(); // What to do? menus can be behind hand!
}
if ((!Window.hasFocus() && !HMD.active) || !Reticle.allowMouseCapture) {
// In desktop it's pretty clear when another app is on top. In that case we bail, because
// hand controllers might be sputtering "valid" data and that will keep someone from deliberately
@ -487,14 +523,18 @@ function update() {
// other apps anyway. So in that case, we DO keep going even though we're not on top. (Fogbugz 1831.)
return off(); // Don't mess with other apps or paused mouse activity
}
leftTrigger.update();
rightTrigger.update();
if (!activeTrigger.state) {
return off(); // No trigger
}
if (getGrabCommunications()) {
return off();
}
var hudPoint2d = activeHudPoint2d(activeHand);
if (!hudPoint2d) {
return off();