author | koda |
Wed, 20 Feb 2013 02:21:58 +0100 | |
branch | webgl |
changeset 8450 | 404ddce27b23 |
parent 8419 | d99f46b676b5 |
child 8466 | 29b891dbf2a0 |
permissions | -rw-r--r-- |
6958 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2004-2012 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
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" |
28 |
||
29 |
||
30 |
void GameStyleModel::loadGameStyles() |
|
31 |
{ |
|
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
32 |
const QString appDir = QString(PHYSFS_getBaseDir()); |
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
33 |
|
6958 | 34 |
beginResetModel(); |
35 |
||
36 |
// empty list, so that we can (re)fill it |
|
37 |
QStandardItemModel::clear(); |
|
38 |
||
39 |
QList<QStandardItem * > items; |
|
40 |
items.append(new QStandardItem("Normal")); |
|
41 |
||
42 |
// define a separator item |
|
43 |
QStandardItem * separator = new QStandardItem("---"); |
|
44 |
separator->setData(QLatin1String("separator"), Qt::AccessibleDescriptionRole); |
|
45 |
separator->setFlags(separator->flags() & ~( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) ); |
|
46 |
||
47 |
items.append(separator); |
|
48 |
||
49 |
||
50 |
QStringList scripts = DataManager::instance().entryList( |
|
51 |
QString("Scripts/Multiplayer"), |
|
52 |
QDir::Files, |
|
53 |
QStringList("*.lua") |
|
54 |
); |
|
55 |
||
56 |
foreach(QString script, scripts) |
|
57 |
{ |
|
58 |
script = script.remove(".lua", Qt::CaseInsensitive); |
|
59 |
||
8049 | 60 |
QFile scriptCfgFile(QString("physfs://Scripts/Multiplayer/%2.cfg").arg(script)); |
6958 | 61 |
|
62 |
QString name = script; |
|
63 |
name = name.replace("_", " "); |
|
64 |
||
65 |
QString scheme = "locked"; |
|
66 |
QString weapons = "locked"; |
|
67 |
||
68 |
if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) |
|
69 |
{ |
|
70 |
QTextStream input(&scriptCfgFile); |
|
71 |
input >> scheme; |
|
72 |
input >> weapons; |
|
73 |
scriptCfgFile.close(); |
|
74 |
||
75 |
if (!scheme.isEmpty()) |
|
76 |
scheme.replace("_", " "); |
|
77 |
||
78 |
if (!weapons.isEmpty()) |
|
79 |
weapons.replace("_", " "); |
|
80 |
} |
|
81 |
||
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
82 |
// 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
|
83 |
QString scriptPath = PHYSFS_getRealDir(QString("Scripts/Multiplayer/%1.lua").arg(script).toLocal8Bit().data()); |
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
84 |
bool isDLC = !scriptPath.startsWith(appDir); |
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
85 |
|
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
86 |
QStandardItem * item = new QStandardItem((isDLC ? "*" : "") + name); |
6958 | 87 |
|
88 |
item->setData(script, ScriptRole); |
|
89 |
item->setData(scheme, SchemeRole); |
|
90 |
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
|
91 |
item->setData(isDLC, IsDlcRole); |
6958 | 92 |
|
93 |
items.append(item); |
|
94 |
} |
|
95 |
||
96 |
QStandardItemModel::appendColumn(items); |
|
97 |
||
98 |
||
99 |
endResetModel(); |
|
100 |
} |
|
101 |
||
102 |
||
103 |
||
104 |