author | unc0rr |
Mon, 12 Jan 2009 18:50:49 +0000 | |
changeset 1652 | 2f15a299ffc6 |
parent 1628 | 4939254196d6 |
child 1782 | e7589e37a6d6 |
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); |
|
1530 | 60 |
GBoxOptionsLayout->addWidget(L_TurnTime, 3, 0); |
61 |
GBoxOptionsLayout->addWidget(L_InitHealth, 4, 0); |
|
62 |
GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 5, 0); |
|
311 | 63 |
|
64 |
SB_TurnTime = new QSpinBox(GBoxOptions); |
|
1479 | 65 |
SB_TurnTime->setRange(1, 99); |
311 | 66 |
SB_TurnTime->setValue(45); |
67 |
SB_TurnTime->setSingleStep(15); |
|
1427 | 68 |
|
311 | 69 |
SB_InitHealth = new QSpinBox(GBoxOptions); |
70 |
SB_InitHealth->setRange(50, 200); |
|
312 | 71 |
SB_InitHealth->setValue(100); |
311 | 72 |
SB_InitHealth->setSingleStep(25); |
1530 | 73 |
GBoxOptionsLayout->addWidget(SB_TurnTime, 3, 1); |
74 |
GBoxOptionsLayout->addWidget(SB_InitHealth, 4, 1); |
|
1427 | 75 |
|
697 | 76 |
WeaponsName = new QComboBox(GBoxOptions); |
1530 | 77 |
GBoxOptionsLayout->addWidget(WeaponsName, 5, 1); |
696 | 78 |
|
1427 | 79 |
connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SIGNAL(initHealthChanged(int))); |
80 |
connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SIGNAL(turnTimeChanged(int))); |
|
81 |
connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SIGNAL(fortsModeChanged(bool))); |
|
82 |
connect(CB_teamsDivide, SIGNAL(toggled(bool)), this, SIGNAL(teamsDivideChanged(bool))); |
|
1530 | 83 |
connect(CB_solid, SIGNAL(toggled(bool)), this, SIGNAL(solidChanged(bool))); |
1531 | 84 |
connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); |
486 | 85 |
|
1427 | 86 |
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SIGNAL(seedChanged(const QString &))); |
87 |
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SIGNAL(mapChanged(const QString &))); |
|
88 |
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SIGNAL(themeChanged(const QString &))); |
|
184 | 89 |
} |
90 |
||
318 | 91 |
quint32 GameCFGWidget::getGameFlags() const |
184 | 92 |
{ |
93 |
quint32 result = 0; |
|
1427 | 94 |
|
184 | 95 |
if (CB_mode_Forts->isChecked()) |
1428 | 96 |
result |= 0x01; |
1427 | 97 |
if (CB_teamsDivide->isChecked()) |
1428 | 98 |
result |= 0x10; |
1530 | 99 |
if (CB_solid->isChecked()) |
100 |
result |= 0x04; |
|
1427 | 101 |
|
184 | 102 |
return result; |
103 |
} |
|
104 |
||
105 |
QString GameCFGWidget::getCurrentSeed() const |
|
106 |
{ |
|
107 |
return pMapContainer->getCurrentSeed(); |
|
108 |
} |
|
249 | 109 |
|
110 |
QString GameCFGWidget::getCurrentMap() const |
|
111 |
{ |
|
112 |
return pMapContainer->getCurrentMap(); |
|
113 |
} |
|
114 |
||
115 |
QString GameCFGWidget::getCurrentTheme() const |
|
116 |
{ |
|
117 |
return pMapContainer->getCurrentTheme(); |
|
118 |
} |
|
312 | 119 |
|
120 |
quint32 GameCFGWidget::getInitHealth() const |
|
121 |
{ |
|
122 |
return SB_InitHealth->value(); |
|
123 |
} |
|
124 |
||
125 |
quint32 GameCFGWidget::getTurnTime() const |
|
126 |
{ |
|
127 |
return SB_TurnTime->value(); |
|
128 |
} |
|
318 | 129 |
|
130 |
QStringList GameCFGWidget::getFullConfig() const |
|
131 |
{ |
|
132 |
QStringList sl; |
|
133 |
sl.append("eseed " + getCurrentSeed()); |
|
134 |
sl.append(QString("e$gmflags %1").arg(getGameFlags())); |
|
135 |
sl.append(QString("e$turntime %1").arg(getTurnTime() * 1000)); |
|
320 | 136 |
QString currentMap = getCurrentMap(); |
137 |
if (currentMap.size() > 0) |
|
318 | 138 |
sl.append("emap " + currentMap); |
320 | 139 |
sl.append("etheme " + getCurrentTheme()); |
318 | 140 |
return sl; |
141 |
} |
|
320 | 142 |
|
143 |
void GameCFGWidget::setSeed(const QString & seed) |
|
144 |
{ |
|
145 |
pMapContainer->setSeed(seed); |
|
146 |
} |
|
147 |
||
148 |
void GameCFGWidget::setMap(const QString & map) |
|
149 |
{ |
|
150 |
pMapContainer->setMap(map); |
|
151 |
} |
|
152 |
||
153 |
void GameCFGWidget::setTheme(const QString & theme) |
|
154 |
{ |
|
155 |
pMapContainer->setTheme(theme); |
|
156 |
} |
|
157 |
||
1427 | 158 |
void GameCFGWidget::setInitHealth(int health) |
320 | 159 |
{ |
160 |
SB_InitHealth->setValue(health); |
|
161 |
} |
|
162 |
||
1427 | 163 |
void GameCFGWidget::setTurnTime(int time) |
320 | 164 |
{ |
165 |
SB_TurnTime->setValue(time); |
|
166 |
} |
|
167 |
||
325 | 168 |
void GameCFGWidget::setFortsMode(bool value) |
320 | 169 |
{ |
170 |
CB_mode_Forts->setChecked(value); |
|
171 |
} |
|
325 | 172 |
|
1427 | 173 |
void GameCFGWidget::setTeamsDivide(bool value) |
325 | 174 |
{ |
1427 | 175 |
CB_teamsDivide->setChecked(value); |
325 | 176 |
} |
697 | 177 |
|
1530 | 178 |
void GameCFGWidget::setSolid(bool value) |
179 |
{ |
|
180 |
CB_solid->setChecked(value); |
|
181 |
} |
|
182 |
||
703 | 183 |
void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo) |
697 | 184 |
{ |
1576
a02353129a41
Check for deprecated ammo schemes at startup and delete them
unc0rr
parents:
1532
diff
changeset
|
185 |
if (ammo.size() != cDefaultAmmoStore->size()) |
1517 | 186 |
QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); |
703 | 187 |
|
1517 | 188 |
int pos = WeaponsName->findText(name); |
189 |
if (pos == -1) { |
|
190 |
WeaponsName->addItem(name, ammo); |
|
191 |
WeaponsName->setCurrentIndex(WeaponsName->count() - 1); |
|
192 |
} else { |
|
193 |
WeaponsName->setItemData(pos, ammo); |
|
194 |
WeaponsName->setCurrentIndex(pos); |
|
195 |
} |
|
1530 | 196 |
} |
1531 | 197 |
|
198 |
void GameCFGWidget::ammoChanged(int index) |
|
199 |
{ |
|
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
|
200 |
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
|
201 |
emit newWeaponScheme(WeaponsName->itemText(index), WeaponsName->itemData(index).toString()); |
1532 | 202 |
} |