author | sheepluva |
Sat, 03 Dec 2016 09:09:16 +0100 | |
changeset 12103 | 966a9739812f |
parent 11046 | 47a8c19ecb60 |
child 12690 | ad1fd7ae479d |
permissions | -rw-r--r-- |
6958 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
6958 | 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
6958 | 17 |
*/ |
18 |
||
19 |
/** |
|
20 |
* @file |
|
21 |
* @brief GameStyleModel class implementation |
|
22 |
*/ |
|
23 |
||
7258 | 24 |
#include <QTextStream> |
25 |
||
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
26 |
#include "physfs.h" |
6958 | 27 |
#include "GameStyleModel.h" |
8466 | 28 |
#include "hwconsts.h" |
6958 | 29 |
|
30 |
||
31 |
void GameStyleModel::loadGameStyles() |
|
32 |
{ |
|
33 |
beginResetModel(); |
|
34 |
||
35 |
// empty list, so that we can (re)fill it |
|
36 |
QStandardItemModel::clear(); |
|
37 |
||
38 |
QList<QStandardItem * > items; |
|
39 |
items.append(new QStandardItem("Normal")); |
|
40 |
||
41 |
// define a separator item |
|
42 |
QStandardItem * separator = new QStandardItem("---"); |
|
43 |
separator->setData(QLatin1String("separator"), Qt::AccessibleDescriptionRole); |
|
44 |
separator->setFlags(separator->flags() & ~( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) ); |
|
45 |
||
46 |
items.append(separator); |
|
47 |
||
48 |
||
49 |
QStringList scripts = DataManager::instance().entryList( |
|
50 |
QString("Scripts/Multiplayer"), |
|
51 |
QDir::Files, |
|
52 |
QStringList("*.lua") |
|
53 |
); |
|
54 |
||
55 |
foreach(QString script, scripts) |
|
56 |
{ |
|
57 |
script = script.remove(".lua", Qt::CaseInsensitive); |
|
58 |
||
8049 | 59 |
QFile scriptCfgFile(QString("physfs://Scripts/Multiplayer/%2.cfg").arg(script)); |
6958 | 60 |
|
61 |
QString name = script; |
|
62 |
name = name.replace("_", " "); |
|
63 |
||
64 |
QString scheme = "locked"; |
|
65 |
QString weapons = "locked"; |
|
66 |
||
67 |
if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) |
|
68 |
{ |
|
69 |
QTextStream input(&scriptCfgFile); |
|
70 |
input >> scheme; |
|
71 |
input >> weapons; |
|
72 |
scriptCfgFile.close(); |
|
73 |
||
74 |
if (!scheme.isEmpty()) |
|
75 |
scheme.replace("_", " "); |
|
76 |
||
77 |
if (!weapons.isEmpty()) |
|
78 |
weapons.replace("_", " "); |
|
79 |
} |
|
80 |
||
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
81 |
// detect if script is dlc |
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
82 |
QString scriptPath = PHYSFS_getRealDir(QString("Scripts/Multiplayer/%1.lua").arg(script).toLocal8Bit().data()); |
8466 | 83 |
bool isDLC = !scriptPath.startsWith(datadir->absolutePath()); |
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
84 |
|
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
85 |
QStandardItem * item = new QStandardItem((isDLC ? "*" : "") + name); |
6958 | 86 |
|
87 |
item->setData(script, ScriptRole); |
|
88 |
item->setData(scheme, SchemeRole); |
|
89 |
item->setData(weapons, WeaponsRole); |
|
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
90 |
item->setData(isDLC, IsDlcRole); |
6958 | 91 |
|
92 |
items.append(item); |
|
93 |
} |
|
94 |
||
95 |
QStandardItemModel::appendColumn(items); |
|
96 |
||
97 |
||
98 |
endResetModel(); |
|
99 |
} |
|
100 |
||
101 |
||
102 |
||
103 |