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 |
|
6958
|
26 |
#include "GameStyleModel.h"
|
|
27 |
|
|
28 |
|
|
29 |
void GameStyleModel::loadGameStyles()
|
|
30 |
{
|
|
31 |
beginResetModel();
|
|
32 |
|
|
33 |
|
|
34 |
// empty list, so that we can (re)fill it
|
|
35 |
QStandardItemModel::clear();
|
|
36 |
|
|
37 |
QList<QStandardItem * > items;
|
|
38 |
items.append(new QStandardItem("Normal"));
|
|
39 |
|
|
40 |
// define a separator item
|
|
41 |
QStandardItem * separator = new QStandardItem("---");
|
|
42 |
separator->setData(QLatin1String("separator"), Qt::AccessibleDescriptionRole);
|
|
43 |
separator->setFlags(separator->flags() & ~( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) );
|
|
44 |
|
|
45 |
items.append(separator);
|
|
46 |
|
|
47 |
|
|
48 |
QStringList scripts = DataManager::instance().entryList(
|
|
49 |
QString("Scripts/Multiplayer"),
|
|
50 |
QDir::Files,
|
|
51 |
QStringList("*.lua")
|
|
52 |
);
|
|
53 |
|
|
54 |
foreach(QString script, scripts)
|
|
55 |
{
|
|
56 |
script = script.remove(".lua", Qt::CaseInsensitive);
|
|
57 |
|
|
58 |
QFile scriptCfgFile(DataManager::instance().findFileForRead(
|
|
59 |
QString("Scripts/Multiplayer/%2.cfg").arg(script)));
|
|
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 |
|
|
81 |
QStandardItem * item = new QStandardItem(name);
|
|
82 |
|
|
83 |
item->setData(script, ScriptRole);
|
|
84 |
item->setData(scheme, SchemeRole);
|
|
85 |
item->setData(weapons, WeaponsRole);
|
|
86 |
|
|
87 |
items.append(item);
|
|
88 |
}
|
|
89 |
|
|
90 |
QStandardItemModel::appendColumn(items);
|
|
91 |
|
|
92 |
|
|
93 |
endResetModel();
|
|
94 |
}
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|