Removed use of Toolbar API for most default scripts.

This commit is contained in:
Anthony J. Thibault 2017-02-16 17:29:35 -08:00
parent 0b9f4d4f11
commit 345f0519ef
7 changed files with 147 additions and 361 deletions

View file

@ -9,49 +9,30 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
(function() { // BEGIN LOCAL_SCOPE (function() { // BEGIN LOCAL_SCOPE
var button;
var TOOLBAR_BUTTON_NAME = "MUTE";
var TABLET_BUTTON_NAME = "AUDIO"; var TABLET_BUTTON_NAME = "AUDIO";
var toolBar = null;
var tablet = null;
var isHUDUIEnabled = Settings.getValue("HUDUIEnabled");
var HOME_BUTTON_TEXTURE = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png"; var HOME_BUTTON_TEXTURE = "http://hifi-content.s3.amazonaws.com/alan/dev/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png";
function onMuteToggled() { function onMuteToggled() {
if (isHUDUIEnabled) { button.editProperties({ isActive: AudioDevice.getMuted() });
button.editProperties({ isActive: AudioDevice.getMuted() });
}
} }
function onClicked(){ function onClicked(){
if (isHUDUIEnabled) { var entity = HMD.tabletID;
var menuItem = "Mute Microphone"; Entities.editEntity(entity, { textures: JSON.stringify({ "tex.close": HOME_BUTTON_TEXTURE }) });
Menu.setIsOptionChecked(menuItem, !Menu.isOptionChecked(menuItem)); tablet.gotoMenuScreen("Audio");
} else {
var entity = HMD.tabletID;
Entities.editEntity(entity, { textures: JSON.stringify({ "tex.close": HOME_BUTTON_TEXTURE }) });
tablet.gotoMenuScreen("Audio");
}
} }
if (Settings.getValue("HUDUIEnabled")) { var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); var button = tablet.addButton({
button = toolBar.addButton({ icon: "icons/tablet-icons/mic-unmute-i.svg",
objectName: TOOLBAR_BUTTON_NAME, activeIcon: "icons/tablet-icons/mic-mute-a.svg",
imageURL: Script.resolvePath("assets/images/tools/mic.svg"), text: TABLET_BUTTON_NAME,
visible: true, sortOrder: 1
alpha: 0.9 });
});
} else {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
icon: "icons/tablet-icons/mic-i.svg",
text: TABLET_BUTTON_NAME,
sortOrder: 1
});
}
onMuteToggled(); onMuteToggled();
button.clicked.connect(onClicked); button.clicked.connect(onClicked);
@ -60,12 +41,7 @@ AudioDevice.muteToggled.connect(onMuteToggled);
Script.scriptEnding.connect(function () { Script.scriptEnding.connect(function () {
button.clicked.disconnect(onClicked); button.clicked.disconnect(onClicked);
AudioDevice.muteToggled.disconnect(onMuteToggled); AudioDevice.muteToggled.disconnect(onMuteToggled);
if (tablet) { tablet.removeButton(button);
tablet.removeButton(button);
}
if (toolBar) {
toolBar.removeButton(TOOLBAR_BUTTON_NAME);
}
}); });
}()); // END LOCAL_SCOPE }()); // END LOCAL_SCOPE

View file

