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