clean up avatar nodes properly (and add some logging)

This commit is contained in:
howard-stearns 2016-12-14 11:26:33 -08:00
parent d5c219a761
commit 66e2c651c6

View file

@ -82,6 +82,7 @@ var pal = new OverlayWindow({
visible: false visible: false
}); });
pal.fromQml.connect(function (message) { // messages are {method, params}, like json-rpc. See also sendToQml. pal.fromQml.connect(function (message) { // messages are {method, params}, like json-rpc. See also sendToQml.
print('From PAL QML:', JSON.stringify(message));
switch (message.method) { switch (message.method) {
case 'selected': case 'selected':
var sessionIds = message.params; var sessionIds = message.params;
@ -110,14 +111,16 @@ function populateUserList() {
var counter = 1; var counter = 1;
AvatarList.getAvatarIdentifiers().sort().forEach(function (id) { // sorting the identifiers is just an aid for debugging AvatarList.getAvatarIdentifiers().sort().forEach(function (id) { // sorting the identifiers is just an aid for debugging
var avatar = AvatarList.getAvatar(id); var avatar = AvatarList.getAvatar(id);
data.push({ var avatarPalDatum = {
displayName: avatar.displayName || ('anonymous ' + counter++), displayName: avatar.displayName || ('anonymous ' + counter++),
userName: "fakeAcct" + (id || "Me"), userName: "fakeAcct" + (id || "Me"),
sessionId: id || '' sessionId: id || ''
}); };
data.push(avatarPalDatum);
if (id) { // No overlay for ourself. if (id) { // No overlay for ourself.
addAvatarNode(id); addAvatarNode(id);
} }
print('PAL data:', JSON.stringify(avatarPalDatum));
}); });
pal.sendToQml({method: 'users', params: data}); pal.sendToQml({method: 'users', params: data});
} }
@ -130,6 +133,7 @@ function updateOverlays() {
} }
var overlay = ExtendedOverlay.get(id); var overlay = ExtendedOverlay.get(id);
if (!overlay) { // For now, we're treating this as a temporary loss, as from the personal space bubble. Add it back. if (!overlay) { // For now, we're treating this as a temporary loss, as from the personal space bubble. Add it back.
print('Adding non-PAL avatar node', id);
overlay = addAvatarNode(id); overlay = addAvatarNode(id);
} }
var avatar = AvatarList.getAvatar(id); var avatar = AvatarList.getAvatar(id);
@ -150,6 +154,7 @@ function updateOverlays() {
// We could re-populateUserList if anything added or removed, but not for now. // We could re-populateUserList if anything added or removed, but not for now.
} }
function removeOverlays() { function removeOverlays() {
selectedId = null;
ExtendedOverlay.some(function (overlay) { overlay.deleteOverlay(); }); ExtendedOverlay.some(function (overlay) { overlay.deleteOverlay(); });
} }
@ -203,22 +208,25 @@ var button = toolBar.addButton({
buttonState: 1, buttonState: 1,
alpha: 0.9 alpha: 0.9
}); });
var isWired = false;
function off() { function off() {
Script.update.disconnect(updateOverlays); if (isWired) { // It is not ok to disconnect these twice, hence guard.
Controller.mousePressEvent.disconnect(handleMouseEvent); Script.update.disconnect(updateOverlays);
triggerMapping.disable(); Controller.mousePressEvent.disconnect(handleMouseEvent);
isWired = false;
}
triggerMapping.disable(); // It's ok if we disable twice.
removeOverlays(); removeOverlays();
} }
function onClicked() { function onClicked() {
if (!pal.visible) { if (!pal.visible) {
populateUserList(); populateUserList();
pal.raise(); pal.raise();
isWired = true;
Script.update.connect(updateOverlays); Script.update.connect(updateOverlays);
Controller.mousePressEvent.connect(handleMouseEvent); Controller.mousePressEvent.connect(handleMouseEvent);
triggerMapping.enable(); triggerMapping.enable();
} else { } // No need for off, as onVisibleChanged will handle it.
off();
}
pal.setVisible(!pal.visible); pal.setVisible(!pal.visible);
} }
@ -229,6 +237,9 @@ function onVisibileChanged() {
button.writeProperty('buttonState', pal.visible ? 0 : 1); button.writeProperty('buttonState', pal.visible ? 0 : 1);
button.writeProperty('defaultState', pal.visible ? 0 : 1); button.writeProperty('defaultState', pal.visible ? 0 : 1);
button.writeProperty('hoverState', pal.visible ? 2 : 3); button.writeProperty('hoverState', pal.visible ? 2 : 3);
if (!pal.visible) {
off();
}
} }
button.clicked.connect(onClicked); button.clicked.connect(onClicked);
pal.visibleChanged.connect(onVisibileChanged); pal.visibleChanged.connect(onVisibileChanged);