author | unc0rr |
Sun, 19 Apr 2009 13:36:51 +0000 | |
changeset 2008 | fc2fb5c938c3 |
parent 1979 | 912e450d4db2 |
child 2009 | 91f461c218ab |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
1878
b3b277d2b891
own md5 function, no qca2 dependancy (patch by nemo with Qt adaptation by me)
unc0rr
parents:
1877
diff
changeset
|
3 |
* Copyright (c) 2006, 2007, 2009 Andrey Korotaev <unC0Rr@gmail.com> |
184 | 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 |
#include <QResizeEvent> |
|
218 | 20 |
#include <QGroupBox> |
311 | 21 |
#include <QCheckBox> |
22 |
#include <QGridLayout> |
|
23 |
#include <QSpinBox> |
|
24 |
#include <QLabel> |
|
1517 | 25 |
#include <QMessageBox> |
1884 | 26 |
#include <QTableView> |
1885 | 27 |
#include <QPushButton> |
1217 | 28 |
|
184 | 29 |
#include "gamecfgwidget.h" |
1217 | 30 |
#include "igbox.h" |
1517 | 31 |
#include "hwconsts.h" |
1884 | 32 |
#include "ammoSchemeModel.h" |
184 | 33 |
|
349 | 34 |
GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) : |
1217 | 35 |
QGroupBox(parent), mainLayout(this) |
184 | 36 |
{ |
240 | 37 |
mainLayout.setMargin(0); |
1217 | 38 |
// mainLayout.setSizeConstraint(QLayout::SetMinimumSize); |
218 | 39 |
|
1217 | 40 |
pMapContainer = new HWMapContainer(this); |
41 |
mainLayout.addWidget(pMapContainer, 0, 0); |
|
218 | 42 |
|
1217 | 43 |
IconedGroupBox *GBoxOptions = new IconedGroupBox(this); |
218 | 44 |
GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
45 |
mainLayout.addWidget(GBoxOptions); |
|
46 |
||
311 | 47 |
QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions); |
1884 | 48 |
|
1890 | 49 |
GameSchemes = new QComboBox(GBoxOptions); |
50 |
GBoxOptionsLayout->addWidget(GameSchemes, 0, 1); |
|
1898
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
51 |
connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int))); |
1885 | 52 |
|
1979 | 53 |
GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Game scheme"), GBoxOptions), 0, 0); |
54 |
||
55 |
||
1885 | 56 |
QPushButton * goToSchemePage = new QPushButton(GBoxOptions); |
57 |
goToSchemePage->setText(tr("Edit schemes")); |
|
58 |
GBoxOptionsLayout->addWidget(goToSchemePage, 1, 0, 1, 2); |
|
59 |
connect(goToSchemePage, SIGNAL(clicked()), this, SIGNAL(goToSchemes())); |
|
1427 | 60 |
|
1784 | 61 |
GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 8, 0); |
311 | 62 |
|
697 | 63 |
WeaponsName = new QComboBox(GBoxOptions); |
1784 | 64 |
GBoxOptionsLayout->addWidget(WeaponsName, 8, 1); |
1874 | 65 |
|
1531 | 66 |
connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); |
486 | 67 |
|
1874 | 68 |
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &))); |
69 |
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &))); |
|
70 |
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &))); |
|
1876 | 71 |
connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int))); |
184 | 72 |
} |
73 |
||
1890 | 74 |
QVariant GameCFGWidget::schemeData(int column) const |
75 |
{ |
|
76 |
return GameSchemes->model()->data(GameSchemes->model()->index(GameSchemes->currentIndex(), column)); |
|
77 |
} |
|
78 |
||
318 | 79 |
quint32 GameCFGWidget::getGameFlags() const |
184 | 80 |
{ |
81 |
quint32 result = 0; |
|
1427 | 82 |
|
1890 | 83 |
if (schemeData(1).toBool()) |
1428 | 84 |
result |= 0x01; |
1890 | 85 |
if (schemeData(2).toBool()) |
1428 | 86 |
result |= 0x10; |
1890 | 87 |
if (schemeData(3).toBool()) |
1530 | 88 |
result |= 0x04; |
1890 | 89 |
if (schemeData(4).toBool()) |
90 |
result |= 0x08; |
|
1895 | 91 |
if (schemeData(5).toBool()) |
92 |
result |= 0x20; |
|
93 |
if (schemeData(6).toBool()) |
|
94 |
result |= 0x40; |
|
95 |
if (schemeData(7).toBool()) |
|
96 |
result |= 0x80; |
|
97 |
if (schemeData(8).toBool()) |
|
98 |
result |= 0x100; |
|
1427 | 99 |
|
184 | 100 |
return result; |
101 |
} |
|
102 |
||
312 | 103 |
quint32 GameCFGWidget::getInitHealth() const |
104 |
{ |
|
1895 | 105 |
return schemeData(11).toInt(); |
312 | 106 |
} |
107 |
||
318 | 108 |
QStringList GameCFGWidget::getFullConfig() const |
109 |
{ |
|
110 |
QStringList sl; |
|
1875 | 111 |
sl.append("eseed " + pMapContainer->getCurrentSeed()); |
318 | 112 |
sl.append(QString("e$gmflags %1").arg(getGameFlags())); |
1895 | 113 |
sl.append(QString("e$damagepct %1").arg(schemeData(9).toInt())); |
114 |
sl.append(QString("e$turntime %1").arg(schemeData(10).toInt() * 1000)); |
|
115 |
sl.append(QString("e$sd_turns %1").arg(schemeData(12).toInt())); |
|
116 |
sl.append(QString("e$casefreq %1").arg(schemeData(13).toInt())); |
|
1802 | 117 |
sl.append(QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter())); |
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
118 |
|
1875 | 119 |
QString currentMap = pMapContainer->getCurrentMap(); |
320 | 120 |
if (currentMap.size() > 0) |
318 | 121 |
sl.append("emap " + currentMap); |
1875 | 122 |
sl.append("etheme " + pMapContainer->getCurrentTheme()); |
318 | 123 |
return sl; |
124 |
} |
|
320 | 125 |
|
703 | 126 |
void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo) |
697 | 127 |
{ |
1576
a02353129a41
Check for deprecated ammo schemes at startup and delete them
unc0rr
parents:
1532
diff
changeset
|
128 |
if (ammo.size() != cDefaultAmmoStore->size()) |
1517 | 129 |
QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); |
703 | 130 |
|
1517 | 131 |
int pos = WeaponsName->findText(name); |
132 |
if (pos == -1) { |
|
133 |
WeaponsName->addItem(name, ammo); |
|
134 |
WeaponsName->setCurrentIndex(WeaponsName->count() - 1); |
|
135 |
} else { |
|
136 |
WeaponsName->setItemData(pos, ammo); |
|
137 |
WeaponsName->setCurrentIndex(pos); |
|
138 |
} |
|
1530 | 139 |
} |
1531 | 140 |
|
1875 | 141 |
void GameCFGWidget::fullNetConfig() |
142 |
{ |
|
143 |
ammoChanged(WeaponsName->currentIndex()); |
|
144 |
||
145 |
seedChanged(pMapContainer->getCurrentSeed()); |
|
1876 | 146 |
templateFilterChanged(pMapContainer->getTemplateFilter()); |
1875 | 147 |
themeChanged(pMapContainer->getCurrentTheme()); |
148 |
||
1921 | 149 |
schemeChanged(GameSchemes->currentIndex()); |
150 |
||
1875 | 151 |
// map must be the last |
152 |
QString map = pMapContainer->getCurrentMap(); |
|
153 |
if (map.size()) |
|
154 |
mapChanged(map); |
|
155 |
} |
|
156 |
||
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
157 |
void GameCFGWidget::setParam(const QString & param, const QStringList & slValue) |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
158 |
{ |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
159 |
if (slValue.size() == 1) |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
160 |
{ |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
161 |
QString value = slValue[0]; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
162 |
if (param == "MAP") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
163 |
pMapContainer->setMap(value); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
164 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
165 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
166 |
if (param == "SEED") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
167 |
pMapContainer->setSeed(value); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
168 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
169 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
170 |
if (param == "THEME") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
171 |
pMapContainer->setTheme(value); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
172 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
173 |
} |
1876 | 174 |
if (param == "TEMPLATE") { |
175 |
pMapContainer->setTemplateFilter(value.toUInt()); |
|
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
176 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
177 |
} |
1876 | 178 |
} |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
179 |
|
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
180 |
if (slValue.size() == 2) |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
181 |
{ |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
182 |
if (param == "AMMO") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
183 |
setNetAmmo(slValue[0], slValue[1]); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
184 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
185 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
186 |
} |
1921 | 187 |
|
188 |
qWarning("Got bad config param from net"); |
|
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
189 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
190 |
|
1874 | 191 |
void GameCFGWidget::ammoChanged(int index) |
192 |
{ |
|
193 |
if (index >= 0) |
|
194 |
emit paramChanged( |
|
195 |
"AMMO", |
|
196 |
QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString() |
|
197 |
); |
|
198 |
} |
|
199 |
||
200 |
void GameCFGWidget::mapChanged(const QString & value) |
|
201 |
{ |
|
202 |
emit paramChanged("MAP", QStringList(value)); |
|
203 |
} |
|
204 |
||
1876 | 205 |
void GameCFGWidget::templateFilterChanged(int value) |
206 |
{ |
|
207 |
emit paramChanged("TEMPLATE", QStringList(QString::number(value))); |
|
208 |
} |
|
209 |
||
1874 | 210 |
void GameCFGWidget::seedChanged(const QString & value) |
211 |
{ |
|
212 |
emit paramChanged("SEED", QStringList(value)); |
|
213 |
} |
|
214 |
||
215 |
void GameCFGWidget::themeChanged(const QString & value) |
|
216 |
{ |
|
217 |
emit paramChanged("THEME", QStringList(value)); |
|
218 |
} |
|
1898
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
219 |
|
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
220 |
void GameCFGWidget::schemeChanged(int value) |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
221 |
{ |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
222 |
QStringList sl; |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
223 |
|
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
224 |
int size = GameSchemes->model()->columnCount(); |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
225 |
for(int i = 0; i < size; ++i) |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
226 |
sl << schemeData(i).toString(); |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
227 |
|
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
228 |
emit paramChanged("SCHEME", sl); |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
229 |
} |