solitare/qml/DrawPile.qml

86 lines
1.9 KiB
QML

import QtQuick
import Solitare
Item {
id: drawPile
width: drawPileCard.width
height: drawPileCard.height
CardModel {
id: drawPileCard
anchors.fill: parent
visible: GameState.drawPile.length > 0
card: GameState.drawPile.length > 0 ? GameState.drawPile[GameState.drawPile.length - 1] : null
isFaceDown: GameState.drawPile.length > 0 ? true : false
}
Rectangle {
id: emptyPileRect
anchors.fill: parent
visible: GameState.drawPile.length === 0
color: "gray"
border.color: "white"
border.width: 3
opacity: 0.4
radius: 10
Image {
id: flipIcon
anchors.centerIn: parent
visible: GameState.throwawayPile.length > 0
source: "qrc:/img/flip_icon.svg"
width: parent.width * 0.5
height: width
}
}
Rectangle {
id: cardCountBackground
color: "black"
opacity: 0.7
width: cardCountText.width + 8 // 8px padding
height: cardCountText.height + 8 // ^^
visible: drawPileCard.visible
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.margins: 4
radius: 4
z: 1 // Behind the text, but above the card
}
Text {
id: cardCountText
text: GameState.drawPile.length
color: "white"
font.pixelSize: 16
font.bold: true
visible: drawPileCard.visible
anchors.centerIn: cardCountBackground
z: 2
}
MouseArea {
anchors.fill: parent
onClicked: {
if (GameState.drawNextCard()) {
if (GameState.isWinnable()) {
console.log("Still winnable");
} else {
console.warn("Game is lost");
}
}
}
}
}