From 77f0fb14912b0546fbc6c6b2392ae47d7d809fe7 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 11 Feb 2017 22:40:19 +1300 Subject: [PATCH] Change the "Mute" tablet button to "Audio" --- .../resources/qml/hifi/tablet/TabletMenu.qml | 21 +++++++++++- .../resources/qml/hifi/tablet/TabletRoot.qml | 8 +++++ .../src/TabletScriptingInterface.cpp | 3 +- .../src/TabletScriptingInterface.h | 2 +- scripts/defaultScripts.js | 2 +- scripts/system/{mute.js => audio.js} | 32 ++++++++++++------- 6 files changed, 52 insertions(+), 16 deletions(-) rename scripts/system/{mute.js => audio.js} (56%) diff --git a/interface/resources/qml/hifi/tablet/TabletMenu.qml b/interface/resources/qml/hifi/tablet/TabletMenu.qml index cd3a9cacae..c154ac0f49 100644 --- a/interface/resources/qml/hifi/tablet/TabletMenu.qml +++ b/interface/resources/qml/hifi/tablet/TabletMenu.qml @@ -14,6 +14,7 @@ FocusScope { property var rootMenu: Menu { objectName:"rootMenu" } property var point: Qt.point(50, 50) + property string subMenu: "" TabletMouseHandler { id: menuPopperUpper } @@ -101,6 +102,24 @@ FocusScope { buildMenu() } function buildMenu() { - menuPopperUpper.popup(tabletMenu, rootMenu.items) + // Build submenu if specified. + if (subMenu !== "") { + var index = 0; + var found = false; + while (!found && index < rootMenu.items.length) { + found = rootMenu.items[index].title === subMenu; + if (!found) { + index += 1; + } + } + subMenu = ""; // Continue with full menu after initially displaying submenu. + if (found) { + menuPopperUpper.popup(tabletMenu, rootMenu.items[index].items); + return; + } + } + + // Otherwise build whole menu. + menuPopperUpper.popup(tabletMenu, rootMenu.items); } } diff --git a/interface/resources/qml/hifi/tablet/TabletRoot.qml b/interface/resources/qml/hifi/tablet/TabletRoot.qml index 40d88165b0..481c7846a9 100644 --- a/interface/resources/qml/hifi/tablet/TabletRoot.qml +++ b/interface/resources/qml/hifi/tablet/TabletRoot.qml @@ -6,9 +6,14 @@ Item { objectName: "tabletRoot" property string username: "Unknown user" property var eventBridge; + property string option: "" signal showDesktop(); + function setOption(value) { + option = value; + } + function loadSource(url) { loader.source = url; } @@ -72,6 +77,9 @@ Item { if (loader.item.hasOwnProperty("sendToScript")) { loader.item.sendToScript.connect(tabletRoot.sendToScript); } + if (loader.item.hasOwnProperty("subMenu")) { + loader.item.subMenu = option; + } loader.item.forceActiveFocus(); } } diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index e40736b201..7e8fdd6bc3 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -213,10 +213,11 @@ void TabletProxy::setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscr } } -void TabletProxy::gotoMenuScreen() { +void TabletProxy::gotoMenuScreen(const QString& submenu) { if (_qmlTabletRoot) { if (_state != State::Menu) { removeButtonsFromHomeScreen(); + QMetaObject::invokeMethod(_qmlTabletRoot, "setOption", Q_ARG(const QVariant&, QVariant(submenu))); auto loader = _qmlTabletRoot->findChild("loader"); QObject::connect(loader, SIGNAL(loaded()), this, SLOT(addButtonsToMenuScreen()), Qt::DirectConnection); QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(VRMENU_SOURCE_URL))); diff --git a/libraries/script-engine/src/TabletScriptingInterface.h b/libraries/script-engine/src/TabletScriptingInterface.h index d5eccb2479..80ab365654 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -72,7 +72,7 @@ public: void setQmlTabletRoot(QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface); - Q_INVOKABLE void gotoMenuScreen(); + Q_INVOKABLE void gotoMenuScreen(const QString& submenu = ""); /**jsdoc * transition to the home screen diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 36b0ddde85..40a77eda55 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -14,7 +14,7 @@ var DEFAULT_SCRIPTS = [ "system/progress.js", "system/away.js", - "system/mute.js", + "system/audio.js", "system/hmd.js", "system/menu.js", "system/bubble.js", diff --git a/scripts/system/mute.js b/scripts/system/audio.js similarity index 56% rename from scripts/system/mute.js rename to scripts/system/audio.js index f28a2eb9a5..dd49f944ea 100644 --- a/scripts/system/mute.js +++ b/scripts/system/audio.js @@ -1,8 +1,7 @@ "use strict"; // -// goto.js -// scripts/system/ +// audio.js // // Created by Howard Stearns on 2 Jun 2016 // Copyright 2016 High Fidelity, Inc. @@ -14,22 +13,33 @@ (function() { // BEGIN LOCAL_SCOPE var button; -var buttonName = "MUTE"; +var TOOLBAR_BUTTON_NAME = "MUTE"; +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"; function onMuteToggled() { - button.editProperties({isActive: AudioDevice.getMuted()}); + if (isHUDUIEnabled) { + button.editProperties({ isActive: AudioDevice.getMuted() }); + } } function onClicked(){ - var menuItem = "Mute Microphone"; - Menu.setIsOptionChecked(menuItem, !Menu.isOptionChecked(menuItem)); + if (isHUDUIEnabled) { + var menuItem = "Mute Microphone"; + Menu.setIsOptionChecked(menuItem, !Menu.isOptionChecked(menuItem)); + } else { + var entity = HMD.tabletID; + Entities.editEntity(entity, { textures: JSON.stringify({ "tex.close": HOME_BUTTON_TEXTURE }) }); + tablet.gotoMenuScreen("Audio"); + } } if (Settings.getValue("HUDUIEnabled")) { toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system"); button = toolBar.addButton({ - objectName: buttonName, + objectName: TOOLBAR_BUTTON_NAME, imageURL: Script.resolvePath("assets/images/tools/mic.svg"), visible: true, alpha: 0.9 @@ -37,10 +47,8 @@ if (Settings.getValue("HUDUIEnabled")) { } else { tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); button = tablet.addButton({ - icon: "icons/tablet-icons/mic-a.svg", - text: buttonName, - activeIcon: "icons/tablet-icons/mic-i.svg", - activeText: "UNMUTE", + icon: "icons/tablet-icons/mic-i.svg", + text: TABLET_BUTTON_NAME, sortOrder: 1 }); } @@ -56,7 +64,7 @@ Script.scriptEnding.connect(function () { tablet.removeButton(button); } if (toolBar) { - toolBar.removeButton(buttonName); + toolBar.removeButton(TOOLBAR_BUTTON_NAME); } });