From 0114962e7554ee77afba06d05ac47fa94caa7cbc Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 14 Jun 2017 15:25:07 -0700 Subject: [PATCH 1/4] Make the Spectator button only appear in HMD (with debug mode) --- scripts/system/spectatorCamera.js | 60 +++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index a3cdea7bd5..e308e252b3 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -17,7 +17,8 @@ // // FUNCTION VAR DECLARATIONS // - var sendToQml, onTabletScreenChanged, fromQml, onTabletButtonClicked, wireEventBridge, startup, shutdown; + var sendToQml, addOrRemoveButton, onTabletScreenChanged, fromQml, + onTabletButtonClicked, wireEventBridge, startup, shutdown; @@ -189,15 +190,51 @@ function onHMDChanged(isHMDMode) { // Will also eventually enable disable app, camera, etc. setDisplay(monitorShowsCameraView); + addOrRemoveButton(false, isHMDMode); + } + + // + // Function Names: addOrRemoveButton() + // + // Relevant Variables: + // button: The tablet button. + // buttonName: The name of the button. + // tablet: The tablet instance to be modified. + // showInDesktop: Set to "true" to show the "SPECTATOR" app in desktop mode + // + // Arguments: + // forceRemove: Set to "true" to force removal of the button, i.e. upon shutdown + // isHMDMode: "true" if user is in HMD; false otherwise + // + // Description: + // Used to add or remove the "SPECTATOR" app button from the HUD/tablet + // + var button = false; + var buttonName = "SPECTATOR"; + var tablet = null; + var showSpectatorInDesktop = false; + function addOrRemoveButton(forceRemove, isHMDMode) { + if (!button) { + if ((isHMDMode || showSpectatorInDesktop) && !forceRemove) { + button = tablet.addButton({ + text: buttonName + }); + button.clicked.connect(onTabletButtonClicked); + } + } else if (button) { + button.clicked.disconnect(onTabletButtonClicked); + tablet.removeButton(button); + button = false; + } else { + print("ERROR adding/removing Spectator button!") + } } // // Function Name: startup() // // Relevant Variables: - // button: The tablet button. - // buttonName: The name of the button. - // tablet: The tablet instance to be modified. + // None // // Arguments: // None @@ -205,15 +242,9 @@ // Description: // startup() will be called when the script is loaded. // - var button; - var buttonName = "SPECTATOR"; - var tablet = null; function startup() { tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); - button = tablet.addButton({ - text: buttonName - }); - button.clicked.connect(onTabletButtonClicked); + addOrRemoveButton(false, HMD.active); tablet.screenChanged.connect(onTabletScreenChanged); Window.domainChanged.connect(spectatorCameraOff); Controller.keyPressEvent.connect(keyPressEvent); @@ -320,7 +351,9 @@ function onTabletScreenChanged(type, url) { wireEventBridge(shouldActivateButton); // for toolbar mode: change button to active when window is first openend, false otherwise. - button.editProperties({ isActive: shouldActivateButton }); + if (button) { + button.editProperties({ isActive: shouldActivateButton }); + } shouldActivateButton = false; onSpectatorCameraScreen = false; } @@ -389,8 +422,7 @@ function shutdown() { spectatorCameraOff(); Window.domainChanged.disconnect(spectatorCameraOff); - tablet.removeButton(button); - button.clicked.disconnect(onTabletButtonClicked); + addOrRemoveButton(true, HMD.active); tablet.screenChanged.disconnect(onTabletScreenChanged); HMD.displayModeChanged.disconnect(onHMDChanged); Controller.keyPressEvent.disconnect(keyPressEvent); From 498ed4cbe8ea9286993466222be4ee0d75dd3379 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 14 Jun 2017 17:00:33 -0700 Subject: [PATCH 2/4] showSpectatorInDesktop true for now --- scripts/system/spectatorCamera.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index e308e252b3..a7f5dbcc79 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -194,7 +194,7 @@ } // - // Function Names: addOrRemoveButton() + // Function Name: addOrRemoveButton() // // Relevant Variables: // button: The tablet button. @@ -203,7 +203,7 @@ // showInDesktop: Set to "true" to show the "SPECTATOR" app in desktop mode // // Arguments: - // forceRemove: Set to "true" to force removal of the button, i.e. upon shutdown + // shouldntAdd: Set to "true" if you don't want to add the button, i.e. upon shutdown // isHMDMode: "true" if user is in HMD; false otherwise // // Description: @@ -212,10 +212,10 @@ var button = false; var buttonName = "SPECTATOR"; var tablet = null; - var showSpectatorInDesktop = false; - function addOrRemoveButton(forceRemove, isHMDMode) { + var showSpectatorInDesktop = true; + function addOrRemoveButton(shouldntAdd, isHMDMode) { if (!button) { - if ((isHMDMode || showSpectatorInDesktop) && !forceRemove) { + if ((isHMDMode || showSpectatorInDesktop) && !shouldntAdd) { button = tablet.addButton({ text: buttonName }); @@ -226,7 +226,7 @@ tablet.removeButton(button); button = false; } else { - print("ERROR adding/removing Spectator button!") + print("ERROR adding/removing Spectator button!"); } } From a795822919e9d11662ed76b5e16a8daefb726e9e Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 14 Jun 2017 17:12:37 -0700 Subject: [PATCH 3/4] Comments and disable camera when switching --- scripts/system/spectatorCamera.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index a7f5dbcc79..f8186f26fe 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -187,12 +187,6 @@ setDisplay(monitorShowsCameraView); } - function onHMDChanged(isHMDMode) { - // Will also eventually enable disable app, camera, etc. - setDisplay(monitorShowsCameraView); - addOrRemoveButton(false, isHMDMode); - } - // // Function Name: addOrRemoveButton() // @@ -407,6 +401,26 @@ } } + // + // Function Name: onHMDChanged() + // + // Relevant Variables: + // None + // + // Arguments: + // isHMDMode: "true" if HMD is on; "false" otherwise + // + // Description: + // Called from C++ when HMD mode is changed + // + function onHMDChanged(isHMDMode) { + setDisplay(monitorShowsCameraView); + addOrRemoveButton(false, isHMDMode); + if (!isHMDMode && !showSpectatorInDesktop) { + spectatorCameraOff(); + } + } + // // Function Name: shutdown() // From 68662bb209f1cc92da2616676883d4a0d9545da8 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 15 Jun 2017 10:20:17 -0700 Subject: [PATCH 4/4] Bugfixes --- scripts/system/spectatorCamera.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/system/spectatorCamera.js b/scripts/system/spectatorCamera.js index f8186f26fe..6095a960cd 100644 --- a/scripts/system/spectatorCamera.js +++ b/scripts/system/spectatorCamera.js @@ -197,7 +197,7 @@ // showInDesktop: Set to "true" to show the "SPECTATOR" app in desktop mode // // Arguments: - // shouldntAdd: Set to "true" if you don't want to add the button, i.e. upon shutdown + // isShuttingDown: Set to "true" if you're calling this function upon script shutdown // isHMDMode: "true" if user is in HMD; false otherwise // // Description: @@ -207,18 +207,20 @@ var buttonName = "SPECTATOR"; var tablet = null; var showSpectatorInDesktop = true; - function addOrRemoveButton(shouldntAdd, isHMDMode) { + function addOrRemoveButton(isShuttingDown, isHMDMode) { if (!button) { - if ((isHMDMode || showSpectatorInDesktop) && !shouldntAdd) { + if ((isHMDMode || showSpectatorInDesktop) && !isShuttingDown) { button = tablet.addButton({ text: buttonName }); button.clicked.connect(onTabletButtonClicked); } } else if (button) { - button.clicked.disconnect(onTabletButtonClicked); - tablet.removeButton(button); - button = false; + if ((!showSpectatorInDesktop || isShuttingDown) && !isHMDMode) { + button.clicked.disconnect(onTabletButtonClicked); + tablet.removeButton(button); + button = false; + } } else { print("ERROR adding/removing Spectator button!"); }