diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 8a0831a3cd..1acc12b3f1 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -45,6 +45,10 @@ function calcSpawnInfo(hand, height) { var headPos = (HMD.active && Camera.mode === "first person") ? HMD.position : Camera.position; var headRot = (HMD.active && Camera.mode === "first person") ? HMD.orientation : Camera.orientation; + if (!hand) { + hand = NO_HANDS; + } + if (HMD.active && hand !== NO_HANDS) { var handController = getControllerWorldLocation(hand, true); var controllerPosition = handController.position; @@ -96,7 +100,7 @@ function calcSpawnInfo(hand, height) { * @param hand [number] -1 indicates no hand, Controller.Standard.RightHand or Controller.Standard.LeftHand * @param clientOnly [bool] true indicates tablet model is only visible to client. */ -WebTablet = function (url, width, dpi, hand, clientOnly) { +WebTablet = function (url, width, dpi, hand, clientOnly, location, invisisble) { var _this = this; @@ -129,11 +133,16 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { "grabbableKey": {"grabbable": true} }), dimensions: {x: this.width, y: this.height, z: this.depth}, - parentID: AVATAR_SELF_ID + parentID: AVATAR_SELF_ID, + visible: !invisisble }; // compute position, rotation & parentJointIndex of the tablet this.calculateTabletAttachmentProperties(hand, true, tabletProperties); + if (location) { + tabletProperties.localPosition = location.localPosition; + tabletProperties.localRotation = location.localRotation; + } this.cleanUpOldTablets(); @@ -164,7 +173,8 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { parentID: this.tabletEntityID, parentJointIndex: -1, showKeyboardFocusHighlight: false, - isAA: HMD.active + isAA: HMD.active, + visible: !invisisble }); var HOME_BUTTON_Y_OFFSET = (this.height / 2) - 0.009; @@ -177,7 +187,8 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { visible: true, drawInFront: false, parentID: this.tabletEntityID, - parentJointIndex: -1 + parentJointIndex: -1, + visible: !invisisble }); this.receive = function (channel, senderID, senderUUID, localOnly) { diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index d5065cb826..14eb7e7ecc 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -12,21 +12,22 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -/* global Script, HMD, WebTablet, UIWebTablet, UserActivityLogger, Settings, Entities, Messages, Tablet, Overlays, MyAvatar */ +/* global Script, HMD, WebTablet, UIWebTablet, UserActivityLogger, Settings, Entities, Messages, Tablet, Overlays, + MyAvatar, Menu, Vec3 */ (function() { // BEGIN LOCAL_SCOPE var tabletShown = false; + var tabletRezzed = false; var tabletLocation = null; var activeHand = null; + var DEFAULT_WIDTH = 0.4375; + var DEFAULT_TABLET_SCALE = 100; + UIWebTablet = null; Script.include("../libraries/WebTablet.js"); - function showTabletUI() { - tabletShown = true; - print("show tablet-ui"); - - var DEFAULT_WIDTH = 0.4375; - var DEFAULT_TABLET_SCALE = 100; + function rezTablet(invisible) { + print("XXX show tablet-ui, not rezzed. position is " + JSON.stringify(tabletLocation)); var toolbarMode = Tablet.getTablet("com.highfidelity.interface.tablet.system").toolbarMode; var TABLET_SCALE = DEFAULT_TABLET_SCALE; if (toolbarMode) { @@ -34,37 +35,88 @@ } else { TABLET_SCALE = Settings.getValue("hmdTabletScale") || DEFAULT_TABLET_SCALE; } - UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml", DEFAULT_WIDTH * (TABLET_SCALE / 100), null, activeHand, true); + + UIWebTablet = new WebTablet("qml/hifi/tablet/TabletRoot.qml", + DEFAULT_WIDTH * (TABLET_SCALE / 100), + null, activeHand, true, tabletLocation, invisible); UIWebTablet.register(); HMD.tabletID = UIWebTablet.tabletEntityID; HMD.homeButtonID = UIWebTablet.homeButtonID; HMD.tabletScreenID = UIWebTablet.webOverlayID; + tabletRezzed = true; + } + + function showTabletUI() { + tabletShown = true; + + if (!tabletRezzed) { + rezTablet(false); + } + + if (UIWebTablet && tabletRezzed) { + if (tabletLocation) { + print("XXX show tablet-ui, already rezzed, already position: " + JSON.stringify(tabletLocation)); + Overlays.editOverlay(HMD.tabletID, { + localPosition: tabletLocation.localPosition, + localRotation: tabletLocation.localRotation, + visible: true + }); + } else { + print("XXX show tablet-ui, already rezzed, no position"); + var tabletProperties = {}; + UIWebTablet.calculateTabletAttachmentProperties(activeHand, true, tabletProperties); + tabletProperties.visible = true; + Overlays.editOverlay(HMD.tabletID, tabletProperties); + } + Overlays.editOverlay(HMD.homeButtonID, { visible: true }); + Overlays.editOverlay(HMD.tabletScreenID, { visible: true }); + } } function hideTabletUI() { tabletShown = false; - print("hide tablet-ui"); + if (UIWebTablet) { + tabletLocation = UIWebTablet.getLocation(); + print("XXX hide tablet-ui, position was " + JSON.stringify(tabletLocation)); + // Overlays.editOverlay(HMD.tabletID, { localPosition: { x: -1000, y: 0, z:0 } }); + Overlays.editOverlay(HMD.tabletID, { visible: false }); + Overlays.editOverlay(HMD.homeButtonID, { visible: false }); + Overlays.editOverlay(HMD.tabletScreenID, { visible: false }); + } else { + print("XXX hide tablet-ui, UIWebTablet is null"); + } + } + + function closeTabletUI() { + tabletShown = false; if (UIWebTablet) { if (UIWebTablet.onClose) { UIWebTablet.onClose(); } tabletLocation = UIWebTablet.getLocation(); + print("XXX close tablet-ui, position was " + JSON.stringify(tabletLocation)); UIWebTablet.unregister(); UIWebTablet.destroy(); UIWebTablet = null; HMD.tabletID = null; HMD.homeButtonID = null; HMD.tabletScreenID = null; + } else { + print("XXX close tablet-ui, UIWebTablet is null"); } + tabletRezzed = false; } + function updateShowTablet() { // close the WebTablet if it we go into toolbar mode. var toolbarMode = Tablet.getTablet("com.highfidelity.interface.tablet.system").toolbarMode; + var visibleToOthers = Settings.getValue("tabletVisibleToOthers"); + if (tabletShown && toolbarMode) { - hideTabletUI(); + closeTabletUI(); HMD.closeTablet(); return; } @@ -78,18 +130,37 @@ tablet.updateAudioBar(currentMicLevel); } - if (tabletShown && UIWebTablet && Overlays.getOverlayType(UIWebTablet.webOverlayID) != "web3d") { + // XXX don't do this check every time? + if (tabletRezzed && UIWebTablet && Overlays.getOverlayType(UIWebTablet.webOverlayID) != "web3d") { // when we switch domains, the tablet entity gets destroyed and recreated. this causes // the overlay to be deleted, but not recreated. If the overlay is deleted for this or any // other reason, close the tablet. - hideTabletUI(); + closeTabletUI(); HMD.closeTablet(); - } else if (HMD.showTablet && !tabletShown && !toolbarMode) { - UserActivityLogger.openedTablet(Settings.getValue("tabletVisibleToOthers")); + print("XXX autodestroying tablet"); + } + + + if (HMD.showTablet && !tabletShown && !toolbarMode) { + UserActivityLogger.openedTablet(visibleToOthers); showTabletUI(); } else if (!HMD.showTablet && tabletShown) { UserActivityLogger.closedTablet(); - hideTabletUI(); + if (visibleToOthers) { + closeTabletUI(); + } else { + hideTabletUI(); + } + } else if (!toolbarMode && !visibleToOthers && !tabletRezzed) { + // pre-make the tablet so it will appear quickly + tabletLocation = { + localPosition: Vec3.sum(MyAvatar.position, { x: -1000, y: 0, z: 0 }), + localRotation: { x: 0, y: 0, z: 0, w: 1 } + }; + print("XXX pre-creating tablet at " + JSON.stringify(tabletLocation)); + rezTablet(true); + tabletLocation = null; + tabletShown = false; } }