Alter away functionality to add onEscape functionality.

This commit is contained in:
Kalila L 2021-02-03 23:13:58 -05:00
parent 3f5be470f1
commit 3e8387a866
3 changed files with 48 additions and 16 deletions

View file

@ -36,6 +36,7 @@ var DEFAULT_SCRIPTS_COMBINED = [
"system/inspect.js",
"system/keyboardShortcuts/keyboardShortcuts.js",
"system/checkForUpdates.js",
"system/onEscape.js",
"system/onFirstRun.js",
"system/appreciate/appreciate_app.js"
];

View file

@ -3,8 +3,6 @@
//
// away.js
//
// examples
//
// Created by Howard Stearns 11/3/15
// Copyright 2015 High Fidelity, Inc.
//
@ -255,17 +253,6 @@ function setActiveProperties() {
Script.clearInterval(avatarMovedInterval);
}
function maybeGoActive(event) {
if (event.isAutoRepeat) { // isAutoRepeat is true when held down (or when Windows feels like it)
return;
}
if (!isAway && (event.text === 'ESC')) {
goAway();
} else {
goActive();
}
}
var wasHmdActive = HMD.active;
var wasMouseCaptured = Reticle.mouseCaptured;
@ -329,12 +316,24 @@ var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable";
var handleMessage = function(channel, message, sender) {
if (channel === CHANNEL_AWAY_ENABLE && sender === MyAvatar.sessionUUID) {
print("away.js | Got message on Hifi-Away-Enable: ", message);
setEnabled(message === 'enable');
if (message === 'enable') {
setEnabled(message === 'enable');
} else if (message === 'toggle') {
toggleAway();
}
}
};
Messages.subscribe(CHANNEL_AWAY_ENABLE);
Messages.messageReceived.connect(handleMessage);
function toggleAway() {
if (!isAway) {
goAway();
} else {
goActive();
}
}
var maybeIntervalTimer = Script.setInterval(function() {
maybeMoveOverlay();
maybeGoAway();
@ -343,7 +342,6 @@ var maybeIntervalTimer = Script.setInterval(function() {
Controller.mousePressEvent.connect(goActive);
Controller.keyPressEvent.connect(maybeGoActive);
// Note peek() so as to not interfere with other mappings.
eventMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(goActive);
eventMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(goActive);
@ -371,7 +369,6 @@ Script.scriptEnding.connect(function () {
HMD.awayStateWhenFocusLostInVRChanged.disconnect(awayStateWhenFocusLostInVRChanged);
Controller.disableMapping(eventMappingName);
Controller.mousePressEvent.disconnect(goActive);
Controller.keyPressEvent.disconnect(maybeGoActive);
Messages.messageReceived.disconnect(handleMessage);
Messages.unsubscribe(CHANNEL_AWAY_ENABLE);
});

View file

@ -0,0 +1,34 @@
'use strict';
//
// onEscape.js
//
// Created by Kalila L. on Feb 3 2021.
// Copyright 2020 Vircadia contributors.
//
// This script manages actions when the user triggers an "escape" key or action.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() { // BEGIN LOCAL_SCOPE
function maybeEscapeKeyPressed (event) {
if (event.isAutoRepeat) { // isAutoRepeat is true when held down (or when Windows feels like it)
return;
}
if (event.text === 'ESC') {
var CHANNEL_AWAY_ENABLE = 'Hifi-Away-Enable';
Messages.sendMessage(CHANNEL_AWAY_ENABLE, 'toggle', true);
}
}
Controller.keyPressEvent.connect(maybeEscapeKeyPressed);
Script.scriptEnding.connect(function () {
Controller.keyPressEvent.disconnect(maybeEscapeKeyPressed);
});
}());