From 112e13383b4a871cf864cc0e53c3417fa6e16d4c Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 10 May 2019 12:03:29 -0700 Subject: [PATCH] Dock it! --- .../hifi/simplifiedUI/avatarApp/AvatarApp.qml | 20 +-- .../simplifiedUI/topBar/SimplifiedTopBar.qml | 115 +++++++++++++++++- interface/src/Application.cpp | 1 + .../simplifiedUI/images/inputDeviceMuted.svg | 34 ++++-- scripts/system/simplifiedUI/simplifiedUI.js | 6 +- 5 files changed, 149 insertions(+), 27 deletions(-) diff --git a/interface/resources/qml/hifi/simplifiedUI/avatarApp/AvatarApp.qml b/interface/resources/qml/hifi/simplifiedUI/avatarApp/AvatarApp.qml index eff6eae5ce..a659ff4e0c 100644 --- a/interface/resources/qml/hifi/simplifiedUI/avatarApp/AvatarApp.qml +++ b/interface/resources/qml/hifi/simplifiedUI/avatarApp/AvatarApp.qml @@ -71,7 +71,7 @@ Rectangle { } onInventoryResult: { - inventoryModel.handlePage(result.status !== "success" && result.message, result); + avatarAppInventoryModel.handlePage(result.status !== "success" && result.message, result); root.updatePreviewUrl(); } } @@ -137,7 +137,7 @@ Rectangle { } HifiModels.PSFListModel { - id: inventoryModel + id: avatarAppInventoryModel itemsPerPage: 4 listModelName: 'inventory' listView: inventoryContentsList @@ -150,8 +150,8 @@ Rectangle { editionFilter, primaryFilter, titleFilter, - inventoryModel.currentPageToRetrieve, - inventoryModel.itemsPerPage + avatarAppInventoryModel.currentPageToRetrieve, + avatarAppInventoryModel.itemsPerPage ); } processPage: function(data) { @@ -181,10 +181,10 @@ Rectangle { ListView { id: inventoryContentsList - visible: inventoryModel.count !== 0 + visible: avatarAppInventoryModel.count !== 0 interactive: contentItem.height > height clip: true - model: inventoryModel + model: avatarAppInventoryModel anchors.fill: parent width: parent.width delegate: AvatarAppComponents.AvatarAppListDelegate { @@ -200,15 +200,15 @@ Rectangle { function getInventory() { - inventoryModel.getFirstPage(); + avatarAppInventoryModel.getFirstPage(); } function updatePreviewUrl() { var previewUrl = ""; var downloadUrl = ""; - for (var i = 0; i < inventoryModel.count; ++i) { - downloadUrl = inventoryModel.get(i).download_url; - previewUrl = inventoryModel.get(i).preview; + for (var i = 0; i < avatarAppInventoryModel.count; ++i) { + downloadUrl = avatarAppInventoryModel.get(i).download_url; + previewUrl = avatarAppInventoryModel.get(i).preview; if (MyAvatar.skeletonModelURL === downloadUrl) { avatarPreviewUrl = previewUrl; return; diff --git a/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml b/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml index 156cd3038d..2c604d27d8 100644 --- a/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml +++ b/interface/resources/qml/hifi/simplifiedUI/topBar/SimplifiedTopBar.qml @@ -14,6 +14,7 @@ import "../inputDeviceButton" as InputDeviceButton import stylesUit 1.0 as HifiStylesUit import TabletScriptingInterface 1.0 import QtGraphicalEffects 1.0 +import "qrc:////qml//hifi//models" as HifiModels // Absolute path so the same code works everywhere. Rectangle { id: root @@ -23,7 +24,94 @@ Rectangle { } color: simplifiedUI.colors.darkBackground - anchors.fill: parent; + anchors.fill: parent + + property bool inventoryFullyReceived: false + + Component.onCompleted: { + Commerce.getLoginStatus(); + } + + Connections { + target: MyAvatar + + onSkeletonModelURLChanged: { + root.updatePreviewUrl(); + } + } + + Connections { + target: Commerce + + onLoginStatusResult: { + if (inventoryFullyReceived) { + return; + } + + if (isLoggedIn) { + Commerce.getWalletStatus(); + } else { + // Show some error to the user + } + } + + onWalletStatusResult: { + if (inventoryFullyReceived) { + return; + } + + if (walletStatus === 5) { + topBarInventoryModel.getFirstPage(); + } else { + // Show some error to the user + } + } + + onInventoryResult: { + if (inventoryFullyReceived) { + return; + } + + topBarInventoryModel.handlePage(result.status !== "success" && result.message, result); + root.updatePreviewUrl(); + + // I _should_ be able to do `if (currentPageToRetrieve > -1)` here, but the + // inventory endpoint doesn't return `response.total_pages`, so the PSFListModel doesn't + // know when to automatically stop fetching new pages. + // This will result in fetching one extra page than is necessary, but that's not a big deal. + if (result.data.assets.length > 0) { + topBarInventoryModel.getNextPage(); + } else { + inventoryFullyReceived = true; + } + } + } + + HifiModels.PSFListModel { + id: topBarInventoryModel + itemsPerPage: 8 + listModelName: 'inventory' + getPage: function () { + var editionFilter = ""; + var primaryFilter = "avatar"; + var titleFilter = ""; + + Commerce.inventory( + editionFilter, + primaryFilter, + titleFilter, + topBarInventoryModel.currentPageToRetrieve, + topBarInventoryModel.itemsPerPage + ); + } + processPage: function(data) { + data.assets.forEach(function (item) { + if (item.status.length > 1) { console.warn("Unrecognized inventory status", item); } + item.status = item.status[0]; + }); + return data.assets; + } + } Item { @@ -34,9 +122,18 @@ Rectangle { anchors.leftMargin: 16 width: height + AnimatedImage { + visible: avatarButtonImage.source === "" + anchors.centerIn: parent + width: parent.width - 10 + height: width + source: "../images/loading.gif" + } + Image { id: avatarButtonImage - source: "images/defaultAvatar.jpg" + visible: source !== "" + source: "" anchors.centerIn: parent width: parent.width - 10 height: width @@ -215,6 +312,20 @@ Rectangle { } + function updatePreviewUrl() { + var previewUrl = ""; + var downloadUrl = ""; + for (var i = 0; i < topBarInventoryModel.count; ++i) { + downloadUrl = topBarInventoryModel.get(i).download_url; + previewUrl = topBarInventoryModel.get(i).preview; + if (MyAvatar.skeletonModelURL === downloadUrl) { + avatarButtonImage.source = previewUrl; + return; + } + } + } + + function fromScript(message) { if (message.source !== "simplifiedUI.js") { return; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ab69e272da..326520d72e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3092,6 +3092,7 @@ void Application::initializeUi() { QUrl{ "hifi/tablet/TabletMenu.qml" }, QUrl{ "hifi/commerce/marketplace/Marketplace.qml" }, QUrl{ "hifi/simplifiedUI/avatarApp/AvatarApp.qml" }, + QUrl{ "hifi/simplifiedUI/topBar/SimplifiedTopBar.qml" }, }, commerceCallback); QmlContextCallback marketplaceCallback = [](QQmlContext* context) { diff --git a/scripts/system/simplifiedUI/images/inputDeviceMuted.svg b/scripts/system/simplifiedUI/images/inputDeviceMuted.svg index faeb14cdf8..26b586c62a 100644 --- a/scripts/system/simplifiedUI/images/inputDeviceMuted.svg +++ b/scripts/system/simplifiedUI/images/inputDeviceMuted.svg @@ -1,12 +1,22 @@ - - - - - - - - - - - - + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/scripts/system/simplifiedUI/simplifiedUI.js b/scripts/system/simplifiedUI/simplifiedUI.js index 3f73bc91c8..e4395effa1 100644 --- a/scripts/system/simplifiedUI/simplifiedUI.js +++ b/scripts/system/simplifiedUI/simplifiedUI.js @@ -14,7 +14,7 @@ // START CONFIG OPTIONS -var DOCKED_QML_SUPPORTED = false; +var DOCKED_QML_SUPPORTED = true; var REMOVE_EXISTING_UI = true; var TOOLBAR_NAME = "com.highfidelity.interface.toolbar.system"; var DEFAULT_SCRIPTS_PATH_PREFIX = ScriptDiscoveryService.defaultScriptsPath + "/"; @@ -379,8 +379,8 @@ function getInputDeviceMutedOverlayTopY() { var inputDeviceMutedOverlay = false; -var INPUT_DEVICE_MUTED_OVERLAY_DEFAULT_X_PX = 320; -var INPUT_DEVICE_MUTED_OVERLAY_DEFAULT_Y_PX = 60; +var INPUT_DEVICE_MUTED_OVERLAY_DEFAULT_X_PX = 353; +var INPUT_DEVICE_MUTED_OVERLAY_DEFAULT_Y_PX = 95; var INPUT_DEVICE_MUTED_MARGIN_BOTTOM_PX = 20; function updateInputDeviceMutedOverlay(isMuted) { if (isMuted) {