Updated mouse look script to use added API endpoints for preventing softlocks with overlays. (Needs testing.)

This commit is contained in:
rampa3 2023-08-28 22:19:54 +02:00
parent 025f530db6
commit 831ef9a3bb

View file

@ -13,6 +13,8 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var tabletUp; var tabletUp;
var keysOnOverlay = Desktop.isOverlayWindowFocused();
var tempOff = false; var tempOff = false;
@ -24,12 +26,14 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
if (!hmd){ if (!hmd){
if (mouseLookEnabled) { if (mouseLookEnabled) {
if (!tablet.tabletShown){ if (!keysOnOverlay) {
Window.displayAnnouncement("Mouse look: ON"); if (!tablet.tabletShown){
mouseLookOn(); Window.displayAnnouncement("Mouse look: ON");
} else { mouseLookOn();
Window.displayAnnouncement("Tablet is up mouse look temporarily OFF."); } else {
} Window.displayAnnouncement("Tablet is up mouse look temporarily OFF.");
}
}
} }
} }
@ -38,17 +42,19 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
function onKeyPressEvent(event) { function onKeyPressEvent(event) {
if (!hmd){ if (!hmd){
if (event.text === 'm') { if (event.text === 'm') {
if (mouseLookEnabled) { if (!keysOnOverlay) {
if (!Camera.getCaptureMouse()){ if (mouseLookEnabled) {
tempOff = false; if (!Camera.getCaptureMouse()){
Window.displayAnnouncement("Mouse look: ON"); tempOff = false;
mouseLookOn(); Window.displayAnnouncement("Mouse look: ON");
} else { mouseLookOn();
tempOff = true; } else {
Window.displayAnnouncement("Mouse look: Temporarily OFF"); tempOff = true;
mouseLookOff(); Window.displayAnnouncement("Mouse look: Temporarily OFF");
} mouseLookOff();
} }
}
}
} }
} }
} }
@ -59,23 +65,25 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
if (!hmd) { if (!hmd) {
if (mouseLookEnabled) { if (mouseLookEnabled) {
if (!tablet.toolbarMode) { if (!tablet.toolbarMode) {
if (tablet.tabletShown) { if (!keysOnOverlay) {
tabletUp = true; if (tablet.tabletShown) {
if (!tempOff) { tabletUp = true;
if (!away) { if (!tempOff) {
Window.displayAnnouncement("Tablet is up mouse look temporarily OFF."); if (!away) {
mouseLookOff(); Window.displayAnnouncement("Tablet is up mouse look temporarily OFF.");
} mouseLookOff();
} }
} else if (!tablet.tabletShown) { }
tabletUp = false; } else if (!tablet.tabletShown) {
if (!tempOff) { tabletUp = false;
if (!away) { if (!tempOff) {
Window.displayAnnouncement("Tablet hidden mouse look ON."); if (!away && !keysOnOverlay) {
mouseLookOn(); Window.displayAnnouncement("Tablet hidden mouse look ON.");
} mouseLookOn();
} }
} }
}
}
} }
} }
} }
@ -87,11 +95,13 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
if (!hmd) { if (!hmd) {
if (mouseLookEnabled) { if (mouseLookEnabled) {
away = true; away = true;
if (!tabletUp){ if (!keysOnOverlay) {
Window.displayAnnouncement("Away state ON mouse look temporarily OFF.") if (!tabletUp){
tempOff = false; Window.displayAnnouncement("Away state ON mouse look temporarily OFF.")
mouseLookOff() tempOff = false;
} mouseLookOff()
}
}
} }
} }
} }
@ -102,10 +112,12 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
if (!hmd) { if (!hmd) {
if (mouseLookEnabled) { if (mouseLookEnabled) {
away = false; away = false;
if (!tabletUp) { if (!keysOnOverlay) {
Window.displayAnnouncement("Away state OFF mouse look ON."); if (!tabletUp) {
mouseLookOn(); Window.displayAnnouncement("Away state OFF mouse look ON.");
} mouseLookOn();
}
}
} }
} }
} }
@ -120,9 +132,11 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
} else { } else {
hmd = false; hmd = false;
if (!tempOff) { if (!tempOff) {
if (!tabletUp) { if (!keysOnOverlay) {
mouseLookOn(); if (!tabletUp) {
} mouseLookOn();
}
}
} }
} }
} }
@ -135,8 +149,28 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
function mouseLookOff() { function mouseLookOff() {
Camera.captureMouse = false; Camera.captureMouse = false;
} }
Camera.modeUpdated.connect(onCameraModeUpdated); Desktop.uiFocusChanged.connect(onUiFocusChanged);
function onUiFocusChanged(keyFocus) {
if (!hmd) {
if (keyFocus) {
keysOnOverlay = true;
if (Camera.captureMouse) {
Camera.captureMouse = false;
}
} else {
keysOnOverlay = false;
if (!tablet.tabletShown) {
if (!tempOff) {
if (!away) {
mouseLookOn();
}
}
}
}
}
}
Script.scriptEnding.connect(onScriptEnding); Script.scriptEnding.connect(onScriptEnding);
@ -148,8 +182,8 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
MyAvatar.wentAway.disconnect(onWentAway); MyAvatar.wentAway.disconnect(onWentAway);
MyAvatar.wentActive.disconnect(onWentActive); MyAvatar.wentActive.disconnect(onWentActive);
HMD.displayModeChanged.disconnect(onDisplayModeChanged); HMD.displayModeChanged.disconnect(onDisplayModeChanged);
Camera.modeUpdated.disconnect(onCameraModeUpdated); Desktop.uiFocusChanged.disconnect(onUiFocusChanged);
Script.scriptEnding.disconnect(onScriptEnding); Script.scriptEnding.disconnect(onScriptEnding);
} }
}()); // END LOCAL_SCOPE }()); // END LOCAL_SCOPE