diff --git a/interface/resources/qml/windows/Window.qml b/interface/resources/qml/windows/Window.qml index 35e0fb961c..d22d8ecbe8 100644 --- a/interface/resources/qml/windows/Window.qml +++ b/interface/resources/qml/windows/Window.qml @@ -296,6 +296,10 @@ Fadable { // fall through default: + if (MyAvatar.isAway) { + // If stuck in a window and a key is pressed this should exit paused mode + MyAvatar.isAway = false; + } // Consume unmodified keyboard entries while the window is focused, to prevent them // from propagating to the application if (event.modifiers === Qt.NoModifier) { diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index c46d87607f..29f41c89fd 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -88,6 +88,7 @@ MyAvatar::MyAvatar(RigPointer rig) : _isPushing(false), _isBeingPushed(false), _isBraking(false), + _isAway(false), _boomLength(ZOOM_DEFAULT), _yawSpeed(YAW_SPEED_DEFAULT), _pitchSpeed(PITCH_SPEED_DEFAULT), @@ -2361,6 +2362,15 @@ bool MyAvatar::hasDriveInput() const { return fabsf(_driveKeys[TRANSLATE_X]) > 0.0f || fabsf(_driveKeys[TRANSLATE_Y]) > 0.0f || fabsf(_driveKeys[TRANSLATE_Z]) > 0.0f; } +void MyAvatar::setAway(bool value) { + _isAway = value; + if (_isAway) { + emit wentAway(); + } else { + emit wentActive(); + } +} + // The resulting matrix is used to render the hand controllers, even if the camera is decoupled from the avatar. // Specificly, if we are rendering using a third person camera. We would like to render the hand controllers in front of the camera, // not in front of the avatar. diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 0bae2ea390..c4fe86356d 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -82,6 +82,7 @@ class MyAvatar : public Avatar { Q_PROPERTY(controller::Pose rightHandTipPose READ getRightHandTipPose) Q_PROPERTY(float energy READ getEnergy WRITE setEnergy) + Q_PROPERTY(float isAway READ getIsAway WRITE setAway) Q_PROPERTY(bool hmdLeanRecenterEnabled READ getHMDLeanRecenterEnabled WRITE setHMDLeanRecenterEnabled) Q_PROPERTY(bool characterControllerEnabled READ getCharacterControllerEnabled WRITE setCharacterControllerEnabled) @@ -328,6 +329,8 @@ signals: void energyChanged(float newEnergy); void positionGoneTo(); void onLoadComplete(); + void wentAway(); + void wentActive(); private: @@ -385,6 +388,7 @@ private: bool _isPushing; bool _isBeingPushed; bool _isBraking; + bool _isAway; float _boomLength; float _yawSpeed; // degrees/sec @@ -521,6 +525,8 @@ private: float getEnergy(); void setEnergy(float value); bool didTeleport(); + bool getIsAway() const { return _isAway; } + void setAway(bool value); }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode); diff --git a/scripts/system/away.js b/scripts/system/away.js index 96813031f1..541fe6f679 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -165,9 +165,36 @@ function goAway(fromStartup) { if (!isEnabled || isAway) { return; } - + + // If we're entering away mode from some other state than startup, then we create our move timer immediately. + // However if we're just stating up, we need to delay this process so that we don't think the initial teleport + // is actually a move. + if (fromStartup === undefined || fromStartup === false) { + avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL); + } else { + var WAIT_FOR_MOVE_ON_STARTUP = 3000; // 3 seconds + Script.setTimeout(function() { + avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL); + }, WAIT_FOR_MOVE_ON_STARTUP); + } + UserActivityLogger.toggledAway(true); + MyAvatar.isAway = true; +} +function goActive() { + if (!isAway) { + return; + } + + UserActivityLogger.toggledAway(false); + MyAvatar.isAway = false; +} + +MyAvatar.wentAway.connect(setAwayProperties) +MyAvatar.wentActive.connect(setActiveProperties) + +function setAwayProperties() { isAway = true; wasMuted = AudioDevice.getMuted(); if (!wasMuted) { @@ -189,27 +216,9 @@ function goAway(fromStartup) { wasHmdMounted = HMD.mounted; // always remember the correct state avatarPosition = MyAvatar.position; - - // If we're entering away mode from some other state than startup, then we create our move timer immediately. - // However if we're just stating up, we need to delay this process so that we don't think the initial teleport - // is actually a move. - if (fromStartup === undefined || fromStartup === false) { - avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL); - } else { - var WAIT_FOR_MOVE_ON_STARTUP = 3000; // 3 seconds - Script.setTimeout(function() { - avatarMovedInterval = Script.setInterval(ifAvatarMovedGoActive, BASIC_TIMER_INTERVAL); - }, WAIT_FOR_MOVE_ON_STARTUP); - } } -function goActive() { - if (!isAway) { - return; - } - - UserActivityLogger.toggledAway(false); - +function setActiveProperties() { isAway = false; if (!wasMuted) { AudioDevice.toggleMute();