From 981d724ee4aa39b8acf4bfd08c06471beafbd259 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Wed, 4 Dec 2024 19:20:06 +0100 Subject: [PATCH] Move ThrowawayPile to it's own file --- CMakeLists.txt | 1 + Main.qml | 23 +---------------------- ThrowawayPile.qml | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 22 deletions(-) create mode 100644 ThrowawayPile.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f2ab2c..54c2036 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ qt_add_qml_module(appSolitare QML_FILES ScoreBar.qml QML_FILES CardModel.qml QML_FILES Tableau.qml + QML_FILES ThrowawayPile.qml SOURCES playingcard.h playingcard.cpp SOURCES gamestate.h gamestate.cpp SOURCES columnslot.h columnslot.cpp diff --git a/Main.qml b/Main.qml index f2fadaf..b78460f 100644 --- a/Main.qml +++ b/Main.qml @@ -54,28 +54,7 @@ ApplicationWindow { spacing: 20 anchors.right: parent.right - // Throwaway pile (last 3 cards visible with overlap) - Row { - // This allows makes the cards overlap - spacing: -60 - - Repeater { - model: Math.min(GameState.throwawayPile.length, 3) - delegate: CardModel { - required property int index // passed from repeater - property int reversedIndex: Math.min(GameState.throwawayPile.length, 3) - 1 - index; - card: GameState.throwawayPile[GameState.throwawayPile.length - 1 - reversedIndex] - isFaceDown: false - onClicked: { - // Only auto-move the last card in the throwaway pile - // cards below it are shown, but shouldn't have a click effect - if (reversedIndex == 0) { - GameState.autoMoveThrownCard() - } - } - } - } - } + ThrowawayPile {} // Draw pile (only the top card is shown) CardModel { diff --git a/ThrowawayPile.qml b/ThrowawayPile.qml new file mode 100644 index 0000000..f73b750 --- /dev/null +++ b/ThrowawayPile.qml @@ -0,0 +1,25 @@ +import QtQuick + +// The throwaway pile (shows last 3 cards) + +Row { + // This allows makes the cards overlap + spacing: -60 + + Repeater { + model: Math.min(GameState.throwawayPile.length, 3) + delegate: CardModel { + required property int index // passed from repeater + property int reversedIndex: Math.min(GameState.throwawayPile.length, 3) - 1 - index; + card: GameState.throwawayPile[GameState.throwawayPile.length - 1 - reversedIndex] + isFaceDown: false + onClicked: { + // Only auto-move the last card in the throwaway pile + // cards below it are shown, but shouldn't have a click effect + if (reversedIndex == 0) { + GameState.autoMoveThrownCard() + } + } + } + } +}