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 |
|
|
24 |
#include "GameStyleModel.h"
|
|
25 |
|
|
26 |
|
|
27 |
void GameStyleModel::loadGameStyles()
|
|
28 |
{
|
|
29 |
beginResetModel();
|
|
30 |
|
|
31 |
|
|
32 |
// empty list, so that we can (re)fill it
|
|
33 |
QStandardItemModel::clear();
|
|
34 |
|
|
35 |
QList<QStandardItem * > items;
|
|
36 |
items.append(new QStandardItem("Normal"));
|
|
37 |
|
|
38 |
// define a separator item
|
|
39 |
QStandardItem * separator = new QStandardItem("---");
|
|
40 |
separator->setData(QLatin1String("separator"), Qt::AccessibleDescriptionRole);
|
|
41 |
separator->setFlags(separator->flags() & ~( Qt::ItemIsEnabled | Qt::ItemIsSelectable ) );
|
|
42 |
|
|
43 |
items.append(separator);
|
|
44 |
|
|
45 |
|
|
46 |
QStringList scripts = DataManager::instance().entryList(
|
|
47 |
QString("Scripts/Multiplayer"),
|
|
48 |
QDir::Files,
|
|
49 |
QStringList("*.lua")
|
|
50 |
);
|
|
51 |
|
|
52 |
foreach(QString script, scripts)
|
|
53 |
{
|
|
54 |
script = script.remove(".lua", Qt::CaseInsensitive);
|
|
55 |
|
|
56 |
QFile scriptCfgFile(DataManager::instance().findFileForRead(
|
|
57 |
QString("Scripts/Multiplayer/%2.cfg").arg(script)));
|
|
58 |
|
|
59 |
QString name = script;
|
|
60 |
name = name.replace("_", " ");
|
|
61 |
|
|
62 |
QString scheme = "locked";
|
|
63 |
QString weapons = "locked";
|
|
64 |
|
|
65 |
if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly))
|
|
66 |
{
|
|
67 |
QTextStream input(&scriptCfgFile);
|
|
68 |
input >> scheme;
|
|
69 |
input >> weapons;
|
|
70 |
scriptCfgFile.close();
|
|
71 |
|
|
72 |
if (!scheme.isEmpty())
|
|
73 |
scheme.replace("_", " ");
|
|
74 |
|
|
75 |
if (!weapons.isEmpty())
|
|
76 |
weapons.replace("_", " ");
|
|
77 |
}
|
|
78 |
|
|
79 |
QStandardItem * item = new QStandardItem(name);
|
|
80 |
|
|
81 |
item->setData(script, ScriptRole);
|
|
82 |
item->setData(scheme, SchemeRole);
|
|
83 |
item->setData(weapons, WeaponsRole);
|
|
84 |
|
|
85 |
items.append(item);
|
|
86 |
}
|
|
87 |
|
|
88 |
QStandardItemModel::appendColumn(items);
|
|
89 |
|
|
90 |
|
|
91 |
endResetModel();
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|