Frontend:
authorsmaxx
Mon, 23 Aug 2010 19:06:34 +0200
changeset 3760 d30f1ba768d7
parent 3759 f352e9dcf516
child 3761 f96b99f944e6
Frontend: * Added a basic campaign page/selection - just missing missions and real progress (don't count on this being active in 0.9.14)
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/pages.cpp
QTfrontend/pages.h
QTfrontend/ui_hwform.cpp
QTfrontend/ui_hwform.h
--- a/QTfrontend/game.cpp	Mon Aug 23 17:53:02 2010 +0200
+++ b/QTfrontend/game.cpp	Mon Aug 23 19:06:34 2010 +0200
@@ -30,7 +30,7 @@
 
 #include <QTextStream>
 
-QString training; // TODO: Cleaner solution?
+QString training, campaign; // TODO: Cleaner solution?
 
 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) :
   TCPBase(true),
@@ -146,11 +146,21 @@
     QByteArray traincfg;
     HWProto::addStringToBuffer(traincfg, "TL");
 
-    HWProto::addStringToBuffer(traincfg, "escript " + datadir->absolutePath() + "/Missions/Training/" + training + ".lua");
+    HWProto::addStringToBuffer(traincfg, "escript " + training);
 
     RawSendIPC(traincfg);
 }
 
+void HWGame::SendCampaignConfig()
+{
+    QByteArray campaigncfg;
+    HWProto::addStringToBuffer(campaigncfg, "TL");
+
+    HWProto::addStringToBuffer(campaigncfg, "escript " + campaign);
+
+    RawSendIPC(campaigncfg);
+}
+
 void HWGame::SendNetConfig()
 {
     commonConfig();
@@ -182,6 +192,10 @@
                     SendTrainingConfig();
                     break;
                 }
+                case gtCampaign: {
+                    SendCampaignConfig();
+                    break;
+                }
             }
             break;
         }
@@ -343,7 +357,16 @@
 void HWGame::StartTraining(const QString & file)
 {
     gameType = gtTraining;
-    training = file;
+    training = datadir->absolutePath() + "/Missions/Tutorial/" + file + ".lua";
+    demo.clear();
+    Start();
+    SetGameState(gsStarted);
+}
+
+void HWGame::StartCampaign(const QString & file)
+{
+    gameType = gtCampaign;
+    campaign = datadir->absolutePath() + "/Missions/Campaign/" + file + ".lua";
     demo.clear();
     Start();
     SetGameState(gsStarted);
--- a/QTfrontend/game.h	Mon Aug 23 17:53:02 2010 +0200
+++ b/QTfrontend/game.h	Mon Aug 23 19:06:34 2010 +0200
@@ -51,6 +51,7 @@
     void StartQuick();
     void StartNet();
     void StartTraining(const QString & file);
+    void StartCampaign(const QString & file);
 
  protected:
     virtual QStringList setArguments();
@@ -76,7 +77,8 @@
         gtQLocal   = 2,
         gtDemo     = 3,
         gtNet      = 4,
-        gtTraining = 5
+        gtTraining = 5,
+        gtCampaign = 6,
     };
     char msgbuf[MAXMSGCHARS];
     QString teams[5];
@@ -93,6 +95,7 @@
     void SendQuickConfig();
     void SendNetConfig();
     void SendTrainingConfig();
+    void SendCampaignConfig();
     void ParseMessage(const QByteArray & msg);
     void SetGameState(GameState state);
 };
--- a/QTfrontend/hwform.cpp	Mon Aug 23 17:53:02 2010 +0200
+++ b/QTfrontend/hwform.cpp	Mon Aug 23 19:06:34 2010 +0200
@@ -104,6 +104,7 @@
 #endif
 
     UpdateTeamsLists();
+    UpdateCampaignPage(0);
     UpdateWeapons();
 
     connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool)));
@@ -171,6 +172,7 @@
 
     connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame()));
     connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), this, SLOT(GoToTraining()));
+    connect(ui.pageSinglePlayer->BtnCampaignPage, SIGNAL(clicked()), this, SLOT(GoToCampaign()));
     connect(ui.pageSinglePlayer->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer()));
     connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves()));
     connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos()));
