Minor rewrite to make script clean up properly on exit, and added conditions to fix misbehavior in situation of going away with open tablet.

This commit is contained in:
rampa3 2023-06-06 23:58:13 +02:00 committed by ksuprynowicz
parent 3daab28245
commit a824fe01e0

View file

@ -6,13 +6,23 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
var oldMode;
var tabletUp;
var away;
var mouseLookEnabled = false;
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
if (mouseLookEnabled) {
mouseLookOn();
if (!tablet.tabletShown){
mouseLookOn();
}
}
Controller.keyPressEvent.connect(function(event) {
Controller.keyPressEvent.connect(onKeyPressEvent);
function onKeyPressEvent(event) {
if (event.text === 'm') {
if (mouseLookEnabled) {
if (!Camera.getCaptureMouse()){
@ -35,31 +45,53 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
mouseLookOff();
}
}
});
}
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
tablet.tabletShownChanged.connect(function () {
if (!tablet.toolbarMode) {
if (tablet.tabletShown) {
Window.displayAnnouncement("Tablet is up mouse look temporarily off.");
mouseLookOff();
tablet.tabletShownChanged.connect(onTabletShownChanged);
} else if (!tablet.tabletShown) {
Window.displayAnnouncement("Tablet hidden mouse look on.");
function onTabletShownChanged() {
if (mouseLookEnabled) {
if (!tablet.toolbarMode) {
if (tablet.tabletShown) {
tabletUp = true;
if (!away) {
Window.displayAnnouncement("Tablet is up mouse look temporarily off.");
mouseLookOff();
}
} else if (!tablet.tabletShown) {
tabletUp = false;
if (!away) {
Window.displayAnnouncement("Tablet hidden mouse look on.");
mouseLookOn();
}
}
}
}
}
MyAvatar.wentAway.connect(onWentAway);
function onWentAway() {
if (mouseLookEnabled) {
away = true;
if (!tabletUp){
Window.displayAnnouncement("Away state ON mouse look temporarily off.")
mouseLookOff()
}
}
}
MyAvatar.wentActive.connect(onWentActive);
function onWentActive() {
if (mouseLookEnabled) {
away = false;
if (!tabletUp) {
Window.displayAnnouncement("Away state OFF mouse look on.");
mouseLookOn();
}
}
});
MyAvatar.wentAway.connect(function () {
Window.displayAnnouncement("Away state ON mouse look temporarily off.")
mouseLookOff()
});
MyAvatar.wentActive.connect(function () {
Window.displayAnnouncement("Away state OFF mouse look on.");
mouseLookOn();
});
}
function mouseLookOn() {
oldMode = Camera.mode;
@ -80,8 +112,16 @@ by rampa3 (https://github.com/rampa3) and vegaslon (https://github.com/vegaslon)
Camera.modeUpdated.connect(onCameraModeUpdated);
Script.scriptEnding.connect(function() {
Script.scriptEnding.connect(onScriptEnding);
function onScriptEnding() {
Camera.captureMouse = false;
});
Controller.keyPressEvent.disconnect(onKeyPressEvent);
tablet.tabletShownChanged.disconnect(onTabletShownChanged);
MyAvatar.wentAway.disconnect(onWentAway);
MyAvatar.wentActive.disconnect(onWentActive);
Camera.modeUpdated.disconnect(onCameraModeUpdated);
Script.scriptEnding.disconnect();
}
}()); // END LOCAL_SCOPE