implementation of a restart-game button. location and appearance is not final :P
authorthunderstruck
Wed, 10 Apr 2013 22:52:38 +0200
changeset 8901 505307b9735d
parent 8899 7493dde4ef51
child 8903 b35752efd5df
implementation of a restart-game button. location and appearance is not final :P
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/ui/page/pagegamestats.cpp
QTfrontend/ui/page/pagegamestats.h
--- a/QTfrontend/game.cpp	Wed Apr 10 22:59:40 2013 +0400
+++ b/QTfrontend/game.cpp	Wed Apr 10 22:52:38 2013 +0200
@@ -38,6 +38,13 @@
 #include <QTextStream>
 #include "ThemeModel.h"
 
+// last game info
+QList<QVariant> lastGameStartArgs = QList<QVariant>();
+GameType lastGameType = gtNone;
+GameCFGWidget * lastGameCfg = NULL;
+QString lastGameAmmo = NULL;
+TeamSelWidget * lastGameTeamSel = NULL;
+
 QString training, campaign, campaignScript, campaignTeam; // TODO: Cleaner solution?
 
 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) :
@@ -48,6 +55,10 @@
     this->config = config;
     this->gamecfg = gamecfg;
     netSuspend = false;
+
+    lastGameCfg = gamecfg;
+    lastGameAmmo = ammo;
+    lastGameTeamSel = pTeamSelWidget;
 }
 
 HWGame::~HWGame()
@@ -228,6 +239,7 @@
                     SendQuickConfig();
                     break;
                 }
+                case gtNone:
                 case gtSave:
                 case gtDemo:
                     break;
