comparing with ID instead of strings

This commit is contained in:
Dante Ruiz 2017-01-20 00:32:15 +00:00
parent fc8b09d2b3
commit 1e7e4576cc
6 changed files with 58 additions and 23 deletions

Binary file not shown.

View file

@ -30,6 +30,9 @@ class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Depen
Q_PROPERTY(bool mounted READ isMounted) Q_PROPERTY(bool mounted READ isMounted)
Q_PROPERTY(bool showTablet READ getShouldShowTablet) Q_PROPERTY(bool showTablet READ getShouldShowTablet)
Q_PROPERTY(QUuid tabletID READ getCurrentTableUIID WRITE setCurrentTabletUIID) Q_PROPERTY(QUuid tabletID READ getCurrentTableUIID WRITE setCurrentTabletUIID)
Q_PROPERTY(unsigned int homeButtonID READ getCurrentHomeButtonUUID WRITE setCurrentHomeButtonUUID)
Q_PROPERTY(QUuid tabletEntityID READ getCurrentTabletEntityID WRITE setCurrentTabletEntityID)
public: public:
Q_INVOKABLE glm::vec3 calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction) const; Q_INVOKABLE glm::vec3 calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction) const;
@ -90,9 +93,17 @@ public:
void setCurrentTabletUIID(QUuid tabletID) { _tabletUIID = tabletID; } void setCurrentTabletUIID(QUuid tabletID) { _tabletUIID = tabletID; }
QUuid getCurrentTableUIID() { return _tabletUIID; } QUuid getCurrentTableUIID() { return _tabletUIID; }
void setCurrentHomeButtonUUID(unsigned int homeButtonID) { _homeButtonID = homeButtonID; }
unsigned int getCurrentHomeButtonUUID() { return _homeButtonID; }
void setCurrentTabletEntityID(QUuid tabletEntityID) {_tabletEntityID = tabletEntityID; }
QUuid getCurrentTabletEntityID() { return _tabletEntityID; }
private: private:
bool _showTablet { false }; bool _showTablet { false };
QUuid _tabletUIID; // this is the entityID of the WebEntity which is part of (a child of) the tablet-ui. QUuid _tabletUIID; // this is the entityID of the WebEntity which is part of (a child of) the tablet-ui.
unsigned int _homeButtonID;
QUuid _tabletEntityID;
// Get the position of the HMD // Get the position of the HMD
glm::vec3 getPosition() const; glm::vec3 getPosition() const;

View file

@ -196,6 +196,7 @@ void TabletProxy::gotoHomeScreen() {
auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader"); auto loader = _qmlTabletRoot->findChild<QQuickItem*>("loader");
QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen())); QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToHomeScreen()));
QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL))); QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(TABLET_SOURCE_URL)));
QMetaObject::invokeMethod(_qmlTabletRoot, "playButtonClickSound");
_state = State::Home; _state = State::Home;
} }
} }

View file