@ -10,11 +10,9 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
/* global Toolbars, Script, Users, Overlays, AvatarList, Controller, Camera, getControllerWorldLocation */ /* global Script, Users, Overlays, AvatarList, Controller, Camera, getControllerWorldLocation */
(function () { // BEGIN LOCAL_SCOPE (function () { // BEGIN LOCAL_SCOPE
var button; var button;
// Used for animating and disappearing the bubble // Used for animating and disappearing the bubble
var bubbleOverlayTimestamp; var bubbleOverlayTimestamp;
@ -23,7 +21,7 @@
// Used for flashing the HUD button upon activation // Used for flashing the HUD button upon activation
var bubbleButtonTimestamp; var bubbleButtonTimestamp;
// Affects bubble height // Affects bubble height
const BUBBLE_HEIGHT_SCALE = 0.15; var BUBBLE_HEIGHT_SCALE = 0.15;
// The bubble model itself // The bubble model itself
var bubbleOverlay = Overlays.addOverlay("model", { var bubbleOverlay = Overlays.addOverlay("model", {
url: Script.resolvePath("assets/models/Bubble-v14.fbx"), // If you'd like to change the model, modify this line (and the dimensions below) url: Script.resolvePath("assets/models/Bubble-v14.fbx"), // If you'd like to change the model, modify this line (and the dimensions below)
@ -39,16 +37,8 @@
// Is the update() function connected? // Is the update() function connected?
var updateConnected = false; var updateConnected = false;
const BUBBLE_VISIBLE_DURATION_MS = 3000; var BUBBLE_VISIBLE_DURATION_MS = 3000;
const BUBBLE_RAISE_ANIMATION_DURATION_MS = 750; var BUBBLE_RAISE_ANIMATION_DURATION_MS = 750;
const BUBBLE_HUD_ICON_FLASH_INTERVAL_MS = 500;
var ASSETS_PATH = Script.resolvePath("assets");
var TOOLS_PATH = Script.resolvePath("assets/images/tools/");
function buttonImageURL() {
return TOOLS_PATH + 'bubble.svg';
}
// Hides the bubble model overlay and resets the button flash state // Hides the bubble model overlay and resets the button flash state
function hideOverlays() { function hideOverlays() {
@ -94,7 +84,7 @@
} }
// The bubble script's update function // The bubble script's update function
update = function () { function update() {
var timestamp = Date.now(); var timestamp = Date.now();
var delay = (timestamp - bubbleOverlayTimestamp); var delay = (timestamp - bubbleOverlayTimestamp);
var overlayAlpha = 1.0 - (delay / BUBBLE_VISIBLE_DURATION_MS); var overlayAlpha = 1.0 - (delay / BUBBLE_VISIBLE_DURATION_MS);
@ -146,7 +136,7 @@
var bubbleActive = Users.getIgnoreRadiusEnabled(); var bubbleActive = Users.getIgnoreRadiusEnabled();
writeButtonProperties(bubbleActive); writeButtonProperties(bubbleActive);
} }
}; }
// When the space bubble is toggled... // When the space bubble is toggled...
function onBubbleToggled() { function onBubbleToggled() {
@ -165,38 +155,26 @@
// Setup the bubble button // Setup the bubble button
var buttonName = "BUBBLE"; var buttonName = "BUBBLE";
if (Settings.getValue("HUDUIEnabled")) { var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var toolbar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); button = tablet.addButton({
button = toolbar.addButton({ icon: "icons/tablet-icons/bubble-i.svg",
objectName: 'bubble', activeIcon: "icons/tablet-icons/bubble-a.svg",
imageURL: buttonImageURL(), text: buttonName,
visible: true, sortOrder: 4
alpha: 0.9 });
});
} else {
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
icon: "icons/tablet-icons/bubble-i.svg",
activeIcon: "icons/tablet-icons/bubble-a.svg",
text: buttonName,
sortOrder: 4
});
}
onBubbleToggled(); onBubbleToggled();
button.clicked.connect(Users.toggleIgnoreRadius); button.clicked.connect(Users.toggleIgnoreRadius);
Users.ignoreRadiusEnabledChanged.connect(onBubbleToggled); Users.ignoreRadiusEnabledChanged.connect(onBubbleToggled);
Users.enteredIgnoreRadius.connect(enteredIgnoreRadius); Users.enteredIgnoreRadius.connect(enteredIgnoreRadius);
// Cleanup the toolbar button and overlays when script is stopped // Cleanup the tablet button and overlays when script is stopped
Script.scriptEnding.connect(function () { Script.scriptEnding.connect(function () {
button.clicked.disconnect(Users.toggleIgnoreRadius); button.clicked.disconnect(Users.toggleIgnoreRadius);
if (tablet) { if (tablet) {
tablet.removeButton(button); tablet.removeButton(button);
} }
if (toolbar) {
toolbar.removeButton('bubble');
}
Users.ignoreRadiusEnabledChanged.disconnect(onBubbleToggled); Users.ignoreRadiusEnabledChanged.disconnect(onBubbleToggled);
Users.enteredIgnoreRadius.disconnect(enteredIgnoreRadius); Users.enteredIgnoreRadius.disconnect(enteredIgnoreRadius);
Overlays.deleteOverlay(bubbleOverlay); Overlays.deleteOverlay(bubbleOverlay);

View file

@ -10,48 +10,21 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
/* globals Tablet, Toolbars, Script, HMD, Controller, Menu */ /* globals Tablet, Script, HMD, Controller, Menu */
(function() { // BEGIN LOCAL_SCOPE (function() { // BEGIN LOCAL_SCOPE
var button;
var buttonName = "HELP"; var buttonName = "HELP";
var toolBar = null; var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var tablet = null; var button = tablet.addButton({
if (Settings.getValue("HUDUIEnabled")) { icon: "icons/tablet-icons/help-i.svg",
toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); activeIcon: "icons/tablet-icons/help-a.svg",
button = toolBar.addButton({ text: buttonName,
objectName: buttonName, sortOrder: 6
imageURL: Script.resolvePath("assets/images/tools/help.svg"), });
visible: true,
alpha: 0.9
});
} else {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
icon: "icons/tablet-icons/help-i.svg",
activeIcon: "icons/tablet-icons/help-a.svg",
text: buttonName,
sortOrder: 6
});
}
var enabled = false; var enabled = false;
function onClicked() { function onClicked() {
// Similar logic to Application::showHelp()
var defaultTab = "kbm";
var handControllerName = "vive";
if (HMD.active) {
if ("Vive" in Controller.Hardware) {
defaultTab = "handControllers";
handControllerName = "vive";
} else if ("OculusTouch" in Controller.Hardware) {
defaultTab = "handControllers";
handControllerName = "oculus";
}
} else if ("SDL2" in Controller.Hardware) {
defaultTab = "gamepad";
}
if (enabled) { if (enabled) {
Menu.closeInfoView('InfoView_html/help.html'); Menu.closeInfoView('InfoView_html/help.html');
enabled = !enabled; enabled = !enabled;
@ -80,9 +53,6 @@
if (tablet) { if (tablet) {
tablet.removeButton(button); tablet.removeButton(button);
} }
if (toolBar) {
toolBar.removeButton(buttonName);
}
}); });
}()); // END LOCAL_SCOPE }()); // END LOCAL_SCOPE

View file

@ -10,7 +10,8 @@
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
/*globals HMD, Toolbars, Script, Menu, Tablet, Camera */ /* globals HMD, Script, Menu, Tablet, Camera */
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
(function() { // BEGIN LOCAL_SCOPE (function() { // BEGIN LOCAL_SCOPE
@ -37,20 +38,13 @@ function updateControllerDisplay() {
} }
var button; var button;
var toolBar = null; var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var tablet = null;
if (Settings.getValue("HUDUIEnabled")) {
toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
} else {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
}
// Independent and Entity mode make people sick. Third Person and Mirror have traps that we need to work through. // Independent and Entity mode make people sick. Third Person and Mirror have traps that we need to work through.
// Disable them in hmd. // Disable them in hmd.
var desktopOnlyViews = ['Mirror', 'Independent Mode', 'Entity Mode']; var desktopOnlyViews = ['Mirror', 'Independent Mode', 'Entity Mode'];
function onHmdChanged(isHmd) { function onHmdChanged(isHmd) {
//TODO change button icon when the hmd changes
if (isHmd) { if (isHmd) {
button.editProperties({ button.editProperties({
icon: "icons/tablet-icons/switch-desk-i.svg", icon: "icons/tablet-icons/switch-desk-i.svg",
@ -67,25 +61,18 @@ function onHmdChanged(isHmd) {
}); });
updateControllerDisplay(); updateControllerDisplay();
} }
function onClicked(){
function onClicked() {
var isDesktop = Menu.isOptionChecked(desktopMenuItemName); var isDesktop = Menu.isOptionChecked(desktopMenuItemName);
Menu.setIsOptionChecked(isDesktop ? headset : desktopMenuItemName, true); Menu.setIsOptionChecked(isDesktop ? headset : desktopMenuItemName, true);
} }
if (headset) { if (headset) {
if (Settings.getValue("HUDUIEnabled")) { button = tablet.addButton({
button = toolBar.addButton({ icon: HMD.active ? "icons/tablet-icons/switch-desk-i.svg" : "icons/tablet-icons/switch-vr-i.svg",
objectName: "hmdToggle", text: HMD.active ? "DESKTOP" : "VR",
imageURL: Script.resolvePath("assets/images/tools/switch.svg"), sortOrder: 2
visible: true, });
alpha: 0.9
});
} else {
button = tablet.addButton({
icon: HMD.active ? "icons/tablet-icons/switch-desk-i.svg" : "icons/tablet-icons/switch-vr-i.svg",
text: HMD.active ? "DESKTOP" : "VR",
sortOrder: 2
});
}
onHmdChanged(HMD.active); onHmdChanged(HMD.active);
button.clicked.connect(onClicked); button.clicked.connect(onClicked);
@ -97,9 +84,6 @@ if (headset) {
if (tablet) { if (tablet) {
tablet.removeButton(button); tablet.removeButton(button);
} }
if (toolBar) {
toolBar.removeButton("hmdToggle");
}
HMD.displayModeChanged.disconnect(onHmdChanged); HMD.displayModeChanged.disconnect(onHmdChanged);
Camera.modeUpdated.disconnect(updateControllerDisplay); Camera.modeUpdated.disconnect(updateControllerDisplay);
}); });

View file

@ -8,7 +8,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
/* global Tablet, Script, HMD, Toolbars, UserActivityLogger, Entities */ /* global Tablet, Script, HMD, UserActivityLogger, Entities */
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */ /* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
(function() { // BEGIN LOCAL_SCOPE (function() { // BEGIN LOCAL_SCOPE
@ -33,8 +33,6 @@ var QUERY_CAN_WRITE_ASSETS = "QUERY_CAN_WRITE_ASSETS";
var CAN_WRITE_ASSETS = "CAN_WRITE_ASSETS"; var CAN_WRITE_ASSETS = "CAN_WRITE_ASSETS";
var WARN_USER_NO_PERMISSIONS = "WARN_USER_NO_PERMISSIONS"; var WARN_USER_NO_PERMISSIONS = "WARN_USER_NO_PERMISSIONS";
var marketplaceWindow = null;
var CLARA_DOWNLOAD_TITLE = "Preparing Download"; var CLARA_DOWNLOAD_TITLE = "Preparing Download";
var messageBox = null; var messageBox = null;
var isDownloadBeingCancelled = false; var isDownloadBeingCancelled = false;
@ -57,52 +55,47 @@ Window.messageBoxClosed.connect(onMessageBoxClosed);
function showMarketplace() { function showMarketplace() {
UserActivityLogger.openedMarketplace(); UserActivityLogger.openedMarketplace();
if (tablet) { tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL);
tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL); tablet.webEventReceived.connect(function (message) {
tablet.webEventReceived.connect(function (message) {
if (message === GOTO_DIRECTORY) {
tablet.gotoWebScreen(MARKETPLACES_URL);
}
if (message === QUERY_CAN_WRITE_ASSETS) { if (message === GOTO_DIRECTORY) {
tablet.emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets()); tablet.gotoWebScreen(MARKETPLACES_URL);
} }
if (message === WARN_USER_NO_PERMISSIONS) { if (message === QUERY_CAN_WRITE_ASSETS) {
Window.alert(NO_PERMISSIONS_ERROR_MESSAGE); tablet.emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets());
} }
if (message.slice(0, CLARA_IO_STATUS.length) === CLARA_IO_STATUS) { if (message === WARN_USER_NO_PERMISSIONS) {
if (isDownloadBeingCancelled) { Window.alert(NO_PERMISSIONS_ERROR_MESSAGE);
return; }
}
var text = message.slice(CLARA_IO_STATUS.length); if (message.slice(0, CLARA_IO_STATUS.length) === CLARA_IO_STATUS) {
if (messageBox === null) { if (isDownloadBeingCancelled) {
messageBox = Window.openMessageBox(CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON);
} else {
Window.updateMessageBox(messageBox, CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON);
}
return; return;
} }
if (message.slice(0, CLARA_IO_DOWNLOAD.length) === CLARA_IO_DOWNLOAD) { var text = message.slice(CLARA_IO_STATUS.length);
if (messageBox !== null) { if (messageBox === null) {
Window.closeMessageBox(messageBox); messageBox = Window.openMessageBox(CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON);
messageBox = null; } else {
} Window.updateMessageBox(messageBox, CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON);
return;
} }
return;
}
if (message === CLARA_IO_CANCELLED_DOWNLOAD) { if (message.slice(0, CLARA_IO_DOWNLOAD.length) === CLARA_IO_DOWNLOAD) {
isDownloadBeingCancelled = false; if (messageBox !== null) {
Window.closeMessageBox(messageBox);
messageBox = null;
} }
}); return;
} else { }
marketplaceWindow.setURL(MARKETPLACE_URL_INITIAL);
marketplaceWindow.setVisible(true); if (message === CLARA_IO_CANCELLED_DOWNLOAD) {
marketplaceVisible = true; isDownloadBeingCancelled = false;
} }
});
} }
function toggleMarketplace() { function toggleMarketplace() {
@ -111,33 +104,12 @@ function toggleMarketplace() {
showMarketplace(); showMarketplace();
} }
var tablet = null; var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var toolBar = null; var marketplaceButton = tablet.addButton({
var marketplaceButton = null; icon: "icons/tablet-icons/market-i.svg",
if (Settings.getValue("HUDUIEnabled")) { text: "MARKET",
marketplaceWindow = new OverlayWebWindow({ sortOrder: 9
title: "Marketplace", });
source: "about:blank",
width: 900,
height: 700,
visible: false
});
marketplaceWindow.setScriptURL(MARKETPLACES_INJECT_SCRIPT_URL);
toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
var toolIconUrl = Script.resolvePath("../assets/images/tools/");
marketplaceButton = toolBar.addButton({
imageURL: toolIconUrl + "market.svg",
objectName: "marketplace",
alpha: 0.9
});
} else {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
marketplaceButton = tablet.addButton({
icon: "icons/tablet-icons/market-i.svg",
text: "MARKET",
sortOrder: 9
});
}
function onCanWriteAssetsChanged() { function onCanWriteAssetsChanged() {
var message = CAN_WRITE_ASSETS + " " + Entities.canWriteAssets(); var message = CAN_WRITE_ASSETS + " " + Entities.canWriteAssets();
@ -152,9 +124,6 @@ marketplaceButton.clicked.connect(onClick);
Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged); Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged);
Script.scriptEnding.connect(function () { Script.scriptEnding.connect(function () {
if (toolBar) {
toolBar.removeButton("marketplace");
}
if (tablet) { if (tablet) {
tablet.removeButton(marketplaceButton); tablet.removeButton(marketplaceButton);
} }

View file

@ -1,6 +1,6 @@
"use strict"; "use strict";
/* jslint vars: true, plusplus: true, forin: true*/ /* jslint vars: true, plusplus: true, forin: true*/
/* globals Tablet, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, OverlayWindow, Toolbars, Vec3, Quat, Controller, print, getControllerWorldLocation */ /* globals Tablet, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, Controller, print, getControllerWorldLocation */
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */ /* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
// //
// pal.js // pal.js
@ -197,16 +197,6 @@ HighlightedEntity.updateOverlays = function updateHighlightedEntities() {
}); });
}; };
//
// The qml window and communications.
//
var pal = new OverlayWindow({
title: 'People Action List',
source: 'hifi/Pal.qml',
width: 580,
height: 640,
visible: false
});
function fromQml(message) { // messages are {method, params}, like json-rpc. See also sendToQml. function fromQml(message) { // messages are {method, params}, like json-rpc. See also sendToQml.
var data; var data;
switch (message.method) { switch (message.method) {
@ -266,11 +256,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
} }
function sendToQml(message) { function sendToQml(message) {
if (currentUIMode === "toolbar") { tablet.sendToQml(message);
pal.sendToQml(message);
} else if (currentUIMode === "tablet") {
tablet.sendToQml(message);
}
} }
// //
@ -490,9 +476,6 @@ triggerPressMapping.from(Controller.Standard.LT).peek().to(makePressHandler(Cont
var button; var button;
var buttonName = "PEOPLE"; var buttonName = "PEOPLE";
var tablet = null; var tablet = null;
var toolBar = null;
var currentUIMode;
function onTabletScreenChanged(type, url) { function onTabletScreenChanged(type, url) {
if (type !== "QML" || url !== "../Pal.qml") { if (type !== "QML" || url !== "../Pal.qml") {
@ -500,33 +483,16 @@ function onTabletScreenChanged(type, url) {
} }
} }
// @param mode {string} "tablet" or "toolbar" function startup() {
function startup(mode) { tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
if (mode === "toolbar") { button = tablet.addButton({
toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); text: buttonName,
button = toolBar.addButton({ icon: "icons/tablet-icons/people-i.svg",
objectName: buttonName, sortOrder: 7
imageURL: Script.resolvePath("assets/images/tools/people.svg"), });
visible: true, tablet.fromQml.connect(fromQml);
alpha: 0.9 button.clicked.connect(onTabletButtonClicked);
}); tablet.screenChanged.connect(onTabletScreenChanged);
pal.fromQml.connect(fromQml);
button.clicked.connect(onToolbarButtonClicked);
pal.visibleChanged.connect(onVisibleChanged);
pal.closed.connect(off);
} else if (mode === "tablet") {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
text: buttonName,
icon: "icons/tablet-icons/people-i.svg",
sortOrder: 7
});
tablet.fromQml.connect(fromQml);
button.clicked.connect(onTabletButtonClicked);
tablet.screenChanged.connect(onTabletScreenChanged);
} else {
print("ERROR: pal.js: bad ui mode");
}
Users.usernameFromIDReply.connect(usernameFromIDReply); Users.usernameFromIDReply.connect(usernameFromIDReply);
Window.domainChanged.connect(clearLocalQMLDataAndClosePAL); Window.domainChanged.connect(clearLocalQMLDataAndClosePAL);
@ -534,12 +500,9 @@ function startup(mode) {
Messages.subscribe(CHANNEL); Messages.subscribe(CHANNEL);
Messages.messageReceived.connect(receiveMessage); Messages.messageReceived.connect(receiveMessage);
Users.avatarDisconnected.connect(avatarDisconnected); Users.avatarDisconnected.connect(avatarDisconnected);
currentUIMode = mode;
} }
// var mode = Settings.getValue("HUDUIEnabled"); startup();
startup("tablet");
var isWired = false; var isWired = false;
var audioTimer; var audioTimer;
@ -561,24 +524,6 @@ function off() {
Users.requestsDomainListData = false; Users.requestsDomainListData = false;
} }
function onToolbarButtonClicked() {
if (!pal.visible) {
Users.requestsDomainListData = true;
populateUserList();
pal.raise();
isWired = true;
Script.update.connect(updateOverlays);
Controller.mousePressEvent.connect(handleMouseEvent);
Controller.mouseMoveEvent.connect(handleMouseMoveEvent);
triggerMapping.enable();
triggerPressMapping.enable();
audioTimer = createAudioInterval(conserveResources ? AUDIO_LEVEL_CONSERVED_UPDATE_INTERVAL_MS : AUDIO_LEVEL_UPDATE_INTERVAL_MS);
} else {
off();
}
pal.setVisible(!pal.visible);
}
function onTabletButtonClicked() { function onTabletButtonClicked() {
tablet.loadQMLSource("../Pal.qml"); tablet.loadQMLSource("../Pal.qml");
Users.requestsDomainListData = true; Users.requestsDomainListData = true;
@ -604,9 +549,6 @@ function receiveMessage(channel, messageString, senderID) {
var message = JSON.parse(messageString); var message = JSON.parse(messageString);
switch (message.method) { switch (message.method) {
case 'select': case 'select':
if (currentUIMode === "toolbar" && !pal.visible) {
onToolbarButtonClicked();
}
sendToQml(message); // Accepts objects, not just strings. sendToQml(message); // Accepts objects, not just strings.
break; break;
default: default:
@ -671,31 +613,14 @@ function avatarDisconnected(nodeID) {
sendToQml({method: 'avatarDisconnected', params: [nodeID]}); sendToQml({method: 'avatarDisconnected', params: [nodeID]});
} }
//
// Button state.
//
function onVisibleChanged() {
button.editProperties({isActive: pal.visible});
}
function clearLocalQMLDataAndClosePAL() { function clearLocalQMLDataAndClosePAL() {
sendToQml({ method: 'clearLocalQMLData' }); sendToQml({ method: 'clearLocalQMLData' });
if (currentUIMode === "toolbar" && pal.visible) {
onToolbarButtonClicked(); // Close the PAL
}
} }
function shutdown() { function shutdown() {
if (currentUIMode === "toolbar") { button.clicked.disconnect(onTabletButtonClicked);
button.clicked.disconnect(onToolbarButtonClicked); tablet.removeButton(button);
toolBar.removeButton(buttonName); tablet.screenChanged.disconnect(onTabletScreenChanged);
pal.visibleChanged.disconnect(onVisibleChanged);
pal.closed.disconnect(off);
} else if (currentUIMode === "tablet") {
button.clicked.disconnect(onTabletButtonClicked);
tablet.removeButton(button);
tablet.screenChanged.disconnect(onTabletScreenChanged);
}
Users.usernameFromIDReply.disconnect(usernameFromIDReply); Users.usernameFromIDReply.disconnect(usernameFromIDReply);
Window.domainChanged.disconnect(clearLocalQMLDataAndClosePAL); Window.domainChanged.disconnect(clearLocalQMLDataAndClosePAL);

View file

@ -7,7 +7,8 @@
// Distributed under the Apache License, Version 2.0 // Distributed under the Apache License, Version 2.0
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
/* globals Tablet, Toolbars, Script, HMD, Settings, DialogsManager, Menu, Reticle, OverlayWebWindow, Desktop, Account, MyAvatar */ /* globals Tablet, Script, HMD, Settings, DialogsManager, Menu, Reticle, OverlayWebWindow, Desktop, Account, MyAvatar */
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
(function() { // BEGIN LOCAL_SCOPE (function() { // BEGIN LOCAL_SCOPE
@ -17,29 +18,15 @@ var resetOverlays;
var reticleVisible; var reticleVisible;
var clearOverlayWhenMoving; var clearOverlayWhenMoving;
var button;
var buttonName = "SNAP"; var buttonName = "SNAP";
var tablet = null;
var toolBar = null;
var buttonConnected = false; var buttonConnected = false;
if (Settings.getValue("HUDUIEnabled")) { var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); var button = tablet.addButton({
button = toolBar.addButton({ icon: "icons/tablet-icons/snap-i.svg",
objectName: buttonName, text: buttonName,
imageURL: Script.resolvePath("assets/images/tools/snap.svg"), sortOrder: 5
visible: true, });
alpha: 0.9,
});
} else {
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
button = tablet.addButton({
icon: "icons/tablet-icons/snap-i.svg",
text: buttonName,
sortOrder: 5
});
}
function shouldOpenFeedAfterShare() { function shouldOpenFeedAfterShare() {
var persisted = Settings.getValue('openFeedAfterShare', true); // might answer true, false, "true", or "false" var persisted = Settings.getValue('openFeedAfterShare', true); // might answer true, false, "true", or "false"
@ -63,42 +50,42 @@ function confirmShare(data) {
var isLoggedIn; var isLoggedIn;
var needsLogin = false; var needsLogin = false;
switch (message) { switch (message) {
case 'ready': case 'ready':
dialog.emitScriptEvent(data); // Send it. dialog.emitScriptEvent(data); // Send it.
outstanding = 0; outstanding = 0;
break; break;
case 'openSettings': case 'openSettings':
Desktop.show("hifi/dialogs/GeneralPreferencesDialog.qml", "GeneralPreferencesDialog"); Desktop.show("hifi/dialogs/GeneralPreferencesDialog.qml", "GeneralPreferencesDialog");
break; break;
case 'setOpenFeedFalse': case 'setOpenFeedFalse':
Settings.setValue('openFeedAfterShare', false); Settings.setValue('openFeedAfterShare', false);
break; break;
case 'setOpenFeedTrue': case 'setOpenFeedTrue':
Settings.setValue('openFeedAfterShare', true); Settings.setValue('openFeedAfterShare', true);
break; break;
default: default:
dialog.webEventReceived.disconnect(onMessage); dialog.webEventReceived.disconnect(onMessage);
dialog.close(); dialog.close();
isLoggedIn = Account.isLoggedIn(); isLoggedIn = Account.isLoggedIn();
message.forEach(function (submessage) { message.forEach(function (submessage) {
if (submessage.share && !isLoggedIn) { if (submessage.share && !isLoggedIn) {
needsLogin = true; needsLogin = true;
submessage.share = false; submessage.share = false;
}
if (submessage.share) {
print('sharing', submessage.localPath);
outstanding++;
Window.shareSnapshot(submessage.localPath, submessage.href);
} else {
print('not sharing', submessage.localPath);
}
});
if (!outstanding && shouldOpenFeedAfterShare()) {
showFeedWindow();
} }
if (needsLogin) { // after the possible feed, so that the login is on top if (submessage.share) {
Account.checkAndSignalForAccessToken(); print('sharing', submessage.localPath);
outstanding++;
Window.shareSnapshot(submessage.localPath, submessage.href);
} else {
print('not sharing', submessage.localPath);
} }
});
if (!outstanding && shouldOpenFeedAfterShare()) {
showFeedWindow();
}
if (needsLogin) { // after the possible feed, so that the login is on top
Account.checkAndSignalForAccessToken();
}
} }
} }
dialog.webEventReceived.connect(onMessage); dialog.webEventReceived.connect(onMessage);
@ -159,7 +146,7 @@ function isDomainOpen(id) {
var url = location.metaverseServerUrl + "/api/v1/user_stories?" + options.join('&'); var url = location.metaverseServerUrl + "/api/v1/user_stories?" + options.join('&');
request.open("GET", url, false); request.open("GET", url, false);
request.send(); request.send();
if (request.status != 200) { if (request.status !== 200) {
return false; return false;
} }
var response = JSON.parse(request.response); // Not parsed for us. var response = JSON.parse(request.response); // Not parsed for us.
@ -229,9 +216,6 @@ Script.scriptEnding.connect(function () {
if (tablet) { if (tablet) {
tablet.removeButton(button); tablet.removeButton(button);
} }
if (toolBar) {
toolBar.removeButton(buttonName);
}
Window.snapshotShared.disconnect(snapshotShared); Window.snapshotShared.disconnect(snapshotShared);
Window.processingGif.disconnect(processingGif); Window.processingGif.disconnect(processingGif);
}); });