diff --git a/interface/resources/meshes/tablet-home-button.fbx b/interface/resources/meshes/tablet-home-button.fbx new file mode 100644 index 0000000000..df82d9122e Binary files /dev/null and b/interface/resources/meshes/tablet-home-button.fbx differ diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index 9e8e70af25..0b09278d16 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -30,6 +30,8 @@ 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) + public: Q_INVOKABLE glm::vec3 calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction) const; @@ -90,9 +92,15 @@ public: void setCurrentTabletUIID(QUuid tabletID) { _tabletUIID = tabletID; } QUuid getCurrentTableUIID() { return _tabletUIID; } + void setCurrentHomeButtonUUID(unsigned int homeButtonID) { _homeButtonID = homeButtonID; } + unsigned int getCurrentHomeButtonUUID() { return _homeButtonID; } + + 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; diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index 7cb52032e3..d874eb8db0 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -196,6 +196,7 @@ void TabletProxy::gotoHomeScreen() { auto loader = _qmlTabletRoot->findChild("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; } } diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 043e3df363..751ca05f3f 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -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.tabletID) { // 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" }; @@ -1867,7 +1886,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; diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 443c9fbf2e..7b321b0dd9 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -114,24 +114,25 @@ 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 + }); 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(); + } }; @@ -189,7 +190,7 @@ WebTablet.prototype.getOverlayObject = function () { WebTablet.prototype.destroy = function () { Overlays.deleteOverlay(this.webOverlayID); Entities.deleteEntity(this.tabletEntityID); - Entities.deleteEntity(this.homeButtonEntity); + Overlays.deleteEntity(this.homeButtonEntity); HMD.displayModeChanged.disconnect(this.myOnHmdChanged); if (HMD.active) { diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index 3fac3a1c05..f625b087d5 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -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; } }