@ -1169,7 +1169,7 @@ function MyController(hand) {
var nearWeb = false; var nearWeb = false;
for (var i = 0; i < candidateEntities.length; i++) { for (var i = 0; i < candidateEntities.length; i++) {
var props = entityPropertiesCache.getProps(candidateEntities[i]); var props = entityPropertiesCache.getProps(candidateEntities[i]);
if (props && (props.type == "Web" || this.isTablet(props))) { if (props && (props.type == "Web" || this.isTablet(candidateEntities[i]))) {
nearWeb = true; nearWeb = true;
break; break;
} }
@ -1243,14 +1243,32 @@ function MyController(hand) {
}; };
this.handleStylusOnHomeButton = function(rayPickInfo) { this.handleStylusOnHomeButton = function(rayPickInfo) {
if (rayPickInfo.entityID) { if (rayPickInfo.overlayID) {
var entity = rayPickInfo.entityID; var homeButton = rayPickInfo.overlayID;
var name = entityPropertiesCache.getProps(entity).name; var hmdHomeButton = HMD.homeButtonID;
if (name == "homeButton") { if (homeButton === hmdHomeButton) {
if (this.homeButtonTouched == false) { if (this.homeButtonTouched == false) {
this.homeButtonTouched = true; this.homeButtonTouched = true;
Controller.triggerHapticPulse(1, 20, this.hand); Controller.triggerHapticPulse(1, 20, this.hand);
Messages.sendLocalMessage("home", entity); Messages.sendLocalMessage("home", homeButton);
}
} else {
this.homeButtonTouched = false;
}
} else {
this.homeButtonTouched = false;
}
};
this.handleLaserOnHomeButton = function(rayPickInfo) {
if (rayPickInfo.overlayID && this.triggerSmoothedGrab()) {
var homeButton = rayPickInfo.overlayID;
var hmdHomeButton = HMD.homeButtonID;
if (homeButton === hmdHomeButton) {
if (this.homeButtonTouched == false) {
this.homeButtonTouched = true;
Controller.triggerHapticPulse(1, 20, this.hand);
Messages.sendLocalMessage("home", homeButton);
} }
} else { } else {
this.homeButtonTouched = false; this.homeButtonTouched = false;
@ -1636,6 +1654,7 @@ function MyController(hand) {
} }
if (rayPickInfo.distance >= WEB_STYLUS_LENGTH / 2.0 + WEB_TOUCH_Y_OFFSET) { if (rayPickInfo.distance >= WEB_STYLUS_LENGTH / 2.0 + WEB_TOUCH_Y_OFFSET) {
this.handleLaserOnHomeButton(rayPickInfo);
if (this.handleLaserOnWebEntity(rayPickInfo)) { if (this.handleLaserOnWebEntity(rayPickInfo)) {
return; return;
} }
@ -1680,8 +1699,8 @@ function MyController(hand) {
Reticle.setVisible(false); Reticle.setVisible(false);
}; };
this.isTablet = function (props) { this.isTablet = function (entityID) {
if (props.name == "WebTablet Tablet") { // XXX what's a better way to know this? if (entityID === HMD.tabletEntityID) { // XXX what's a better way to know this?
return true; return true;
} }
return false; return false;
@ -1703,7 +1722,7 @@ function MyController(hand) {
id: this.hand + 1, // 0 is reserved for hardware mouse id: this.hand + 1, // 0 is reserved for hardware mouse
pos2D: projectOntoEntityXYPlane(entity, rayPickInfo.intersection), pos2D: projectOntoEntityXYPlane(entity, rayPickInfo.intersection),
pos3D: rayPickInfo.intersection, pos3D: rayPickInfo.intersection,
normal: rayPickInfo.normal, normal: rayPickInfo.normal,
direction: rayPickInfo.searchRay.direction, direction: rayPickInfo.searchRay.direction,
button: "None" button: "None"
}; };
@ -1865,7 +1884,7 @@ function MyController(hand) {
Entities.sendHoverOverEntity(entity, pointerEvent); Entities.sendHoverOverEntity(entity, pointerEvent);
} }
if (this.triggerSmoothedGrab() && (!isEditing() || this.isTablet(props))) { if (this.triggerSmoothedGrab() && (!isEditing() || this.isTablet(entity))) {
this.grabbedEntity = entity; this.grabbedEntity = entity;
this.setState(STATE_ENTITY_LASER_TOUCHING, "begin touching entity '" + name + "'"); this.setState(STATE_ENTITY_LASER_TOUCHING, "begin touching entity '" + name + "'");
return true; return true;

View file

@ -112,24 +112,26 @@ WebTablet = function (url, width, dpi, hand, clientOnly) {
showKeyboardFocusHighlight: false showKeyboardFocusHighlight: false
}); });
var HOME_BUTTON_Y_OFFSET = -0.25; var HOME_BUTTON_Y_OFFSET = -0.26;
this.homeButtonEntity = Entities.addEntity({ this.homeButtonEntity = Overlays.addOverlay("model", {
name: "homeButton", name: "homeButton",
type: "Model", url: Script.resourcesPath() + "meshes/tablet-home-button.fbx",
modelURL: HOME_BUTTON_URL, localPosition: {x: 0.0, y: HOME_BUTTON_Y_OFFSET, z: -0.01},
dimensions: { x: 0.04, y: 0.04, z: 0.02 }, localRotation: Quat.angleAxis(0, Y_AXIS),
collisionless: true, solid: true,
localPosition: {x: 0, y: HOME_BUTTON_Y_OFFSET, z: -0.01}, visible: true,
dimensions: { x: 0.04, y: 0.04, z: 0.02},
drawInFront: false,
parentID: this.tabletEntityID, parentID: this.tabletEntityID,
script: Script.resolvePath("../tablet-ui/HomeButton.js") parentJointIndex: -1
}, clientOnly); });
//setEntityCustomData('grabbableKey', this.homeButtonEntity, {wantsTrigger: true});
setEntityCustomData('grabbableKey', this.homeButtonEntity, {wantsTrigger: true});
this.receive = function (channel, senderID, senderUUID, localOnly) { this.receive = function (channel, senderID, senderUUID, localOnly) {
if (_this.homeButtonEntity === senderID) { if (_this.homeButtonEntity === parseInt(senderID)) {
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
tablet.gotoHomeScreen(); tablet.gotoHomeScreen();
} }
}; };
@ -165,7 +167,7 @@ WebTablet.prototype.getOverlayObject = function () {
WebTablet.prototype.destroy = function () { WebTablet.prototype.destroy = function () {
Overlays.deleteOverlay(this.webOverlayID); Overlays.deleteOverlay(this.webOverlayID);
Entities.deleteEntity(this.tabletEntityID); Entities.deleteEntity(this.tabletEntityID);
Entities.deleteEntity(this.homeButtonEntity); //Entities.deleteEntity(this.homeButtonEntity);
HMD.displayModeChanged.disconnect(this.myOnHmdChanged); HMD.displayModeChanged.disconnect(this.myOnHmdChanged);
}; };

View file

@ -27,6 +27,7 @@
UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml", null, null, activeHand, true); UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml", null, null, activeHand, true);
UIWebTablet.register(); UIWebTablet.register();
HMD.tabletID = UIWebTablet.tabletEntityID; HMD.tabletID = UIWebTablet.tabletEntityID;
HMD.homeButtonID = UIWebTablet.homeButtonEntity;
} }
function hideTabletUI() { function hideTabletUI() {
@ -42,6 +43,7 @@
UIWebTablet.destroy(); UIWebTablet.destroy();
UIWebTablet = null; UIWebTablet = null;
HMD.tabletID = null; HMD.tabletID = null;
HMD.homeButtonID = null;
} }
} }