QTfrontend/mission.cpp
changeset 14462 4c743ef80b1b
child 14463 bd1db668b7c0
equal deleted inserted replaced
14461:9844450389a4 14462:4c743ef80b1b
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2018 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    17  */
       
    18 
       
    19 #include "mission.h"
       
    20 #include "hwconsts.h"
       
    21 #include "DataManager.h"
       
    22 #include <QSettings>
       
    23 #include <QObject>
       
    24 #include <QLocale>
       
    25 
       
    26 QSettings* getMissionTeamFile(QString & missionName, QString & teamName)
       
    27 {
       
    28     QSettings* teamfile = new QSettings(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0);
       
    29     teamfile->setIniCodec("UTF-8");
       
    30     // if entry not found check if there is written without _
       
    31     // if then is found rename it to use _
       
    32     QString cleanedMissionName = missionName;
       
    33     cleanedMissionName = cleanedMissionName.replace(QString("_"),QString(" "));
       
    34     if (!teamfile->childGroups().contains("Mission " + cleanedMissionName) &&
       
    35             teamfile->childGroups().contains("Mission " + cleanedMissionName)){
       
    36         teamfile->beginGroup("Mission " + cleanedMissionName);
       
    37         QStringList keys = teamfile->childKeys();
       
    38         teamfile->endGroup();
       
    39         for (int i=0;i<keys.size();i++) {
       
    40             QVariant value = teamfile->value("Mission " + cleanedMissionName + "/" + keys[i]);
       
    41             teamfile->setValue("Mission " + missionName + "/" + keys[i], value);
       
    42         }
       
    43         teamfile->remove("Mission " + cleanedMissionName);
       
    44     }
       
    45 
       
    46     return teamfile;
       
    47 }
       
    48 
       
    49 /**
       
    50     Returns true if the specified mission has been completed
       
    51     missionName: Name of the mission in question
       
    52     teamName: Name of the playing team
       
    53 */
       
    54 bool isMissionWon(QString & missionName, QString & teamName)
       
    55 {
       
    56     QSettings* teamfile = getMissionTeamFile(missionName, teamName);
       
    57     bool won = teamfile->value("Mission " + missionName + "/Won", false).toBool();
       
    58     return won;
       
    59 }