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