From 12b1a429f7af7ae43183177c3241fecd947885ba Mon Sep 17 00:00:00 2001 From: Erik Schilling <ablu.erikschilling@gmail.com> Date: Mon, 16 Mar 2015 19:57:24 +0100 Subject: [PATCH] Added button for buying items Tabbing an item once reveals a button. Tabbing that one will buy one unit of that item. --- example/qml/main/ShopPage.qml | 73 ++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/example/qml/main/ShopPage.qml b/example/qml/main/ShopPage.qml index 36d9623..3564dc9 100644 --- a/example/qml/main/ShopPage.qml +++ b/example/qml/main/ShopPage.qml @@ -1,4 +1,6 @@ import QtQuick 2.0 +import QtQuick.Layouts 1.1 + import Mana 1.0 Item { @@ -9,39 +11,64 @@ Item { model: itemDB.isLoaded ? gameClient.shopListModel : null delegate: MouseArea { + id: item property variant info: itemDB.getInfo(model.itemId) + property bool extended: false anchors.left: parent.left anchors.right: parent.right + anchors.rightMargin: 10 - height: 36 + //height: extended ? 100 : 36 + height: layout.height - Image { - id: itemGraphic - x: 2; y: 2 - // TODO: use imageprovider for this + handling dye - source: resourceManager.dataUrl + resourceManager.itemIconsPrefix + info.image - smooth: false - } + ColumnLayout { + id: layout + anchors.left: parent.left + anchors.right: parent.right - Text { - text: info.name + RowLayout { + anchors.left: parent.left + anchors.right: parent.right + Image { + id: itemGraphic + x: 2; y: 2 + // TODO: use imageprovider for this + handling dye + source: resourceManager.dataUrl + resourceManager.itemIconsPrefix + info.image + smooth: false + } - anchors.left: parent.left - anchors.leftMargin: 2 + 32 + 5 - anchors.verticalCenter: parent.verticalCenter - font.pixelSize: 12 - } + Text { + text: info.name - Text { - text: amount - visible: amount > 0 + Layout.fillWidth: true + font.pixelSize: 12 + } - anchors.right: parent.right - anchors.rightMargin: 4 - anchors.verticalCenter: parent.verticalCenter - font.bold: true - font.pixelSize: 12 + Text { + text: amount + visible: amount > 0 + + font.bold: true + font.pixelSize: 12 + } + } + + BrownButton { + text: "Buy" + visible: item.extended + + Layout.alignment: Qt.AlignHCenter + Layout.preferredWidth: 100 + + onClicked: { + onClicked: gameClient.buySell(model.itemId, 1); + } + } + } + + onClicked: { + extended = !extended; } } }