author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 09 Apr 2019 00:45:14 +0200 | |
changeset 14783 | bbec6b28d072 |
parent 14530 | 029f40c609b4 |
permissions | -rw-r--r-- |
14467
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
1 |
/* |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
3 |
* Copyright (c) 2004-2018 Andrey Korotaev <unC0Rr@gmail.com> |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
4 |
* |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
8 |
* |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
13 |
* |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
17 |
*/ |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
18 |
|
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
19 |
#include "mission.h" |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
20 |
#include "hwconsts.h" |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
21 |
#include "DataManager.h" |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
22 |
#include <QSettings> |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
23 |
#include <QObject> |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
24 |
#include <QLocale> |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
25 |
|
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
26 |
QSettings* getMissionTeamFile(QString & missionName, QString & teamName) |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
27 |
{ |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
28 |
QSettings* teamfile = new QSettings(cfgdir->absolutePath() + "/Teams/" + teamName + ".hwt", QSettings::IniFormat, 0); |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
29 |
teamfile->setIniCodec("UTF-8"); |
14468
bd1db668b7c0
Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents:
14467
diff
changeset
|
30 |
if (!teamfile->childGroups().contains("Mission " + missionName) && |
bd1db668b7c0
Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents:
14467
diff
changeset
|
31 |
teamfile->childGroups().contains("Mission " + missionName)){ |
bd1db668b7c0
Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents:
14467
diff
changeset
|
32 |
teamfile->beginGroup("Mission " + missionName); |
14467
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
33 |
QStringList keys = teamfile->childKeys(); |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
34 |
teamfile->endGroup(); |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
35 |
for (int i=0;i<keys.size();i++) { |
14468
bd1db668b7c0
Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents:
14467
diff
changeset
|
36 |
QVariant value = teamfile->value("Mission " + missionName + "/" + keys[i]); |
14467
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
37 |
teamfile->setValue("Mission " + missionName + "/" + keys[i], value); |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
38 |
} |
14468
bd1db668b7c0
Add Lua functions to save/get mission variables
Wuzzy <Wuzzy2@mail.ru>
parents:
14467
diff
changeset
|
39 |
teamfile->remove("Mission " + missionName); |
14467
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
40 |
} |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
41 |
|
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
42 |
return teamfile; |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
43 |
} |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
44 |
|
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
45 |
/** |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
46 |
Returns true if the specified mission has been completed |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
47 |
missionName: Name of the mission in question |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
48 |
teamName: Name of the playing team |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
49 |
*/ |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
50 |
bool isMissionWon(QString & missionName, QString & teamName) |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
51 |
{ |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
52 |
QSettings* teamfile = getMissionTeamFile(missionName, teamName); |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
53 |
bool won = teamfile->value("Mission " + missionName + "/Won", false).toBool(); |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
54 |
return won; |
4c743ef80b1b
Add team selection in training page and basic check mark support
Wuzzy <Wuzzy2@mail.ru>
parents:
diff
changeset
|
55 |
} |
14530
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
56 |
|
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
57 |
/** |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
58 |
Returns true if the mission value adressed with the provided |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
59 |
missionName: Name of the mission in question |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
60 |
teamName: Name of the playing team |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
61 |
key: name of key to check |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
62 |
*/ |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
63 |
bool missionValueExists(QString & missionName, QString & teamName, QString key) |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
64 |
{ |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
65 |
QSettings* teamfile = getMissionTeamFile(missionName, teamName); |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
66 |
return teamfile->contains("Mission " + missionName + "/" + key); |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
67 |
} |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
68 |
/** |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
69 |
Returns a mission value. |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
70 |
NOTE: Check whether the mission value exists first, using missionValueExists. |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
71 |
missionName: Name of the mission in question |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
72 |
teamName: Name of the playing team |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
73 |
key: name of key to read its value from |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
74 |
*/ |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
75 |
QVariant getMissionValue(QString & missionName, QString & teamName, QString key) |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
76 |
{ |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
77 |
QSettings* teamfile = getMissionTeamFile(missionName, teamName); |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
78 |
return teamfile->value("Mission " + missionName + "/" + key); |
029f40c609b4
Display team records in training menu
Wuzzy <Wuzzy2@mail.ru>
parents:
14468
diff
changeset
|
79 |
} |