@@ -179,6 +181,10 @@
     connect(ui.pageTraining->BtnStartTrain, SIGNAL(clicked()), this, SLOT(StartTraining()));
     connect(ui.pageTraining->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
 
+    connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
+    connect(ui.pageCampaign->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
+    connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
+
     connect(ui.pageSelectWeapon->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
 
     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
@@ -310,13 +316,15 @@
     }
 
     if(teamslist.empty()) {
-        HWTeam defaultTeam("DefaultTeam");
+        HWTeam defaultTeam(tr("DefaultTeam"));
         defaultTeam.SaveToFile();
-        teamslist.push_back("DefaultTeam");
+        teamslist.push_back(tr("DefaultTeam"));
     }
 
     ui.pageOptions->CBTeamName->clear();
     ui.pageOptions->CBTeamName->addItems(teamslist);
+    ui.pageCampaign->CBTeam->clear();
+    ui.pageCampaign->CBTeam->addItems(teamslist);
 }
 
 void HWForm::GoToMain()
@@ -334,6 +342,11 @@
     GoToPage(ID_PAGE_TRAINING);
 }
 
+void HWForm::GoToCampaign()
+{
+    GoToPage(ID_PAGE_CAMPAIGN);
+}
+
 void HWForm::GoToSetup()
 {
     GoToPage(ID_PAGE_SETUP);
@@ -962,7 +975,14 @@
 {
     CreateGame(0, 0, 0);
 
-    game->StartTraining(ui.pageTraining->CBSelect->currentText());
+    game->StartTraining(ui.pageTraining->CBSelect->itemData(ui.pageTraining->CBSelect->currentIndex()).toString());
+}
+
+void HWForm::StartCampaign()
+{
+    CreateGame(0, 0, 0);
+
+    game->StartCampaign(ui.pageCampaign->CBSelect->itemData(ui.pageCampaign->CBSelect->currentIndex()).toString());
 }
 
 void HWForm::CreateNetGame()
@@ -1075,3 +1095,18 @@
         wBackground->move(0, 0);
     }
 }
+
+void HWForm::UpdateCampaignPage(int index)
+{
+    HWTeam team(ui.pageCampaign->CBTeam->currentText());
+    ui.pageCampaign->CBSelect->clear();
+
+    QDir tmpdir;
+    tmpdir.cd(datadir->absolutePath());
+    tmpdir.cd("Missions/Campaign");
+    tmpdir.setFilter(QDir::Files);
+    QStringList entries = tmpdir.entryList(QStringList("*#*.lua"));
+    //entries.sort();
+    for(int i = 0; (i < entries.count()) && (i <= team.CampaignProgress); i++)
+        ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2"), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
+}
--- a/QTfrontend/hwform.h	Mon Aug 23 17:53:02 2010 +0200
+++ b/QTfrontend/hwform.h	Mon Aug 23 19:06:34 2010 +0200
@@ -69,6 +69,7 @@
     void GoToNetType();
     void GoToInfo();
     void GoToTraining();
+    void GoToCampaign();
     void GoToSelectWeapon();
     void GoToSelectWeaponSet(const QString & name);
     void GoToSelectNewWeapon();
@@ -90,6 +91,7 @@
     void SimpleGame();
     void PlayDemo();
     void StartTraining();
+    void StartCampaign();
     void NetConnect();
     void NetConnectServer(const QString & host, quint16 port);
     void NetConnectOfficialServer();
@@ -107,6 +109,7 @@
     void UpdateWeapons();
     void onFrontendFullscreen(bool value);
     void Music(bool checked);
+    void UpdateCampaignPage(int index);
 
     void NetGameChangeStatus(bool isMaster);
     void NetGameMaster();
@@ -143,7 +146,8 @@
         ID_PAGE_CONNECTING      = 15,
         ID_PAGE_SCHEME          = 16,
         ID_PAGE_ADMIN           = 17,
-        ID_PAGE_NETTYPE         = 18
+        ID_PAGE_NETTYPE         = 18,
+        ID_PAGE_CAMPAIGN        = 19
         };
     HWGame * game;
     HWNetServer* pnetserver;
--- a/QTfrontend/pages.cpp	Mon Aug 23 17:53:02 2010 +0200
+++ b/QTfrontend/pages.cpp	Mon Aug 23 19:06:34 2010 +0200
@@ -924,7 +924,10 @@
     topLine->addStretch();
 
 
