From 4357e5046b51d9a1168b8a82b0341cd53a9f5bf5 Mon Sep 17 00:00:00 2001 From: jbreitwi <josephine.breitwiller@etu.ec-lyon.fr> Date: Mon, 31 Mar 2025 09:50:48 +0200 Subject: [PATCH] popupDialogue finie --- applicationQT2048/CMakeLists.txt | 2 +- applicationQT2048/GamePage.qml | 10 ++++-- applicationQT2048/Main.qml | 4 +-- applicationQT2048/PopupDialogue.qml | 50 +++++++++++++++++++++++++++++ applicationQT2048/gamemanager.cpp | 10 ++++-- applicationQT2048/gamemanager.h | 2 +- applicationQT2048/popupDialogue.qml | 24 -------------- 7 files changed, 69 insertions(+), 33 deletions(-) create mode 100644 applicationQT2048/PopupDialogue.qml delete mode 100644 applicationQT2048/popupDialogue.qml diff --git a/applicationQT2048/CMakeLists.txt b/applicationQT2048/CMakeLists.txt index 39e333f..181e6da 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 04bce11..ddd257b 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 f38b5d4..e00517f 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 0000000..6ccbcdf --- /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 be6a6aa..ba90f22 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 445ffa2..c89791b 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 12adc3c..0000000 --- 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); - } -} -- GitLab