author | Wuzzy <almikes@aol.com> |
Tue, 10 Oct 2017 22:45:48 +0200 | |
changeset 12685 | ad1fd7ae479d |
parent 11046 | 47a8c19ecb60 |
child 12686 | d5e09024d722 |
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 |
||
12685
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
35 |
QIcon dlcIcon; |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
36 |
dlcIcon.addFile(":/res/dlcMarker.png", QSize(), QIcon::Normal, QIcon::On); |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
37 |
QPixmap emptySpace = QPixmap(7, 15); |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
38 |
emptySpace.fill(QColor(0, 0, 0, 0)); |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
39 |
QIcon notDlcIcon = QIcon(emptySpace); |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
40 |
|
6958 | 41 |
// empty list, so that we can (re)fill it |
42 |
QStandardItemModel::clear(); |
|
43 |
||
44 |
QList<QStandardItem * > items; |
|
12685
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
45 |
items.append(new QStandardItem(notDlcIcon, "Normal")); |
6958 | 46 |
|
47 |
// define a separator item |
|
48 |
QStandardItem * separator = new QStandardItem("---"); |
|
49 |
separator->setData(QLatin1String("separator"), Qt::AccessibleDescriptionRole); |
|
50 |
separator->setFlags(separator->flags() & ~( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) ); |
|
51 |
||
52 |
items.append(separator); |
|
53 |
||
54 |
||
55 |
QStringList scripts = DataManager::instance().entryList( |
|
56 |
QString("Scripts/Multiplayer"), |
|
57 |
QDir::Files, |
|
58 |
QStringList("*.lua") |
|
59 |
); |
|
60 |
||
61 |
foreach(QString script, scripts) |
|
62 |
{ |
|
63 |
script = script.remove(".lua", Qt::CaseInsensitive); |
|
64 |
||
8049 | 65 |
QFile scriptCfgFile(QString("physfs://Scripts/Multiplayer/%2.cfg").arg(script)); |
6958 | 66 |
|
67 |
QString name = script; |
|
68 |
name = name.replace("_", " "); |
|
69 |
||
70 |
QString scheme = "locked"; |
|
71 |
QString weapons = "locked"; |
|
72 |
||
73 |
if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) |
|
74 |
{ |
|
75 |
QTextStream input(&scriptCfgFile); |
|
76 |
input >> scheme; |
|
77 |
input >> weapons; |
|
78 |
scriptCfgFile.close(); |
|
79 |
||
80 |
if (!scheme.isEmpty()) |
|
81 |
scheme.replace("_", " "); |
|
82 |
||
83 |
if (!weapons.isEmpty()) |
|
84 |
weapons.replace("_", " "); |
|
85 |
} |
|
86 |
||
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8049
diff
changeset
|
87 |
// 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
|
88 |
QString scriptPath = PHYSFS_getRealDir(QString("Scripts/Multiplayer/%1.lua").arg(script).toLocal8Bit().data()); |
8466 | 89 |
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
|
90 |
|
12685
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
91 |
QStandardItem * item; |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
92 |
if (isDLC) |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
93 |
item = new QStandardItem(dlcIcon, name); |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
94 |
else |
ad1fd7ae479d
Mark custom maps/forts/scripts with circle icon instead of icon
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
95 |
item = new QStandardItem(notDlcIcon, name); |
6958 | 96 |
|
97 |
item->setData(script, ScriptRole); |
|
98 |
item->setData(scheme, SchemeRole); |
|
99 |
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
|
100 |
item->setData(isDLC, IsDlcRole); |
6958 | 101 |
|
102 |
items.append(item); |
|
103 |
} |
|
104 |
||
105 |
QStandardItemModel::appendColumn(items); |
|
106 |
||
107 |
||
108 |
endResetModel(); |
|
109 |
} |
|
110 |
||
111 |
||
112 |
||
113 |