Small improvements

This commit is contained in:
Zach Fox 2017-08-11 16:28:08 -07:00
parent c38837c200
commit d8e5f7a067
2 changed files with 10 additions and 6 deletions

View file

@ -24,9 +24,10 @@ Rectangle {
HifiConstants { id: hifi; } HifiConstants { id: hifi; }
id: checkoutRoot; id: checkoutRoot;
property bool inventoryReceived: false;
property bool balanceReceived: false;
property string itemId: ""; property string itemId: "";
property string itemHref: ""; property string itemHref: "";
property int hfcBalance: 0;
property int balanceAfterPurchase: 0; property int balanceAfterPurchase: 0;
property bool alreadyOwned: false; property bool alreadyOwned: false;
// Style // Style
@ -48,14 +49,16 @@ Rectangle {
if (failureMessage.length) { if (failureMessage.length) {
console.log("Failed to get balance", failureMessage); console.log("Failed to get balance", failureMessage);
} else { } else {
hfcBalance = balance; balanceReceived = true;
balanceAfterPurchase = hfcBalance - parseInt(itemPriceText.text, 10); hfcBalanceText.text = balance;
balanceAfterPurchase = balance - parseInt(itemPriceText.text, 10);
} }
} }
onInventoryResult: { onInventoryResult: {
if (failureMessage.length) { if (failureMessage.length) {
console.log("Failed to get inventory", failureMessage); console.log("Failed to get inventory", failureMessage);
} else { } else {
inventoryReceived = true;
if (inventory.indexOf(itemId) !== -1) { if (inventory.indexOf(itemId) !== -1) {
alreadyOwned = true; alreadyOwned = true;
} else { } else {
@ -234,7 +237,7 @@ Rectangle {
} }
RalewayRegular { RalewayRegular {
id: hfcBalanceText; id: hfcBalanceText;
text: hfcBalance; text: "--";
// Text size // Text size
size: hfcBalanceTextLabel.size; size: hfcBalanceTextLabel.size;
// Anchors // Anchors
@ -378,7 +381,7 @@ Rectangle {
// "Buy" button // "Buy" button
HifiControlsUit.Button { HifiControlsUit.Button {
id: buyButton; id: buyButton;
enabled: balanceAfterPurchase >= 0 && !alreadyOwned; enabled: balanceAfterPurchase >= 0 && !alreadyOwned && inventoryReceived && balanceReceived;
color: hifi.buttons.black; color: hifi.buttons.black;
colorScheme: hifi.colorSchemes.dark; colorScheme: hifi.colorSchemes.dark;
anchors.top: parent.top; anchors.top: parent.top;
@ -388,7 +391,7 @@ Rectangle {
anchors.right: parent.right; anchors.right: parent.right;
anchors.rightMargin: 20; anchors.rightMargin: 20;
width: parent.width/2 - anchors.rightMargin*2; width: parent.width/2 - anchors.rightMargin*2;
text: alreadyOwned ? "Already Owned" : "Buy"; text: (inventoryReceived && balanceReceived) ? (alreadyOwned ? "Already Owned" : "Buy") : "--";
onClicked: { onClicked: {
commerce.buy(itemId, parseInt(itemPriceText.text)); commerce.buy(itemId, parseInt(itemPriceText.text));
} }

View file

@ -115,6 +115,7 @@ Rectangle {
} }
RalewayRegular { RalewayRegular {
id: hfcBalanceText; id: hfcBalanceText;
text: "--";
// Text size // Text size
size: hfcBalanceTextLabel.size; size: hfcBalanceTextLabel.size;
// Anchors // Anchors