QTfrontend/campaign.cpp
branchspacecampaign
changeset 9278 33a30ce9782f
parent 9275 3df990e2ee0e
child 9284 13b76fa362b4
--- a/QTfrontend/campaign.cpp	Fri Jun 28 15:45:11 2013 +0300
+++ b/QTfrontend/campaign.cpp	Fri Jun 28 18:55:01 2013 +0300
@@ -18,9 +18,11 @@
 
 #include "campaign.h"
 #include "hwconsts.h"
+#include "DataManager.h"
 #include <QSettings>
 #include <QMap>
 #include <QDebug>
+#include <QObject>
 
 QStringList getCampMissionList(QString & campaign)
 {
@@ -75,6 +77,63 @@
 	return missionList;
 }
 
+QStringList getDescriptions(QString & campaignName, QString & teamName)
+{    
+    QStringList descriptionList;
+	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--)
+		{
+			//update descruiptions here
+			descriptionList += m_info.value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc",
+                                            QObject::tr("No description available")).toString();
+		}
+	} 
+	else if(unlockedMissions>0)
+	{
+		qDebug("IN HERE !!!");  
+		for(unsigned int i=1;i<=unlockedMissions;i++)
+		{
+			QString missionNum = QString("%1").arg(i);
+			descriptionList += m_info.value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc",
+                                            QObject::tr("No description available")).toString();
+		}
+	}
+	return descriptionList;
+}
+
 unsigned int getCampProgress(QString & teamName, QString & campName)
 {
     QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);