diff --git a/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js b/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js index 763a0a0a27..69aaad4247 100644 --- a/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js +++ b/scripts/system/controllers/controllerModules/nearParentGrabOverlay.js @@ -9,7 +9,7 @@ /* global Script, MyAvatar, Controller, RIGHT_HAND, LEFT_HAND, getControllerJointIndex, enableDispatcherModule, disableDispatcherModule, Messages, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, makeDispatcherModuleParameters, Overlays, makeRunningValues, Vec3, resizeTablet, getTabletWidthFromSettings, - NEAR_GRAB_RADIUS, HMD, Uuid + NEAR_GRAB_RADIUS, HMD, Uuid, HIFI_EDIT_MANIPULATION_CHANNEL */ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); @@ -172,10 +172,14 @@ Script.include("/~/system/libraries/utils.js"); return null; }; + this.isEditing = false; + this.setIsEditing = function (editing) { + this.isEditing = editing; + }; this.isReady = function (controllerData) { - if ((controllerData.triggerClicks[this.hand] === 0 && - controllerData.secondaryValues[this.hand] === 0)) { + if ((controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0) + || this.isEditing) { this.robbed = false; return makeRunningValues(false, [], []); } @@ -198,7 +202,8 @@ Script.include("/~/system/libraries/utils.js"); }; this.run = function (controllerData) { - if (controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0) { + if ((controllerData.triggerClicks[this.hand] === 0 && controllerData.secondaryValues[this.hand] === 0) + || this.isEditing) { this.endNearParentingGrabOverlay(); this.robbed = false; return makeRunningValues(false, [], []); @@ -226,6 +231,28 @@ Script.include("/~/system/libraries/utils.js"); enableDispatcherModule("LeftNearParentingGrabOverlay", leftNearParentingGrabOverlay); enableDispatcherModule("RightNearParentingGrabOverlay", rightNearParentingGrabOverlay); + function onMessageReceived(channel, data, senderID) { + var message; + + if (channel !== HIFI_EDIT_MANIPULATION_CHANNEL || senderID !== MyAvatar.sessionUUID) { + return; + } + + try { + message = JSON.parse(data); + } catch (e) { + return; + } + + if (message.hand === Controller.Standard.LeftHand) { + leftNearParentingGrabOverlay.setIsEditing(message.action === "startEdit"); + } else if (message.hand === Controller.Standard.RightHand) { + rightNearParentingGrabOverlay.setIsEditing(message.action === "startEdit"); + } + } + Messages.subscribe(HIFI_EDIT_MANIPULATION_CHANNEL); + Messages.messageReceived.connect(onMessageReceived); + function cleanup() { leftNearParentingGrabOverlay.cleanup(); rightNearParentingGrabOverlay.cleanup(); diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index e9d5255d28..f7b997a897 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -24,6 +24,7 @@ HAPTIC_PULSE_DURATION:true, DISPATCHER_HOVERING_LIST:true, DISPATCHER_HOVERING_STYLE:true, + HIFI_EDIT_MANIPULATION_CHANNEL:true, Entities, makeDispatcherModuleParameters:true, makeRunningValues:true, @@ -149,6 +150,8 @@ DISPATCHER_PROPERTIES = [ "userData" ]; +HIFI_EDIT_MANIPULATION_CHANNEL = "HiFi-Edit-Manipulation"; + // priority -- a lower priority means the module will be asked sooner than one with a higher priority in a given update step // activitySlots -- indicates which "slots" must not yet be in use for this module to start // requiredDataForReady -- which "situation" parts this module looks at to decide if it will start @@ -590,6 +593,7 @@ if (typeof module !== 'undefined') { TRIGGER_OFF_VALUE: TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE: TRIGGER_ON_VALUE, DISPATCHER_HOVERING_LIST: DISPATCHER_HOVERING_LIST, + HIFI_EDIT_MANIPULATION_CHANNEL: HIFI_EDIT_MANIPULATION_CHANNEL, worldPositionToRegistrationFrameMatrix: worldPositionToRegistrationFrameMatrix }; } diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index 3bb36d632e..8f972e14c2 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -14,7 +14,7 @@ // /* global SelectionManager, SelectionDisplay, grid, rayPlaneIntersection, rayPlaneIntersection2, pushCommandForSelections, - getMainTabletIDs, getControllerWorldLocation, TRIGGER_ON_VALUE */ + getMainTabletIDs, getControllerWorldLocation, TRIGGER_ON_VALUE, HIFI_EDIT_MANIPULATION_CHANNEL */ const SPACE_LOCAL = "local"; const SPACE_WORLD = "world"; @@ -983,6 +983,7 @@ SelectionDisplay = (function() { that.triggerPressMapping = Controller.newMapping(Script.resolvePath('') + '-press'); that.triggeredHand = NO_HAND; that.pressedHand = NO_HAND; + that.editingHand = NO_HAND; that.triggered = function() { return that.triggeredHand !== NO_HAND; }; @@ -1115,6 +1116,11 @@ SelectionDisplay = (function() { activeTool = hitTool; that.clearDebugPickPlane(); if (activeTool.onBegin) { + Messages.sendLocalMessage(HIFI_EDIT_MANIPULATION_CHANNEL, JSON.stringify({ + action: "startEdit", + hand: that.triggeredHand + })); + that.editingHand = that.triggeredHand; activeTool.onBegin(event, pickRay, results); } else { print("ERROR: entitySelectionTool.mousePressEvent - ActiveTool(" + activeTool.mode + ") missing onBegin"); @@ -1263,6 +1269,11 @@ SelectionDisplay = (function() { if (wantDebug) { print(" Triggering ActiveTool(" + activeTool.mode + ")'s onEnd"); } + Messages.sendLocalMessage(HIFI_EDIT_MANIPULATION_CHANNEL, JSON.stringify({ + action: "finishEdit", + hand: that.editingHand + })); + that.editingHand = NO_HAND; activeTool.onEnd(event); } else if (wantDebug) { print(" ActiveTool(" + activeTool.mode + ")'s missing onEnd");