Closer still

This commit is contained in:
Zach Fox 2017-07-26 14:10:41 -07:00
parent 65c28ca821
commit 3a05219c59
3 changed files with 68 additions and 34 deletions

View file

@ -89,8 +89,7 @@ bool ContextOverlayInterface::createOrDestroyContextOverlay(const EntityItemID&
entityPosition = entityPosition - (entityProperties.getRotation() * (adjustPos * entityProperties.getDimensions()));
}
qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'true' for Entity ID:" << entityItemID;
qApp->getEntities()->getTree()->findEntityByEntityItemID(entityItemID)->setShouldHighlight(true);
enableEntityHighlight(entityItemID);
AABox boundingBox = AABox(entityPosition - (entityDimensions / 2.0f), entityDimensions * 2.0f);
@ -99,8 +98,7 @@ bool ContextOverlayInterface::createOrDestroyContextOverlay(const EntityItemID&
if (!_currentEntityWithContextOverlay.isNull() && _currentEntityWithContextOverlay != entityItemID) {
qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'false' for Entity ID:" << _currentEntityWithContextOverlay;
qApp->getEntities()->getTree()->findEntityByEntityItemID(_currentEntityWithContextOverlay)->setShouldHighlight(false);
disableEntityHighlight(_currentEntityWithContextOverlay);
}
// Update the cached "Current Entity with Context Overlay" variable
@ -169,8 +167,7 @@ bool ContextOverlayInterface::destroyContextOverlay(const EntityItemID& entityIt
if (_contextOverlayID != UNKNOWN_OVERLAY_ID) {
qCDebug(context_overlay) << "Destroying Context Overlay on top of entity with ID: " << entityItemID;
if (!_currentEntityWithContextOverlay.isNull() && _currentEntityWithContextOverlay != entityItemID) {
qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'false' for Entity ID:" << _currentEntityWithContextOverlay;
qApp->getEntities()->getTree()->findEntityByEntityItemID(_currentEntityWithContextOverlay)->setShouldHighlight(false);
disableEntityHighlight(_currentEntityWithContextOverlay);
}
setCurrentEntityWithContextOverlay(QUuid());
_entityMarketplaceID.clear();
@ -218,15 +215,13 @@ void ContextOverlayInterface::contextOverlays_hoverLeaveOverlay(const OverlayID&
void ContextOverlayInterface::contextOverlays_hoverEnterEntity(const EntityItemID& entityID, const PointerEvent& event) {
if (contextOverlayFilterPassed(entityID)) {
qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'true' for Entity ID:" << entityID;
qApp->getEntities()->getTree()->findEntityByEntityItemID(entityID)->setShouldHighlight(true);
enableEntityHighlight(entityID);
}
}
void ContextOverlayInterface::contextOverlays_hoverLeaveEntity(const EntityItemID& entityID, const PointerEvent& event) {
if (_currentEntityWithContextOverlay != entityID) {
qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'false' for Entity ID:" << entityID;
qApp->getEntities()->getTree()->findEntityByEntityItemID(entityID)->setShouldHighlight(false);
disableEntityHighlight(entityID);
}
}
@ -245,3 +240,13 @@ void ContextOverlayInterface::openMarketplace() {
_isInMarketplaceInspectionMode = true;
}
}
void ContextOverlayInterface::enableEntityHighlight(const EntityItemID& entityItemID) {
qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'true' for Entity ID:" << entityItemID;
qApp->getEntities()->getTree()->findEntityByEntityItemID(entityItemID)->setShouldHighlight(true);
}
void ContextOverlayInterface::disableEntityHighlight(const EntityItemID& entityItemID) {
qCDebug(context_overlay) << "Setting 'shouldHighlight' to 'false' for Entity ID:" << entityItemID;
qApp->getEntities()->getTree()->findEntityByEntityItemID(entityItemID)->setShouldHighlight(false);
}

View file

@ -63,6 +63,7 @@ public slots:
void contextOverlays_hoverLeaveOverlay(const OverlayID& overlayID, const PointerEvent& event);
void contextOverlays_hoverEnterEntity(const EntityItemID& entityID, const PointerEvent& event);
void contextOverlays_hoverLeaveEntity(const EntityItemID& entityID, const PointerEvent& event);
bool contextOverlayFilterPassed(const EntityItemID& entityItemID);
private:
bool _verboseLogging { true };
@ -74,7 +75,8 @@ private:
void openMarketplace();
bool _isInMarketplaceInspectionMode { false };
bool contextOverlayFilterPassed(const EntityItemID& entityItemID);
void enableEntityHighlight(const EntityItemID& entityItemID);
void disableEntityHighlight(const EntityItemID& entityItemID);
};
#endif // hifi_ContextOverlayInterface_h

View file

@ -187,7 +187,8 @@ var DEFAULT_GRABBABLE_DATA = {
var USE_BLACKLIST = true;
var blacklist = [];
var potentialEntityWithContextOverlay = false;
var hoveredEntityID = false;
var contextOverlayTimer = false;
var entityWithContextOverlay = false;
var contextualHand = -1;
@ -2231,28 +2232,54 @@ function MyController(hand) {
entityPropertiesCache.addEntity(rayPickInfo.entityID);
}
if (rayPickInfo.entityID && !entityWithContextOverlay) {
Script.setTimeout(function () {
if (rayPickInfo.entityID === potentialEntityWithContextOverlay &&
!entityWithContextOverlay
&& contextualHand !== -1) {
var pointerEvent = {
type: "Move",
id: contextualHand + 1, // 0 is reserved for hardware mouse
pos2D: projectOntoEntityXYPlane(rayPickInfo.entityID, rayPickInfo.intersection),
pos3D: rayPickInfo.intersection,
normal: rayPickInfo.normal,
direction: rayPickInfo.searchRay.direction,
button: "Secondary"
};
if (ContextOverlay.createOrDestroyContextOverlay(rayPickInfo.entityID, pointerEvent)) {
entityWithContextOverlay = rayPickInfo.entityID;
potentialEntityWithContextOverlay = false;
}
if (rayPickInfo.entityID) {
if (hoveredEntityID !== rayPickInfo.entityID) {
pointerEvent = {
type: "Move",
id: this.hand + 1, // 0 is reserved for hardware mouse
pos2D: projectOntoEntityXYPlane(entity, rayPickInfo.intersection),
pos3D: rayPickInfo.intersection,
normal: rayPickInfo.normal,
direction: rayPickInfo.searchRay.direction,
button: "None"
};
if (hoveredEntityID) {
Entities.sendHoverLeaveEntity(hoveredEntityID, pointerEvent);
}
}, 500);
contextualHand = this.hand;
potentialEntityWithContextOverlay = rayPickInfo.entityID;
hoveredEntityID = rayPickInfo.entityID;
Entities.sendHoverEnterEntity(hoveredEntityID, pointerEvent);
}
if (contextOverlayTimer && rayPickInfo.entityID != hoveredEntityID) {
Script.clearTimeout(contextOverlayTimer);
}
// If we already have a context overlay, we don't want to move it to
// another entity while we're searching.
if (!entityWithContextOverlay) {
contextOverlayTimer = Script.setTimeout(function () {
if (rayPickInfo.entityID === hoveredEntityID &&
!entityWithContextOverlay
&& contextualHand !== -1) {
var pointerEvent = {
type: "Move",
id: contextualHand + 1, // 0 is reserved for hardware mouse
pos2D: projectOntoEntityXYPlane(rayPickInfo.entityID, rayPickInfo.intersection),
pos3D: rayPickInfo.intersection,
normal: rayPickInfo.normal,
direction: rayPickInfo.searchRay.direction,
button: "Secondary"
};
if (ContextOverlay.createOrDestroyContextOverlay(rayPickInfo.entityID, pointerEvent)) {
entityWithContextOverlay = rayPickInfo.entityID;
hoveredEntityID = false;
}
}
contextOverlayTimer = false;
}, 500);
contextualHand = this.hand;
}
}
var candidateHotSpotEntities = Entities.findEntities(handPosition, MAX_EQUIP_HOTSPOT_RADIUS);
@ -3503,7 +3530,7 @@ function MyController(hand) {
if (entityWithContextOverlay) {
ContextOverlay.destroyContextOverlay(entityWithContextOverlay);
entityWithContextOverlay = false;
potentialEntityWithContextOverlay = false;
hoveredEntityID = false;
}
if (isInEditMode()) {