author | displacer |
Wed, 09 Jan 2008 21:22:22 +0000 | |
changeset 696 | d6f32ed6edc8 |
parent 677 | 9d0bcc3c903a |
child 697 | 44f167938201 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
2 |
* Hedgewars, a worms-like 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); |
|
58 |
||
59 |
SB_TurnTime = new QSpinBox(GBoxOptions); |
|
60 |
SB_TurnTime->setRange(15, 90); |
|
61 |
SB_TurnTime->setValue(45); |
|
62 |
SB_TurnTime->setSingleStep(15); |
|
63 |
SB_InitHealth = new QSpinBox(GBoxOptions); |
|
64 |
SB_InitHealth->setRange(50, 200); |
|
312 | 65 |
SB_InitHealth->setValue(100); |
311 | 66 |
SB_InitHealth->setSingleStep(25); |
67 |
GBoxOptionsLayout->addWidget(SB_TurnTime, 1, 1); |
|
68 |
GBoxOptionsLayout->addWidget(SB_InitHealth, 2, 1); |
|
218 | 69 |
|
696 | 70 |
QGroupBox *GBoxWeapons = new QGroupBox(this); |
71 |
GBoxWeapons->setTitle(QGroupBox::tr("Weapons")); |
|
72 |
QHBoxLayout* lt=new QHBoxLayout(GBoxWeapons); |
|
73 |
WeaponsName = new QComboBox(GBoxWeapons); |
|
74 |
lt->addWidget(WeaponsName); |
|
75 |
mainLayout.addWidget(GBoxWeapons); |
|
76 |
||
77 |
mainLayout.addWidget(new QWidget(this), 100); |
|
325 | 78 |
|
326 | 79 |
connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SLOT(onInitHealthChanged(int))); |
80 |
connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SLOT(onTurnTimeChanged(int))); |
|
325 | 81 |
connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SLOT(onFortsModeChanged(bool))); |
486 | 82 |
|
325 | 83 |
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(onSeedChanged(const QString &))); |
84 |
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(onThemeChanged(const QString &))); |
|
85 |
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(onMapChanged(const QString &))); |
|
184 | 86 |
} |
87 |
||
318 | 88 |
quint32 GameCFGWidget::getGameFlags() const |
184 | 89 |
{ |
90 |
quint32 result = 0; |
|
91 |
if (CB_mode_Forts->isChecked()) |
|
92 |
result |= 1; |
|
93 |
return result; |
|
94 |
} |
|
95 |
||
96 |
QString GameCFGWidget::getCurrentSeed() const |
|
97 |
{ |
|
98 |
return pMapContainer->getCurrentSeed(); |
|
99 |
} |
|
249 | 100 |
|
101 |
QString GameCFGWidget::getCurrentMap() const |
|
102 |
{ |
|
103 |
return pMapContainer->getCurrentMap(); |
|
104 |
} |
|
105 |
||
106 |
QString GameCFGWidget::getCurrentTheme() const |
|
107 |
{ |
|
108 |
return pMapContainer->getCurrentTheme(); |
|
109 |
} |
|
312 | 110 |
|
111 |
quint32 GameCFGWidget::getInitHealth() const |
|
112 |
{ |
|
113 |
return SB_InitHealth->value(); |
|
114 |
} |
|
115 |
||
116 |
quint32 GameCFGWidget::getTurnTime() const |
|
117 |
{ |
|
118 |
return SB_TurnTime->value(); |
|
119 |
} |
|
318 | 120 |
|
121 |
QStringList GameCFGWidget::getFullConfig() const |
|
122 |
{ |
|
123 |
QStringList sl; |
|
124 |
sl.append("eseed " + getCurrentSeed()); |
|
125 |
sl.append(QString("e$gmflags %1").arg(getGameFlags())); |
|
126 |
sl.append(QString("e$turntime %1").arg(getTurnTime() * 1000)); |
|
320 | 127 |
QString currentMap = getCurrentMap(); |
128 |
if (currentMap.size() > 0) |
|
318 | 129 |
sl.append("emap " + currentMap); |
320 | 130 |
sl.append("etheme " + getCurrentTheme()); |
318 | 131 |
return sl; |
132 |
} |
|
320 | 133 |
|
134 |
void GameCFGWidget::setSeed(const QString & seed) |
|
135 |
{ |
|
136 |
pMapContainer->setSeed(seed); |
|
137 |
} |
|
138 |
||
139 |
void GameCFGWidget::setMap(const QString & map) |
|
140 |
{ |
|
141 |
pMapContainer->setMap(map); |
|
142 |
} |
|
143 |
||
144 |
void GameCFGWidget::setTheme(const QString & theme) |
|
145 |
{ |
|
146 |
pMapContainer->setTheme(theme); |
|
147 |
} |
|
148 |
||
325 | 149 |
void GameCFGWidget::setInitHealth(quint32 health) |
320 | 150 |
{ |
151 |
SB_InitHealth->setValue(health); |
|
152 |
} |
|
153 |
||
325 | 154 |
void GameCFGWidget::setTurnTime(quint32 time) |
320 | 155 |
{ |
156 |
SB_TurnTime->setValue(time); |
|
157 |
} |
|
158 |
||
325 | 159 |
void GameCFGWidget::setFortsMode(bool value) |
320 | 160 |
{ |
161 |
CB_mode_Forts->setChecked(value); |
|
162 |
} |
|
325 | 163 |
|
164 |
void GameCFGWidget::onInitHealthChanged(int health) |
|
165 |
{ |
|
166 |
emit initHealthChanged(health); |
|
167 |
} |
|
168 |
||
169 |
void GameCFGWidget::onTurnTimeChanged(int time) |
|
170 |
{ |
|
171 |
emit turnTimeChanged(time); |
|
172 |
} |
|
173 |
||
174 |
void GameCFGWidget::onFortsModeChanged(bool value) |
|
175 |
{ |
|
176 |
emit fortsModeChanged(value); |
|
177 |
} |
|
178 |
||
179 |
void GameCFGWidget::onSeedChanged(const QString & seed) |
|
180 |
{ |
|
181 |
emit seedChanged(seed); |
|
182 |
} |
|
183 |
||
184 |
void GameCFGWidget::onMapChanged(const QString & map) |
|
185 |
{ |
|
186 |
emit mapChanged(map); |
|
187 |
} |
|
188 |
||
189 |
void GameCFGWidget::onThemeChanged(const QString & theme) |
|
190 |
{ |
|
191 |
emit themeChanged(theme); |
|
192 |
} |