21 #include "DataManager.h" |
21 #include "DataManager.h" |
22 #include <QSettings> |
22 #include <QSettings> |
23 #include <QObject> |
23 #include <QObject> |
24 #include <QLocale> |
24 #include <QLocale> |
25 |
25 |
26 QList<MissionInfo> getCampMissionList(QString & campaignName, QString & teamName) |
26 QSettings* getCampTeamFile(QString & campaignName, QString & teamName) |
27 { |
27 { |
28 QList<MissionInfo> missionInfoList; |
28 QSettings* teamfile = new QSettings(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0); |
29 QSettings teamfile(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0); |
29 teamfile->setIniCodec("UTF-8"); |
30 teamfile.setIniCodec("UTF-8"); |
|
31 |
|
32 // if entry not found check if there is written without _ |
30 // if entry not found check if there is written without _ |
33 // if then is found rename it to use _ |
31 // if then is found rename it to use _ |
34 QString spaceCampName = campaignName; |
32 QString spaceCampName = campaignName; |
35 spaceCampName = spaceCampName.replace(QString("_"),QString(" ")); |
33 spaceCampName = spaceCampName.replace(QString("_"),QString(" ")); |
36 if (!teamfile.childGroups().contains("Campaign " + campaignName) and |
34 if (!teamfile->childGroups().contains("Campaign " + campaignName) and |
37 teamfile.childGroups().contains("Campaign " + spaceCampName)){ |
35 teamfile->childGroups().contains("Campaign " + spaceCampName)){ |
38 teamfile.beginGroup("Campaign " + spaceCampName); |
36 teamfile->beginGroup("Campaign " + spaceCampName); |
39 QStringList keys = teamfile.childKeys(); |
37 QStringList keys = teamfile->childKeys(); |
40 teamfile.endGroup(); |
38 teamfile->endGroup(); |
41 for (int i=0;i<keys.size();i++) { |
39 for (int i=0;i<keys.size();i++) { |
42 QVariant value = teamfile.value("Campaign " + spaceCampName + "/" + keys[i]); |
40 QVariant value = teamfile->value("Campaign " + spaceCampName + "/" + keys[i]); |
43 teamfile.setValue("Campaign " + campaignName + "/" + keys[i], value); |
41 teamfile->setValue("Campaign " + campaignName + "/" + keys[i], value); |
44 } |
42 } |
45 teamfile.remove("Campaign " + spaceCampName); |
43 teamfile->remove("Campaign " + spaceCampName); |
46 } |
44 } |
47 |
45 |
48 int progress = teamfile.value("Campaign " + campaignName + "/Progress", 0).toInt(); |
46 return teamfile; |
49 int unlockedMissions = teamfile.value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt(); |
47 } |
|
48 |
|
49 bool isCampWon(QString & campaignName, QString & teamName) |
|
50 { |
|
51 QSettings* teamfile = getCampTeamFile(campaignName, teamName); |
|
52 bool won = teamfile->value("Campaign " + campaignName + "/Won", false).toBool(); |
|
53 return won; |
|
54 } |
|
55 |
|
56 QList<MissionInfo> getCampMissionList(QString & campaignName, QString & teamName) |
|
57 { |
|
58 QList<MissionInfo> missionInfoList; |
|
59 QSettings* teamfile = getCampTeamFile(campaignName, teamName); |
|
60 |
|
61 int progress = teamfile->value("Campaign " + campaignName + "/Progress", 0).toInt(); |
|
62 int unlockedMissions = teamfile->value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt(); |
50 |
63 |
51 QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0); |
64 QSettings campfile("physfs://Missions/Campaign/" + campaignName + "/campaign.ini", QSettings::IniFormat, 0); |
52 campfile.setIniCodec("UTF-8"); |
65 campfile.setIniCodec("UTF-8"); |
53 |
66 |
54 DataManager & dataMgr = DataManager::instance(); |
67 DataManager & dataMgr = DataManager::instance(); |
90 else if(unlockedMissions>0) |
103 else if(unlockedMissions>0) |
91 { |
104 { |
92 for(int i=1;i<=unlockedMissions;i++) |
105 for(int i=1;i<=unlockedMissions;i++) |
93 { |
106 { |
94 QString missionNum = QString("%1").arg(i); |
107 QString missionNum = QString("%1").arg(i); |
95 int missionNumber = teamfile.value("Campaign " + campaignName + "/Mission"+missionNum, -1).toInt(); |
108 int missionNumber = teamfile->value("Campaign " + campaignName + "/Mission"+missionNum, -1).toInt(); |
96 MissionInfo missionInfo; |
109 MissionInfo missionInfo; |
97 missionInfo.name = campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString(); |
110 missionInfo.name = campfile.value(QString("Mission %1/Name").arg(missionNumber)).toString(); |
98 QString script = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString(); |
111 QString script = campfile.value(QString("Mission %1/Script").arg(missionNumber)).toString(); |
99 missionInfo.script = script; |
112 missionInfo.script = script; |
100 missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc", |
113 missionInfo.description = m_info.value(campaignName+"-"+ script.replace(QString(".lua"),QString("")) + ".desc", |