author | unc0rr |
Fri, 24 Apr 2009 16:53:38 +0000 | |
changeset 2014 | c028362c5d72 |
parent 2009 | 91f461c218ab |
child 2017 | 7845c77c8d31 |
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 |
|
2009 | 61 |
GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 2, 0); |
311 | 62 |
|
697 | 63 |
WeaponsName = new QComboBox(GBoxOptions); |
2009 | 64 |
GBoxOptionsLayout->addWidget(WeaponsName, 2, 1); |
1874 | 65 |
|
1531 | 66 |
connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); |
2009 | 67 |
|
68 |
QPushButton * goToWeaponPage = new QPushButton(GBoxOptions); |
|
69 |
goToWeaponPage->setText(tr("Edit weapons")); |
|
70 |
GBoxOptionsLayout->addWidget(goToWeaponPage, 3, 0, 1, 2); |
|
71 |
||
72 |
connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons())); |
|
486 | 73 |
|
1874 | 74 |
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &))); |
75 |
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &))); |
|
76 |
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &))); |
|
1876 | 77 |
connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int))); |
184 | 78 |
} |
79 |
||
2009 | 80 |
void GameCFGWidget::jumpToWeapons() |
81 |
{ |
|
82 |
emit goToWeapons(WeaponsName->currentText()); |
|
83 |
} |
|
84 |
||
1890 | 85 |
QVariant GameCFGWidget::schemeData(int column) const |
86 |
{ |
|
87 |
return GameSchemes->model()->data(GameSchemes->model()->index(GameSchemes->currentIndex(), column)); |
|
88 |
} |
|
89 |
||
318 | 90 |
quint32 GameCFGWidget::getGameFlags() const |
184 | 91 |
{ |
92 |
quint32 result = 0; |
|
1427 | 93 |
|
1890 | 94 |
if (schemeData(1).toBool()) |
1428 | 95 |
result |= 0x01; |
1890 | 96 |
if (schemeData(2).toBool()) |
1428 | 97 |
result |= 0x10; |
1890 | 98 |
if (schemeData(3).toBool()) |
1530 | 99 |
result |= 0x04; |
1890 | 100 |
if (schemeData(4).toBool()) |
101 |
result |= 0x08; |
|
1895 | 102 |
if (schemeData(5).toBool()) |
103 |
result |= 0x20; |
|
104 |
if (schemeData(6).toBool()) |
|
105 |
result |= 0x40; |
|
106 |
if (schemeData(7).toBool()) |
|
107 |
result |= 0x80; |
|
108 |
if (schemeData(8).toBool()) |
|
109 |
result |= 0x100; |
|
1427 | 110 |
|
184 | 111 |
return result; |
112 |
} |
|
113 |
||
312 | 114 |
quint32 GameCFGWidget::getInitHealth() const |
115 |
{ |
|
1895 | 116 |
return schemeData(11).toInt(); |
312 | 117 |
} |
118 |
||
318 | 119 |
QStringList GameCFGWidget::getFullConfig() const |
120 |
{ |
|
121 |
QStringList sl; |
|
1875 | 122 |
sl.append("eseed " + pMapContainer->getCurrentSeed()); |
318 | 123 |
sl.append(QString("e$gmflags %1").arg(getGameFlags())); |
1895 | 124 |
sl.append(QString("e$damagepct %1").arg(schemeData(9).toInt())); |
125 |
sl.append(QString("e$turntime %1").arg(schemeData(10).toInt() * 1000)); |
|
126 |
sl.append(QString("e$sd_turns %1").arg(schemeData(12).toInt())); |
|
127 |
sl.append(QString("e$casefreq %1").arg(schemeData(13).toInt())); |
|
1802 | 128 |
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
|
129 |
|
1875 | 130 |
QString currentMap = pMapContainer->getCurrentMap(); |
320 | 131 |
if (currentMap.size() > 0) |
318 | 132 |
sl.append("emap " + currentMap); |
1875 | 133 |
sl.append("etheme " + pMapContainer->getCurrentTheme()); |
318 | 134 |
return sl; |
135 |
} |
|
320 | 136 |
|
703 | 137 |
void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo) |
697 | 138 |
{ |
1576
a02353129a41
Check for deprecated ammo schemes at startup and delete them
unc0rr
parents:
1532
diff
changeset
|
139 |
if (ammo.size() != cDefaultAmmoStore->size()) |
1517 | 140 |
QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); |
703 | 141 |
|
1517 | 142 |
int pos = WeaponsName->findText(name); |
143 |
if (pos == -1) { |
|
144 |
WeaponsName->addItem(name, ammo); |
|
145 |
WeaponsName->setCurrentIndex(WeaponsName->count() - 1); |
|
146 |
} else { |
|
147 |
WeaponsName->setItemData(pos, ammo); |
|
148 |
WeaponsName->setCurrentIndex(pos); |
|
149 |
} |
|
1530 | 150 |
} |
1531 | 151 |
|
1875 | 152 |
void GameCFGWidget::fullNetConfig() |
153 |
{ |
|
154 |
ammoChanged(WeaponsName->currentIndex()); |
|
155 |
||
156 |
seedChanged(pMapContainer->getCurrentSeed()); |
|
1876 | 157 |
templateFilterChanged(pMapContainer->getTemplateFilter()); |
1875 | 158 |
themeChanged(pMapContainer->getCurrentTheme()); |
159 |
||
1921 | 160 |
schemeChanged(GameSchemes->currentIndex()); |
161 |
||
1875 | 162 |
// map must be the last |
163 |
QString map = pMapContainer->getCurrentMap(); |
|
164 |
if (map.size()) |
|
165 |
mapChanged(map); |
|
166 |
} |
|
167 |
||
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
168 |
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
|
169 |
{ |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
170 |
if (slValue.size() == 1) |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
171 |
{ |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
172 |
QString value = slValue[0]; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
173 |
if (param == "MAP") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
174 |
pMapContainer->setMap(value); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
175 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
176 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
177 |
if (param == "SEED") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
178 |
pMapContainer->setSeed(value); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
179 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
180 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
181 |
if (param == "THEME") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
182 |
pMapContainer->setTheme(value); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
183 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
184 |
} |
1876 | 185 |
if (param == "TEMPLATE") { |
186 |
pMapContainer->setTemplateFilter(value.toUInt()); |
|
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
187 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
188 |
} |
1876 | 189 |
} |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
190 |
|
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
191 |
if (slValue.size() == 2) |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
192 |
{ |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
193 |
if (param == "AMMO") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
194 |
setNetAmmo(slValue[0], slValue[1]); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
195 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
196 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
197 |
} |
1921 | 198 |
|
199 |
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
|
200 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
201 |
|
1874 | 202 |
void GameCFGWidget::ammoChanged(int index) |
203 |
{ |
|
204 |
if (index >= 0) |
|
205 |
emit paramChanged( |
|
206 |
"AMMO", |
|
207 |
QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString() |
|
208 |
); |
|
209 |
} |
|
210 |
||
211 |
void GameCFGWidget::mapChanged(const QString & value) |
|
212 |
{ |
|
213 |
emit paramChanged("MAP", QStringList(value)); |
|
214 |
} |
|
215 |
||
1876 | 216 |
void GameCFGWidget::templateFilterChanged(int value) |
217 |
{ |
|
218 |
emit paramChanged("TEMPLATE", QStringList(QString::number(value))); |
|
219 |
} |
|
220 |
||
1874 | 221 |
void GameCFGWidget::seedChanged(const QString & value) |
222 |
{ |
|
223 |
emit paramChanged("SEED", QStringList(value)); |
|
224 |
} |
|
225 |
||
226 |
void GameCFGWidget::themeChanged(const QString & value) |
|
227 |
{ |
|
228 |
emit paramChanged("THEME", QStringList(value)); |
|
229 |
} |
|
1898
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
230 |
|
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
231 |
void GameCFGWidget::schemeChanged(int value) |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
232 |
{ |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
233 |
QStringList sl; |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
234 |
|
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
235 |
int size = GameSchemes->model()->columnCount(); |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
236 |
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
|
237 |
sl << schemeData(i).toString(); |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
238 |
|
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
239 |
emit paramChanged("SCHEME", sl); |
f0ab0c77946d
Send scheme data over net (but recieving part isn't implemented yet)
unc0rr
parents:
1895
diff
changeset
|
240 |
} |