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);
+ − 40
GBoxMapLayout->addWidget(new QWidget);
+ − 41
GBoxMapLayout->addWidget(pMapContainer);
+ − 42
GBoxMapLayout->addWidget(new QWidget);
+ − 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
+ − 70
mainLayout.addWidget(new QWidget, 100);
325
+ − 71
326
+ − 72
connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SLOT(onInitHealthChanged(int)));
+ − 73
connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SLOT(onTurnTimeChanged(int)));
325
+ − 74
connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SLOT(onFortsModeChanged(bool)));
486
+ − 75
325
+ − 76
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(onSeedChanged(const QString &)));
+ − 77
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(onThemeChanged(const QString &)));
+ − 78
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(onMapChanged(const QString &)));
184
+ − 79
}
+ − 80
318
+ − 81
quint32 GameCFGWidget::getGameFlags() const
184
+ − 82
{
+ − 83
quint32 result = 0;
+ − 84
if (CB_mode_Forts->isChecked())
+ − 85
result |= 1;
+ − 86
return result;
+ − 87
}
+ − 88
+ − 89
QString GameCFGWidget::getCurrentSeed() const
+ − 90
{
+ − 91
return pMapContainer->getCurrentSeed();
+ − 92
}
249
+ − 93
+ − 94
QString GameCFGWidget::getCurrentMap() const
+ − 95
{
+ − 96
return pMapContainer->getCurrentMap();
+ − 97
}
+ − 98
+ − 99
QString GameCFGWidget::getCurrentTheme() const
+ − 100
{
+ − 101
return pMapContainer->getCurrentTheme();
+ − 102
}
312
+ − 103
+ − 104
quint32 GameCFGWidget::getInitHealth() const
+ − 105
{
+ − 106
return SB_InitHealth->value();
+ − 107
}
+ − 108
+ − 109
quint32 GameCFGWidget::getTurnTime() const
+ − 110
{
+ − 111
return SB_TurnTime->value();
+ − 112
}
318
+ − 113
+ − 114
QStringList GameCFGWidget::getFullConfig() const
+ − 115
{
+ − 116
QStringList sl;
+ − 117
sl.append("eseed " + getCurrentSeed());
+ − 118
sl.append(QString("e$gmflags %1").arg(getGameFlags()));
+ − 119
sl.append(QString("e$turntime %1").arg(getTurnTime() * 1000));
320
+ − 120
QString currentMap = getCurrentMap();
+ − 121
if (currentMap.size() > 0)
318
+ − 122
sl.append("emap " + currentMap);
320
+ − 123
sl.append("etheme " + getCurrentTheme());
318
+ − 124
return sl;
+ − 125
}
320
+ − 126
+ − 127
void GameCFGWidget::setSeed(const QString & seed)
+ − 128
{
+ − 129
pMapContainer->setSeed(seed);
+ − 130
}
+ − 131
+ − 132
void GameCFGWidget::setMap(const QString & map)
+ − 133
{
+ − 134
pMapContainer->setMap(map);
+ − 135
}
+ − 136
+ − 137
void GameCFGWidget::setTheme(const QString & theme)
+ − 138
{
+ − 139
pMapContainer->setTheme(theme);
+ − 140
}
+ − 141
325
+ − 142
void GameCFGWidget::setInitHealth(quint32 health)
320
+ − 143
{
+ − 144
SB_InitHealth->setValue(health);
+ − 145
}
+ − 146
325
+ − 147
void GameCFGWidget::setTurnTime(quint32 time)
320
+ − 148
{
+ − 149
SB_TurnTime->setValue(time);
+ − 150
}
+ − 151
325
+ − 152
void GameCFGWidget::setFortsMode(bool value)
320
+ − 153
{
+ − 154
CB_mode_Forts->setChecked(value);
+ − 155
}
325
+ − 156
+ − 157
void GameCFGWidget::onInitHealthChanged(int health)
+ − 158
{
+ − 159
emit initHealthChanged(health);
+ − 160
}
+ − 161
+ − 162
void GameCFGWidget::onTurnTimeChanged(int time)
+ − 163
{
+ − 164
emit turnTimeChanged(time);
+ − 165
}
+ − 166
+ − 167
void GameCFGWidget::onFortsModeChanged(bool value)
+ − 168
{
+ − 169
emit fortsModeChanged(value);
+ − 170
}
+ − 171
+ − 172
void GameCFGWidget::onSeedChanged(const QString & seed)
+ − 173
{
+ − 174
emit seedChanged(seed);
+ − 175
}
+ − 176
+ − 177
void GameCFGWidget::onMapChanged(const QString & map)
+ − 178
{
+ − 179
emit mapChanged(map);
+ − 180
}
+ − 181
+ − 182
void GameCFGWidget::onThemeChanged(const QString & theme)
+ − 183
{
+ − 184
emit themeChanged(theme);
+ − 185
}