From c6aaf88b6ff51d200e5dd2ff3f6a608a476cc33b Mon Sep 17 00:00:00 2001 From: Valentino Orlandi Date: Sun, 10 Sep 2023 16:22:27 +0200 Subject: [PATCH] Introduced GameDialog for games Moved out from DialogMsg. Removed Game variant from MsgType enum in DialogMsg. --- logdoctor/CMakeLists.txt | 3 + logdoctor/games/crisscross/game.cpp | 17 +- logdoctor/games/game_dialog.cpp | 23 +++ logdoctor/games/game_dialog.h | 38 +++++ logdoctor/games/game_dialog.ui | 198 ++++++++++++++++++++++++ logdoctor/games/snake/game.cpp | 8 +- logdoctor/modules/dialogs/dialogmsg.cpp | 3 - logdoctor/modules/dialogs/dialogmsg.h | 3 +- 8 files changed, 273 insertions(+), 20 deletions(-) create mode 100644 logdoctor/games/game_dialog.cpp create mode 100644 logdoctor/games/game_dialog.h create mode 100644 logdoctor/games/game_dialog.ui diff --git a/logdoctor/CMakeLists.txt b/logdoctor/CMakeLists.txt index 8d751ea7..4f769600 100644 --- a/logdoctor/CMakeLists.txt +++ b/logdoctor/CMakeLists.txt @@ -130,6 +130,9 @@ set(PROJECT_SOURCES tools/crapnote/crapnote.h tools/crapnote/crapnote.cpp + games/game_dialog.ui + games/game_dialog.h + games/game_dialog.cpp games/crisscross/crisscross.ui games/crisscross/game.h games/crisscross/game.cpp diff --git a/logdoctor/games/crisscross/game.cpp b/logdoctor/games/crisscross/game.cpp index 0e0254a2..280b3f4b 100644 --- a/logdoctor/games/crisscross/game.cpp +++ b/logdoctor/games/crisscross/game.cpp @@ -4,9 +4,9 @@ #include "globals/global_configs.h" -#include "modules/stylesheets.h" +#include "games/game_dialog.h" -#include "modules/dialogs/dialogmsg.h" +#include "modules/stylesheets.h" #include @@ -227,20 +227,19 @@ void CrissCross::victory() } // display a dialog - QString message; + QString title, message; if ( (this->p_turn == 1 && this->p1_human) || (this->p_turn == 2 && this->p2_human) ) { // user won + title = CrissCross::tr("Victory"); message = CrissCross::tr("You beated me!"); } else { // AI won message = CrissCross::tr("This time you lost!"); } - DialogMsg dialog( - CrissCross::tr("Victory"), + GameDialog dialog( + title, message, - "", - MsgType::Game, this ); std::ignore = dialog.exec(); @@ -271,11 +270,9 @@ void CrissCross::draw() } // display a dialog - DialogMsg dialog( + GameDialog dialog( CrissCross::tr("Draw"), CrissCross::tr("Nice match"), - "", - MsgType::Game, this ); std::ignore = dialog.exec(); diff --git a/logdoctor/games/game_dialog.cpp b/logdoctor/games/game_dialog.cpp new file mode 100644 index 00000000..fd0eeeb3 --- /dev/null +++ b/logdoctor/games/game_dialog.cpp @@ -0,0 +1,23 @@ + +#include "game_dialog.h" +#include "ui_game_dialog.h" + + +GameDialog::GameDialog(const QString& title, const QString& text, QWidget* parent ) + : QDialog{ parent } + , ui{ new Ui::GameDialog } +{ + ui->setupUi(this); + + // insert the given text + this->ui->label_Title->setText( title ); + this->ui->label_Message->setText( text ); + + // adjust the initial size + this->adjustSize(); +} + +void GameDialog::on_button_Ok_clicked() +{ + this->done( 1 ); +} diff --git a/logdoctor/games/game_dialog.h b/logdoctor/games/game_dialog.h new file mode 100644 index 00000000..6687b797 --- /dev/null +++ b/logdoctor/games/game_dialog.h @@ -0,0 +1,38 @@ +#ifndef GAMEDIALOG_H +#define GAMEDIALOG_H + +#include + + +namespace Ui { + class GameDialog; +} + +//! GameDialog +/*! + A dialog message to provide informations to the user +*/ +class GameDialog : public QDialog +{ + Q_OBJECT + +public: + + //! Dialog constructor + /*! + \param title The title + \param text The message + \param parent The parent Widget + */ + explicit GameDialog( const QString& title, const QString& text, QWidget *parent=nullptr ); + +private slots: + + //! Called when the OK button gets clicked + void on_button_Ok_clicked(); + +private: + QSharedPointer ui; +}; + +#endif // GAMEDIALOG_H diff --git a/logdoctor/games/game_dialog.ui b/logdoctor/games/game_dialog.ui new file mode 100644 index 00000000..3f35c08b --- /dev/null +++ b/logdoctor/games/game_dialog.ui @@ -0,0 +1,198 @@ + + + GameDialog + + + + 0 + 0 + 512 + 192 + + + + + 512 + 192 + + + + + Metropolis + 13 + + + + + :/logo/logo/logdoctor.svg + + + + true + + + + + + + 0 + 0 + + + + + 0 + + + 0 + + + + + + 92 + 92 + + + + + 92 + 92 + + + + :/logo/logo/logdoctor.svg + + + true + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 0 + 32 + + + + + Metropolis + 13 + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + 8 + + + + + + + + 0 + 32 + + + + + 16777215 + 32 + + + + + Metropolis + 11 + + + + + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + true + + + 8 + + + + + + + + + + + 0 + 48 + + + + + 16777215 + 48 + + + + + + + Qt::Horizontal + + + + 333 + 27 + + + + + + + + + 96 + 32 + + + + + 96 + 32 + + + + Ok + + + + + + + + + + + + + diff --git a/logdoctor/games/snake/game.cpp b/logdoctor/games/snake/game.cpp index 4bdbc54f..dc556486 100644 --- a/logdoctor/games/snake/game.cpp +++ b/logdoctor/games/snake/game.cpp @@ -4,7 +4,7 @@ #include "modules/stylesheets.h" -#include "modules/dialogs/dialogmsg.h" +#include "games/game_dialog.h" #include #include @@ -234,13 +234,11 @@ void SnakeGame::processGameLogic() if ( game_over ) { this->game_loop->stop(); this->playing &= false; - DialogMsg dialog( + GameDialog dialog( SnakeGame::tr("Game Over"), this->game_over_msg, - "", - MsgType::Game, this - ); + ); std::ignore = dialog.exec(); } else { diff --git a/logdoctor/modules/dialogs/dialogmsg.cpp b/logdoctor/modules/dialogs/dialogmsg.cpp index 8b3f996c..8242f00b 100644 --- a/logdoctor/modules/dialogs/dialogmsg.cpp +++ b/logdoctor/modules/dialogs/dialogmsg.cpp @@ -26,9 +26,6 @@ DialogMsg::DialogMsg(const QString& title, const QString& text, const QString& a case MsgType::Error: this->ui->label_Icon->setPixmap( QPixmap(":/icons/icons/dialogs/err.png") ); break; - case MsgType::Game: - this->ui->label_Icon->setPixmap( QPixmap(":/logo/logo/logdoctor.svg").scaled( QSize(64,64) ) ); - break; default: // shouldn't be here throw GenericException("Unexpected dialog type: "+ std::to_string(static_cast(type))); diff --git a/logdoctor/modules/dialogs/dialogmsg.h b/logdoctor/modules/dialogs/dialogmsg.h index 92b65267..2bf88a1a 100644 --- a/logdoctor/modules/dialogs/dialogmsg.h +++ b/logdoctor/modules/dialogs/dialogmsg.h @@ -7,8 +7,7 @@ enum class MsgType { Info = 0, Warning = 1, - Error = 2, - Game = 3 + Error = 2 };