use click handler only, remove triggerClicked

This commit is contained in:
David Back 2018-07-31 11:51:16 -07:00
parent 93335feba1
commit 4a722a62f7
2 changed files with 37 additions and 79 deletions

View file

@ -66,44 +66,33 @@ Script.include("/~/system/libraries/utils.js");
this.sendPickData = function(controllerData) { this.sendPickData = function(controllerData) {
if (controllerData.triggerClicks[this.hand]) { if (controllerData.triggerClicks[this.hand]) {
var hand = this.hand === RIGHT_HAND ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
if (!this.triggerClicked) { if (!this.triggerClicked) {
this.selectedTarget = controllerData.rayPicks[this.hand]; this.selectedTarget = controllerData.rayPicks[this.hand];
if (!this.selectedTarget.intersects) { if (!this.selectedTarget.intersects) {
Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({ Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({
method: "clearSelection" method: "clearSelection",
hand: hand
})); }));
} }
Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({
method: "triggerClicked",
clicked: true,
rightHand: this.hand === RIGHT_HAND
}));
} }
if (this.selectedTarget.type === Picks.INTERSECTED_ENTITY) { if (this.selectedTarget.type === Picks.INTERSECTED_ENTITY) {
if (!this.isTabletMaterialEntity(this.selectedTarget.objectID)) { if (!this.isTabletMaterialEntity(this.selectedTarget.objectID)) {
Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({ Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({
method: "selectEntity", method: "selectEntity",
entityID: this.selectedTarget.objectID entityID: this.selectedTarget.objectID,
hand: hand
})); }));
} }
} else if (this.selectedTarget.type === Picks.INTERSECTED_OVERLAY) { } else if (this.selectedTarget.type === Picks.INTERSECTED_OVERLAY) {
Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({ Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({
method: "selectOverlay", method: "selectOverlay",
overlayID: this.selectedTarget.objectID overlayID: this.selectedTarget.objectID,
hand: hand
})); }));
} }
this.triggerClicked = true; this.triggerClicked = true;
} else {
if (this.triggerClicked) {
Messages.sendLocalMessage("entityToolUpdates", JSON.stringify({
method: "triggerClicked",
clicked: false,
rightHand: this.hand === RIGHT_HAND
}));
}
this.triggerClicked = false;
} }
this.sendPointingAtData(controllerData); this.sendPointingAtData(controllerData);

View file

