solitare/qml/DrawPile.qml

86 lines
1.9 KiB
QML
Raw Normal View History

2024-12-04 18:22:20 +00:00
import QtQuick
2024-12-05 00:22:18 +00:00
import Solitare
2024-12-04 18:22:20 +00:00
2024-12-07 21:16:37 +00:00
Item {
id: drawPile
width: drawPileCard.width
height: drawPileCard.height
CardModel {
id: drawPileCard
2024-12-07 22:10:16 +00:00
2024-12-07 21:16:37 +00:00
anchors.fill: parent
2024-12-07 22:10:16 +00:00
visible: GameState.drawPile.length > 0
2024-12-07 21:16:37 +00:00
card: GameState.drawPile.length > 0 ? GameState.drawPile[GameState.drawPile.length - 1] : null
isFaceDown: GameState.drawPile.length > 0 ? true : false
2024-12-07 22:10:16 +00:00
}
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
2024-12-06 03:55:48 +00:00
}
2024-12-07 21:16:37 +00:00
}
Rectangle {
id: cardCountBackground
color: "black"
opacity: 0.7
2024-12-07 22:10:16 +00:00
width: cardCountText.width + 8 // 8px padding
height: cardCountText.height + 8 // ^^
2024-12-07 21:16:37 +00:00
2024-12-07 22:10:16 +00:00
visible: drawPileCard.visible
2024-12-07 21:16:37 +00:00
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.margins: 4
2024-12-07 22:10:16 +00:00
radius: 4
2024-12-07 21:16:37 +00:00
z: 1 // Behind the text, but above the card
}
Text {
2024-12-07 22:10:16 +00:00
id: cardCountText
2024-12-07 21:16:37 +00:00
text: GameState.drawPile.length
color: "white"
font.pixelSize: 16
font.bold: true
2024-12-07 22:10:16 +00:00
visible: drawPileCard.visible
2024-12-07 21:16:37 +00:00
anchors.centerIn: cardCountBackground
z: 2
2024-12-04 18:22:20 +00:00
}
2024-12-07 22:10:16 +00:00
MouseArea {
anchors.fill: parent
onClicked: {
if (GameState.drawNextCard()) {
if (GameState.isWinnable()) {
console.log("Still winnable");
} else {
console.warn("Game is lost");
}
}
}
}
2024-12-04 18:22:20 +00:00
}