From 1b7c89c41d9455a6fbddeb54381e8e63f3b6e013 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 12 Dec 2016 22:08:58 +0000 Subject: [PATCH 1/6] 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, ""); From 737f11fb7ab49cd7696b92c0d8d1918c60023223 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 12 Dec 2016 23:03:38 +0000 Subject: [PATCH 2/6] merge fix --- scripts/system/libraries/WebTablet.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 26bd295975..5f0891d642 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -39,7 +39,7 @@ function calcSpawnInfo() { } // ctor -WebTablet = function (url, width, dpi, clientOnly) { +WebTablet = function (url, width, dpi, location, clientOnly) { var _this = this; var ASPECT = 4.0 / 3.0; var WIDTH = width || DEFAULT_WIDTH; @@ -99,11 +99,10 @@ WebTablet = function (url, width, dpi, 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, + localPosition: {x: 0, y: HOME_BUTTON_Y_OFFSET, z: 0}, dimensions: {x: 0.05, y: 0.05, z: 0.05}, parentID: this.tabletEntityID, script: "https://people.ucsc.edu/~druiz4/scripts/homeButton.js" From ccecce77de1ba7a96fbed2da5fa573af3860487f Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 12 Dec 2016 23:21:14 +0000 Subject: [PATCH 3/6] removed unneeded whitespace --- scripts/system/libraries/WebTablet.js | 6 ++---- scripts/system/marketplaces/marketplace.js | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 5f0891d642..115a7ed262 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -15,7 +15,7 @@ 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,7 +39,7 @@ function calcSpawnInfo() { } // ctor -WebTablet = function (url, width, dpi, location, clientOnly) { +WebTablet = function (url, width, dpi, location, clientOnly) { var _this = this; var ASPECT = 4.0 / 3.0; var WIDTH = width || DEFAULT_WIDTH; @@ -71,8 +71,6 @@ 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; diff --git a/scripts/system/marketplaces/marketplace.js b/scripts/system/marketplaces/marketplace.js index 67d335c4c3..04e59697d1 100644 --- a/scripts/system/marketplaces/marketplace.js +++ b/scripts/system/marketplaces/marketplace.js @@ -30,7 +30,6 @@ 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"; From 92993202a447ba1336f7624d0957eb49b3533e36 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 12 Dec 2016 23:24:56 +0000 Subject: [PATCH 4/6] removed double variable definition --- scripts/system/libraries/WebTablet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 115a7ed262..dd1365500b 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -40,13 +40,13 @@ function calcSpawnInfo() { // ctor WebTablet = function (url, width, dpi, location, clientOnly) { + var _this = this; var ASPECT = 4.0 / 3.0; var WIDTH = width || DEFAULT_WIDTH; var HEIGHT = WIDTH * ASPECT; var DEPTH = 0.025; var DPI = dpi || DEFAULT_DPI; - var _this = this; var tabletProperties = { name: "WebTablet Tablet", From 6a8465a6cab79c469db07adba02f61ca8d7e7d98 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 12 Dec 2016 23:26:06 +0000 Subject: [PATCH 5/6] removed more whitespace --- scripts/system/libraries/WebTablet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index dd1365500b..a8f1154617 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -15,7 +15,7 @@ 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. From cc0e25720eb9dad03df4773081076b889c3eb6d1 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Mon, 12 Dec 2016 23:29:11 +0000 Subject: [PATCH 6/6] mimimize the git diffs --- scripts/system/libraries/WebTablet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index a8f1154617..6607b044ff 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"; + // returns object with two fields: // * position - position in front of the user // * rotation - rotation of entity so it faces the user.