mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:49:27 +02:00
Add inventory; also fix some bugs
This commit is contained in:
parent
26ad79aa01
commit
e1064938cd
4 changed files with 230 additions and 7 deletions
|
@ -269,7 +269,13 @@ Rectangle {
|
||||||
if (buyFailed) {
|
if (buyFailed) {
|
||||||
sendToScript({method: 'checkout_cancelClicked', params: itemId});
|
sendToScript({method: 'checkout_cancelClicked', params: itemId});
|
||||||
} else {
|
} else {
|
||||||
sendToScript({method: 'checkout_buyClicked', success: commerce.buy(itemId, parseInt(itemPriceText.text)), itemId: itemId, itemHref: itemHref});
|
var success = commerce.buy(itemId, parseInt(itemPriceText.text));
|
||||||
|
sendToScript({method: 'checkout_buyClicked', success: success, itemId: itemId, itemHref: itemHref});
|
||||||
|
if (success) {
|
||||||
|
if (urlHandler.canHandleUrl(itemHref)) {
|
||||||
|
urlHandler.handleUrl(itemHref);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
188
interface/resources/qml/hifi/commerce/Inventory.qml
Normal file
188
interface/resources/qml/hifi/commerce/Inventory.qml
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
//
|
||||||
|
// Inventory.qml
|
||||||
|
// qml/hifi/commerce
|
||||||
|
//
|
||||||
|
// Inventory
|
||||||
|
//
|
||||||
|
// Created by Zach Fox on 2017-08-10
|
||||||
|
// Copyright 2017 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
import Hifi 1.0 as Hifi
|
||||||
|
import QtQuick 2.5
|
||||||
|
import QtQuick.Controls 1.4
|
||||||
|
import "../../styles-uit"
|
||||||
|
import "../../controls-uit" as HifiControlsUit
|
||||||
|
import "../../controls" as HifiControls
|
||||||
|
|
||||||
|
// references XXX from root context
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
HifiConstants { id: hifi; }
|
||||||
|
|
||||||
|
id: inventoryRoot;
|
||||||
|
property string referrerURL: "";
|
||||||
|
// Style
|
||||||
|
color: hifi.colors.baseGray;
|
||||||
|
Hifi.QmlCommerce {
|
||||||
|
id: commerce;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// TITLE BAR START
|
||||||
|
//
|
||||||
|
Item {
|
||||||
|
id: titleBarContainer;
|
||||||
|
// Size
|
||||||
|
width: inventoryRoot.width;
|
||||||
|
height: 50;
|
||||||
|
// Anchors
|
||||||
|
anchors.left: parent.left;
|
||||||
|
anchors.top: parent.top;
|
||||||
|
|
||||||
|
// Title Bar text
|
||||||
|
RalewaySemiBold {
|
||||||
|
id: titleBarText;
|
||||||
|
text: "Inventory";
|
||||||
|
// Text size
|
||||||
|
size: hifi.fontSizes.overlayTitle;
|
||||||
|
// Anchors
|
||||||
|
anchors.fill: parent;
|
||||||
|
anchors.leftMargin: 16;
|
||||||
|
// Style
|
||||||
|
color: hifi.colors.lightGrayText;
|
||||||
|
// Alignment
|
||||||
|
horizontalAlignment: Text.AlignHLeft;
|
||||||
|
verticalAlignment: Text.AlignVCenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Separator
|
||||||
|
HifiControlsUit.Separator {
|
||||||
|
anchors.left: parent.left;
|
||||||
|
anchors.right: parent.right;
|
||||||
|
anchors.bottom: parent.bottom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// TITLE BAR END
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// HFC BALANCE START
|
||||||
|
//
|
||||||
|
Item {
|
||||||
|
id: hfcBalanceContainer;
|
||||||
|
// Size
|
||||||
|
width: inventoryRoot.width;
|
||||||
|
height: childrenRect.height + 20;
|
||||||
|
// Anchors
|
||||||
|
anchors.left: parent.left;
|
||||||
|
anchors.leftMargin: 16;
|
||||||
|
anchors.top: titleBarContainer.bottom;
|
||||||
|
anchors.topMargin: 4;
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// HFC BALANCE END
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// ACTION BUTTONS START
|
||||||
|
//
|
||||||
|
Item {
|
||||||
|
id: actionButtonsContainer;
|
||||||
|
// Size
|
||||||
|
width: inventoryRoot.width;
|
||||||
|
height: 40;
|
||||||
|
// Anchors
|
||||||
|
anchors.left: parent.left;
|
||||||
|
anchors.top: hfcBalanceContainer.bottom;
|
||||||
|
|
||||||
|
// "Back" button
|
||||||
|
HifiControlsUit.Button {
|
||||||
|
id: backButton;
|
||||||
|
color: hifi.buttons.black;
|
||||||
|
colorScheme: hifi.colorSchemes.dark;
|
||||||
|
anchors.top: parent.top;
|
||||||
|
anchors.topMargin: 3;
|
||||||
|
anchors.bottom: parent.bottom;
|
||||||
|
anchors.bottomMargin: 3;
|
||||||
|
anchors.left: parent.left;
|
||||||
|
anchors.leftMargin: 20;
|
||||||
|
width: parent.width/2 - anchors.leftMargin*2;
|
||||||
|
text: "Back"
|
||||||
|
onClicked: {
|
||||||
|
sendToScript({method: 'inventory_backClicked', referrerURL: referrerURL});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// ACTION BUTTONS END
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// FUNCTION DEFINITIONS START
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Function Name: fromScript()
|
||||||
|
//
|
||||||
|
// Relevant Variables:
|
||||||
|
// None
|
||||||
|
//
|
||||||
|
// Arguments:
|
||||||
|
// message: The message sent from the JavaScript, in this case the Marketplaces JavaScript.
|
||||||
|
// Messages are in format "{method, params}", like json-rpc.
|
||||||
|
//
|
||||||
|
// Description:
|
||||||
|
// Called when a message is received from a script.
|
||||||
|
//
|
||||||
|
function fromScript(message) {
|
||||||
|
switch (message.method) {
|
||||||
|
case 'updateInventory':
|
||||||
|
referrerURL = message.referrerURL;
|
||||||
|
hfcBalanceText.text = message.hfcBalance;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log('Unrecognized message from marketplaces.js:', JSON.stringify(message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
signal sendToScript(var message);
|
||||||
|
|
||||||
|
//
|
||||||
|
// FUNCTION DEFINITIONS END
|
||||||
|
//
|
||||||
|
}
|
|
@ -89,6 +89,25 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addInventoryButton() {
|
||||||
|
// Why isn't this an id?! This really shouldn't be a class on the website, but it is.
|
||||||
|
var navbarBrandElement = document.getElementsByClassName('navbar-brand')[0];
|
||||||
|
var inventoryElement = document.createElement('a');
|
||||||
|
inventoryElement.classList.add("btn");
|
||||||
|
inventoryElement.classList.add("btn-default");
|
||||||
|
inventoryElement.id = "inventoryButton";
|
||||||
|
inventoryElement.setAttribute('href', "#");
|
||||||
|
inventoryElement.innerHTML = "INVENTORY";
|
||||||
|
inventoryElement.style = "height:100%;margin-top:0;padding:15px 15px;";
|
||||||
|
navbarBrandElement.parentNode.insertAdjacentElement('beforeend', inventoryElement);
|
||||||
|
$('#inventoryButton').on('click', function () {
|
||||||
|
EventBridge.emitWebEvent(JSON.stringify({
|
||||||
|
type: "INVENTORY",
|
||||||
|
referrerURL: window.location.href
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function buyButtonClicked(id, name, author, price, href) {
|
function buyButtonClicked(id, name, author, price, href) {
|
||||||
EventBridge.emitWebEvent(JSON.stringify({
|
EventBridge.emitWebEvent(JSON.stringify({
|
||||||
type: "CHECKOUT",
|
type: "CHECKOUT",
|
||||||
|
@ -134,6 +153,7 @@
|
||||||
// since that doesn't trigger another AJAX request.
|
// since that doesn't trigger another AJAX request.
|
||||||
injectBuyButtonOnMainPage();
|
injectBuyButtonOnMainPage();
|
||||||
}
|
}
|
||||||
|
addInventoryButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectHiFiItemPageCode() {
|
function injectHiFiItemPageCode() {
|
||||||
|
@ -149,6 +169,7 @@
|
||||||
href);
|
href);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
addInventoryButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateClaraCode() {
|
function updateClaraCode() {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html");
|
var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html");
|
||||||
var MARKETPLACES_INJECT_SCRIPT_URL = Script.resolvePath("../html/js/marketplacesInject.js");
|
var MARKETPLACES_INJECT_SCRIPT_URL = Script.resolvePath("../html/js/marketplacesInject.js");
|
||||||
var MARKETPLACE_CHECKOUT_QML_PATH = Script.resourcesPath() + "qml/hifi/commerce/Checkout.qml";
|
var MARKETPLACE_CHECKOUT_QML_PATH = Script.resourcesPath() + "qml/hifi/commerce/Checkout.qml";
|
||||||
|
var MARKETPLACE_INVENTORY_QML_PATH = Script.resourcesPath() + "qml/hifi/commerce/Inventory.qml";
|
||||||
|
|
||||||
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";
|
||||||
// var HOME_BUTTON_TEXTURE = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png";
|
// var HOME_BUTTON_TEXTURE = Script.resourcesPath() + "meshes/tablet-with-home-button.fbx/tablet-with-home-button.fbm/button-root.png";
|
||||||
|
@ -86,7 +87,7 @@
|
||||||
|
|
||||||
function onScreenChanged(type, url) {
|
function onScreenChanged(type, url) {
|
||||||
onMarketplaceScreen = type === "Web" && url === MARKETPLACE_URL_INITIAL;
|
onMarketplaceScreen = type === "Web" && url === MARKETPLACE_URL_INITIAL;
|
||||||
wireEventBridge(type === "QML" && url === MARKETPLACE_CHECKOUT_QML_PATH);
|
wireEventBridge(type === "QML" && (url === MARKETPLACE_CHECKOUT_QML_PATH || url === MARKETPLACE_INVENTORY_QML_PATH));
|
||||||
// for toolbar mode: change button to active when window is first openend, false otherwise.
|
// for toolbar mode: change button to active when window is first openend, false otherwise.
|
||||||
marketplaceButton.editProperties({ isActive: onMarketplaceScreen });
|
marketplaceButton.editProperties({ isActive: onMarketplaceScreen });
|
||||||
if (type === "Web" && url.indexOf(MARKETPLACE_URL) !== -1) {
|
if (type === "Web" && url.indexOf(MARKETPLACE_URL) !== -1) {
|
||||||
|
@ -139,6 +140,13 @@
|
||||||
action: "inspectionModeSetting",
|
action: "inspectionModeSetting",
|
||||||
data: Settings.getValue("inspectionMode", false)
|
data: Settings.getValue("inspectionMode", false)
|
||||||
}));
|
}));
|
||||||
|
} else if (parsedJsonMessage.type === "INVENTORY") {
|
||||||
|
tablet.pushOntoStack(MARKETPLACE_INVENTORY_QML_PATH);
|
||||||
|
tablet.sendToQml({
|
||||||
|
method: 'updateInventory',
|
||||||
|
referrerURL: parsedJsonMessage.referrerURL,
|
||||||
|
hfcBalance: 10
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,17 +207,17 @@
|
||||||
break;
|
break;
|
||||||
case 'checkout_buyClicked':
|
case 'checkout_buyClicked':
|
||||||
if (message.success === true) {
|
if (message.success === true) {
|
||||||
tablet.gotoWebScreen(message.itemHref);
|
tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + message.itemId, MARKETPLACES_INJECT_SCRIPT_URL);
|
||||||
Script.setTimeout(function () {
|
|
||||||
tablet.gotoWebScreen(MARKETPLACE_URL + '/items/' + message.itemId, MARKETPLACES_INJECT_SCRIPT_URL);
|
|
||||||
}, 100);
|
|
||||||
} else {
|
} else {
|
||||||
tablet.sendToQml({ method: 'buyFailed' });
|
tablet.sendToQml({ method: 'buyFailed' });
|
||||||
}
|
}
|
||||||
//tablet.popFromStack();
|
//tablet.popFromStack();
|
||||||
break;
|
break;
|
||||||
|
case 'inventory_backClicked':
|
||||||
|
tablet.gotoWebScreen(message.referrerURL, MARKETPLACES_INJECT_SCRIPT_URL);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print('Unrecognized message from Checkout.qml: ' + JSON.stringify(message));
|
print('Unrecognized message from Checkout.qml or Inventory.qml: ' + JSON.stringify(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue