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>
|
1217
|
25 |
|
184
|
26 |
#include "gamecfgwidget.h"
|
1217
|
27 |
#include "igbox.h"
|
184
|
28 |
|
349
|
29 |
GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) :
|
1217
|
30 |
QGroupBox(parent), mainLayout(this)
|
184
|
31 |
{
|
240
|
32 |
mainLayout.setMargin(0);
|
1217
|
33 |
// mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
|
218
|
34 |
|
1217
|
35 |
pMapContainer = new HWMapContainer(this);
|
|
36 |
mainLayout.addWidget(pMapContainer, 0, 0);
|
218
|
37 |
|
1217
|
38 |
IconedGroupBox *GBoxOptions = new IconedGroupBox(this);
|
218
|
39 |
GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
40 |
mainLayout.addWidget(GBoxOptions);
|
|
41 |
|
311
|
42 |
QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
|
1427
|
43 |
|
218
|
44 |
CB_mode_Forts = new QCheckBox(GBoxOptions);
|
184
|
45 |
CB_mode_Forts->setText(QCheckBox::tr("Forts mode"));
|
311
|
46 |
GBoxOptionsLayout->addWidget(CB_mode_Forts, 0, 0, 1, 2);
|
|
47 |
|
1427
|
48 |
CB_teamsDivide = new QCheckBox(GBoxOptions);
|
|
49 |
CB_teamsDivide->setText(QCheckBox::tr("Divide teams"));
|
|
50 |
GBoxOptionsLayout->addWidget(CB_teamsDivide, 1, 0, 1, 2);
|
|
51 |
|
311
|
52 |
L_TurnTime = new QLabel(QLabel::tr("Turn time"), GBoxOptions);
|
|
53 |
L_InitHealth = new QLabel(QLabel::tr("Initial health"), GBoxOptions);
|
1427
|
54 |
GBoxOptionsLayout->addWidget(L_TurnTime, 2, 0);
|
|
55 |
GBoxOptionsLayout->addWidget(L_InitHealth, 3, 0);
|
|
56 |
GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 4, 0);
|
311
|
57 |
|
|
58 |
SB_TurnTime = new QSpinBox(GBoxOptions);
|
1427
|
59 |
SB_TurnTime->setRange(5, 90);
|
311
|
60 |
SB_TurnTime->setValue(45);
|
|
61 |
SB_TurnTime->setSingleStep(15);
|
1427
|
62 |
|
311
|
63 |
SB_InitHealth = new QSpinBox(GBoxOptions);
|
|
64 |
SB_InitHealth->setRange(50, 200);
|
312
|
65 |
SB_InitHealth->setValue(100);
|
311
|
66 |
SB_InitHealth->setSingleStep(25);
|
1427
|
67 |
GBoxOptionsLayout->addWidget(SB_TurnTime, 2, 1);
|
|
68 |
GBoxOptionsLayout->addWidget(SB_InitHealth, 3, 1);
|
|
69 |
|
697
|
70 |
WeaponsName = new QComboBox(GBoxOptions);
|
1427
|
71 |
GBoxOptionsLayout->addWidget(WeaponsName, 4, 1);
|
696
|
72 |
|
1427
|
73 |
connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SIGNAL(initHealthChanged(int)));
|
|
74 |
connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SIGNAL(turnTimeChanged(int)));
|
|
75 |
connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SIGNAL(fortsModeChanged(bool)));
|
|
76 |
connect(CB_teamsDivide, SIGNAL(toggled(bool)), this, SIGNAL(teamsDivideChanged(bool)));
|
697
|
77 |
connect(WeaponsName, SIGNAL(activated(const QString&)), this, SIGNAL(newWeaponsName(const QString&)));
|
486
|
78 |
|
1427
|
79 |
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SIGNAL(seedChanged(const QString &)));
|
|
80 |
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SIGNAL(mapChanged(const QString &)));
|
|
81 |
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SIGNAL(themeChanged(const QString &)));
|
184
|
82 |
}
|
|
83 |
|
318
|
84 |
quint32 GameCFGWidget::getGameFlags() const
|
184
|
85 |
{
|
|
86 |
quint32 result = 0;
|
1427
|
87 |
|
184
|
88 |
if (CB_mode_Forts->isChecked())
|
|
89 |
result |= 1;
|
1427
|
90 |
if (CB_teamsDivide->isChecked())
|
|
91 |
result |= 1;
|
|
92 |
|
184
|
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 |
|
697
|
121 |
QString GameCFGWidget::getNetAmmo() const
|
|
122 |
{
|
|
123 |
return curNetAmmo;
|
|
124 |
}
|
|
125 |
|
318
|
126 |
QStringList GameCFGWidget::getFullConfig() const
|
|
127 |
{
|
|
128 |
QStringList sl;
|
|
129 |
sl.append("eseed " + getCurrentSeed());
|
|
130 |
sl.append(QString("e$gmflags %1").arg(getGameFlags()));
|
|
131 |
sl.append(QString("e$turntime %1").arg(getTurnTime() * 1000));
|
320
|
132 |
QString currentMap = getCurrentMap();
|
|
133 |
if (currentMap.size() > 0)
|
318
|
134 |
sl.append("emap " + currentMap);
|
320
|
135 |
sl.append("etheme " + getCurrentTheme());
|
318
|
136 |
return sl;
|
|
137 |
}
|
320
|
138 |
|
|
139 |
void GameCFGWidget::setSeed(const QString & seed)
|
|
140 |
{
|
|
141 |
pMapContainer->setSeed(seed);
|
|
142 |
}
|
|
143 |
|
|
144 |
void GameCFGWidget::setMap(const QString & map)
|
|
145 |
{
|
|
146 |
pMapContainer->setMap(map);
|
|
147 |
}
|
|
148 |
|
|
149 |
void GameCFGWidget::setTheme(const QString & theme)
|
|
150 |
{
|
|
151 |
pMapContainer->setTheme(theme);
|
|
152 |
}
|
|
153 |
|
1427
|
154 |
void GameCFGWidget::setInitHealth(int health)
|
320
|
155 |
{
|
|
156 |
SB_InitHealth->setValue(health);
|
|
157 |
}
|
|
158 |
|
1427
|
159 |
void GameCFGWidget::setTurnTime(int time)
|
320
|
160 |
{
|
|
161 |
SB_TurnTime->setValue(time);
|
|
162 |
}
|
|
163 |
|
325
|
164 |
void GameCFGWidget::setFortsMode(bool value)
|
320
|
165 |
{
|
|
166 |
CB_mode_Forts->setChecked(value);
|
|
167 |
}
|
325
|
168 |
|
1427
|
169 |
void GameCFGWidget::setTeamsDivide(bool value)
|
325
|
170 |
{
|
1427
|
171 |
CB_teamsDivide->setChecked(value);
|
325
|
172 |
}
|
697
|
173 |
|
703
|
174 |
void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo)
|
697
|
175 |
{
|
703
|
176 |
curNetAmmoName=name;
|
697
|
177 |
curNetAmmo=ammo;
|
703
|
178 |
|
|
179 |
WeaponsName->setEditable(false);
|
|
180 |
WeaponsName->clear();
|
|
181 |
WeaponsName->addItem(name);
|
697
|
182 |
}
|