From a21ff75a49f0a4b037ebd2c64fa11619b77a86eb Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 11 Aug 2017 12:08:19 -0700 Subject: [PATCH] Big progress! --- .../resources/qml/hifi/commerce/Checkout.qml | 111 +++++++++++++++++- .../resources/qml/hifi/commerce/Inventory.qml | 74 +++++++++++- scripts/system/html/js/marketplacesInject.js | 2 +- scripts/system/marketplaces/marketplaces.js | 6 + 4 files changed, 187 insertions(+), 6 deletions(-) diff --git a/interface/resources/qml/hifi/commerce/Checkout.qml b/interface/resources/qml/hifi/commerce/Checkout.qml index 78c3744a27..82a652a7b9 100644 --- a/interface/resources/qml/hifi/commerce/Checkout.qml +++ b/interface/resources/qml/hifi/commerce/Checkout.qml @@ -26,6 +26,8 @@ Rectangle { id: checkoutRoot; property string itemId; property string itemHref; + property int balanceAfterPurchase: commerce.balance() - parseInt(itemPriceText.text, 10); + property bool alreadyOwned: checkAlreadyOwned(itemId); // Style color: hifi.colors.baseGray; Hifi.QmlCommerce { @@ -172,11 +174,56 @@ Rectangle { } } + // HFC Balance text + Item { + id: hfcBalanceContainer; + // Anchors + anchors.top: itemAuthorContainer.bottom; + anchors.topMargin: 16; + anchors.left: parent.left; + anchors.leftMargin: 16; + anchors.right: parent.right; + anchors.rightMargin: 16; + height: childrenRect.height; + + RalewaySemiBold { + id: hfcBalanceTextLabel; + text: "HFC Balance:"; + // Anchors + anchors.top: parent.top; + anchors.left: parent.left; + width: paintedWidth; + // Text size + size: 20; + // Style + color: hifi.colors.lightGrayText; + // Alignment + horizontalAlignment: Text.AlignHLeft; + verticalAlignment: Text.AlignVCenter; + } + RalewayRegular { + id: hfcBalanceText; + text: commerce.balance(); + // Text size + size: hfcBalanceTextLabel.size; + // Anchors + anchors.top: parent.top; + anchors.left: hfcBalanceTextLabel.right; + anchors.leftMargin: 16; + width: paintedWidth; + // Style + color: hifi.colors.lightGrayText; + // Alignment + horizontalAlignment: Text.AlignHLeft; + verticalAlignment: Text.AlignVCenter; + } + } + // Item Price text Item { id: itemPriceContainer; // Anchors - anchors.top: itemAuthorContainer.bottom; + anchors.top: hfcBalanceContainer.bottom; anchors.topMargin: 4; anchors.left: parent.left; anchors.leftMargin: 16; @@ -215,6 +262,51 @@ Rectangle { verticalAlignment: Text.AlignVCenter; } } + + // HFC "Balance After Purchase" text + Item { + id: hfcBalanceAfterPurchaseContainer; + // Anchors + anchors.top: itemPriceContainer.bottom; + anchors.topMargin: 4; + anchors.left: parent.left; + anchors.leftMargin: 16; + anchors.right: parent.right; + anchors.rightMargin: 16; + height: childrenRect.height; + + RalewaySemiBold { + id: hfcBalanceAfterPurchaseTextLabel; + text: "HFC Balance After Purchase:"; + // Anchors + anchors.top: parent.top; + anchors.left: parent.left; + width: paintedWidth; + // Text size + size: 20; + // Style + color: hifi.colors.lightGrayText; + // Alignment + horizontalAlignment: Text.AlignHLeft; + verticalAlignment: Text.AlignVCenter; + } + RalewayRegular { + id: hfcBalanceAfterPurchaseText; + text: balanceAfterPurchase; + // Text size + size: hfcBalanceAfterPurchaseTextLabel.size; + // Anchors + anchors.top: parent.top; + anchors.left: hfcBalanceAfterPurchaseTextLabel.right; + anchors.leftMargin: 16; + width: paintedWidth; + // Style + color: (balanceAfterPurchase >= 0) ? hifi.colors.lightGrayText : hifi.colors.redHighlight; + // Alignment + horizontalAlignment: Text.AlignHLeft; + verticalAlignment: Text.AlignVCenter; + } + } } // // ITEM DESCRIPTION END @@ -231,7 +323,8 @@ Rectangle { height: 40; // Anchors anchors.left: parent.left; - anchors.top: itemDescriptionContainer.bottom; + anchors.bottom: parent.bottom; + anchors.bottomMargin: 8; // "Cancel" button HifiControlsUit.Button { @@ -255,6 +348,7 @@ Rectangle { HifiControlsUit.Button { property bool buyFailed: false; id: buyButton; + enabled: balanceAfterPurchase >= 0 && !alreadyOwned; color: hifi.buttons.black; colorScheme: hifi.colorSchemes.dark; anchors.top: parent.top; @@ -264,7 +358,7 @@ Rectangle { anchors.right: parent.right; anchors.rightMargin: 20; width: parent.width/2 - anchors.rightMargin*2; - text: "Buy" + text: alreadyOwned ? "Already Owned" : "Buy"; onClicked: { if (buyFailed) { sendToScript({method: 'checkout_cancelClicked', params: itemId}); @@ -287,6 +381,16 @@ Rectangle { // // FUNCTION DEFINITIONS START // + + function checkAlreadyOwned(idToCheck) { + var inventory = commerce.inventory(); + if (inventory.indexOf(idToCheck) !== -1) { + return true; + } else { + return false; + } + } + // // Function Name: fromScript() // @@ -308,7 +412,6 @@ Rectangle { itemAuthorText.text = message.params.itemAuthor; itemPriceText.text = message.params.itemPrice; itemHref = message.params.itemHref; - buyButton.text = "Buy"; buyButton.buyFailed = false; break; case 'buyFailed': diff --git a/interface/resources/qml/hifi/commerce/Inventory.qml b/interface/resources/qml/hifi/commerce/Inventory.qml index f86be8b359..91fa3b9126 100644 --- a/interface/resources/qml/hifi/commerce/Inventory.qml +++ b/interface/resources/qml/hifi/commerce/Inventory.qml @@ -120,6 +120,77 @@ Rectangle { // HFC BALANCE END // + // + // INVENTORY CONTENTS START + // + Item { + id: inventoryContentsContainer; + // Anchors + anchors.left: parent.left; + anchors.leftMargin: 16; + anchors.right: parent.right; + anchors.rightMargin: 16; + anchors.top: hfcBalanceContainer.bottom; + anchors.topMargin: 8; + anchors.bottom: actionButtonsContainer.top; + anchors.bottomMargin: 8; + + RalewaySemiBold { + id: inventoryContentsLabel; + text: "Inventory:"; + // Anchors + anchors.top: parent.top; + anchors.left: parent.left; + width: paintedWidth; + // Text size + size: 24; + // Style + color: hifi.colors.lightGrayText; + // Alignment + horizontalAlignment: Text.AlignHLeft; + verticalAlignment: Text.AlignVCenter; + } + ListView { + id: inventoryContentsList; + // Anchors + anchors.top: inventoryContentsLabel.bottom; + anchors.topMargin: 8; + anchors.left: parent.left; + anchors.bottom: parent.bottom; + width: parent.width; + model: commerce.inventory(); + delegate: Item { + width: parent.width; + height: 30; + RalewayRegular { + id: thisItemId; + // Text size + size: 20; + // Style + color: hifi.colors.blueAccent; + text: modelData; + // Alignment + horizontalAlignment: Text.AlignHLeft; + } + MouseArea { + anchors.fill: parent; + hoverEnabled: enabled; + onClicked: { + sendToScript({method: 'inventory_itemClicked', itemId: thisItemId.text}); + } + onEntered: { + thisItemId.color = hifi.colors.blueHighlight; + } + onExited: { + thisItemId.color = hifi.colors.blueAccent; + } + } + } + } + } + // + // INVENTORY CONTENTS END + // // // ACTION BUTTONS START @@ -131,7 +202,8 @@ Rectangle { height: 40; // Anchors anchors.left: parent.left; - anchors.top: hfcBalanceContainer.bottom; + anchors.bottom: parent.bottom; + anchors.bottomMargin: 8; // "Back" button HifiControlsUit.Button { diff --git a/scripts/system/html/js/marketplacesInject.js b/scripts/system/html/js/marketplacesInject.js index 600159926e..80c8f8a0e4 100644 --- a/scripts/system/html/js/marketplacesInject.js +++ b/scripts/system/html/js/marketplacesInject.js @@ -114,7 +114,7 @@ itemId: id, itemName: name, itemAuthor: author, - itemPrice: price, + itemPrice: Math.round(Math.random() * 50), itemHref: href })); } diff --git a/scripts/system/marketplaces/marketplaces.js b/scripts/system/marketplaces/marketplaces.js index 8aa36353c4..e44e9fda94 100644 --- a/scripts/system/marketplaces/marketplaces.js +++ b/scripts/system/marketplaces/marketplaces.js @@ -212,6 +212,12 @@ } //tablet.popFromStack(); break; + case 'inventory_itemClicked': + var itemId = message.itemId; + if (itemId && itemId !== "") { + tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + itemId, MARKETPLACES_INJECT_SCRIPT_URL); + } + break; case 'inventory_backClicked': tablet.gotoWebScreen(message.referrerURL, MARKETPLACES_INJECT_SCRIPT_URL); break;