mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-19 22:41:58 +02:00
Initial Commit.
Signed-off-by: Armored Dragon <publicmail@armoreddragon.com>
This commit is contained in:
parent
53de22fd00
commit
b27f24e4a9
1 changed files with 65 additions and 175 deletions
|
@ -1,205 +1,96 @@
|
||||||
/*
|
//
|
||||||
mouseLook.js – mouse look switching script
|
// mouseLook.js
|
||||||
by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
|
//
|
||||||
*/
|
// By Armored Dragon (June 6). Refactored from Rampa3 & Vegaslon work
|
||||||
(function() { // BEGIN LOCAL_SCOPE
|
// Copyright 2024 Overte e.V.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
var away;
|
(() => {
|
||||||
|
// States ----
|
||||||
|
let mouse_look_active = Settings.getValue("mouselook-active", false);
|
||||||
|
let mouse_look_enabled = Camera.getMouseLook();
|
||||||
|
let hmd_active = HMD.active;
|
||||||
|
let overlay_active = Desktop.isOverlayWindowFocused();
|
||||||
|
|
||||||
var hmd = HMD.active;
|
// Resources ----
|
||||||
|
let tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
var mouseLookEnabled = Camera.getMouseLook();
|
|
||||||
|
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
||||||
|
|
||||||
var tabletUp;
|
|
||||||
|
|
||||||
var keysOnOverlay = Desktop.isOverlayWindowFocused();
|
|
||||||
|
|
||||||
var tempOff = false;
|
|
||||||
|
|
||||||
var altMode = false;
|
|
||||||
|
|
||||||
|
// Events ----
|
||||||
Camera.mouseLookChanged.connect(onMouseLookChanged);
|
Camera.mouseLookChanged.connect(onMouseLookChanged);
|
||||||
|
|
||||||
function onMouseLookChanged(newMouseLook) {
|
|
||||||
mouseLookEnabled = newMouseLook;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hmd){
|
|
||||||
if (mouseLookEnabled) {
|
|
||||||
if (!keysOnOverlay) {
|
|
||||||
if (!tablet.tabletShown){
|
|
||||||
Window.displayAnnouncement("Mouse look: ON");
|
|
||||||
mouseLookOn();
|
|
||||||
} else {
|
|
||||||
Window.displayAnnouncement("Tablet is up – mouse look temporarily OFF.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Controller.keyPressEvent.connect(onKeyPressEvent);
|
Controller.keyPressEvent.connect(onKeyPressEvent);
|
||||||
|
Desktop.uiFocusChanged.connect(onUiFocusChanged);
|
||||||
|
HMD.displayModeChanged.connect(onDisplayModeChanged);
|
||||||
|
MyAvatar.wentActive.connect(onWentActive);
|
||||||
|
MyAvatar.wentAway.connect(onWentAway);
|
||||||
|
tablet.tabletShownChanged.connect(onTabletShownChanged);
|
||||||
|
Script.scriptEnding.connect(onScriptEnding);
|
||||||
|
|
||||||
|
// Program ----
|
||||||
|
function onMouseLookChanged(newMouseLook) {
|
||||||
|
mouse_look_enabled = newMouseLook;
|
||||||
|
}
|
||||||
|
|
||||||
function onKeyPressEvent(event) {
|
function onKeyPressEvent(event) {
|
||||||
if (!hmd){
|
// Toggle using the m key
|
||||||
if(event.isAlt){
|
if (event.text.toLowerCase() === "m") {
|
||||||
if (keysOnOverlay) return;
|
if (Camera.captureMouse) {
|
||||||
if (!mouseLookEnabled) return;
|
mouse_look_active = false;
|
||||||
mouseLookOff();
|
Settings.setValue("mouselook-active", false);
|
||||||
Window.displayAnnouncement("Mouse look: Temporarily OFF");
|
disableMouseLook();
|
||||||
tempOff = true;
|
|
||||||
altMode = true;
|
|
||||||
}
|
|
||||||
if (tempOff && altMode && ['left', 'right', 'up', 'down', 'esc', 'w', 'a', 's', 'd'].includes(event.text.toLowerCase())){
|
|
||||||
if (keysOnOverlay) return;
|
|
||||||
if (!mouseLookEnabled) return;
|
|
||||||
mouseLookOn();
|
|
||||||
tempOff = false;
|
|
||||||
altMode = false
|
|
||||||
}
|
|
||||||
if (event.text.toLowerCase() === 'm') {
|
|
||||||
if (!keysOnOverlay) {
|
|
||||||
if (mouseLookEnabled) {
|
|
||||||
if (!Camera.getCaptureMouse()){
|
|
||||||
tempOff = false;
|
|
||||||
Window.displayAnnouncement("Mouse look: ON");
|
|
||||||
mouseLookOn();
|
|
||||||
} else {
|
} else {
|
||||||
tempOff = true;
|
mouse_look_active = true;
|
||||||
Window.displayAnnouncement("Mouse look: Temporarily OFF");
|
Settings.setValue("mouselook-active", true);
|
||||||
mouseLookOff();
|
enableMouseLook();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tablet.tabletShownChanged.connect(onTabletShownChanged);
|
|
||||||
|
|
||||||
function onTabletShownChanged() {
|
function onTabletShownChanged() {
|
||||||
if (!hmd) {
|
if (tablet.tabletShown) disableMouseLook();
|
||||||
if (mouseLookEnabled) {
|
else enableMouseLook();
|
||||||
if (!tablet.toolbarMode) {
|
|
||||||
if (!keysOnOverlay) {
|
|
||||||
if (tablet.tabletShown) {
|
|
||||||
tabletUp = true;
|
|
||||||
if (!tempOff) {
|
|
||||||
if (!away) {
|
|
||||||
Window.displayAnnouncement("Tablet is up – mouse look temporarily OFF.");
|
|
||||||
mouseLookOff();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (!tablet.tabletShown) {
|
|
||||||
tabletUp = false;
|
|
||||||
if (!tempOff) {
|
|
||||||
if (!away && !keysOnOverlay) {
|
|
||||||
Window.displayAnnouncement("Tablet hidden – mouse look ON.");
|
|
||||||
mouseLookOn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MyAvatar.wentAway.connect(onWentAway);
|
|
||||||
|
|
||||||
function onWentAway() {
|
function onWentAway() {
|
||||||
if (!hmd) {
|
disableMouseLook();
|
||||||
if (mouseLookEnabled) {
|
|
||||||
away = true;
|
|
||||||
if (!keysOnOverlay) {
|
|
||||||
if (!tabletUp){
|
|
||||||
Window.displayAnnouncement("Away state ON – mouse look temporarily OFF.")
|
|
||||||
tempOff = false;
|
|
||||||
mouseLookOff()
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MyAvatar.wentActive.connect(onWentActive);
|
|
||||||
|
|
||||||
function onWentActive() {
|
function onWentActive() {
|
||||||
if (!hmd) {
|
enableMouseLook();
|
||||||
if (mouseLookEnabled) {
|
|
||||||
away = false;
|
|
||||||
if (!keysOnOverlay) {
|
|
||||||
if (!tabletUp) {
|
|
||||||
Window.displayAnnouncement("Away state OFF – mouse look ON.");
|
|
||||||
mouseLookOn();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HMD.displayModeChanged.connect(onDisplayModeChanged);
|
|
||||||
|
|
||||||
function onDisplayModeChanged() {
|
function onDisplayModeChanged() {
|
||||||
if (mouseLookEnabled) {
|
hmd_active = HMD.active;
|
||||||
if (HMD.active) {
|
if (hmd_active) disableMouseLook();
|
||||||
hmd = true;
|
else enableMouseLook();
|
||||||
mouseLookOff();
|
}
|
||||||
|
|
||||||
|
function onUiFocusChanged(keyFocus) {
|
||||||
|
if (keyFocus) {
|
||||||
|
overlay_active = true;
|
||||||
|
disableMouseLook();
|
||||||
} else {
|
} else {
|
||||||
hmd = false;
|
overlay_active = false;
|
||||||
if (!tempOff) {
|
enableMouseLook();
|
||||||
if (!keysOnOverlay) {
|
|
||||||
if (!tabletUp) {
|
|
||||||
mouseLookOn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mouseLookOn() {
|
function enableMouseLook() {
|
||||||
if (mouseLookEnabled)
|
if (hmd_active) return;
|
||||||
|
if (tablet.tabletShown) return;
|
||||||
|
if (overlay_active) return;
|
||||||
|
if (!mouse_look_active) return; // Mouse look disabled via the hotkey
|
||||||
|
|
||||||
Camera.captureMouse = true;
|
Camera.captureMouse = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mouseLookOff() {
|
function disableMouseLook() {
|
||||||
Camera.captureMouse = false;
|
Camera.captureMouse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Desktop.uiFocusChanged.connect(onUiFocusChanged);
|
|
||||||
|
|
||||||
function onUiFocusChanged(keyFocus) {
|
|
||||||
if (!hmd) {
|
|
||||||
if (mouseLookEnabled) {
|
|
||||||
if (keyFocus) {
|
|
||||||
keysOnOverlay = true;
|
|
||||||
if (Camera.captureMouse) {
|
|
||||||
mouseLookOff();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
keysOnOverlay = false;
|
|
||||||
if (!tablet.tabletShown) {
|
|
||||||
if (!tempOff) {
|
|
||||||
if (!away) {
|
|
||||||
mouseLookOn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Messages.messageReceived.connect(onMessageReceived);
|
|
||||||
function onMessageReceived(channel, message, sender, localOnly) {
|
|
||||||
if (channel === "Hifi-Away-Enable")
|
|
||||||
if (message === 'enable') mouseLookOn();
|
|
||||||
}
|
|
||||||
|
|
||||||
Script.scriptEnding.connect(onScriptEnding);
|
|
||||||
|
|
||||||
function onScriptEnding() {
|
function onScriptEnding() {
|
||||||
Camera.captureMouse = false;
|
Camera.captureMouse = false;
|
||||||
Camera.mouseLookChanged.disconnect(onMouseLookChanged);
|
Camera.mouseLookChanged.disconnect(onMouseLookChanged);
|
||||||
|
@ -211,5 +102,4 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
|
||||||
Desktop.uiFocusChanged.disconnect(onUiFocusChanged);
|
Desktop.uiFocusChanged.disconnect(onUiFocusChanged);
|
||||||
Script.scriptEnding.disconnect(onScriptEnding);
|
Script.scriptEnding.disconnect(onScriptEnding);
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
}()); // END LOCAL_SCOPE
|
|
||||||
|
|
Loading…
Reference in a new issue