Merge pull request #13090 from druiz17/fix-entity-highlighting

fix highlighting issues (master)
This commit is contained in:
John Conklin II 2018-05-07 10:20:38 -07:00 committed by GitHub
commit 1e6e182c63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 6 deletions

View file

@ -56,6 +56,12 @@
return canGrabEntity;
};
this.clearAll = function() {
this.highlightedEntities.forEach(function(entity) {
dispatcherUtils.unhighlightTargetEntity(entity);
});
};
this.hasHyperLink = function(props) {
return (props.href !== "" && props.href !== undefined);
};
@ -89,7 +95,9 @@
}
if (this.isGrabable(controllerData, props) || this.hasHyperLink(props)) {
dispatcherUtils.highlightTargetEntity(props.id);
newHighlightedEntities.push(props.id);
if (newHighlightedEntities.indexOf(props.id) < 0) {
newHighlightedEntities.push(props.id);
}
}
}
@ -119,7 +127,6 @@
if (channel === 'Hifi-unhighlight-entity') {
try {
data = JSON.parse(message);
var hand = data.hand;
if (hand === dispatcherUtils.LEFT_HAND) {
leftHighlightNearbyEntities.removeEntityFromHighlightList(data.entityID);
@ -129,6 +136,9 @@
} catch (e) {
print("Failed to parse message");
}
} else if (channel === 'Hifi-unhighlight-all') {
leftHighlightNearbyEntities.clearAll();
rightHighlightNearbyEntities.clearAll();
}
}
};
@ -143,6 +153,7 @@
dispatcherUtils.disableDispatcherModule("RightHighlightNearbyEntities");
}
Messages.subscribe('Hifi-unhighlight-entity');
Messages.subscribe('Hifi-unhighlight-all');
Messages.messageReceived.connect(handleMessage);
Script.scriptEnding.connect(cleanup);
}());

View file

@ -78,6 +78,7 @@ Script.include("/~/system/libraries/utils.js");
if (controllerData.triggerValues[this.hand] < TRIGGER_ON_VALUE) {
this.triggerClicked = false;
}
Messages.sendLocalMessage('Hifi-unhighlight-all', '');
return makeRunningValues(true, [], []);
}
this.triggerClicked = false;

View file

@ -12,14 +12,16 @@
/* jslint bitwise: true */
/* global Script, print, Entities, Picks, HMD */
/* global Script, print, Entities, Picks, HMD, Controller, MyAvatar, isInEditMode*/
(function() {
Script.include("/~/system/libraries/utils.js");
var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
function MouseHighlightEntities() {
this.highlightedEntity = null;
this.grabbedEntity = null;
this.parameters = dispatcherUtils.makeDispatcherModuleParameters(
5,
@ -27,13 +29,18 @@
[],
100);
this.setGrabbedEntity = function(entity) {
this.grabbedEntity = entity;
this.highlightedEntity = null;
};
this.isReady = function(controllerData) {
if (HMD.active) {
if (this.highlightedEntity) {
dispatcherUtils.unhighlightTargetEntity(this.highlightedEntity);
this.highlightedEntity = null;
}
} else {
} else if (!this.grabbedEntity && !isInEditMode()) {
var pickResult = controllerData.mouseRayPick;
if (pickResult.type === Picks.INTERSECTED_ENTITY) {
var targetEntityID = pickResult.objectID;
@ -70,8 +77,29 @@
var mouseHighlightEntities = new MouseHighlightEntities();
dispatcherUtils.enableDispatcherModule("MouseHighlightEntities", mouseHighlightEntities);
var handleMessage = function(channel, message, sender) {
var data;
if (sender === MyAvatar.sessionUUID) {
if (channel === 'Hifi-Object-Manipulation') {
try {
data = JSON.parse(message);
if (data.action === 'grab') {
var grabbedEntity = data.grabbedEntity;
mouseHighlightEntities.setGrabbedEntity(grabbedEntity);
} else if (data.action === 'release') {
mouseHighlightEntities.setGrabbedEntity(null);
}
} catch (e) {
print("Warning: mouseHighlightEntities -- error parsing Hifi-Object-Manipulation: " + message);
}
}
}
};
function cleanup() {
dispatcherUtils.disableDispatcherModule("MouseHighlightEntities");
}
Messages.subscribe('Hifi-Object-Manipulation');
Messages.messageReceived.connect(handleMessage);
Script.scriptEnding.connect(cleanup);
})();

View file

@ -409,7 +409,7 @@ Grabber.prototype.pressEvent = function(event) {
var args = "mouse";
Entities.callEntityMethod(this.entityID, "startDistanceGrab", args);
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
Messages.sendLocalMessage('Hifi-Object-Manipulation', JSON.stringify({
action: 'grab',
grabbedEntity: this.entityID
}));
@ -450,7 +450,7 @@ Grabber.prototype.releaseEvent = function(event) {
var args = "mouse";
Entities.callEntityMethod(this.entityID, "releaseGrab", args);
Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({
Messages.sendLocalMessage('Hifi-Object-Manipulation', JSON.stringify({
action: 'release',
grabbedEntity: this.entityID,
joint: "mouse"