handle removal of an overlay for an avatar that is removed

This commit is contained in:
Stephen Birarda 2016-07-12 15:10:02 -07:00
parent 7bd8c45098
commit aeabae4faf

View file

@ -36,6 +36,20 @@ function removeOverlays() {
ignoreOverlays = {}; ignoreOverlays = {};
} }
// handle clicks on the toolbar button
function buttonClicked(){
if (isShowingOverlays) {
removeOverlays();
isShowingOverlays = false;
} else {
isShowingOverlays = true;
}
button.writeProperty('buttonState', isShowingOverlays ? 0 : 1);
}
button.clicked.connect(buttonClicked);
var OVERLAY_SIZE = 0.25; var OVERLAY_SIZE = 0.25;
function updateOverlays() { function updateOverlays() {
@ -80,19 +94,19 @@ function updateOverlays() {
} }
} }
// handle clicks on the toolbar button Script.update.connect(updateOverlays);
function buttonClicked(){
AvatarList.avatarRemovedEvent.connect(function(avatarID){
if (isShowingOverlays) { if (isShowingOverlays) {
removeOverlays(); // we are currently showing overlays and an avatar just went away
isShowingOverlays = false;
} else { // first remove the rendered overlay
isShowingOverlays = true; Overlays.deleteOverlay(ignoreOverlays[avatarID]);
// delete the saved ID of the overlay from our ignored overlays object
delete ignoreOverlays[avatarID];
} }
})
button.writeProperty('buttonState', isShowingOverlays ? 0 : 1);
}
button.clicked.connect(buttonClicked);
Controller.mousePressEvent.connect(function(event){ Controller.mousePressEvent.connect(function(event){
// handle click events so we can detect when our overlays are clicked // handle click events so we can detect when our overlays are clicked
@ -118,16 +132,11 @@ Controller.mousePressEvent.connect(function(event){
// matched to an overlay, ask for the matching avatar to be ignored // matched to an overlay, ask for the matching avatar to be ignored
Users.ignore(avatarID); Users.ignore(avatarID);
// remove the actual overlay so it is no longer rendered // cleanup of the overlay is handled by the connection to avatarRemovedEvent
Overlays.deleteOverlay(ignoreOverlay);
// remove the overlay ID and avatar ID from our internal array
delete ignoreOverlays[avatarID];
} }
} }
}); });
Script.update.connect(updateOverlays);
// cleanup the toolbar button and overlays when script is stopped // cleanup the toolbar button and overlays when script is stopped
Script.scriptEnding.connect(function() { Script.scriptEnding.connect(function() {