diff --git a/applicationQT2048/CMakeLists.txt b/applicationQT2048/CMakeLists.txt index 39e333f79475e49b689aab25bc8b4379c8bcf8f0..181e6daf06f9774b10bafb0f220d6824141986fc 100644 --- a/applicationQT2048/CMakeLists.txt +++ b/applicationQT2048/CMakeLists.txt @@ -21,7 +21,7 @@ qt_add_qml_module(appapplicationQT2048 SOURCES gamemanager.h gamemanager.cpp SOURCES gamemanager.h gamemanager.cpp QML_FILES Main.qml - QML_FILES popupDialogue.qml + QML_FILES PopupDialogue.qml ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. diff --git a/applicationQT2048/GamePage.qml b/applicationQT2048/GamePage.qml index 04bce111907c30c952aeabc3b3af8b3c97155fd9..ddd257bc80512d19b6efd315265b1580136195a1 100644 --- a/applicationQT2048/GamePage.qml +++ b/applicationQT2048/GamePage.qml @@ -5,6 +5,8 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier id: gamePage focus: true // Active le focus pour capter les événements clavier + + Rectangle { width: 400 height: 600 @@ -34,7 +36,11 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier } - + PopupDialogue{ + id : popup + x : 100 + y : 200 + } Text { @@ -142,7 +148,7 @@ FocusScope { // Permet de capter le focus pour les raccourcis clavier id: buttonMouseArea anchors.fill: parent - onClicked: gameManager.restartGame() + onClicked: popup.open() } } diff --git a/applicationQT2048/Main.qml b/applicationQT2048/Main.qml index f38b5d4be7057eb97fe1e89c2566bd12c34994e9..e00517ffa36af3da06835350b2ca1aa08124b2c5 100644 --- a/applicationQT2048/Main.qml +++ b/applicationQT2048/Main.qml @@ -1,5 +1,5 @@ -import QtQuick 2.15 -import QtQuick.Controls 2.15 +import QtQuick +import QtQuick.Controls ApplicationWindow { visible: true diff --git a/applicationQT2048/PopupDialogue.qml b/applicationQT2048/PopupDialogue.qml new file mode 100644 index 0000000000000000000000000000000000000000..6ccbcdfcd7deec9cd38f5aba891fa282d450d87b --- /dev/null +++ b/applicationQT2048/PopupDialogue.qml @@ -0,0 +1,50 @@ +import QtQuick +import QtQuick.Controls + +Popup { + id: partieNameDialogue + width: 250 + height: 150 + modal: true + closePolicy: Popup.CloseOnEscape + onOpened: textInput.text = "" + + Column { + spacing: 10 + width: parent.width + padding: 10 + + Label { + text: "Pour enregistrer la partie précédente, entrez un nom pour la partie.\nSi vous ne souhaitez pas enregistrer, appuyez sur Annuler." + wrapMode: Text.Wrap + width: parent.width + } + + TextField { + id: textInput + width: parent.width + placeholderText: "Ex: Partie 1" + } + + Row { + spacing: 10 + width: parent.width + + Button { + text: "OK" + onClicked: { + gameManager.restartGame(textInput.text); + partieNameDialogue.close(); + } + } + + Button { + text: "Annuler" + onClicked: { + gameManager.restartGame("false"); + partieNameDialogue.close(); + } + } + } + } +} diff --git a/applicationQT2048/gamemanager.cpp b/applicationQT2048/gamemanager.cpp index be6a6aaf828402e45102b0ba2744ae91badd4846..ba90f22f8cf22bb6e5021b2a4c266692babcd0f0 100644 --- a/applicationQT2048/gamemanager.cpp +++ b/applicationQT2048/gamemanager.cpp @@ -1,7 +1,6 @@ #include "gamemanager.h" #include "random" #include <QFileInfo> - #include <QDebug> GameManager::GameManager(QObject *parent) : QObject(parent), grid(4, std::vector<int>(4, 0)) { @@ -184,11 +183,14 @@ void GameManager::moveDown() { } -void GameManager::restartGame() { +void GameManager::restartGame(QString partieName) { //demander pour sauvergarder la partie précédente - enregistrerPartie("partie1"); + if(partieName=="false"){ + }else{ + enregistrerPartie(partieName); + }; // Réinitialisation des variables @@ -383,3 +385,5 @@ void GameManager::chargerPartie(QString partieName){ } + + diff --git a/applicationQT2048/gamemanager.h b/applicationQT2048/gamemanager.h index 445ffa2e3b7992049275727147459b1724eaa4af..c89791b34aa28266b26f5c86b70c3d81848ba5b5 100644 --- a/applicationQT2048/gamemanager.h +++ b/applicationQT2048/gamemanager.h @@ -23,7 +23,7 @@ public: Q_INVOKABLE void moveRight(); Q_INVOKABLE void moveUp(); Q_INVOKABLE void moveDown(); - Q_INVOKABLE void restartGame(); + Q_INVOKABLE void restartGame(QString partieName); Q_INVOKABLE void undo(); Q_INVOKABLE void chargerPartie(QString partieName); diff --git a/applicationQT2048/popupDialogue.qml b/applicationQT2048/popupDialogue.qml deleted file mode 100644 index 12adc3c6aabbd02ddc03b2d99620630816b105bc..0000000000000000000000000000000000000000 --- a/applicationQT2048/popupDialogue.qml +++ /dev/null @@ -1,24 +0,0 @@ -import QtQuick -import QtQuick.Controls -import QtQuick.Dialogs - -Dialog { - id: partieNameDialogue - title: "Pour enregistrer la partie précédente entrez un nom pour la partie. Si vous ne souhaitez pas enregistrer cette partie appuyer sur Cancel." - modal: true - standardButtons: Dialog.Ok | Dialog.Cancel - - Column { - spacing: 10 - width: parent.width - TextField { - id: textInput - width: parent.width - placeholderText: "Ex: Partie 1" - } - } - - onAccepted: { - gameManager.recupererNomPartie(textInput.text); - } -}