From 1b7c89c41d9455a6fbddeb54381e8e63f3b6e013 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 12 Dec 2016 22:08:58 +0000 Subject: [PATCH] home button working --- scripts/system/libraries/WebTablet.js | 45 ++++++++++++++++++++-- scripts/system/marketplaces/marketplace.js | 3 ++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 703ed40c95..26bd295975 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -14,8 +14,8 @@ var Y_AXIS = {x: 0, y: 1, z: 0}; var DEFAULT_DPI = 32; var DEFAULT_WIDTH = 0.5; -var TABLET_URL = "https://s3.amazonaws.com/hifi-public/tony/tablet.fbx"; +var TABLET_URL = "https://s3.amazonaws.com/hifi-public/tony/tablet.fbx" // returns object with two fields: // * position - position in front of the user // * rotation - rotation of entity so it faces the user. @@ -39,8 +39,8 @@ function calcSpawnInfo() { } // ctor -WebTablet = function (url, width, dpi, location, clientOnly) { - +WebTablet = function (url, width, dpi, clientOnly) { + var _this = this; var ASPECT = 4.0 / 3.0; var WIDTH = width || DEFAULT_WIDTH; var HEIGHT = WIDTH * ASPECT; @@ -71,8 +71,11 @@ WebTablet = function (url, width, dpi, location, clientOnly) { this.tabletEntityID = Entities.addEntity(tabletProperties, clientOnly); + + var WEB_ENTITY_REDUCTION_FACTOR = {x: 0.78, y: 0.85}; var WEB_ENTITY_Z_OFFSET = -0.01; + var HOME_BUTTON_Y_OFFSET = -0.32; this.createWebEntity = function(url) { if (_this.webEntityID) { @@ -96,6 +99,28 @@ WebTablet = function (url, width, dpi, location, clientOnly) { this.createWebEntity(url); + var homeButtonPosition = Vec3.sum(spawnInfo.position, Vec3.multiply(HOME_BUTTON_Y_OFFSET, Quat.getUp(webEntityRotation))); + this.homeButtonEntity = Entities.addEntity({ + name: "homeButton", + type: "Sphere", + position: homeButtonPosition, + dimensions: {x: 0.05, y: 0.05, z: 0.05}, + parentID: this.tabletEntityID, + script: "https://people.ucsc.edu/~druiz4/scripts/homeButton.js" + }, clientOnly); + + this.receive = function (channel, senderID, senderUUID, localOnly) { + if (_this.homeButtonEntity == senderID) { + if (_this.clicked) { + Entities.editEntity(_this.homeButtonEntity, {color: {red: 0, green: 255, blue: 255}}); + _this.clicked = false; + } else { + Entities.editEntity(_this.homeButtonEntity, {color: {red: 255, green: 255, blue: 0}}); + _this.clicked = true; + } + } + } + this.state = "idle"; this.getRoot = function() { @@ -105,15 +130,29 @@ WebTablet = function (url, width, dpi, location, clientOnly) { this.getLocation = function() { return Entities.getEntityProperties(_this.tabletEntityID, ["localPosition", "localRotation"]); }; + this.clicked = false; }; WebTablet.prototype.destroy = function () { Entities.deleteEntity(this.webEntityID); Entities.deleteEntity(this.tabletEntityID); + Entities.deleteEntity(this.homeButtonEntity); }; WebTablet.prototype.pickle = function () { return JSON.stringify({webEntityID: this.webEntityID, tabletEntityID: this.tabletEntityID}); }; + + +WebTablet.prototype.register = function() { + Messages.subscribe("home"); + Messages.messageReceived.connect(this.receive); +} + +WebTablet.prototype.unregister = function() { + Messages.unsubscribe("home"); + Messages.messageReceived.disconnect(this.receive); +} + WebTablet.unpickle = function (string) { if (!string) { return; diff --git a/scripts/system/marketplaces/marketplace.js b/scripts/system/marketplaces/marketplace.js index c5e9eaccc7..67d335c4c3 100644 --- a/scripts/system/marketplaces/marketplace.js +++ b/scripts/system/marketplaces/marketplace.js @@ -30,6 +30,7 @@ var TOOLBAR_MARGIN_Y = 0; var marketplaceVisible = false; var marketplaceWebTablet; + // We persist clientOnly data in the .ini file, and reconsistitute it on restart. // To keep things consistent, we pickle the tablet data in Settings, and kill any existing such on restart and domain change. var persistenceKey = "io.highfidelity.lastDomainTablet"; @@ -54,6 +55,7 @@ function showMarketplace(marketplaceID) { null, // dpi null, // location true); // client-only + marketplaceWebTablet.register(); } Settings.setValue(persistenceKey, marketplaceWebTablet.pickle()); } else { @@ -74,6 +76,7 @@ function hideTablet(tablet) { return; } updateButtonState(false); + tablet.unregister(); tablet.destroy(); marketplaceWebTablet = null; Settings.setValue(persistenceKey, "");