Introduced GameDialog for games
Moved out from DialogMsg. Removed Game variant from MsgType enum in DialogMsg.
This commit is contained in:
parent
bdeea864e8
commit
c6aaf88b6f
|
@ -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
|
||||
|
|
|
@ -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 <QPushButton>
|
||||
|
||||
|
@ -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();
|
||||
|
|
|
@ -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 );
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef GAMEDIALOG_H
|
||||
#define GAMEDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
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::GameDialog> ui;
|
||||
};
|
||||
|
||||
#endif // GAMEDIALOG_H
|
|
@ -0,0 +1,198 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GameDialog</class>
|
||||
<widget class="QDialog" name="GameDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>512</width>
|
||||
<height>192</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>512</width>
|
||||
<height>192</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Metropolis</family>
|
||||
<pointsize>13</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normalon>:/logo/logo/logdoctor.svg</normalon>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_Message">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0" rowspan="3">
|
||||
<widget class="QLabel" name="label_Icon">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>92</width>
|
||||
<height>92</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>92</width>
|
||||
<height>92</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="../resources/resources.qrc">:/logo/logo/logdoctor.svg</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="label_Message">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Metropolis</family>
|
||||
<pointsize>13</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="indent">
|
||||
<number>8</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_Title">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Metropolis</family>
|
||||
<pointsize>11</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="indent">
|
||||
<number>8</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_Buttons">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>333</width>
|
||||
<height>27</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="button_Ok">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>96</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>96</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Ok</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../resources/resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "modules/stylesheets.h"
|
||||
|
||||
#include "modules/dialogs/dialogmsg.h"
|
||||
#include "games/game_dialog.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QKeyEvent>
|
||||
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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<int>(type)));
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
enum class MsgType {
|
||||
Info = 0,
|
||||
Warning = 1,
|
||||
Error = 2,
|
||||
Game = 3
|
||||
Error = 2
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue