author | unc0rr |
Sat, 14 Feb 2009 16:44:50 +0000 | |
changeset 1793 | 3e8caf5fee58 |
parent 1784 | dfe9bafb4590 |
child 1797 | fedd8649fdd9 |
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); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
65 |
L_CaseProb = new QLabel(QLabel::tr("Bonus factor"), 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); |
|
311 | 71 |
|
72 |
SB_TurnTime = new QSpinBox(GBoxOptions); |
|
1479 | 73 |
SB_TurnTime->setRange(1, 99); |
311 | 74 |
SB_TurnTime->setValue(45); |
75 |
SB_TurnTime->setSingleStep(15); |
|
1427 | 76 |
|
311 | 77 |
SB_InitHealth = new QSpinBox(GBoxOptions); |
78 |
SB_InitHealth->setRange(50, 200); |
|
312 | 79 |
SB_InitHealth->setValue(100); |
311 | 80 |
SB_InitHealth->setSingleStep(25); |
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
81 |
|
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
82 |
SB_SuddenDeath = new QSpinBox(GBoxOptions); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
83 |
SB_SuddenDeath->setRange(0, 50); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
84 |
SB_SuddenDeath->setValue(15); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
85 |
SB_SuddenDeath->setSingleStep(3); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
86 |
|
1783 | 87 |
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
|
88 |
SB_CaseProb->setRange(0, 9); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
89 |
SB_CaseProb->setValue(5); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
90 |
|
1784 | 91 |
GBoxOptionsLayout->addWidget(SB_TurnTime, 4, 1); |
92 |
GBoxOptionsLayout->addWidget(SB_InitHealth, 5, 1); |
|
93 |
GBoxOptionsLayout->addWidget(SB_SuddenDeath, 6, 1); |
|
94 |
GBoxOptionsLayout->addWidget(SB_CaseProb, 7, 1); |
|
1427 | 95 |
|
697 | 96 |
WeaponsName = new QComboBox(GBoxOptions); |
1784 | 97 |
GBoxOptionsLayout->addWidget(WeaponsName, 8, 1); |
696 | 98 |
|
1427 | 99 |
connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SIGNAL(initHealthChanged(int))); |
100 |
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
|
101 |
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
|
102 |
connect(SB_CaseProb, SIGNAL(valueChanged(int)), this, SIGNAL(caseProbabilityChanged(int))); |
1427 | 103 |
connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SIGNAL(fortsModeChanged(bool))); |
104 |
connect(CB_teamsDivide, SIGNAL(toggled(bool)), this, SIGNAL(teamsDivideChanged(bool))); |
|
1530 | 105 |
connect(CB_solid, SIGNAL(toggled(bool)), this, SIGNAL(solidChanged(bool))); |
1784 | 106 |
connect(CB_border, SIGNAL(toggled(bool)), this, SIGNAL(borderChanged(bool))); |
1531 | 107 |
connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); |
486 | 108 |
|
1427 | 109 |
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SIGNAL(seedChanged(const QString &))); |
110 |
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SIGNAL(mapChanged(const QString &))); |
|
111 |
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SIGNAL(themeChanged(const QString &))); |
|
184 | 112 |
} |
113 |
||
318 | 114 |
quint32 GameCFGWidget::getGameFlags() const |
184 | 115 |
{ |
116 |
quint32 result = 0; |
|
1427 | 117 |
|
184 | 118 |
if (CB_mode_Forts->isChecked()) |
1428 | 119 |
result |= 0x01; |
1427 | 120 |
if (CB_teamsDivide->isChecked()) |
1428 | 121 |
result |= 0x10; |
1530 | 122 |
if (CB_solid->isChecked()) |
123 |
result |= 0x04; |
|
1784 | 124 |
if (CB_border->isChecked()) |
125 |
result |= 0x08; |
|
1427 | 126 |
|
184 | 127 |
return result; |
128 |
} |
|
129 |
||
130 |
QString GameCFGWidget::getCurrentSeed() const |
|
131 |
{ |
|
132 |
return pMapContainer->getCurrentSeed(); |
|
133 |
} |
|
249 | 134 |
|
135 |
QString GameCFGWidget::getCurrentMap() const |
|
136 |
{ |
|
137 |
return pMapContainer->getCurrentMap(); |
|
138 |
} |
|
139 |
||
140 |
QString GameCFGWidget::getCurrentTheme() const |
|
141 |
{ |
|
142 |
return pMapContainer->getCurrentTheme(); |
|
143 |
} |
|
312 | 144 |
|
145 |
quint32 GameCFGWidget::getInitHealth() const |
|
146 |
{ |
|
147 |
return SB_InitHealth->value(); |
|
148 |
} |
|
149 |
||
150 |
quint32 GameCFGWidget::getTurnTime() const |
|
151 |
{ |
|
152 |
return SB_TurnTime->value(); |
|
153 |
} |
|
318 | 154 |
|
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
155 |
quint32 GameCFGWidget::getSuddenDeathTurns() const |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
156 |
{ |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
157 |
return SB_SuddenDeath->value(); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
158 |
} |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
159 |
|
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
160 |
quint32 GameCFGWidget::getCaseProbability() const |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
161 |
{ |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
162 |
return SB_CaseProb->value(); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
163 |
} |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
164 |
|
318 | 165 |
QStringList GameCFGWidget::getFullConfig() const |
166 |
{ |
|
167 |
QStringList sl; |
|
168 |
sl.append("eseed " + getCurrentSeed()); |
|
169 |
sl.append(QString("e$gmflags %1").arg(getGameFlags())); |
|
170 |
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
|
171 |
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
|
172 |
sl.append(QString("e$casefreq %1").arg(getCaseProbability())); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
173 |
|
320 | 174 |
QString currentMap = getCurrentMap(); |
175 |
if (currentMap.size() > 0) |
|
318 | 176 |
sl.append("emap " + currentMap); |
320 | 177 |
sl.append("etheme " + getCurrentTheme()); |
318 | 178 |
return sl; |
179 |
} |
|
320 | 180 |
|
181 |
void GameCFGWidget::setSeed(const QString & seed) |
|
182 |
{ |
|
183 |
pMapContainer->setSeed(seed); |
|
184 |
} |
|
185 |
||
186 |
void GameCFGWidget::setMap(const QString & map) |
|
187 |
{ |
|
188 |
pMapContainer->setMap(map); |
|
189 |
} |
|
190 |
||
191 |
void GameCFGWidget::setTheme(const QString & theme) |
|
192 |
{ |
|
193 |
pMapContainer->setTheme(theme); |
|
194 |
} |
|
195 |
||
1427 | 196 |
void GameCFGWidget::setInitHealth(int health) |
320 | 197 |
{ |
198 |
SB_InitHealth->setValue(health); |
|
199 |
} |
|
200 |
||
1427 | 201 |
void GameCFGWidget::setTurnTime(int time) |
320 | 202 |
{ |
203 |
SB_TurnTime->setValue(time); |
|
204 |
} |
|
205 |
||
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
206 |
void GameCFGWidget::setSuddenDeathTurns(int turns) |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
207 |
{ |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
208 |
SB_SuddenDeath->setValue(turns); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
209 |
} |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
210 |
|
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
211 |
void GameCFGWidget::setCaseProbability(int prob) |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
212 |
{ |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
213 |
SB_CaseProb->setValue(prob); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
214 |
} |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
215 |
|
325 | 216 |
void GameCFGWidget::setFortsMode(bool value) |
320 | 217 |
{ |
218 |
CB_mode_Forts->setChecked(value); |
|
219 |
} |
|
325 | 220 |
|
1427 | 221 |
void GameCFGWidget::setTeamsDivide(bool value) |
325 | 222 |
{ |
1427 | 223 |
CB_teamsDivide->setChecked(value); |
325 | 224 |
} |
697 | 225 |
|
1530 | 226 |
void GameCFGWidget::setSolid(bool value) |
227 |
{ |
|
228 |
CB_solid->setChecked(value); |
|
229 |
} |
|
230 |
||
1784 | 231 |
void GameCFGWidget::setBorder(bool value) |
232 |
{ |
|
233 |
CB_border->setChecked(value); |
|
234 |
} |
|
235 |
||
703 | 236 |
void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo) |
697 | 237 |
{ |
1576
a02353129a41
Check for deprecated ammo schemes at startup and delete them
unc0rr
parents:
1532
diff
changeset
|
238 |
if (ammo.size() != cDefaultAmmoStore->size()) |
1517 | 239 |
QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); |
703 | 240 |
|
1517 | 241 |
int pos = WeaponsName->findText(name); |
242 |
if (pos == -1) { |
|
243 |
WeaponsName->addItem(name, ammo); |
|
244 |
WeaponsName->setCurrentIndex(WeaponsName->count() - 1); |
|
245 |
} else { |
|
246 |
WeaponsName->setItemData(pos, ammo); |
|
247 |
WeaponsName->setCurrentIndex(pos); |
|
248 |
} |
|
1530 | 249 |
} |
1531 | 250 |
|
251 |
void GameCFGWidget::ammoChanged(int index) |
|
252 |
{ |
|
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
|
253 |
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
|
254 |
emit newWeaponScheme(WeaponsName->itemText(index), WeaponsName->itemData(index).toString()); |
1532 | 255 |
} |