@@ -435,6 +447,9 @@
 
 void HWGame::StartLocal()
 {
+    lastGameStartArgs.clear();
+    lastGameType = gtLocal;
+
     gameType = gtLocal;
     demo.clear();
     Start(false);
@@ -443,6 +458,9 @@
 
 void HWGame::StartQuick()
 {
+    lastGameStartArgs.clear();
+    lastGameType = gtQLocal;
+
     gameType = gtQLocal;
     demo.clear();
     Start(false);
@@ -451,6 +469,10 @@
 
 void HWGame::StartTraining(const QString & file)
 {
+    lastGameStartArgs.clear();
+    lastGameStartArgs.append(file);
+    lastGameType = gtTraining;
+
     gameType = gtTraining;
     training = "Missions/Training/" + file + ".lua";
     demo.clear();
@@ -460,6 +482,12 @@
 
 void HWGame::StartCampaign(const QString & camp, const QString & campScript, const QString & campTeam)
 {
+    lastGameStartArgs.clear();
+    lastGameStartArgs.append(camp);
+    lastGameStartArgs.append(campScript);
+    lastGameStartArgs.append(campTeam);
+    lastGameType = gtCampaign;
+
     gameType = gtCampaign;
     campaign = camp;
     campaignScript = "Missions/Campaign/" + camp + "/" + campScript;
--- a/QTfrontend/game.h	Wed Apr 10 22:59:40 2013 +0400
+++ b/QTfrontend/game.h	Wed Apr 10 22:52:38 2013 +0200
@@ -29,6 +29,18 @@
 class GameCFGWidget;
 class TeamSelWidget;
 
+enum GameType
+{
+    gtNone     = 0,
+    gtLocal    = 1,
+    gtQLocal   = 2,
+    gtDemo     = 3,
+    gtNet      = 4,
+    gtTraining = 5,
+    gtCampaign = 6,
+    gtSave     = 7,
+};
+
 enum GameState
 {
     gsNotStarted = 0,
@@ -49,6 +61,13 @@
 
 bool checkForDir(const QString & dir);
 
+// last game info
+extern QList<QVariant> lastGameStartArgs;
+extern GameType lastGameType;
+extern GameCFGWidget * lastGameCfg;
+extern QString lastGameAmmo;
+extern TeamSelWidget * lastGameTeamSel;
+
 class HWGame : public TCPBase
 {
         Q_OBJECT
@@ -86,16 +105,6 @@
         void FromNetChat(const QString & msg);
 
     private:
-        enum GameType
-        {
-            gtLocal    = 1,
-            gtQLocal   = 2,
-            gtDemo     = 3,
-            gtNet      = 4,
-            gtTraining = 5,
-            gtCampaign = 6,
-            gtSave     = 7,
-        };
         char msgbuf[MAXMSGCHARS];
         QString ammostr;
         GameUIConfig * config;
--- a/QTfrontend/hwform.cpp	Wed Apr 10 22:59:40 2013 +0400
+++ b/QTfrontend/hwform.cpp	Wed Apr 10 22:52:38 2013 +0200
@@ -286,6 +286,7 @@
     connect(ui.pageInfo->BtnSnapshots, SIGNAL(clicked()), this, SLOT(OpenSnapshotFolder()));
 
     connect(ui.pageGameStats, SIGNAL(saveDemoRequested()), this, SLOT(saveDemoWithCustomName()));
+    connect(ui.pageGameStats, SIGNAL(restartGameRequested()), this, SLOT(restartGame()));
 
     connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame()));
     connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
@@ -674,6 +675,21 @@
         }
     }
 
+    if (id == ID_PAGE_GAMESTATS)
+    {
+        switch(lastGameType) {
+        case gtLocal:
+        case gtQLocal:
+        case gtTraining:
+        case gtCampaign:
+            ui.pageGameStats->restartBtnVisible(true);
+            break;
+        default:
+            ui.pageGameStats->restartBtnVisible(false);
+            break;
+        }
+    }
+
     if (id == ID_PAGE_MAIN)
     {
         ui.pageOptions->setTeamOptionsEnabled(true);
@@ -2014,6 +2030,31 @@
     }
 }
 
+void HWForm::restartGame()
+{
+    // get rid off old game stats page
+    if(ui.Pages->currentIndex() == ID_PAGE_GAMESTATS)
+        GoBack();
+
+    CreateGame(lastGameCfg, lastGameTeamSel, lastGameAmmo);
+
+    switch(lastGameType) {
+    case gtTraining:
+        game->StartTraining(lastGameStartArgs.at(0).toString());
+        break;
+    case gtQLocal:
+        game->StartQuick();
+        break;
+    case gtCampaign:
+        game->StartCampaign(lastGameStartArgs.at(0).toString(), lastGameStartArgs.at(1).toString(), lastGameStartArgs.at(2).toString());
+        break;
+    case gtLocal:
+        game->StartLocal();
+        break;
+    default:
+        break;
+    }
+}
 
 void HWForm::ShowErrorMessage(const QString & msg)
 {
--- a/QTfrontend/hwform.h	Wed Apr 10 22:59:40 2013 +0400
+++ b/QTfrontend/hwform.h	Wed Apr 10 22:52:38 2013 +0200
@@ -143,6 +143,7 @@
         void openRegistrationPage();
 
         void startGame();
+        void restartGame();
 
     private:
         void _NetConnect(const QString & hostName, quint16 port, QString nick);
--- a/QTfrontend/ui/page/pagegamestats.cpp	Wed Apr 10 22:59:40 2013 +0400
+++ b/QTfrontend/ui/page/pagegamestats.cpp	Wed Apr 10 22:52:38 2013 +0200
@@ -97,10 +97,12 @@
     return pageLayout;
 }
 
+//TODO button placement, image etc
 QLayout * PageGameStats::footerLayoutDefinition()
 {
     QHBoxLayout * bottomLayout = new QHBoxLayout();
 
+    btnRestart = addButton(":/res/Start.png", bottomLayout, 0, true);
     btnSave = addButton(":/res/Save.png", bottomLayout, 0, true);
     btnSave->setStyleSheet("QPushButton{margin: 24px 0 0 0;}");
     bottomLayout->setAlignment(btnSave, Qt::AlignRight | Qt::AlignBottom);
@@ -112,6 +114,7 @@
 {
     connect(this, SIGNAL(pageEnter()), this, SLOT(renderStats()));
     connect(btnSave, SIGNAL(clicked()), this, SIGNAL(saveDemoRequested()));
+    connect(btnRestart, SIGNAL(clicked()), this, SIGNAL(restartGameRequested()));
 }
 
 PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent)
@@ -133,6 +136,11 @@
     lastColor = 0;
 }
 
+void PageGameStats::restartBtnVisible(bool visible)
+{
+    btnRestart->setVisible(visible);
+}
+
 void PageGameStats::renderStats()
 {
     QGraphicsScene * scene = new QGraphicsScene();
--- a/QTfrontend/ui/page/pagegamestats.h	Wed Apr 10 22:59:40 2013 +0400
+++ b/QTfrontend/ui/page/pagegamestats.h	Wed Apr 10 22:52:38 2013 +0200
@@ -44,6 +44,7 @@
         PageGameStats(QWidget* parent = 0);
 
         QPushButton *btnSave;
+        QPushButton *btnRestart;
         QLabel *labelGameStats;
         QLabel *labelGameWin;
         QLabel *labelGameRank;
@@ -53,9 +54,11 @@
         void GameStats(char type, const QString & info);
         void clear();
         void renderStats();
+        void restartBtnVisible(bool visible);
 
     signals:
         void saveDemoRequested();
+        void restartGameRequested();
 
     private:
         void AddStatText(const QString & msg);