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