author | unc0rr |
Thu, 12 Mar 2009 20:19:33 +0000 | |
changeset 1887 | d68939b3f7f0 |
parent 1885 | 75489216b5b0 |
child 1890 | de5cfe3beb22 |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
1878
b3b277d2b891
own md5 function, no qca2 dependancy (patch by nemo with Qt adaptation by me)
unc0rr
parents:
1877
diff
changeset
|
3 |
* Copyright (c) 2006, 2007, 2009 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> |
1884 | 26 |
#include <QTableView> |
1885 | 27 |
#include <QPushButton> |
1217 | 28 |
|
184 | 29 |
#include "gamecfgwidget.h" |
1217 | 30 |
#include "igbox.h" |
1517 | 31 |
#include "hwconsts.h" |
1884 | 32 |
#include "ammoSchemeModel.h" |
184 | 33 |
|
349 | 34 |
GameCFGWidget::GameCFGWidget(QWidget* parent, bool externalControl) : |
1217 | 35 |
QGroupBox(parent), mainLayout(this) |
184 | 36 |
{ |
240 | 37 |
mainLayout.setMargin(0); |
1217 | 38 |
// mainLayout.setSizeConstraint(QLayout::SetMinimumSize); |
218 | 39 |
|
1217 | 40 |
pMapContainer = new HWMapContainer(this); |
41 |
mainLayout.addWidget(pMapContainer, 0, 0); |
|
218 | 42 |
|
1217 | 43 |
IconedGroupBox *GBoxOptions = new IconedGroupBox(this); |
218 | 44 |
GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
45 |
mainLayout.addWidget(GBoxOptions); |
|
46 |
||
311 | 47 |
QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions); |
1884 | 48 |
|
1887 | 49 |
tv = new QTableView(this); |
1884 | 50 |
GBoxOptionsLayout->addWidget(tv, 0, 0, 1, 2); |
1885 | 51 |
|
52 |
QPushButton * goToSchemePage = new QPushButton(GBoxOptions); |
|
53 |
goToSchemePage->setText(tr("Edit schemes")); |
|
54 |
GBoxOptionsLayout->addWidget(goToSchemePage, 1, 0, 1, 2); |
|
55 |
connect(goToSchemePage, SIGNAL(clicked()), this, SIGNAL(goToSchemes())); |
|
1427 | 56 |
|
1784 | 57 |
GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 8, 0); |
311 | 58 |
|
697 | 59 |
WeaponsName = new QComboBox(GBoxOptions); |
1784 | 60 |
GBoxOptionsLayout->addWidget(WeaponsName, 8, 1); |
1874 | 61 |
|
1531 | 62 |
connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); |
486 | 63 |
|
1874 | 64 |
connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &))); |
65 |
connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &))); |
|
66 |
connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &))); |
|
1876 | 67 |
connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int))); |
184 | 68 |
} |
69 |
||
318 | 70 |
quint32 GameCFGWidget::getGameFlags() const |
184 | 71 |
{ |
72 |
quint32 result = 0; |
|
1427 | 73 |
|
1885 | 74 |
/* if (CB_mode_Forts->isChecked()) |
1428 | 75 |
result |= 0x01; |
1427 | 76 |
if (CB_teamsDivide->isChecked()) |
1428 | 77 |
result |= 0x10; |
1530 | 78 |
if (CB_solid->isChecked()) |
79 |
result |= 0x04; |
|
1784 | 80 |
if (CB_border->isChecked()) |
1885 | 81 |
result |= 0x08;*/ |
1427 | 82 |
|
184 | 83 |
return result; |
84 |
} |
|
85 |
||
312 | 86 |
quint32 GameCFGWidget::getInitHealth() const |
87 |
{ |
|
1885 | 88 |
// return SB_InitHealth->value(); |
312 | 89 |
} |
90 |
||
318 | 91 |
QStringList GameCFGWidget::getFullConfig() const |
92 |
{ |
|
93 |
QStringList sl; |
|
1875 | 94 |
sl.append("eseed " + pMapContainer->getCurrentSeed()); |
318 | 95 |
sl.append(QString("e$gmflags %1").arg(getGameFlags())); |
1885 | 96 |
// sl.append(QString("e$turntime %1").arg(SB_TurnTime->value() * 1000)); |
97 |
// sl.append(QString("e$sd_turns %1").arg(SB_SuddenDeath->value())); |
|
98 |
// sl.append(QString("e$casefreq %1").arg(SB_CaseProb->value())); |
|
1802 | 99 |
sl.append(QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter())); |
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1628
diff
changeset
|
100 |
|
1875 | 101 |
QString currentMap = pMapContainer->getCurrentMap(); |
320 | 102 |
if (currentMap.size() > 0) |
318 | 103 |
sl.append("emap " + currentMap); |
1875 | 104 |
sl.append("etheme " + pMapContainer->getCurrentTheme()); |
318 | 105 |
return sl; |
106 |
} |
|
320 | 107 |
|
703 | 108 |
void GameCFGWidget::setNetAmmo(const QString& name, const QString& ammo) |
697 | 109 |
{ |
1576
a02353129a41
Check for deprecated ammo schemes at startup and delete them
unc0rr
parents:
1532
diff
changeset
|
110 |
if (ammo.size() != cDefaultAmmoStore->size()) |
1517 | 111 |
QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); |
703 | 112 |
|
1517 | 113 |
int pos = WeaponsName->findText(name); |
114 |
if (pos == -1) { |
|
115 |
WeaponsName->addItem(name, ammo); |
|
116 |
WeaponsName->setCurrentIndex(WeaponsName->count() - 1); |
|
117 |
} else { |
|
118 |
WeaponsName->setItemData(pos, ammo); |
|
119 |
WeaponsName->setCurrentIndex(pos); |
|
120 |
} |
|
1530 | 121 |
} |
1531 | 122 |
|
1875 | 123 |
void GameCFGWidget::fullNetConfig() |
124 |
{ |
|
125 |
ammoChanged(WeaponsName->currentIndex()); |
|
126 |
||
127 |
seedChanged(pMapContainer->getCurrentSeed()); |
|
1876 | 128 |
templateFilterChanged(pMapContainer->getTemplateFilter()); |
1875 | 129 |
themeChanged(pMapContainer->getCurrentTheme()); |
130 |
||
131 |
// map must be the last |
|
132 |
QString map = pMapContainer->getCurrentMap(); |
|
133 |
if (map.size()) |
|
134 |
mapChanged(map); |
|
135 |
} |
|
136 |
||
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
137 |
void GameCFGWidget::setParam(const QString & param, const QStringList & slValue) |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
138 |
{ |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
139 |
if (slValue.size() == 1) |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
140 |
{ |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
141 |
QString value = slValue[0]; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
142 |
if (param == "MAP") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
143 |
pMapContainer->setMap(value); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
144 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
145 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
146 |
if (param == "SEED") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
147 |
pMapContainer->setSeed(value); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
148 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
149 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
150 |
if (param == "THEME") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
151 |
pMapContainer->setTheme(value); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
152 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
153 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
154 |
if (param == "HEALTH") { |
1885 | 155 |
// SB_InitHealth->setValue(value.toUInt()); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
156 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
157 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
158 |
if (param == "TURNTIME") { |
1885 | 159 |
// SB_TurnTime->setValue(value.toUInt()); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
160 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
161 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
162 |
if (param == "SD_TURNS") { |
1885 | 163 |
// SB_SuddenDeath->setValue(value.toUInt()); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
164 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
165 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
166 |
if (param == "CASEFACTOR") { |
1885 | 167 |
// SB_CaseProb->setValue(value.toUInt()); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
168 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
169 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
170 |
if (param == "FORTSMODE") { |
1885 | 171 |
// CB_mode_Forts->setChecked(value.toUInt() != 0); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
172 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
173 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
174 |
if (param == "DIVIDETEAMS") { |
1885 | 175 |
// CB_teamsDivide->setChecked(value.toUInt() != 0); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
176 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
177 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
178 |
if (param == "SOLIDLAND") { |
1885 | 179 |
// CB_solid->setChecked(value.toUInt() != 0); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
180 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
181 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
182 |
if (param == "BORDER") { |
1885 | 183 |
// CB_border->setChecked(value.toUInt() != 0); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
184 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
185 |
} |
1876 | 186 |
if (param == "TEMPLATE") { |
187 |
pMapContainer->setTemplateFilter(value.toUInt()); |
|
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
188 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
189 |
} |
1876 | 190 |
} |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
191 |
|
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
192 |
if (slValue.size() == 2) |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
193 |
{ |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
194 |
if (param == "AMMO") { |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
195 |
setNetAmmo(slValue[0], slValue[1]); |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
196 |
return; |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
197 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
198 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
199 |
} |
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1802
diff
changeset
|
200 |
|
1874 | 201 |
void GameCFGWidget::ammoChanged(int index) |
202 |
{ |
|
203 |
if (index >= 0) |
|
204 |
emit paramChanged( |
|
205 |
"AMMO", |
|
206 |
QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString() |
|
207 |
); |
|
208 |
} |
|
209 |
||
210 |
void GameCFGWidget::mapChanged(const QString & value) |
|
211 |
{ |
|
212 |
emit paramChanged("MAP", QStringList(value)); |
|
213 |
} |
|
214 |
||
1876 | 215 |
void GameCFGWidget::templateFilterChanged(int value) |
216 |
{ |
|
217 |
emit paramChanged("TEMPLATE", QStringList(QString::number(value))); |
|
218 |
} |
|
219 |
||
1874 | 220 |
void GameCFGWidget::seedChanged(const QString & value) |
221 |
{ |
|
222 |
emit paramChanged("SEED", QStringList(value)); |
|
223 |
} |
|
224 |
||
225 |
void GameCFGWidget::themeChanged(const QString & value) |
|
226 |
{ |
|
227 |
emit paramChanged("THEME", QStringList(value)); |
|
228 |
} |