diff --git a/examples/away.js b/examples/away.js index 82b9c881c6..643edbd149 100644 --- a/examples/away.js +++ b/examples/away.js @@ -152,9 +152,19 @@ function maybeMoveOverlay() { // MAIN CONTROL var wasMuted, isAway; +var wasOverlaysVisible = Menu.isOptionChecked("Overlays"); var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too. var eventMapping = Controller.newMapping(eventMappingName); +// backward compatible version of getting HMD.mounted, so it works in old clients +function safeGetHMDMounted() { + if (HMD.mounted === undefined) { + return true; + } + return HMD.mounted; +} +var wasHmdMounted = safeGetHMDMounted(); + function goAway() { if (isAway) { return; @@ -169,12 +179,20 @@ function goAway() { playAwayAnimation(); // animation is still seen by others showOverlay(); + // remember the View > Overlays state... + wasOverlaysVisible = Menu.isOptionChecked("Overlays"); + + // show overlays so that people can see the "Away" message + Menu.setIsOptionChecked("Overlays", true); + // tell the Reticle, we want to stop capturing the mouse until we come back Reticle.allowMouseCapture = false; if (HMD.active) { Reticle.visible = false; } + wasHmdMounted = safeGetHMDMounted(); // always remember the correct state } + function goActive() { if (!isAway) { return; @@ -188,12 +206,16 @@ function goActive() { stopAwayAnimation(); hideOverlay(); + // restore overlays state to what it was when we went "away" + Menu.setIsOptionChecked("Overlays", wasOverlaysVisible); + // tell the Reticle, we are ready to capture the mouse again and it should be visible Reticle.allowMouseCapture = true; Reticle.visible = true; if (HMD.active) { Reticle.position = HMD.getHUDLookAtPosition2D(); } + wasHmdMounted = safeGetHMDMounted(); // always remember the correct state } function maybeGoActive(event) { @@ -206,6 +228,7 @@ function maybeGoActive(event) { goActive(); } } + var wasHmdActive = HMD.active; var wasMouseCaptured = Reticle.mouseCaptured; @@ -225,6 +248,13 @@ function maybeGoAway() { goAway(); } } + + // If you've removed your HMD from your head, and we can detect it, we will also go away... + var hmdMounted = safeGetHMDMounted(); + if (HMD.active && !hmdMounted && wasHmdMounted) { + wasHmdMounted = hmdMounted; + goAway(); + } } Script.update.connect(maybeMoveOverlay); diff --git a/libraries/ui/src/ui/Menu.cpp b/libraries/ui/src/ui/Menu.cpp index a5d801869d..1e6cfb1846 100644 --- a/libraries/ui/src/ui/Menu.cpp +++ b/libraries/ui/src/ui/Menu.cpp @@ -222,8 +222,11 @@ void Menu::setIsOptionChecked(const QString& menuOption, bool isChecked) { return; } QAction* menu = _actionHash.value(menuOption); - if (menu) { - menu->setChecked(isChecked); + if (menu && menu->isCheckable()) { + auto wasChecked = menu->isChecked(); + if (wasChecked != isChecked) { + menu->trigger(); + } } }