--- a/QTfrontend/hwform.cpp Sun Jun 16 00:46:11 2013 +0400
+++ b/QTfrontend/hwform.cpp Mon Jun 17 16:56:58 2013 +0200
@@ -102,7 +102,7 @@
#include "DataManager.h"
#include "AutoUpdater.h"
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
#define WINVER 0x0500
#include <windows.h>
#else
@@ -110,7 +110,7 @@
#include <sys/types.h>
#endif
-#ifdef Q_WS_MAC
+#ifdef Q_OS_MAC
#include <sys/sysctl.h>
#endif
@@ -194,6 +194,8 @@
//connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
#endif
+ previousCampaignName = "";
+ previousTeamName = "";
UpdateTeamsLists();
InitCampaignPage();
UpdateCampaignPage(0);
@@ -306,7 +308,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.pageCampaign->CBMission, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPageMission(int)));
connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first
@@ -1892,7 +1894,7 @@
void HWForm::UpdateCampaignPage(int index)
{
Q_UNUSED(index);
-
+
HWTeam team(ui.pageCampaign->CBTeam->currentText());
ui.pageCampaign->CBMission->clear();
@@ -1901,11 +1903,73 @@
QString tName = team.name();
unsigned int n = missionEntries.count();
unsigned int m = getCampProgress(tName, campaignName);
+
+ // if the campaign name changes update the campaignMissionDescriptions list
+ // this will be used later in UpdateCampaignPageMission() to update
+ // the mission description in the campaign page
+ bool updateMissionList = false;
+ QSettings * m_info;
+ if(previousCampaignName.compare(campaignName)!=0 ||
+ previousTeamName.compare(tName) != 0)
+ {
+ if (previousTeamName.compare(tName) != 0 &&
+ previousTeamName.compare("") != 0)
+ index = qMin(m + 1, n);
+ previousCampaignName = campaignName;
+ previousTeamName = tName;
+ updateMissionList = true;
+ // the following code was based on pagetraining.cpp
+ DataManager & dataMgr = DataManager::instance();
+ // get locale
+ QSettings settings(dataMgr.settingsFileName(),
+ QSettings::IniFormat);
+ QString loc = settings.value("misc/locale", "").toString();
+ if (loc.isEmpty())
+ loc = QLocale::system().name();
+ QString campaignDescFile = QString("physfs://Locale/campaigns_" + loc + ".txt");
+ // if file is non-existant try with language only
+ if (!QFile::exists(campaignDescFile))
+ campaignDescFile = QString("physfs://Locale/campaigns_" + loc.remove(QRegExp("_.*$")) + ".txt");
+ // fallback if file for current locale is non-existant
+ if (!QFile::exists(campaignDescFile))
+ campaignDescFile = QString("physfs://Locale/campaigns_en.txt");
+
+ m_info = new QSettings(campaignDescFile, QSettings::IniFormat, this);
+ m_info->setIniCodec("UTF-8");
+ campaignMissionDescriptions.clear();
+ ui.pageCampaign->CBMission->clear();
+ }
+
for (unsigned int i = qMin(m + 1, n); i > 0; i--)
{
- ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1]));
+ if(updateMissionList)
+ {
+ campaignMissionDescriptions += m_info->value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc",
+ tr("No description available")).toString();
+ }
+ ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1]));
}
+ if(updateMissionList)
+ delete m_info;
+
+ UpdateCampaignPageMission(index);
+}
+
+void HWForm::UpdateCampaignPageMission(int index)
+{
+ // update thumbnail
+ QString campaignName = ui.pageCampaign->CBCampaign->currentText();
+ unsigned int mNum = ui.pageCampaign->CBMission->count() - ui.pageCampaign->CBMission->currentIndex();
+ QString image = getCampaignImage(campaignName,mNum);
+ ui.pageCampaign->btnPreview->setIcon(QIcon((":/res/campaign/"+campaignName+"/"+image)));
+ // update description
+ // when campaign changes the UpdateCampaignPageMission is triggered with wrong values
+ // this will cause segfault. This check prevents illegal memory reads
+ if(index > -1 && index < campaignMissionDescriptions.count()) {
+ ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
+ ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]);
+ }
}
void HWForm::UpdateCampaignPageProgress(int index)
@@ -1923,7 +1987,7 @@
QString prefix = "\"" + datadir->absolutePath() + "\"";
QString userPrefix = "\"" + cfgdir->absolutePath() + "\"";
-#ifdef Q_WS_WIN
+#ifdef Q_OS_WIN
prefix = prefix.replace("/","\\");
userPrefix = userPrefix.replace("/","\\");
#endif