From 4a74522884b8576f0243eb9e5bcb064be1db0dea Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Mon, 10 Jul 2017 15:16:16 -0700 Subject: [PATCH] Ensure tablet button shows up; protections for controller mapping --- .../resources/qml/hifi/SpectatorCamera.qml | 6 ++-- scripts/system/spectatorCamera.js | 30 ++++++++++++++----- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/interface/resources/qml/hifi/SpectatorCamera.qml b/interface/resources/qml/hifi/SpectatorCamera.qml index 4f27ab8b8e..ca434caca0 100644 --- a/interface/resources/qml/hifi/SpectatorCamera.qml +++ b/interface/resources/qml/hifi/SpectatorCamera.qml @@ -227,11 +227,9 @@ Rectangle { height: 250; color: spectatorCameraPreview.visible ? "transparent" : "black"; - - AnimatedImage { source: "../../images/static.gif" - visible: !spectatorCameraPreview.visible; + visible: !cameraToggleCheckBox.checked; anchors.fill: parent; opacity: 0.15; } @@ -242,7 +240,7 @@ Rectangle { text: "Turn on Spectator Camera for a preview\nof what your monitor shows."; size: 16; color: hifi.colors.lightGrayText; - visible: !spectatorCameraPreview.visible; + visible: !cameraToggleCheckBox.checked; anchors.fill: parent; horizontalAlignment: Text.AlignHCenter; verticalAlignment: Text.AlignVCenter; diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index b4011843a5..96785a7a03 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -149,7 +149,7 @@ button.clicked.connect(onTabletButtonClicked); } } else if (button) { - if (!showSpectatorInDesktop || isShuttingDown) { + if ((!isHMDMode && !showSpectatorInDesktop) || isShuttingDown) { button.clicked.disconnect(onTabletButtonClicked); tablet.removeButton(button); button = false; @@ -298,6 +298,9 @@ const SWITCH_VIEW_FROM_CONTROLLER_DEFAULT = false; var switchViewFromController = !!Settings.getValue('spectatorCamera/switchViewFromController', SWITCH_VIEW_FROM_CONTROLLER_DEFAULT); function setControllerMappingStatus(status) { + if (!controllerMapping) { + return; + } if (status) { controllerMapping.enable(); } else { @@ -326,11 +329,16 @@ var controllerMapping; var controllerType = "Other"; function registerButtonMappings() { + var VRDevices = Controller.getDeviceNames().toString(); - if (VRDevices.includes("Vive")) { - controllerType = "Vive"; - } else if (VRDevices.includes("OculusTouch")) { - controllerType = "OculusTouch"; + if (VRDevices) { + if (VRDevices.includes("Vive")) { + controllerType = "Vive"; + } else if (VRDevices.includes("OculusTouch")) { + controllerType = "OculusTouch"; + } else { + return; // Neither Vive nor Touch detected + } } controllerMappingName = 'Hifi-SpectatorCamera-Mapping'; @@ -379,6 +387,9 @@ sendToQml({ method: 'updateControllerMappingCheckbox', setting: switchViewFromController, controller: controllerType }); Menu.setIsOptionChecked("Disable Preview", false); Menu.setIsOptionChecked("Mono Preview", true); + if (!controllerMapping) { + registerButtonMappings(); + } } } @@ -432,8 +443,11 @@ // Function Name: onHMDChanged() // // Description: - // -Called from C++ when HMD mode is changed. The argument "isHMDMode" should be true if HMD is on; false otherwise. + // -Called from C++ when HMD mode is changed. The argument "isHMDMode" is true if HMD is on; false otherwise. function onHMDChanged(isHMDMode) { + if (!controllerMapping) { + registerButtonMappings(); + } setDisplay(monitorShowsCameraView); addOrRemoveButton(false, isHMDMode); if (!isHMDMode && !showSpectatorInDesktop) { @@ -458,7 +472,9 @@ } HMD.displayModeChanged.disconnect(onHMDChanged); Controller.keyPressEvent.disconnect(keyPressEvent); - controllerMapping.disable(); + if (controllerMapping) { + controllerMapping.disable(); + } } // These functions will be called when the script is loaded.