this seems to work ok, but I have to clean up the code spacecampaign
authorPeriklis Ntanasis <pntanasis@gmail.com>
Fri, 28 Jun 2013 22:06:57 +0300
branchspacecampaign
changeset 9290 478aa681e702
parent 9288 180cab35c9c1
child 9292 187ce630dddc
this seems to work ok, but I have to clean up the code
QTfrontend/campaign.cpp
QTfrontend/campaign.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
--- a/QTfrontend/campaign.cpp	Fri Jun 28 20:14:32 2013 +0300
+++ b/QTfrontend/campaign.cpp	Fri Jun 28 22:06:57 2013 +0300
@@ -77,6 +77,73 @@
 	return missionList;
 }
 
+QList<MissionInfo> getCampMissionList3(QString & campaignName, QString & teamName)
+{    
+	// TODO: add default image if there isn't an available one
+    QList<MissionInfo> missionInfoList;
+	QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
+    teamfile.setIniCodec("UTF-8");
+    unsigned int progress = teamfile.value("Campaign " + campaignName + "/Progress", 0).toInt();
+    qDebug("HERE is progress : %d",progress);
+    unsigned int unlockedMissions = teamfile.value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt();
+    qDebug("HERE is unlocked missions : %d",unlockedMissions);
+    
+    QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0);
+    campfile.setIniCodec("UTF-8");
+    unsigned int missionsNumber = campfile.value("MissionNum", 0).toInt();
+    qDebug("HERE is number of missions : %d",missionsNumber);  
+    
+    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");
+
+        QSettings m_info(campaignDescFile, QSettings::IniFormat, 0);
+        m_info.setIniCodec("UTF-8");
+    
+    if(progress>=0 and unlockedMissions==0)
+    {
+		for(unsigned int i=progress+1;i>0;i--)
+		{
+			MissionInfo missionInfo;
+			missionInfo.name = campfile.value(QString("Mission %1/Name").arg(i)).toString();
+			missionInfo.description = m_info.value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc",
+                                            QObject::tr("No description available")).toString();
+            missionInfo.script = campfile.value(QString("Mission %1/Script").arg(i)).toString();
+            missionInfo.image = campfile.value(QString("Mission %1/Script").arg(i)).toString().replace(QString(".lua"),QString(".png"));
+			missionInfoList.append(missionInfo);
+		}
+	} 
+	else if(unlockedMissions>0)
+	{
+		qDebug("IN HERE !!!");  
+		for(unsigned int i=1;i<=unlockedMissions;i++)
+		{
+			QString missionNum = QString("%1").arg(i);
+			int missionNumber = teamfile.value("Campaign " + campaignName + "/Mission"+missionNum, -1).toInt();
+			MissionInfo missionInfo;
+			missionInfo.name = campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString();
+			missionInfo.description = m_info.value(campaignName+"-"+ getCampaignMissionName(campaignName,missionNumber) + ".desc",
+                                            QObject::tr("No description available")).toString();
+            missionInfo.script = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString();
+            missionInfo.image = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString().replace(QString(".lua"),QString(".png"));
+			missionInfoList.append(missionInfo);
+		}
+	}
+	return missionInfoList;
+}
+
 QStringList getDescriptions(QString & campaignName, QString & teamName)
 {    
     QStringList descriptionList;
--- a/QTfrontend/campaign.h	Fri Jun 28 20:14:32 2013 +0300
+++ b/QTfrontend/campaign.h	Fri Jun 28 22:06:57 2013 +0300
@@ -22,6 +22,15 @@
 #include <QString>
 #include <QStringList>
 
+class MissionInfo
+{
+	public:
+		QString name;
+		QString description;
+		QString script;
+		QString image;
+};
+
 QStringList getCampMissionList(QString & campaign);
 unsigned int getCampProgress(QString & teamName, QString & campName);
 QString getCampaignScript(QString campaign, unsigned int mNum);
@@ -31,5 +40,6 @@
 QStringList getCampMissionList2(QString & campaignName, QString & teamName);
 QStringList getDescriptions(QString & campaignName, QString & teamName);
 QStringList getImages(QString & campaignName, QString & teamName);
+QList<MissionInfo> getCampMissionList3(QString & campaignName, QString & teamName);
 
 #endif
--- a/QTfrontend/hwform.cpp	Fri Jun 28 20:14:32 2013 +0300
+++ b/QTfrontend/hwform.cpp	Fri Jun 28 22:06:57 2013 +0300
@@ -1727,7 +1727,7 @@
     QString camp = ui.pageCampaign->CBCampaign->currentText();
     //unsigned int mNum = combo->count() - combo->currentIndex();
     //QString miss = getCampaignScript(camp, mNum);
-    QString miss = campaignMissionImages[ui.pageCampaign->CBMission->currentIndex()].replace(QString(".png"),QString(".lua"));
+    QString miss = campaignMissionInfo[ui.pageCampaign->CBMission->currentIndex()].script;
     QString campTeam = ui.pageCampaign->CBTeam->currentText();
 
     game->StartCampaign(camp, miss, campTeam);
@@ -1904,6 +1904,8 @@
     QString campaignName = ui.pageCampaign->CBCampaign->currentText();
     QString tName = team.name();
     QStringList missionEntries = getCampMissionList2(campaignName,tName);
+    
+    campaignMissionInfo = getCampMissionList3(campaignName,tName);
 
 	//unlockedMissionsHash = getUnlockedMissions2(campaignName, tName);
     // if the campaign name changes update the campaignMissionDescriptions list
@@ -1916,7 +1918,7 @@
     campaignMissionImages = getImages(campaignName,tName);
     for(int i=0;i<missionEntries.size();i++)
     {
-        ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(missionEntries.size()-i) + QString(missionEntries[i]), QString(missionEntries[i]));
+        ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(campaignMissionInfo.size()-i) + QString(campaignMissionInfo[i].name), QString(campaignMissionInfo[i].name));
 	}
 }
 
@@ -1932,8 +1934,8 @@
     if(index > -1 && index < campaignMissionDescriptions.count()) {
 		qDebug("INSIDE IF *******");
         ui.pageCampaign->lbltitle->setText("<h2>"+ui.pageCampaign->CBMission->currentText()+"</h2>");
-        ui.pageCampaign->lbldescription->setText(campaignMissionDescriptions[index]);
-    ui.pageCampaign->btnPreview->setIcon(QIcon((":/res/campaign/"+campaignName+"/"+campaignMissionImages[index])));
+        ui.pageCampaign->lbldescription->setText(campaignMissionInfo[index].description);
+		ui.pageCampaign->btnPreview->setIcon(QIcon((":/res/campaign/"+campaignName+"/"+campaignMissionInfo[index].image)));
     }
 }
 
--- a/QTfrontend/hwform.h	Fri Jun 28 20:14:32 2013 +0300
+++ b/QTfrontend/hwform.h	Fri Jun 28 22:06:57 2013 +0300
@@ -35,6 +35,7 @@
 #include "ui_hwform.h"
 #include "SDLInteraction.h"
 #include "bgwidget.h"
+#include "campaign.h"
 
 #ifdef __APPLE__
 #include "InstallController.h"
@@ -197,7 +198,8 @@
         QString previousCampaignName;
         QString previousTeamName;
         QStringList campaignMissionDescriptions;
-        QStringList campaignMissionImages;
+        QStringList campaignMissionImages;        
+        QList<MissionInfo> campaignMissionInfo;
         QTime eggTimer;
         BGWidget * wBackground;
         QSignalMapper * pageSwitchMapper;