diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index f71af03e26..cb1870ed73 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -52,6 +52,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); this.blacklist = []; this.pointerManager = new PointerManager(); this.miniTabletID = null; + this.niniTabletHand = LEFT_HAND; // a module can occupy one or more "activity" slots while it's running. If all the required slots for a module are // not set to false (not in use), a module cannot start. When a module is using a slot, that module's name @@ -216,6 +217,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Overlays.findOverlays(controllerLocations[h].position, NEAR_MAX_RADIUS * sensorScaleFactor); // Tablet and mini-tablet must be within NEAR_TABLET_MAX_RADIUS in order to be grabbed. + // Mini tablet can only be grabbed the hand it's displayed on. var tabletIndex = nearbyOverlays.indexOf(HMD.tabletID); var miniTabletIndex = nearbyOverlays.indexOf(_this.miniTabletID); if (tabletIndex !== -1 || miniTabletIndex !== -1) { @@ -225,7 +227,8 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); if (tabletIndex !== -1 && closebyOverlays.indexOf(HMD.tabletID) === -1) { nearbyOverlays.splice(tabletIndex, 1); } - if (miniTabletIndex !== -1 && closebyOverlays.indexOf(_this.miniTabletID) === -1) { + if (miniTabletIndex !== -1 + && (closebyOverlays.indexOf(_this.miniTabletID) === -1) || h !== _this.miniTabletHand) { nearbyOverlays.splice(miniTabletIndex, 1); } } @@ -469,14 +472,14 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); filter: Picks.PICK_ENTITIES | Picks.PICK_OVERLAYS, enabled: true }); - this.handleHandMessage = function(channel, message, sender) { - var data; + this.handleHandMessage = function(channel, data, sender) { + var message; if (sender === MyAvatar.sessionUUID) { try { if (channel === 'Hifi-Hand-RayPick-Blacklist') { - data = JSON.parse(message); - var action = data.action; - var id = data.id; + message = JSON.parse(data); + var action = message.action; + var id = message.id; var index = _this.blacklist.indexOf(id); if (action === 'add' && index === -1) { @@ -490,8 +493,10 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); _this.setBlacklist(); } } - } else if (channel === 'Hifi-MiniTablet-ID') { - _this.miniTabletID = message; + } else if (channel === 'Hifi-MiniTablet-Details') { + message = JSON.parse(data); + _this.miniTabletID = message.overlay; + _this.miniTabletHand = message.hand; } } catch (e) { @@ -530,7 +535,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Entities.mousePressOnEntity.connect(mousePress); var controllerDispatcher = new ControllerDispatcher(); Messages.subscribe('Hifi-Hand-RayPick-Blacklist'); - Messages.subscribe('Hifi-MiniTablet-ID'); + Messages.subscribe('Hifi-MiniTablet-Details'); Messages.messageReceived.connect(controllerDispatcher.handleHandMessage); Script.scriptEnding.connect(controllerDispatcher.cleanup); Script.setTimeout(controllerDispatcher.update, BASIC_TIMER_INTERVAL_MS); diff --git a/scripts/system/miniTablet.js b/scripts/system/miniTablet.js index 2e5a5d86a2..78fc3aa34e 100644 --- a/scripts/system/miniTablet.js +++ b/scripts/system/miniTablet.js @@ -236,8 +236,11 @@ function updateMiniTabletID() { // Send mini-tablet overlay ID to controllerDispatcher so that it can use a smaller near grab distance. - Messages.sendLocalMessage("Hifi-MiniTablet-ID", miniOverlay); - // Send mini-tablet UI overlay ID to stylusInput so that it styluses can be used on it. + Messages.sendLocalMessage("Hifi-MiniTablet-Details", JSON.stringify({ + overlay: miniOverlay, + hand: uiHand + })); + // Send mini-tablet UI overlay ID to stylusInput so that styluses can be used on it. Messages.sendLocalMessage("Hifi-MiniTablet-UI-ID", miniUIOverlay); } @@ -474,8 +477,6 @@ miniOverlayObject = Overlays.getOverlayObject(miniUIOverlay); miniOverlayObject.webEventReceived.connect(onWebEventReceived); - - // updateMiniTabletID(); Other scripts relying on this may not be ready yet so do this in show(). } function destroy() { @@ -527,11 +528,10 @@ MINI_HIDING = 2, MINI_SHOWING = 3, MINI_VISIBLE = 4, - MINI_GRABBED = 5, - MINI_EXPANDING = 6, - TABLET_OPEN = 7, - STATE_STRINGS = ["MINI_DISABLED", "MINI_HIDDEN", "MINI_HIDING", "MINI_SHOWING", "MINI_VISIBLE", "MINI_GRABBED", - "MINI_EXPANDING", "TABLET_OPEN"], + MINI_EXPANDING = 5, + TABLET_OPEN = 6, + STATE_STRINGS = ["MINI_DISABLED", "MINI_HIDDEN", "MINI_HIDING", "MINI_SHOWING", "MINI_VISIBLE", "MINI_EXPANDING", + "TABLET_OPEN"], STATE_MACHINE, miniState = MINI_DISABLED, miniHand, @@ -812,18 +812,6 @@ } } - function updateMiniGrabbed() { - // Hide mini tablet if tablet proper has been displayed by other means. - if (HMD.showTablet) { - setState(MINI_HIDDEN); - } - } - - function exitMiniGrabbed() { - // Explicitly unparent mini tablet in case controller grabbing code has reparented it. - ui.release(); - } - function expandMini() { var scaleFactor = (Date.now() - miniExpandStart) / MINI_EXPAND_DURATION; if (scaleFactor < 1) { @@ -913,11 +901,6 @@ update: updateMiniVisible, exit: null }, - MINI_GRABBED: { // Mini tablet is grabbed by other hand. - enter: null, - update: updateMiniGrabbed, - exit: exitMiniGrabbed - }, MINI_EXPANDING: { // Mini tablet is expanding before showing tablet proper. enter: enterMiniExpanding, update: updateMiniExanding, @@ -979,7 +962,6 @@ MINI_HIDING: MINI_HIDING, MINI_SHOWING: MINI_SHOWING, MINI_VISIBLE: MINI_VISIBLE, - MINI_GRABBED: MINI_GRABBED, MINI_EXPANDING: MINI_EXPANDING, TABLET_OPEN: TABLET_OPEN, updateState: updateState, @@ -1017,14 +999,6 @@ // Tablet may have been grabbed after it replaced expanded mini tablet. miniState.setState(miniState.MINI_HIDDEN); } else if (message.action === "grab" && miniState.getState() === miniState.MINI_VISIBLE) { - miniHand = miniState.getHand(); - hand = message.joint === HAND_NAMES[miniHand] ? miniHand : otherHand(miniHand); - if (hand === miniHand) { - miniState.setState(miniState.MINI_EXPANDING, { hand: hand, goto: false }); - } else { - miniState.setState(miniState.MINI_GRABBED); - } - } else if (message.action === "release" && miniState.getState() === miniState.MINI_GRABBED) { miniHand = miniState.getHand(); hand = message.joint === HAND_NAMES[miniHand] ? miniHand : otherHand(miniHand); miniState.setState(miniState.MINI_EXPANDING, { hand: hand, goto: false });