author | unc0rr |
Sun, 15 Feb 2009 14:38:02 +0000 | |
changeset 1797 | fedd8649fdd9 |
parent 1784 | dfe9bafb4590 |
child 1802 | dd148e2506e2 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
486 | 3 |
* Copyright (c) 2006, 2007 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> |
1217 | 26 |
|
184 | 27 |
#include "gamecfgwidget.h" |
1217 | 28 |
#include "igbox.h" |
1517 | 29 |
#include "hwconsts.h" |
184 | 30 |
|
349 | 31 |
GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) : |
1217 | 32 |
QGroupBox(parent), mainLayout(this) |
184 | 33 |
{ |
240 | 34 |
mainLayout.setMargin(0); |
1217 | 35 |
// mainLayout.setSizeConstraint(QLayout::SetMinimumSize); |
218 | 36 |
|
1217 | 37 |
pMapContainer = new HWMapContainer(this); |
38 |
mainLayout.addWidget(pMapContainer, 0, 0); |
|
218 | 39 |
|
1217 | 40 |
IconedGroupBox *GBoxOptions = new IconedGroupBox(this); |
218 | 41 |
GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
42 |
mainLayout.addWidget(GBoxOptions); |
|
43 |
||
311 | 44 |
QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions); |
1427 | 45 |
|
218 | 46 |
CB_mode_Forts = new QCheckBox(GBoxOptions); |
184 | 47 |
CB_mode_Forts->setText(QCheckBox::tr("Forts mode")); |
311 | 48 |
GBoxOptionsLayout->addWidget(CB_mode_Forts, 0, 0, 1, 2); |
49 |
||
1427 | 50 |
CB_teamsDivide = new QCheckBox(GBoxOptions); |
51 |
CB_teamsDivide->setText(QCheckBox::tr("Divide teams")); |
|
52 |
GBoxOptionsLayout->addWidget(CB_teamsDivide, 1, 0, 1, 2); |
|
53 |
||
1530 | 54 |
CB_solid = new QCheckBox(GBoxOptions); |
55 |
CB_solid->setText(QCheckBox::tr("Solid land")); |
|
56 |
GBoxOptionsLayout->addWidget(CB_solid, 2, 0, 1, 2); |
|
57 |
||
1784 | 58 |
CB_border = new QCheckBox(GBoxOptions); |
59 |
CB_border->setText(QCheckBox::tr("Add Border")); |
|
60 |
GBoxOptionsLayout->addWidget(CB_border, 3, 0, 1, 2); |
|
61 |
||
311 | 62 |
L_TurnTime = new QLabel(QLabel::tr("Turn time"), GBoxOptions); |
63 |
L_InitHealth = new QLabel(QLabel::tr("Initial health"), GBoxOptions); |
|
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
64 |
L_SuddenDeath = new QLabel(QLabel::tr("Turns before SD"), GBoxOptions); |
1797 | 65 |
L_CaseProb = new QLabel(QLabel::tr("Crate drops"), GBoxOptions); |
1784 | 66 |
GBoxOptionsLayout->addWidget(L_TurnTime, 4, 0); |
67 |
GBoxOptionsLayout->addWidget(L_InitHealth, 5, 0); |
|
68 |
GBoxOptionsLayout->addWidget(L_SuddenDeath, 6, 0); |
|
69 |
GBoxOptionsLayout->addWidget(L_CaseProb, 7, 0); |
|
70 |
GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 8, 0); |
|
1797 | 71 |
GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Generated Map Filter"), GBoxOptions), 9, 0); |
311 | 72 |
|
73 |
SB_TurnTime = new QSpinBox(GBoxOptions); |
|
1479 | 74 |
SB_TurnTime->setRange(1, 99); |
311 | 75 |
SB_TurnTime->setValue(45); |
76 |
SB_TurnTime->setSingleStep(15); |
|
1427 | 77 |
|
311 | 78 |
SB_InitHealth = new QSpinBox(GBoxOptions); |
79 |
SB_InitHealth->setRange(50, 200); |
|
312 | 80 |
SB_InitHealth->setValue(100); |
311 | 81 |
SB_InitHealth->setSingleStep(25); |
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
82 |
|
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
83 |
SB_SuddenDeath = new QSpinBox(GBoxOptions); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
84 |
SB_SuddenDeath->setRange(0, 50); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
85 |
SB_SuddenDeath->setValue(15); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
86 |
SB_SuddenDeath->setSingleStep(3); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
87 |
|
1783 | 88 |
SB_CaseProb = new FreqSpinBox(GBoxOptions); |
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
89 |
SB_CaseProb->setRange(0, 9); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
90 |
SB_CaseProb->setValue(5); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
91 |
|
1784 | 92 |
GBoxOptionsLayout->addWidget(SB_TurnTime, 4, 1); |
93 |
GBoxOptionsLayout->addWidget(SB_InitHealth, 5, 1); |
|
94 |
GBoxOptionsLayout->addWidget(SB_SuddenDeath, 6, 1); |
|
95 |
GBoxOptionsLayout->addWidget(SB_CaseProb, 7, 1); |
|
1427 | 96 |
|
697 | 97 |
WeaponsName = new QComboBox(GBoxOptions); |
1784 | 98 |
GBoxOptionsLayout->addWidget(WeaponsName, 8, 1); |
696 | 99 |
|
1797 | 100 |
CB_TemplateFilter = new QComboBox(GBoxOptions); |
101 |
CB_TemplateFilter->addItem(tr("All"), 0); |
|
102 |
CB_TemplateFilter->addItem(tr("Small"), 1); |
|
103 |
CB_TemplateFilter->addItem(tr("Medium"), 2); |
|
104 |
CB_TemplateFilter->addItem(tr("Large"), 3); |
|
105 |
CB_TemplateFilter->addItem(tr("Cavern"), 4); |
|
106 |
CB_TemplateFilter->addItem(tr("Wacky"), 5); |
|
107 |
GBoxOptionsLayout->addWidget(CB_TemplateFilter, 9, 1); |
|
108 |
||
1427 | 109 |
connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SIGNAL(initHealthChanged(int))); |
110 |
connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SIGNAL(turnTimeChanged(int))); |
|
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
111 |
connect(SB_SuddenDeath, SIGNAL(valueChanged(int)), this, SIGNAL(suddenDeathTurnsChanged(int))); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
112 |
connect(SB_CaseProb, SIGNAL(valueChanged(int)), this, SIGNAL(caseProbabilityChanged(int))); |
1427 | 113 |
connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SIGNAL(fortsModeChanged(bool))); |
114 |
connect(CB_teamsDivide, SIGNAL(toggled(bool)), this, SIGNAL(teamsDivideChanged(bool))); |
|
1530 | 115 |
connect(CB_solid, SIGNAL(toggled(bool)), this, SIGNAL(solidChanged(bool))); |
1784 | 116 |
connect(CB_border, SIGNAL(toggled(bool)), this, SIGNAL(borderChanged(bool))); |
1531 | 117 |
connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); |
1797 | 118 |
connect(CB_TemplateFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(templateFilterChanged(int))); |
119 |
connect(CB_TemplateFilter, SIGNAL(currentIndexChanged(int)), this, SLOT(templateFilterChanged(int))); |
|
486 | 120 |
|
1427 | 121 |
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SIGNAL(seedChanged(const QString &))); |
122 |
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SIGNAL(mapChanged(const QString &))); |
|
123 |
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SIGNAL(themeChanged(const QString &))); |
|
184 | 124 |
} |
125 |
||
318 | 126 |
quint32 GameCFGWidget::getGameFlags() const |
184 | 127 |
{ |
128 |
quint32 result = 0; |
|
1427 | 129 |
|
184 | 130 |
if (CB_mode_Forts->isChecked()) |
1428 | 131 |
result |= 0x01; |
1427 | 132 |
if (CB_teamsDivide->isChecked()) |
1428 | 133 |
result |= 0x10; |
1530 | 134 |
if (CB_solid->isChecked()) |
135 |
result |= 0x04; |
|
1784 | 136 |
if (CB_border->isChecked()) |
137 |
result |= 0x08; |
|
1427 | 138 |
|
184 | 139 |
return result; |
140 |
} |
|
141 |
||
142 |
QString GameCFGWidget::getCurrentSeed() const |
|
143 |
{ |
|
144 |
return pMapContainer->getCurrentSeed(); |
|
145 |
} |
|
249 | 146 |
|
147 |
QString GameCFGWidget::getCurrentMap() const |
|
148 |
{ |
|
149 |
return pMapContainer->getCurrentMap(); |
|
150 |
} |
|
151 |
||
152 |
QString GameCFGWidget::getCurrentTheme() const |
|
153 |
{ |
|
154 |
return pMapContainer->getCurrentTheme(); |
|
155 |
} |
|
312 | 156 |
|
157 |
quint32 GameCFGWidget::getInitHealth() const |
|
158 |
{ |
|
159 |
return SB_InitHealth->value(); |
|
160 |
} |
|
161 |
||
162 |
quint32 GameCFGWidget::getTurnTime() const |
|
163 |
{ |
|
164 |
return SB_TurnTime->value(); |
|
165 |
} |
|
318 | 166 |
|
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
167 |
quint32 GameCFGWidget::getSuddenDeathTurns() const |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
168 |
{ |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
169 |
return SB_SuddenDeath->value(); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
170 |
} |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
171 |
|
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
172 |
quint32 GameCFGWidget::getCaseProbability() const |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
173 |
{ |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
174 |
return SB_CaseProb->value(); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
175 |
} |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
176 |
|
1797 | 177 |
quint32 GameCFGWidget::getTemplateFilter() const |
178 |
{ |
|
179 |
return CB_TemplateFilter->itemData(CB_TemplateFilter->currentIndex()).toInt(); |
|
180 |
} |
|
181 |
||
318 | 182 |
QStringList GameCFGWidget::getFullConfig() const |
183 |
{ |
|
184 |
QStringList sl; |
|
185 |
sl.append("eseed " + getCurrentSeed()); |
|
186 |
sl.append(QString("e$gmflags %1").arg(getGameFlags())); |
|
187 |
sl.append(QString("e$turntime %1").arg(getTurnTime() * 1000)); |
|
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
188 |
sl.append(QString("e$sd_turns %1").arg(getSuddenDeathTurns())); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
189 |
sl.append(QString("e$casefreq %1").arg(getCaseProbability())); |
1797 | 190 |
sl.append(QString("e$template_filter %1").arg(getTemplateFilter())); |
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
191 |
|
320 | 192 |
QString currentMap = getCurrentMap(); |
193 |
if (currentMap.size() > 0) |
|
318 | 194 |
sl.append("emap " + currentMap); |
320 | 195 |
sl.append("etheme " + getCurrentTheme()); |
318 | 196 |
return sl; |
197 |
} |
|
320 | 198 |
|
199 |
void GameCFGWidget::setSeed(const QString & seed) |
|
200 |
{ |
|
201 |
pMapContainer->setSeed(seed); |
|
202 |
} |
|
203 |
||
204 |
void GameCFGWidget::setMap(const QString & map) |
|
205 |
{ |
|
206 |
pMapContainer->setMap(map); |
|
207 |
} |
|
208 |
||
209 |
void GameCFGWidget::setTheme(const QString & theme) |
|
210 |
{ |
|
211 |
pMapContainer->setTheme(theme); |
|
212 |
} |
|
213 |
||
1427 | 214 |
void GameCFGWidget::setInitHealth(int health) |
320 | 215 |
{ |
216 |
SB_InitHealth->setValue(health); |
|
217 |
} |
|
218 |
||
1427 | 219 |
void GameCFGWidget::setTurnTime(int time) |
320 | 220 |
{ |
221 |
SB_TurnTime->setValue(time); |
|
222 |
} |
|
223 |
||
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
224 |
void GameCFGWidget::setSuddenDeathTurns(int turns) |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
225 |
{ |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
226 |
SB_SuddenDeath->setValue(turns); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
227 |
} |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
228 |
|
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
229 |
void GameCFGWidget::setCaseProbability(int prob) |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
230 |
{ |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
231 |
SB_CaseProb->setValue(prob); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
232 |
} |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
233 |
|
325 | 234 |
void GameCFGWidget::setFortsMode(bool value) |
320 | 235 |
{ |
236 |
CB_mode_Forts->setChecked(value); |
|
237 |
} |
|
325 | 238 |
|
1427 | 239 |
void GameCFGWidget::setTeamsDivide(bool value) |
325 | 240 |
{ |
1427 | 241 |
CB_teamsDivide->setChecked(value); |
325 | 242 |
} |
697 | 243 |
|
1530 | 244 |
void GameCFGWidget::setSolid(bool value) |
245 |
{ |
|
246 |
CB_solid->setChecked(value); |
|
247 |
} |
|
248 |
||
1784 | 249 |
void GameCFGWidget::setBorder(bool value) |
250 |
{ |
|
251 |
CB_border->setChecked(value); |
|
252 |
} |
|
253 |
||
703 | 254 |
void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo) |
697 | 255 |
{ |
1576
a02353129a41
Check for deprecated ammo schemes at startup and delete them
unc0rr
parents:
1532
diff
changeset
|
256 |
if (ammo.size() != cDefaultAmmoStore->size()) |
1517 | 257 |
QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); |
703 | 258 |
|
1517 | 259 |
int pos = WeaponsName->findText(name); |
260 |
if (pos == -1) { |
|
261 |
WeaponsName->addItem(name, ammo); |
|
262 |
WeaponsName->setCurrentIndex(WeaponsName->count() - 1); |
|
263 |
} else { |
|
264 |
WeaponsName->setItemData(pos, ammo); |
|
265 |
WeaponsName->setCurrentIndex(pos); |
|
266 |
} |
|
1530 | 267 |
} |
1531 | 268 |
|
1797 | 269 |
void GameCFGWidget::setTemplateFilter(int filter) |
270 |
{ |
|
271 |
CB_TemplateFilter->setCurrentIndex(filter); |
|
272 |
} |
|
273 |
||
274 |
void GameCFGWidget::templateFilterChanged(int filter) |
|
275 |
{ |
|
276 |
pMapContainer->setTemplateFilter(filter); |
|
277 |
emit newTemplateFilter(filter); |
|
278 |
} |
|
279 |
||
1531 | 280 |
void GameCFGWidget::ammoChanged(int index) |
281 |
{ |
|
1628
4939254196d6
Don't send empty ammo scheme to server when changing ammo schemes in room (fixes 'bad state' server message)
unc0rr
parents:
1576
diff
changeset
|
282 |
if (index >= 0) |
4939254196d6
Don't send empty ammo scheme to server when changing ammo schemes in room (fixes 'bad state' server message)
unc0rr
parents:
1576
diff
changeset
|
283 |
emit newWeaponScheme(WeaponsName->itemText(index), WeaponsName->itemData(index).toString()); |
1532 | 284 |
} |