@ -53,26 +53,24 @@ SelectionManager = (function() {
} }
if (messageParsed.method === "selectEntity") { if (messageParsed.method === "selectEntity") {
if (wantDebug) { if (!SelectionDisplay.triggered() || SelectionDisplay.triggeredHand === messageParsed.hand) {
print("setting selection to " + messageParsed.entityID); if (wantDebug) {
print("setting selection to " + messageParsed.entityID);
}
that.setSelections([messageParsed.entityID]);
} }
that.setSelections([messageParsed.entityID]);
} else if (messageParsed.method === "clearSelection") { } else if (messageParsed.method === "clearSelection") {
that.clearSelections(); if (!SelectionDisplay.triggered() || SelectionDisplay.triggeredHand === messageParsed.hand) {
that.clearSelections();
}
} else if (messageParsed.method === "pointingAt") { } else if (messageParsed.method === "pointingAt") {
if (messageParsed.rightHand) { if (messageParsed.hand === Controller.Standard.RightHand) {
that.pointingAtDesktopWindowRight = messageParsed.desktopWindow; that.pointingAtDesktopWindowRight = messageParsed.desktopWindow;
that.pointingAtTabletRight = messageParsed.tablet; that.pointingAtTabletRight = messageParsed.tablet;
} else { } else {
that.pointingAtDesktopWindowLeft = messageParsed.desktopWindow; that.pointingAtDesktopWindowLeft = messageParsed.desktopWindow;
that.pointingAtTabletLeft = messageParsed.tablet; that.pointingAtTabletLeft = messageParsed.tablet;
} }
} else if (messageParsed.method === "triggerClicked") {
if (messageParsed.rightHand) {
that.triggerClickedRight = messageParsed.clicked;
} else {
that.triggerClickedLeft = messageParsed.clicked;
}
} }
} }
@ -115,9 +113,6 @@ SelectionManager = (function() {
that.pointingAtDesktopWindowRight = false; that.pointingAtDesktopWindowRight = false;
that.pointingAtTabletLeft = false; that.pointingAtTabletLeft = false;
that.pointingAtTabletRight = false; that.pointingAtTabletRight = false;
that.triggerClickedRight = false;
that.triggerClickedLeft = false;
that.saveProperties = function() { that.saveProperties = function() {
that.savedProperties = {}; that.savedProperties = {};
@ -761,62 +756,36 @@ SelectionDisplay = (function() {
// We get mouseMoveEvents from the handControllers, via handControllerPointer. // We get mouseMoveEvents from the handControllers, via handControllerPointer.
// But we dont' get mousePressEvents. // But we dont' get mousePressEvents.
that.triggerMapping = Controller.newMapping(Script.resolvePath('') + '-click'); that.triggerMapping = Controller.newMapping(Script.resolvePath('') + '-click');
that.triggerPressMapping = Controller.newMapping(Script.resolvePath('') + '-press');
Script.scriptEnding.connect(that.triggerMapping.disable); Script.scriptEnding.connect(that.triggerMapping.disable);
that.triggeredHand = NO_TRIGGER_HAND; that.triggeredHand = NO_TRIGGER_HAND;
that.triggered = function() { that.triggered = function() {
return that.triggeredHand !== NO_TRIGGER_HAND; return that.triggeredHand !== NO_TRIGGER_HAND;
} }
function triggerPress(hand) {
var pointingAtDesktopWindow = (hand === Controller.Standard.RightHand &&
SelectionManager.pointingAtDesktopWindowRight) ||
(hand === Controller.Standard.LeftHand &&
SelectionManager.pointingAtDesktopWindowLeft);
var pointingAtTablet = (hand === Controller.Standard.RightHand && SelectionManager.pointingAtTabletRight) ||
(hand === Controller.Standard.LeftHand && SelectionManager.pointingAtTabletLeft);
if (pointingAtDesktopWindow || pointingAtTablet) {
return;
}
that.triggeredHand = hand;
that.mousePressEvent({});
}
function triggerRelease(hand) {
that.triggeredHand = NO_TRIGGER_HAND;
that.mouseReleaseEvent({});
var otherTriggerClicked = hand == Controller.Standard.RightHand ? SelectionManager.triggerClickedLeft :
SelectionManager.triggerClickedRight;
// When one hand is released check if the other hand is clicked and should then trigger a press
if (otherTriggerClicked) {
var otherHand = hand == Controller.Standard.RightHand ? Controller.Standard.LeftHand :
Controller.Standard.RightHand;
triggerPress(otherHand);
}
}
function handleTriggerPress(hand, triggerClicked) {
// Don't allow both hands to trigger at the same time
if (that.triggered() && hand !== that.triggeredHand) {
return;
}
if (!that.triggered() && triggerClicked) {
triggerPress(hand);
} else if (that.triggered() && !triggerClicked) {
triggerRelease(hand);
}
}
function makePressHandler(hand) {
return function (value) {
var triggerClicked = hand == Controller.Standard.RightHand ? SelectionManager.triggerClickedRight :
SelectionManager.triggerClickedLeft;
handleTriggerPress(hand, triggerClicked);
};
}
function makeClickHandler(hand) { function makeClickHandler(hand) {
return function (clicked) { return function (clicked) {
handleTriggerPress(hand, clicked); print("DBACK TEST makeClickHandler " + hand + " " + clicked);
// Don't allow both hands to trigger at the same time
if (that.triggered() && hand !== that.triggeredHand) {
return;
}
if (!that.triggered() && clicked) {
var pointingAtDesktopWindow = (hand === Controller.Standard.RightHand &&
SelectionManager.pointingAtDesktopWindowRight) ||
(hand === Controller.Standard.LeftHand &&
SelectionManager.pointingAtDesktopWindowLeft);
var pointingAtTablet = (hand === Controller.Standard.RightHand && SelectionManager.pointingAtTabletRight) ||
(hand === Controller.Standard.LeftHand && SelectionManager.pointingAtTabletLeft);
if (pointingAtDesktopWindow || pointingAtTablet) {
return;
}
that.triggeredHand = hand;
that.mousePressEvent({});
} else if (that.triggered() && !clicked) {
that.triggeredHand = NO_TRIGGER_HAND;
that.mouseReleaseEvent({});
}
}; };
} }
that.triggerPressMapping.from(Controller.Standard.RT).peek().to(makePressHandler(Controller.Standard.RightHand));
that.triggerPressMapping.from(Controller.Standard.LT).peek().to(makePressHandler(Controller.Standard.LeftHand));
that.triggerMapping.from(Controller.Standard.RTClick).peek().to(makeClickHandler(Controller.Standard.RightHand)); that.triggerMapping.from(Controller.Standard.RTClick).peek().to(makeClickHandler(Controller.Standard.RightHand));
that.triggerMapping.from(Controller.Standard.LTClick).peek().to(makeClickHandler(Controller.Standard.LeftHand)); that.triggerMapping.from(Controller.Standard.LTClick).peek().to(makeClickHandler(Controller.Standard.LeftHand));