Improve rendering of empty cards in tableau columns
This commit is contained in:
parent
70be6491a3
commit
511ca3744a
|
@ -3,38 +3,73 @@ import Solitare
|
||||||
|
|
||||||
// In solitare, Tableau refers to the part of the board where all of the columns are placed
|
// In solitare, Tableau refers to the part of the board where all of the columns are placed
|
||||||
Row {
|
Row {
|
||||||
|
id: tableau
|
||||||
spacing: 10
|
spacing: 10
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
|
id: colRepeater
|
||||||
model: GameState.columns.length
|
model: GameState.columns.length
|
||||||
|
|
||||||
delegate: Column {
|
delegate: Column {
|
||||||
required property int index // passed from repeater
|
required property int index // passed from repeater
|
||||||
|
|
||||||
spacing: -80 // Overlap
|
onChildrenChanged: {
|
||||||
|
spacing = -(slotRepeater.itemAt(0).height * 0.8); // Overlap
|
||||||
|
}
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
|
id: slotRepeater
|
||||||
model: GameState.columns[parent.index].length > 0 ? GameState.columns[parent.index].length : 1 // Render an empty slot for an empty column
|
model: GameState.columns[parent.index].length > 0 ? GameState.columns[parent.index].length : 1 // Render an empty slot for an empty column
|
||||||
|
|
||||||
delegate: CardModel {
|
delegate: ColumnSlotModel {
|
||||||
required property int index
|
required property int index // passed from repeater
|
||||||
property ColumnSlot col: GameState.columns[parent.index].length > 0 ? GameState.columns[parent.index][index] : null // empty column (single empty slot)
|
cardId: index
|
||||||
|
columnId: parent.index // this is actually passed from the Column, not the Repeater
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
card: col ? col.card : null
|
component ColumnSlotModel: Item {
|
||||||
isFaceDown: col ? !col.revealed : false
|
required property int columnId
|
||||||
onClicked: {
|
required property int cardId
|
||||||
if (col && col.revealed) {
|
property ColumnSlot colSlot: GameState.columns[columnId].length > 0 ? GameState.columns[columnId][cardId] : null
|
||||||
if (GameState.autoMoveColumnCard(parent.index, index)) {
|
|
||||||
if (GameState.isWinnable()) {
|
height: colCard.height
|
||||||
console.log("Still winnable")
|
width: colCard.width
|
||||||
} else {
|
|
||||||
console.log("Game is lost")
|
CardModel {
|
||||||
}
|
id: colCard
|
||||||
}
|
|
||||||
|
anchors.fill: parent
|
||||||
|
visible: parent.colSlot !== null
|
||||||
|
|
||||||
|
card: parent.colSlot ? parent.colSlot.card : null
|
||||||
|
isFaceDown: parent.colSlot ? !parent.colSlot.revealed : false
|
||||||
|
onClicked: {
|
||||||
|
if (parent.colSlot && parent.colSlot.revealed) {
|
||||||
|
if (GameState.autoMoveColumnCard(parent.columnId, parent.cardId)) {
|
||||||
|
if (GameState.isWinnable()) {
|
||||||
|
console.log("Still winnable");
|
||||||
|
} else {
|
||||||
|
console.log("Game is lost");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: emptySlotRect
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
visible: parent.colSlot === null
|
||||||
|
|
||||||
|
color: "gray"
|
||||||
|
border.color: "white"
|
||||||
|
border.width: 2
|
||||||
|
opacity: 0.2
|
||||||
|
radius: 5
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue