QTfrontend/hwform.cpp
changeset 7411 efc75c2d3be9
parent 7313 162bc562335b
parent 7245 53f73f4ae203
child 7490 c422845b8d1f
--- a/QTfrontend/hwform.cpp	Fri Jul 20 18:48:04 2012 -0400
+++ b/QTfrontend/hwform.cpp	Thu Aug 30 12:13:24 2012 -0400
@@ -51,6 +51,7 @@
 #include "hwform.h"
 #include "game.h"
 #include "team.h"
+#include "campaign.h"
 #include "teamselect.h"
 #include "selectWeapon.h"
 #include "gameuiconfig.h"
@@ -162,6 +163,7 @@
 #endif
 
     UpdateTeamsLists();
+    InitCampaignPage();
     UpdateCampaignPage(0);
     UpdateWeapons();
 
@@ -273,6 +275,7 @@
 
     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
+    connect(ui.pageCampaign->CBCampaign, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
 
 
     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
@@ -1354,6 +1357,7 @@
 void HWForm::CreateGame(GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget, QString ammo)
 {
     game = new HWGame(config, gamecfg, ammo, pTeamSelWidget);
+    connect(game, SIGNAL(CampStateChanged(int)), this, SLOT(UpdateCampaignPageProgress(int)));
     connect(game, SIGNAL(GameStateChanged(GameState)), this, SLOT(GameStateChanged(GameState)));
     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
@@ -1418,7 +1422,13 @@
 {
     CreateGame(0, 0, 0);
 
-    game->StartCampaign(ui.pageCampaign->CBSelect->itemData(ui.pageCampaign->CBSelect->currentIndex()).toString());
+    QComboBox *combo = ui.pageCampaign->CBMission;
+    QString camp = ui.pageCampaign->CBCampaign->currentText();
+    unsigned int mNum = combo->count() - combo->currentIndex();
+    QString miss = getCampaignScript(camp, mNum);
+    QString campTeam = ui.pageCampaign->CBTeam->currentText();
+
+    game->StartCampaign(camp, miss, campTeam);
 }
 
 void HWForm::CreateNetGame()
@@ -1544,24 +1554,49 @@
     }
 }
 
+void HWForm::InitCampaignPage()
+{
+    ui.pageCampaign->CBCampaign->clear();
+    HWTeam team(ui.pageCampaign->CBTeam->currentText());
+
+    QStringList entries = DataManager::instance().entryList(
+                                  "Missions/Campaign",
+                                  QDir::Dirs,
+                                  QStringList("[^\\.]*")
+                              );
+
+    unsigned int n = entries.count();
+    for(unsigned int i = 0; i < n; i++)
+    {
+        ui.pageCampaign->CBCampaign->addItem(QString(entries[i]), QString(entries[i]));
+    }
+}
+
+
 void HWForm::UpdateCampaignPage(int index)
 {
     Q_UNUSED(index);
 
     HWTeam team(ui.pageCampaign->CBTeam->currentText());
-    ui.pageCampaign->CBSelect->clear();
+    ui.pageCampaign->CBMission->clear();
+
+    QString campaignName = ui.pageCampaign->CBCampaign->currentText();
+    QStringList missionEntries = getCampMissionList(campaignName);
+    QString tName = team.name();
+    unsigned int n = missionEntries.count();
+    unsigned int m = getCampProgress(tName, campaignName);
 
-    QStringList entries = DataManager::instance().entryList(
-                              "Missions/Campaign",
-                              QDir::Files,
-                              QStringList("*#*.lua")
-                          );
+    for (unsigned int i = min(m + 1, n); i > 0; i--)
+    {
+        ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1]));
+    }
+}
 
-    unsigned int n = entries.count();
-    for(unsigned int i = 0; (i < n) && (i <= team.campaignProgress()); i++)
-    {
-        ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
-    }
+void HWForm::UpdatecampaignPageProgress(int index)
+{
+  int missionIndex = ui.pageCampaign->CBMission->currentIndex();
+  UpdateCampaignPage(0);
+  ui.pageCampaign->CBMission->setCurrentIndex(missionIndex);
 }
 
 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]