more on campaign page - wip spacecampaign
authorPeriklis Ntanasis <pntanasis@gmail.com>
Fri, 28 Jun 2013 15:45:11 +0300
branchspacecampaign
changeset 9275 3df990e2ee0e
parent 9272 6fa30e491b37
child 9278 33a30ce9782f
more on campaign page - wip
QTfrontend/campaign.cpp
QTfrontend/campaign.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
share/hedgewars/Data/Missions/Campaign/A Space Adventure/campaign.ini
--- a/QTfrontend/campaign.cpp	Fri Jun 28 02:38:56 2013 +0300
+++ b/QTfrontend/campaign.cpp	Fri Jun 28 15:45:11 2013 +0300
@@ -19,7 +19,7 @@
 #include "campaign.h"
 #include "hwconsts.h"
 #include <QSettings>
-#include <QHash>
+#include <QMap>
 #include <QDebug>
 
 QStringList getCampMissionList(QString & campaign)
@@ -36,16 +36,10 @@
     return missionList;
 }
 
-unsigned int getCampProgress(QString & teamName, QString & campName)
-{
-    QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
-    teamfile.setIniCodec("UTF-8");
-    return teamfile.value("Campaign " + campName + "/Progress", 0).toInt();
-}
-
-QHash<QString,QString> getUnlockedMissions2(QString & campaignName, QString & teamName)
-{
-	QHash<QString,QString> hash;
+// works ok
+QStringList getCampMissionList2(QString & campaignName, QString & teamName)
+{    
+    QStringList missionList;
 	QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
     teamfile.setIniCodec("UTF-8");
     unsigned int progress = teamfile.value("Campaign " + campaignName + "/Progress", 0).toInt();
@@ -58,9 +52,54 @@
     unsigned int missionsNumber = campfile.value("MissionNum", 0).toInt();
     qDebug("HERE is number of missions : %d",missionsNumber);  
     
-    if(progress>0)
+    if(progress>=0 and unlockedMissions==0)
     {
-		for(unsigned int i=1;i<=missionsNumber;i++)
+		for(unsigned int i=progress+1;i>0;i--)
+		{
+			missionList += campfile.value(QString("Mission %1/Name").arg(i)).toString();
+		}
+	} 
+	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();
+			qDebug("Campaign %s Mission %d",campaignName.toUtf8().constData(),i);  
+			qDebug("MISSION NUMBER : %d",missionNumber);  
+			missionList += campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString();
+			qDebug(campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString().toUtf8().constData());
+		}
+	}
+	return missionList;
+}
+
+unsigned int getCampProgress(QString & teamName, QString & campName)
+{
+    QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
+    teamfile.setIniCodec("UTF-8");
+    return teamfile.value("Campaign " + campName + "/Progress", 0).toInt();
+}
+
+QMap<QString,QString> getUnlockedMissions2(QString & campaignName, QString & teamName)
+{
+	QMap<QString,QString> hash;
+	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);  
+    
+    if(progress>=0 and unlockedMissions==0)
+    {
+		for(unsigned int i=1;i<=progress+1;i++)
 		{
 			hash[getCampaignScript(campaignName,i)] = campfile.value(QString("Mission %1/Name").arg(i)).toString();
 		}
--- a/QTfrontend/campaign.h	Fri Jun 28 02:38:56 2013 +0300
+++ b/QTfrontend/campaign.h	Fri Jun 28 15:45:11 2013 +0300
@@ -27,6 +27,7 @@
 QString getCampaignScript(QString campaign, unsigned int mNum);
 QString getCampaignImage(QString campaign, unsigned int mNum);
 QString getCampaignMissionName(QString campaign, unsigned int mNum);
-QHash<QString,QString> getUnlockedMissions2(QString & campaignName, QString & teamName);
+QMap<QString,QString> getUnlockedMissions2(QString & campaignName, QString & teamName);
+QStringList getCampMissionList2(QString & campaignName, QString & teamName);
 
 #endif
--- a/QTfrontend/hwform.cpp	Fri Jun 28 02:38:56 2013 +0300
+++ b/QTfrontend/hwform.cpp	Fri Jun 28 15:45:11 2013 +0300
@@ -1900,12 +1900,12 @@
     ui.pageCampaign->CBMission->clear();
 
     QString campaignName = ui.pageCampaign->CBCampaign->currentText();
-    QStringList missionEntries = getCampMissionList(campaignName);
     QString tName = team.name();
+    QStringList missionEntries = getCampMissionList2(campaignName,tName);
     unsigned int n = missionEntries.count();
     unsigned int m = getCampProgress(tName, campaignName);
 
-	getUnlockedMissions2(campaignName, tName);
+	//unlockedMissionsHash = getUnlockedMissions2(campaignName, tName);
     // 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
@@ -1942,7 +1942,7 @@
         campaignMissionDescriptions.clear();
         ui.pageCampaign->CBMission->clear();
     }
-
+/*
     for (unsigned int i = qMin(m + 1, n); i > 0; i--)
     {
         if(updateMissionList)
@@ -1951,7 +1951,16 @@
                                             tr("No description available")).toString();
         }
         ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(i) + QString(missionEntries[i-1]), QString(missionEntries[i-1]));
-    }
+    }*/
+    for(int i=0;i<missionEntries.size();i++)
+    {
+		/*if(updateMissionList)
+        {
+            campaignMissionDescriptions += m_info->value(campaignName+"-"+ getCampaignMissionName(campaignName,i) + ".desc",
+                                            tr("No description available")).toString();
+        }*/
+        ui.pageCampaign->CBMission->addItem(QString("Mission %1: ").arg(missionEntries.size()-i) + QString(missionEntries[i]), QString(missionEntries[i]));
+	}
     if(updateMissionList)
         delete m_info;
 
--- a/QTfrontend/hwform.h	Fri Jun 28 02:38:56 2013 +0300
+++ b/QTfrontend/hwform.h	Fri Jun 28 15:45:11 2013 +0300
@@ -28,6 +28,7 @@
 #include <QNetworkReply>
 #include <QNetworkRequest>
 #include <QNetworkAccessManager>
+#include <QMap>
 
 #include "netserver.h"
 #include "game.h"
@@ -200,6 +201,7 @@
         BGWidget * wBackground;
         QSignalMapper * pageSwitchMapper;
         QByteArray m_lastDemo;
+        QMap<QString,QString> unlockedMissionsHash;
 
         QPropertyAnimation *animationNewSlide;
         QPropertyAnimation *animationOldSlide;
--- a/share/hedgewars/Data/Missions/Campaign/A Space Adventure/campaign.ini	Fri Jun 28 02:38:56 2013 +0300
+++ b/share/hedgewars/Data/Missions/Campaign/A Space Adventure/campaign.ini	Fri Jun 28 15:45:11 2013 +0300
@@ -8,3 +8,15 @@
 [Mission 2]
 Name=Moon:The First Stop
 Script=moon01.lua
+
+[Mission 3]
+Name=FRUIT
+Script=fruit.lua
+
+[Mission 4]
+Name=DESERT
+Script=desert.lua
+
+[Mission 5]
+Name=ICE
+Script=ice.lua