1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
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 <QGridLayout> |
|
20 #include <QPushButton> |
|
21 #include <QComboBox> |
|
22 #include <QLabel> |
|
23 #include <QLineEdit> |
|
24 #include <QTabWidget> |
|
25 #include <QGroupBox> |
|
26 #include <QToolBox> |
|
27 |
|
28 #include "pageeditteam.h" |
|
29 #include "sdlkeys.h" |
|
30 #include "hwconsts.h" |
|
31 #include "SquareLabel.h" |
|
32 #include "hats.h" |
|
33 #include "HWApplication.h" |
|
34 |
|
35 PageEditTeam::PageEditTeam(QWidget* parent, SDLInteraction * sdli) : |
|
36 AbstractPage(parent) |
|
37 { |
|
38 mySdli = sdli; |
|
39 QGridLayout * pageLayout = new QGridLayout(this); |
|
40 QTabWidget * tbw = new QTabWidget(this); |
|
41 QWidget * page1 = new QWidget(this); |
|
42 QWidget * page2 = new QWidget(this); |
|
43 tbw->addTab(page1, tr("General")); |
|
44 tbw->addTab(page2, tr("Advanced")); |
|
45 pageLayout->addWidget(tbw, 0, 0, 1, 3); |
|
46 BtnTeamDiscard = addButton(":/res/Exit.png", pageLayout, 1, 0, true); |
|
47 BtnTeamSave = addButton(":/res/Save.png", pageLayout, 1, 2, true);; |
|
48 BtnTeamSave->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}"); |
|
49 BtnTeamDiscard->setFixedHeight(BtnTeamSave->height()); |
|
50 BtnTeamDiscard->setStyleSheet("QPushButton{margin-top: 31px;}"); |
|
51 |
|
52 QHBoxLayout * page1Layout = new QHBoxLayout(page1); |
|
53 page1Layout->setAlignment(Qt::AlignTop); |
|
54 QGridLayout * page2Layout = new QGridLayout(page2); |
|
55 |
|
56 // ====== Page 1 ====== |
|
57 QVBoxLayout * vbox1 = new QVBoxLayout(); |
|
58 QVBoxLayout * vbox2 = new QVBoxLayout(); |
|
59 page1Layout->addLayout(vbox1); |
|
60 page1Layout->addLayout(vbox2); |
|
61 |
|
62 GBoxHedgehogs = new QGroupBox(this); |
|
63 GBoxHedgehogs->setTitle(QGroupBox::tr("Team Members")); |
|
64 GBoxHedgehogs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
65 QGridLayout * GBHLayout = new QGridLayout(GBoxHedgehogs); |
|
66 |
|
67 signalMapper1 = new QSignalMapper(this); |
|
68 signalMapper2 = new QSignalMapper(this); |
|
69 |
|
70 connect(signalMapper1, SIGNAL(mapped(int)), this, SLOT(fixHHname(int))); |
|
71 |
|
72 HatsModel * hatsModel = new HatsModel(GBoxHedgehogs); |
|
73 for(int i = 0; i < 8; i++) |
|
74 { |
|
75 HHHats[i] = new QComboBox(GBoxHedgehogs); |
|
76 HHHats[i]->setModel(hatsModel); |
|
77 HHHats[i]->setIconSize(QSize(32, 37)); |
|
78 //HHHats[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents); |
|
79 //HHHats[i]->setModelColumn(1); |
|
80 //HHHats[i]->setMinimumWidth(132); |
|
81 GBHLayout->addWidget(HHHats[i], i, 0); |
|
82 |
|
83 HHNameEdit[i] = new QLineEdit(GBoxHedgehogs); |
|
84 HHNameEdit[i]->setMaxLength(64); |
|
85 HHNameEdit[i]->setMinimumWidth(120); |
|
86 GBHLayout->addWidget(HHNameEdit[i], i, 1); |
|
87 |
|
88 connect(HHNameEdit[i], SIGNAL(editingFinished()), signalMapper1, SLOT(map())); |
|
89 signalMapper1->setMapping(HHNameEdit[i], i); |
|
90 |
|
91 randButton[i] = addButton(":/res/dice.png", GBHLayout, i, 3, true); |
|
92 |
|
93 connect(randButton[i], SIGNAL(clicked()), signalMapper2, SLOT(map())); |
|
94 signalMapper2->setMapping(randButton[i], i); |
|
95 } |
|
96 |
|
97 randTeamButton = addButton(QPushButton::tr("Random Team"), GBHLayout, 9, false); |
|
98 |
|
99 vbox1->addWidget(GBoxHedgehogs); |
|
100 |
|
101 |
|
102 GBoxTeam = new QGroupBox(this); |
|
103 GBoxTeam->setTitle(QGroupBox::tr("Team Settings")); |
|
104 GBoxTeam->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
|
105 QGridLayout * GBTLayout = new QGridLayout(GBoxTeam); |
|
106 QLabel * tmpLabel = new QLabel(GBoxTeam); |
|
107 tmpLabel->setText(QLabel::tr("Name")); |
|
108 GBTLayout->addWidget(tmpLabel, 0, 0); |
|
109 tmpLabel = new QLabel(GBoxTeam); |
|
110 tmpLabel->setText(QLabel::tr("Type")); |
|
111 GBTLayout->addWidget(tmpLabel, 1, 0); |
|
112 tmpLabel = new QLabel(GBoxTeam); |
|
113 tmpLabel->setText(QLabel::tr("Grave")); |
|
114 GBTLayout->addWidget(tmpLabel, 2, 0); |
|
115 tmpLabel = new QLabel(GBoxTeam); |
|
116 tmpLabel->setText(QLabel::tr("Flag")); |
|
117 GBTLayout->addWidget(tmpLabel, 3, 0); |
|
118 tmpLabel = new QLabel(GBoxTeam); |
|
119 tmpLabel->setText(QLabel::tr("Voice")); |
|
120 GBTLayout->addWidget(tmpLabel, 4, 0); |
|
121 |
|
122 |
|
123 TeamNameEdit = new QLineEdit(GBoxTeam); |
|
124 TeamNameEdit->setMaxLength(64); |
|
125 GBTLayout->addWidget(TeamNameEdit, 0, 1); |
|
126 vbox2->addWidget(GBoxTeam); |
|
127 |
|
128 CBTeamLvl = new QComboBox(GBoxTeam); |
|
129 CBTeamLvl->setIconSize(QSize(48, 48)); |
|
130 CBTeamLvl->addItem(QIcon(":/res/botlevels/0.png"), QComboBox::tr("Human")); |
|
131 for(int i = 5; i > 0; i--) |
|
132 CBTeamLvl->addItem( |
|
133 QIcon(QString(":/res/botlevels/%1.png").arg(6 - i)), |
|
134 QString("%1 %2").arg(QComboBox::tr("Level")).arg(i) |
|
135 ); |
|
136 GBTLayout->addWidget(CBTeamLvl, 1, 1); |
|
137 |
|
138 CBGrave = new QComboBox(GBoxTeam); |
|
139 CBGrave->setMaxCount(65535); |
|
140 CBGrave->setIconSize(QSize(32, 32)); |
|
141 GBTLayout->addWidget(CBGrave, 2, 1); |
|
142 |
|
143 CBFlag = new QComboBox(GBoxTeam); |
|
144 CBFlag->setMaxCount(65535); |
|
145 CBFlag->setIconSize(QSize(22, 15)); |
|
146 GBTLayout->addWidget(CBFlag, 3, 1); |
|
147 |
|
148 { |
|
149 QHBoxLayout * hbox = new QHBoxLayout(); |
|
150 CBVoicepack = new QComboBox(GBoxTeam); |
|
151 { |
|
152 QDir tmpdir; |
|
153 QStringList list; |
|
154 tmpdir.cd(cfgdir->absolutePath()); |
|
155 if (tmpdir.cd("Data/Sounds/voices")) |
|
156 { |
|
157 list = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); |
|
158 CBVoicepack->addItems(list); |
|
159 } |
|
160 |
|
161 tmpdir.cd(datadir->absolutePath()); |
|
162 tmpdir.cd("Sounds/voices"); |
|
163 QStringList tmplist = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); |
|
164 QStringList tmplist2; |
|
165 for (QStringList::Iterator it = tmplist.begin(); it != tmplist.end(); ++it) |
|
166 if (!list.contains(*it,Qt::CaseInsensitive)) tmplist2.append(*it); |
|
167 |
|
168 CBVoicepack->addItems(tmplist2); |
|
169 } |
|
170 hbox->addWidget(CBVoicepack, 100); |
|
171 BtnTestSound = addButton(":/res/PlaySound.png", hbox, 1, true); |
|
172 hbox->setStretchFactor(BtnTestSound, 1); |
|
173 connect(BtnTestSound, SIGNAL(clicked()), this, SLOT(testSound())); |
|
174 GBTLayout->addLayout(hbox, 4, 1); |
|
175 } |
|
176 |
|
177 GBoxFort = new QGroupBox(this); |
|
178 GBoxFort->setTitle(QGroupBox::tr("Fort")); |
|
179 QGridLayout * GBFLayout = new QGridLayout(GBoxFort); |
|
180 CBFort = new QComboBox(GBoxFort); |
|
181 CBFort->setMaxCount(65535); |
|
182 GBFLayout->addWidget(CBFort, 0, 0); |
|
183 FortPreview = new SquareLabel(GBoxFort); |
|
184 FortPreview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
185 FortPreview->setMinimumSize(128, 128); |
|
186 FortPreview->setPixmap(QPixmap()); |
|
187 // perhaps due to handling its own paintevents, SquareLabel doesn't play nice with the stars |
|
188 //FortPreview->setAttribute(Qt::WA_PaintOnScreen, true); |
|
189 GBFLayout->addWidget(FortPreview, 1, 0); |
|
190 vbox2->addWidget(GBoxFort); |
|
191 |
|
192 QDir tmpdir; |
|
193 QStringList userforts; |
|
194 tmpdir.cd(cfgdir->absolutePath()); |
|
195 if (tmpdir.cd("Data/Forts")) |
|
196 { |
|
197 tmpdir.setFilter(QDir::Files); |
|
198 userforts = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"); |
|
199 CBFort->addItems(userforts); |
|
200 } |
|
201 |
|
202 tmpdir.cd("../Graphics/Graves"); |
|
203 QStringList userlist = tmpdir.entryList(QStringList("*.png")); |
|
204 for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) |
|
205 { |
|
206 QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Graves/" + *it); |
|
207 QIcon icon(pix.copy(0, 0, 32, 32)); |
|
208 CBGrave->addItem(icon, QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1")); |
|
209 } |
|
210 |
|
211 tmpdir.cd(datadir->absolutePath()); |
|
212 tmpdir.cd("Forts"); |
|
213 tmpdir.setFilter(QDir::Files); |
|
214 |
|
215 QStringList tmplist = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"); |
|
216 QStringList dataforts; |
|
217 for (QStringList::Iterator it = tmplist.begin(); it != tmplist.end(); ++it) |
|
218 if (!userforts.contains(*it,Qt::CaseInsensitive)) dataforts.append(*it); |
|
219 |
|
220 CBFort->addItems(dataforts); |
|
221 connect(CBFort, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(CBFort_activated(const QString &))); |
|
222 |
|
223 tmpdir.cd("../Graphics/Graves"); |
|
224 QStringList datalist = tmpdir.entryList(QStringList("*.png")); |
|
225 for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) |
|
226 { |
|
227 if (userlist.contains(*it,Qt::CaseInsensitive)) continue; |
|
228 QPixmap pix(datadir->absolutePath() + "/Graphics/Graves/" + *it); |
|
229 QIcon icon(pix.copy(0, 0, 32, 32)); |
|
230 CBGrave->addItem(icon, (*it).replace(QRegExp("^(.*)\\.png"), "\\1")); |
|
231 } |
|
232 |
|
233 // add the default flag |
|
234 CBFlag->addItem(QIcon(QPixmap(datadir->absolutePath() + "/Graphics/Flags/hedgewars.png").copy(0, 0, 22, 15)), "Hedgewars", "hedgewars"); |
|
235 CBFlag->insertSeparator(CBFlag->count()); |
|
236 |
|
237 tmpdir.cd(cfgdir->absolutePath()); |
|
238 tmpdir.cd("Data/Graphics/Flags"); |
|
239 userlist = tmpdir.entryList(QStringList("*.png")); |
|
240 |
|
241 // add all country flags |
|
242 for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) |
|
243 { |
|
244 QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + *it); |
|
245 QIcon icon(pix.copy(0, 0, 22, 15)); |
|
246 if(it->compare("cpu.png") && it->compare("hedgewars.png") && (it->indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags |
|
247 { |
|
248 QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
249 CBFlag->addItem(icon, QString(flag).replace("_", " "), flag); |
|
250 } |
|
251 } |
|
252 |
|
253 CBFlag->insertSeparator(CBFlag->count()); |
|
254 |
|
255 // add all community flags |
|
256 for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) |
|
257 { |
|
258 QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + *it); |
|
259 QIcon icon(pix.copy(0, 0, 22, 15)); |
|
260 if(it->indexOf("cm_") > -1) // skip non community flags this time |
|
261 { |
|
262 QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
263 CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag); |
|
264 } |
|
265 } |
|
266 |
|
267 CBFlag->insertSeparator(CBFlag->count()); |
|
268 |
|
269 tmpdir.cd(datadir->absolutePath()); |
|
270 tmpdir.cd("Graphics/Flags"); |
|
271 datalist = tmpdir.entryList(QStringList("*.png")); |
|
272 |
|
273 // add all country flags |
|
274 for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) |
|
275 { |
|
276 if (userlist.contains(*it,Qt::CaseInsensitive)) continue; |
|
277 QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it); |
|
278 QIcon icon(pix.copy(0, 0, 22, 15)); |
|
279 if(it->compare("cpu.png") && it->compare("hedgewars.png") && (it->indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags |
|
280 { |
|
281 QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
282 CBFlag->addItem(icon, QString(flag).replace("_", " "), flag); |
|
283 } |
|
284 } |
|
285 |
|
286 CBFlag->insertSeparator(CBFlag->count()); |
|
287 |
|
288 // add all community flags |
|
289 for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) |
|
290 { |
|
291 if (userlist.contains(*it,Qt::CaseInsensitive)) continue; |
|
292 QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it); |
|
293 QIcon icon(pix.copy(0, 0, 22, 15)); |
|
294 if(it->indexOf("cm_") > -1) // skip non community flags this time |
|
295 { |
|
296 QString flag = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
297 CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag); |
|
298 } |
|
299 } |
|
300 |
|
301 vbox1->addStretch(); |
|
302 vbox2->addStretch(); |
|
303 |
|
304 // ====== Page 2 ====== |
|
305 GBoxBinds = new QGroupBox(this); |
|
306 GBoxBinds->setTitle(QGroupBox::tr("Key binds")); |
|
307 QGridLayout * GBBLayout = new QGridLayout(GBoxBinds); |
|
308 BindsBox = new QToolBox(GBoxBinds); |
|
309 BindsBox->setLineWidth(0); |
|
310 GBBLayout->addWidget(BindsBox); |
|
311 page2Layout->addWidget(GBoxBinds, 0, 0); |
|
312 |
|
313 quint16 i = 0; |
|
314 quint16 num = 0; |
|
315 QWidget * curW = NULL; |
|
316 QGridLayout * pagelayout = NULL; |
|
317 QLabel* l = NULL; |
|
318 while (i < BINDS_NUMBER) { |
|
319 if(cbinds[i].category != NULL) |
|
320 { |
|
321 if(curW != NULL) |
|
322 { |
|
323 l = new QLabel(curW); |
|
324 l->setText(""); |
|
325 pagelayout->addWidget(l, num++, 0, 1, 2); |
|
326 } |
|
327 curW = new QWidget(this); |
|
328 BindsBox->addItem(curW, HWApplication::translate("binds (categories)", cbinds[i].category)); |
|
329 pagelayout = new QGridLayout(curW); |
|
330 num = 0; |
|
331 } |
|
332 if(cbinds[i].description != NULL) |
|
333 { |
|
334 l = new QLabel(curW); |
|
335 l->setText((num > 0 ? QString("\n") : QString("")) + HWApplication::translate("binds (descriptions)", cbinds[i].description)); |
|
336 pagelayout->addWidget(l, num++, 0, 1, 2); |
|
337 } |
|
338 |
|
339 l = new QLabel(curW); |
|
340 l->setText(HWApplication::translate("binds", cbinds[i].name)); |
|
341 l->setAlignment(Qt::AlignRight); |
|
342 pagelayout->addWidget(l, num, 0); |
|
343 CBBind[i] = new QComboBox(curW); |
|
344 for(int j = 0; sdlkeys[j][1][0] != '\0'; j++) |
|
345 CBBind[i]->addItem(HWApplication::translate("binds (keys)", sdlkeys[j][1]).contains(": ") ? HWApplication::translate("binds (keys)", sdlkeys[j][1]) : HWApplication::translate("binds (keys)", "Keyboard") + QString(": ") + HWApplication::translate("binds (keys)", sdlkeys[j][1]), sdlkeys[j][0]); |
|
346 pagelayout->addWidget(CBBind[i++], num++, 1); |
|
347 } |
|
348 } |
|
349 |
|
350 void PageEditTeam::fixHHname(int idx) |
|
351 { |
|
352 HHNameEdit[idx]->setText(HHNameEdit[idx]->text().trimmed()); |
|
353 |
|
354 if (HHNameEdit[idx]->text().isEmpty()) |
|
355 HHNameEdit[idx]->setText(QLineEdit::tr("hedgehog %1").arg(idx+1)); |
|
356 } |
|
357 |
|
358 void PageEditTeam::CBFort_activated(const QString & fortname) |
|
359 { |
|
360 QFile tmp; |
|
361 tmp.setFileName(cfgdir->absolutePath() + "/Data/Forts/" + fortname + "L.png"); |
|
362 if (!tmp.exists()) tmp.setFileName(datadir->absolutePath() + "/Forts/" + fortname + "L.png"); |
|
363 QPixmap pix(QFileInfo(tmp).absoluteFilePath()); |
|
364 FortPreview->setPixmap(pix); |
|
365 } |
|
366 |
|
367 void PageEditTeam::testSound() |
|
368 { |
|
369 Mix_Chunk *sound; |
|
370 QDir tmpdir; |
|
371 mySdli->SDLMusicInit(); |
|
372 |
|
373 tmpdir.cd(cfgdir->absolutePath()); |
|
374 if (!tmpdir.cd("Data/Sounds/voices/"+CBVoicepack->currentText())) |
|
375 { |
|
376 tmpdir.cd(datadir->absolutePath()); |
|
377 tmpdir.cd("Sounds/voices"); |
|
378 tmpdir.cd(CBVoicepack->currentText()); |
|
379 } |
|
380 |
|
381 QStringList list = tmpdir.entryList(QStringList() << "Illgetyou.ogg" << "Incoming.ogg" << "Stupid.ogg" << "Coward.ogg" << "Firstblood.ogg", QDir::Files); |
|
382 if (list.size()) { |
|
383 sound = Mix_LoadWAV(QString(tmpdir.absolutePath() + "/" + list[rand() % list.size()]).toLocal8Bit().constData()); |
|
384 Mix_PlayChannel(-1, sound, 0); |
|
385 } |
|
386 } |
|