241 PageEditTeam::PageEditTeam(QWidget* parent) : |
242 PageEditTeam::PageEditTeam(QWidget* parent) : |
242 AbstractPage(parent) |
243 AbstractPage(parent) |
243 { |
244 { |
244 initPage(); |
245 initPage(); |
245 |
246 |
|
247 QRegExp pngSuffix("\\.png$"); |
|
248 |
246 m_playerHash = "0000000000000000000000000000000000000000"; |
249 m_playerHash = "0000000000000000000000000000000000000000"; |
247 |
250 |
248 QDir tmpdir; |
251 HWDataManager & dataMgr = HWDataManager::instance(); |
|
252 |
249 QStringList list; |
253 QStringList list; |
250 tmpdir.cd(cfgdir->absolutePath()); |
254 |
251 if (tmpdir.cd("Data/Sounds/voices")) |
255 |
252 { |
256 // voicepacks |
253 list = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); |
257 list = dataMgr.entryList("Sounds/voices", |
254 CBVoicepack->addItems(list); |
258 QDir::AllDirs | QDir::NoDotAndDotDot); |
255 } |
259 |
256 |
260 CBVoicepack->addItems(list); |
257 tmpdir.cd(datadir->absolutePath()); |
261 |
258 tmpdir.cd("Sounds/voices"); |
262 |
259 QStringList tmplist = tmpdir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); |
263 // forts |
260 QStringList tmplist2; |
264 list = dataMgr.entryList("Forts", QDir::Files, QStringList("*L.png")); |
261 foreach (const QString & line, tmplist) |
265 list.replaceInStrings(QRegExp("L\\.png$"), ""); |
262 { |
266 CBFort->addItems(list); |
263 if (!list.contains(line,Qt::CaseInsensitive)) |
267 |
264 tmplist2.append(line); |
268 |
265 } |
269 // graves |
266 |
270 list = |
267 CBVoicepack->addItems(tmplist2); |
271 dataMgr.entryList("Graphics/Graves", QDir::Files, QStringList("*.png")); |
268 |
272 |
269 QStringList userforts; |
273 foreach (QString file, list) |
270 tmpdir.cd(cfgdir->absolutePath()); |
274 { |
271 if (tmpdir.cd("Data/Forts")) |
275 QPixmap pix(dataMgr.findFileForRead("Graphics/Graves/" + file)); |
272 { |
276 if ((pix.height() > 32) || pix.width() > 32) |
273 tmpdir.setFilter(QDir::Files); |
277 pix = pix.copy(0, 0, 32, 32); |
274 userforts = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"); |
278 QIcon icon(pix); |
275 CBFort->addItems(userforts); |
279 |
276 } |
280 QString grave = QString(file).remove(pngSuffix); |
277 |
281 |
278 tmpdir.cd("../Graphics/Graves"); |
|
279 QStringList userlist = tmpdir.entryList(QStringList("*.png")); |
|
280 for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) |
|
281 { |
|
282 QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Graves/" + *it); |
|
283 QIcon icon(pix.copy(0, 0, 32, 32)); |
|
284 CBGrave->addItem(icon, QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1")); |
|
285 } |
|
286 |
|
287 tmpdir.cd(datadir->absolutePath()); |
|
288 tmpdir.cd("Forts"); |
|
289 tmpdir.setFilter(QDir::Files); |
|
290 |
|
291 tmplist = tmpdir.entryList(QStringList("*L.png")).replaceInStrings(QRegExp("^(.*)L\\.png"), "\\1"); |
|
292 QStringList dataforts; |
|
293 foreach (const QString & line, tmplist) |
|
294 { |
|
295 if (!userforts.contains(line,Qt::CaseInsensitive)) |
|
296 dataforts.append(line); |
|
297 } |
|
298 |
|
299 CBFort->addItems(dataforts); |
|
300 |
|
301 tmpdir.cd("../Graphics/Graves"); |
|
302 QStringList datalist = tmpdir.entryList(QStringList("*.png")); |
|
303 foreach (const QString & line, datalist) |
|
304 { |
|
305 if (userlist.contains(line,Qt::CaseInsensitive)) continue; |
|
306 QPixmap pix(datadir->absolutePath() + "/Graphics/Graves/" + line); |
|
307 QIcon icon(pix.copy(0, 0, 32, 32)); |
|
308 QString grave = line; |
|
309 grave = grave.replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
310 CBGrave->addItem(icon, grave); |
282 CBGrave->addItem(icon, grave); |
311 } |
283 } |
312 |
284 |
|
285 // flags |
|
286 |
|
287 list = |
|
288 dataMgr.entryList("Graphics/Flags", QDir::Files, QStringList("*.png")); |
|
289 |
|
290 // skip cpu and hedgewars flags |
|
291 int idx = list.indexOf("cpu.png"); |
|
292 if (idx >= 0) |
|
293 list.removeAt(idx); |
|
294 idx = list.indexOf("hedgewars.png"); |
|
295 if (idx >= 0) |
|
296 list.removeAt(idx); |
|
297 |
313 // add the default flag |
298 // add the default flag |
314 CBFlag->addItem(QIcon(QPixmap(datadir->absolutePath() + "/Graphics/Flags/hedgewars.png").copy(0, 0, 22, 15)), "Hedgewars", "hedgewars"); |
299 QPixmap hwFlag(dataMgr.findFileForRead("Graphics/Flags/hedgewars.png")); |
315 CBFlag->insertSeparator(CBFlag->count()); |
300 CBFlag->addItem(QIcon(hwFlag.copy(0, 0, 22, 15)), "Hedgewars", "hedgewars"); |
316 |
301 |
317 tmpdir.cd(cfgdir->absolutePath()); |
302 // add seperator after |
318 tmpdir.cd("Data/Graphics/Flags"); |
303 CBFlag->insertSeparator(1); |
319 userlist = tmpdir.entryList(QStringList("*.png")); |
304 |
320 |
305 int insertAt = 2; // insert country flags after Hedgewars flag and seperator |
|
306 |
321 // add all country flags |
307 // add all country flags |
322 foreach (const QString & line, userlist) |
308 foreach (const QString & file, list) |
323 { |
309 { |
324 QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + line); |
310 QIcon icon(QPixmap(dataMgr.findFileForRead("Graphics/Flags/" + file))); |
325 QIcon icon(pix.copy(0, 0, 22, 15)); |
311 |
326 // TODO improve readablility |
312 QString flag = QString(file).remove(pngSuffix); |
327 if(line.compare("cpu.png") && line.compare("hedgewars.png") && (line.indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags |
313 |
|
314 bool isCountryFlag = !file.startsWith("cm_"); |
|
315 |
|
316 if (isCountryFlag) |
328 { |
317 { |
329 QString flag = line; |
318 CBFlag->insertItem(insertAt, icon, flag.replace("_", " "), flag); |
330 flag = flag.replace(QRegExp("^(.*)\\.png"), "\\1"); |
319 insertAt++; |
331 CBFlag->addItem(icon, flag.replace("_", " "), flag); |
|
332 } |
320 } |
333 } |
321 else // append community flags at end |
334 |
322 CBFlag->addItem(icon, flag.replace("cm_", QComboBox::tr("Community") + ": "), flag); |
335 CBFlag->insertSeparator(CBFlag->count()); |
323 } |
336 |
324 |
337 // add all community flags |
325 // add separator between country flags and community flags |
338 for (QStringList::Iterator it = userlist.begin(); it != userlist.end(); ++it ) |
326 CBFlag->insertSeparator(insertAt); |
339 { |
|
340 QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Flags/" + *it); |
|
341 QIcon icon(pix.copy(0, 0, 22, 15)); |
|
342 if(it->indexOf("cm_") > -1) // skip non community flags this time |
|
343 { |
|
344 QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
345 CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag); |
|
346 } |
|
347 } |
|
348 |
|
349 CBFlag->insertSeparator(CBFlag->count()); |
|
350 |
|
351 tmpdir.cd(datadir->absolutePath()); |
|
352 tmpdir.cd("Graphics/Flags"); |
|
353 datalist = tmpdir.entryList(QStringList("*.png")); |
|
354 |
|
355 // add all country flags |
|
356 for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) |
|
357 { |
|
358 if (userlist.contains(*it,Qt::CaseInsensitive)) continue; |
|
359 QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it); |
|
360 QIcon icon(pix.copy(0, 0, 22, 15)); |
|
361 if(it->compare("cpu.png") && it->compare("hedgewars.png") && (it->indexOf("cm_") == -1)) // skip cpu and hedgewars flags as well as all community flags |
|
362 { |
|
363 QString flag = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
364 CBFlag->addItem(icon, QString(flag).replace("_", " "), flag); |
|
365 } |
|
366 } |
|
367 |
|
368 CBFlag->insertSeparator(CBFlag->count()); |
|
369 |
|
370 // add all community flags |
|
371 for (QStringList::Iterator it = datalist.begin(); it != datalist.end(); ++it ) |
|
372 { |
|
373 if (userlist.contains(*it,Qt::CaseInsensitive)) continue; |
|
374 QPixmap pix(datadir->absolutePath() + "/Graphics/Flags/" + *it); |
|
375 QIcon icon(pix.copy(0, 0, 22, 15)); |
|
376 if(it->indexOf("cm_") > -1) // skip non community flags this time |
|
377 { |
|
378 QString flag = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
|
379 CBFlag->addItem(icon, QString(flag).replace("cm_", QComboBox::tr("Community") + ": "), flag); |
|
380 } |
|
381 } |
|
382 } |
327 } |
383 |
328 |
384 void PageEditTeam::fixHHname(int idx) |
329 void PageEditTeam::fixHHname(int idx) |
385 { |
330 { |
386 HHNameEdit[idx]->setText(HHNameEdit[idx]->text().trimmed()); |
331 HHNameEdit[idx]->setText(HHNameEdit[idx]->text().trimmed()); |