author | unc0rr |
Sun, 10 Aug 2008 20:18:40 +0000 | |
changeset 1191 | 5539aa59f703 |
parent 1066 | 1f1b3686a2b0 |
child 1214 | 090f94cd663e |
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> |
|
184 | 25 |
#include "gamecfgwidget.h" |
26 |
||
349 | 27 |
GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) : |
184 | 28 |
QWidget(parent), mainLayout(this) |
29 |
{ |
|
240 | 30 |
mainLayout.setMargin(0); |
452 | 31 |
mainLayout.setSizeConstraint(QLayout::SetMinimumSize); |
218 | 32 |
QGroupBox *GBoxMap = new QGroupBox(this); |
33 |
GBoxMap->setTitle(QGroupBox::tr("Landscape")); |
|
34 |
GBoxMap->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
|
35 |
mainLayout.addWidget(GBoxMap); |
|
36 |
||
37 |
QHBoxLayout *GBoxMapLayout = new QHBoxLayout(GBoxMap); |
|
240 | 38 |
GBoxMapLayout->setMargin(0); |
218 | 39 |
pMapContainer = new HWMapContainer(GBoxMap); |
677
9d0bcc3c903a
Save some vertical pixels using fewer margin in HWMapContainer
unc0rr
parents:
486
diff
changeset
|
40 |
GBoxMapLayout->addStretch(); |
218 | 41 |
GBoxMapLayout->addWidget(pMapContainer); |
677
9d0bcc3c903a
Save some vertical pixels using fewer margin in HWMapContainer
unc0rr
parents:
486
diff
changeset
|
42 |
GBoxMapLayout->addStretch(); |
218 | 43 |
|
44 |
QGroupBox *GBoxOptions = new QGroupBox(this); |
|
45 |
GBoxOptions->setTitle(QGroupBox::tr("Game scheme")); |
|
46 |
GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
|
47 |
mainLayout.addWidget(GBoxOptions); |
|
48 |
||
311 | 49 |
QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions); |
218 | 50 |
CB_mode_Forts = new QCheckBox(GBoxOptions); |
184 | 51 |
CB_mode_Forts->setText(QCheckBox::tr("Forts mode")); |
311 | 52 |
GBoxOptionsLayout->addWidget(CB_mode_Forts, 0, 0, 1, 2); |
53 |
||
54 |
L_TurnTime = new QLabel(QLabel::tr("Turn time"), GBoxOptions); |
|
55 |
L_InitHealth = new QLabel(QLabel::tr("Initial health"), GBoxOptions); |
|
56 |
GBoxOptionsLayout->addWidget(L_TurnTime, 1, 0); |
|
57 |
GBoxOptionsLayout->addWidget(L_InitHealth, 2, 0); |
|
697 | 58 |
GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 3, 0); |
311 | 59 |
|
60 |
SB_TurnTime = new QSpinBox(GBoxOptions); |
|
61 |
SB_TurnTime->setRange(15, 90); |
|
62 |
SB_TurnTime->setValue(45); |
|
63 |
SB_TurnTime->setSingleStep(15); |
|
64 |
SB_InitHealth = new QSpinBox(GBoxOptions); |
|
65 |
SB_InitHealth->setRange(50, 200); |
|
312 | 66 |
SB_InitHealth->setValue(100); |
311 | 67 |
SB_InitHealth->setSingleStep(25); |
68 |
GBoxOptionsLayout->addWidget(SB_TurnTime, 1, 1); |
|
69 |
GBoxOptionsLayout->addWidget(SB_InitHealth, 2, 1); |
|
697 | 70 |
WeaponsName = new QComboBox(GBoxOptions); |
71 |
GBoxOptionsLayout->addWidget(WeaponsName, 3, 1); |
|
696 | 72 |
|
73 |
mainLayout.addWidget(new QWidget(this), 100); |
|
325 | 74 |
|
326 | 75 |
connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SLOT(onInitHealthChanged(int))); |
76 |
connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SLOT(onTurnTimeChanged(int))); |
|
325 | 77 |
connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SLOT(onFortsModeChanged(bool))); |
697 | 78 |
connect(WeaponsName, SIGNAL(activated(const QString&)), this, SIGNAL(newWeaponsName(const QString&))); |
486 | 79 |
|
325 | 80 |
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(onSeedChanged(const QString &))); |
81 |
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(onThemeChanged(const QString &))); |
|
82 |
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(onMapChanged(const QString &))); |
|
184 | 83 |
} |
84 |
||
318 | 85 |
quint32 GameCFGWidget::getGameFlags() const |
184 | 86 |
{ |
87 |
quint32 result = 0; |
|
88 |
if (CB_mode_Forts->isChecked()) |
|
89 |
result |= 1; |
|
90 |
return result; |
|
91 |
} |
|
92 |
||
93 |
QString GameCFGWidget::getCurrentSeed() const |
|
94 |
{ |
|
95 |
return pMapContainer->getCurrentSeed(); |
|
96 |
} |
|
249 | 97 |
|
98 |
QString GameCFGWidget::getCurrentMap() const |
|
99 |
{ |
|
100 |
return pMapContainer->getCurrentMap(); |
|
101 |
} |
|
102 |
||
103 |
QString GameCFGWidget::getCurrentTheme() const |
|
104 |
{ |
|
105 |
return pMapContainer->getCurrentTheme(); |
|
106 |
} |
|
312 | 107 |
|
108 |
quint32 GameCFGWidget::getInitHealth() const |
|
109 |
{ |
|
110 |
return SB_InitHealth->value(); |
|
111 |
} |
|
112 |
||
113 |
quint32 GameCFGWidget::getTurnTime() const |
|
114 |
{ |
|
115 |
return SB_TurnTime->value(); |
|
116 |
} |
|
318 | 117 |
|
697 | 118 |
QString GameCFGWidget::getNetAmmo() const |
119 |
{ |
|
120 |
return curNetAmmo; |
|
121 |
} |
|
122 |
||
318 | 123 |
QStringList GameCFGWidget::getFullConfig() const |
124 |
{ |
|
125 |
QStringList sl; |
|
126 |
sl.append("eseed " + getCurrentSeed()); |
|
127 |
sl.append(QString("e$gmflags %1").arg(getGameFlags())); |
|
128 |
sl.append(QString("e$turntime %1").arg(getTurnTime() * 1000)); |
|
320 | 129 |
QString currentMap = getCurrentMap(); |
130 |
if (currentMap.size() > 0) |
|
318 | 131 |
sl.append("emap " + currentMap); |
320 | 132 |
sl.append("etheme " + getCurrentTheme()); |
318 | 133 |
return sl; |
134 |
} |
|
320 | 135 |
|
136 |
void GameCFGWidget::setSeed(const QString & seed) |
|
137 |
{ |
|
138 |
pMapContainer->setSeed(seed); |
|
139 |
} |
|
140 |
||
141 |
void GameCFGWidget::setMap(const QString & map) |
|
142 |
{ |
|
143 |
pMapContainer->setMap(map); |
|
144 |
} |
|
145 |
||
146 |
void GameCFGWidget::setTheme(const QString & theme) |
|
147 |
{ |
|
148 |
pMapContainer->setTheme(theme); |
|
149 |
} |
|
150 |
||
325 | 151 |
void GameCFGWidget::setInitHealth(quint32 health) |
320 | 152 |
{ |
153 |
SB_InitHealth->setValue(health); |
|
154 |
} |
|
155 |
||
325 | 156 |
void GameCFGWidget::setTurnTime(quint32 time) |
320 | 157 |
{ |
158 |
SB_TurnTime->setValue(time); |
|
159 |
} |
|
160 |
||
325 | 161 |
void GameCFGWidget::setFortsMode(bool value) |
320 | 162 |
{ |
163 |
CB_mode_Forts->setChecked(value); |
|
164 |
} |
|
325 | 165 |
|
166 |
void GameCFGWidget::onInitHealthChanged(int health) |
|
167 |
{ |
|
168 |
emit initHealthChanged(health); |
|
169 |
} |
|
170 |
||
171 |
void GameCFGWidget::onTurnTimeChanged(int time) |
|
172 |
{ |
|
173 |
emit turnTimeChanged(time); |
|
174 |
} |
|
175 |
||
176 |
void GameCFGWidget::onFortsModeChanged(bool value) |
|
177 |
{ |
|
178 |
emit fortsModeChanged(value); |
|
179 |
} |
|
180 |
||
181 |
void GameCFGWidget::onSeedChanged(const QString & seed) |
|
182 |
{ |
|
183 |
emit seedChanged(seed); |
|
184 |
} |
|
185 |
||
186 |
void GameCFGWidget::onMapChanged(const QString & map) |
|
187 |
{ |
|
188 |
emit mapChanged(map); |
|
189 |
} |
|
190 |
||
191 |
void GameCFGWidget::onThemeChanged(const QString & theme) |
|
192 |
{ |
|
193 |
emit themeChanged(theme); |
|
194 |
} |
|
697 | 195 |
|
703 | 196 |
void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo) |
697 | 197 |
{ |
703 | 198 |
curNetAmmoName=name; |
697 | 199 |
curNetAmmo=ammo; |
703 | 200 |
|
201 |
WeaponsName->setEditable(false); |
|
202 |
WeaponsName->clear(); |
|
203 |
WeaponsName->addItem(name); |
|
697 | 204 |
} |