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 showTablet READ getShouldShowTablet)
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:
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; }
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:
bool _showTablet { false };
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
glm::vec3 getPosition() const;

View file

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

View file

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

View file

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

View file

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