# HG changeset patch # User Wuzzy # Date 1462320659 -7200 # Node ID b05db9ca6e1c1b92a6c7848553bb42ec9a794f54 # Parent 3792a9f9fa9c9f77e4fbc25b43f503641d8d472b Add support for storing and displaying success of campaign missions diff -r 3792a9f9fa9c -r b05db9ca6e1c QTfrontend/campaign.cpp --- a/QTfrontend/campaign.cpp Wed May 04 00:14:41 2016 +0200 +++ b/QTfrontend/campaign.cpp Wed May 04 02:10:59 2016 +0200 @@ -46,6 +46,32 @@ return teamfile; } +/** + Returns true if the specified mission has been completed + campaignName: Name of the campaign in question + missionInList: QComboBox index of the mission as selected in the mission widget + teamName: Name of the playing team +*/ +bool isMissionWon(QString & campaignName, int missionInList, QString & teamName) +{ + QSettings* teamfile = getCampTeamFile(campaignName, teamName); + int progress = teamfile->value("Campaign " + campaignName + "/Progress", 0).toInt(); + int unlockedMissions = teamfile->value("Campaign " + campaignName + "/UnlockedMissions", 0).toInt(); + if(progress>0 and unlockedMissions==0) + { + return progress > (progress - missionInList); + } + else if(unlockedMissions>0) + { + int fileMissionId = missionInList + 1; + int actualMissionId = teamfile->value(QString("Campaign %1/Mission%2").arg(campaignName, QString::number(fileMissionId)), false).toInt(); + return teamfile->value(QString("Campaign %1/Mission%2Won").arg(campaignName, QString::number(actualMissionId)), false).toBool(); + } + else + return false; +} + +/** Returns true if the campaign has been won by the team */ bool isCampWon(QString & campaignName, QString & teamName) { QSettings* teamfile = getCampTeamFile(campaignName, teamName); diff -r 3792a9f9fa9c -r b05db9ca6e1c QTfrontend/campaign.h --- a/QTfrontend/campaign.h Wed May 04 00:14:41 2016 +0200 +++ b/QTfrontend/campaign.h Wed May 04 02:10:59 2016 +0200 @@ -34,6 +34,7 @@ QSettings* getCampTeamFile(QString & campaignName, QString & teamName); bool isCampWon(QString & campaignName, QString & teamName); +bool isMissionWon(QString & campaignName, int missionInList, QString & teamName); QList getCampMissionList(QString & campaignName, QString & teamName); #endif diff -r 3792a9f9fa9c -r b05db9ca6e1c QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Wed May 04 00:14:41 2016 +0200 +++ b/QTfrontend/hwform.cpp Wed May 04 02:10:59 2016 +0200 @@ -1883,6 +1883,10 @@ for(int i=0;iCBMission->addItem(QString(campaignMissionInfo[i].name), QString(campaignMissionInfo[i].name)); + if(isMissionWon(campaignName, i, tName)) + ui.pageCampaign->CBMission->setItemIcon(i, finishedIcon); + else + ui.pageCampaign->CBMission->setItemIcon(i, QIcon()); } }