-    BtnTrainPage = addButton(":/res/Trainings.png", middleLine, 0, true);
+    BtnCampaignPage = addButton(":/res/SimpleGame.png", middleLine, 0, true);
+    BtnCampaignPage->setToolTip(tr("Campaign Mode (...). IN DEVELOPMENT"));
+
+    BtnTrainPage = addButton(":/res/Trainings.png", middleLine, 1, true);
     BtnTrainPage->setToolTip(tr("Training Mode (Practice your skills in a range of training missions). IN DEVELOPMENT"));
 
     BtnBack = addButton(":/res/Exit.png", bottomLine, 0, true);
@@ -955,6 +958,8 @@
     tmpdir.cd("Missions/Training");
     tmpdir.setFilter(QDir::Files);
     CBSelect->addItems(tmpdir.entryList(QStringList("*.lua")).replaceInStrings(QRegExp("^(.*)\\.lua"), "\\1"));
+    for(int i = 0; i < CBSelect->count(); i++)
+        CBSelect->setItemData(i, CBSelect->itemText(i));
 
     pageLayout->addWidget(CBSelect, 1, 1);
     
@@ -966,6 +971,29 @@
     BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true);
 }
 
+PageCampaign::PageCampaign(QWidget* parent) : AbstractPage(parent)
+{
+    QGridLayout * pageLayout = new QGridLayout(this);
+    pageLayout->setColumnStretch(0, 1);
+    pageLayout->setColumnStretch(1, 2);
+    pageLayout->setColumnStretch(2, 1);
+    pageLayout->setRowStretch(0, 1);
+    pageLayout->setRowStretch(3, 1);
+
+    CBSelect = new QComboBox(this);
+    CBTeam = new QComboBox(this);
+
+    pageLayout->addWidget(CBTeam, 1, 1);
+    pageLayout->addWidget(CBSelect, 2, 1);
+    
+    BtnStartCampaign = new QPushButton(this);
+    BtnStartCampaign->setFont(*font14);
+    BtnStartCampaign->setText(QPushButton::tr("Go!"));
+    pageLayout->addWidget(BtnStartCampaign, 2, 2);
+
+    BtnBack = addButton(":/res/Exit.png", pageLayout, 4, 0, true);
+}
+
 PageSelectWeapon::PageSelectWeapon(QWidget* parent) :
   AbstractPage(parent)
 {
--- a/QTfrontend/pages.h	Mon Aug 23 17:53:02 2010 +0200
+++ b/QTfrontend/pages.h	Mon Aug 23 19:06:34 2010 +0200
@@ -334,6 +334,7 @@
 
     QPushButton *BtnSimpleGamePage;
     QPushButton *BtnTrainPage;
+    QPushButton *BtnCampaignPage;
     QPushButton *BtnMultiplayer;
     QPushButton *BtnLoad;
     QPushButton *BtnDemos;
@@ -353,6 +354,19 @@
     QComboBox   *CBSelect;
 };
 
+class PageCampaign : public AbstractPage
+{
+    Q_OBJECT
+
+public:
+    PageCampaign(QWidget* parent = 0);
+
+    QPushButton *BtnStartCampaign;
+    QPushButton *BtnBack;
+    QComboBox   *CBSelect;
+    QComboBox   *CBTeam;
+};
+
 class PageSelectWeapon : public AbstractPage
 {
     Q_OBJECT
--- a/QTfrontend/ui_hwform.cpp	Mon Aug 23 17:53:02 2010 +0200
+++ b/QTfrontend/ui_hwform.cpp	Mon Aug 23 19:06:34 2010 +0200
@@ -113,4 +113,7 @@
 
     pageNetType = new PageNetType();
     Pages->addWidget(pageNetType);
+
+    pageCampaign = new PageCampaign();
+    Pages->addWidget(pageCampaign);
 }
--- a/QTfrontend/ui_hwform.h	Mon Aug 23 17:53:02 2010 +0200
+++ b/QTfrontend/ui_hwform.h	Mon Aug 23 19:06:34 2010 +0200
@@ -32,6 +32,7 @@
 class PageGameStats;
 class PageSinglePlayer;
 class PageTraining;
+class PageCampaign;
 class PageSelectWeapon;
 class PageInGame;
 class PageRoomsList;
@@ -70,6 +71,7 @@
     PageScheme *pageScheme;
     PageAdmin *pageAdmin;
     PageNetType *pageNetType;
+    PageCampaign *pageCampaign;
 
     QStackedLayout *Pages;
     QFont *font14;