32 #include "hwconsts.h" |
32 #include "hwconsts.h" |
33 #include "ammoSchemeModel.h" |
33 #include "ammoSchemeModel.h" |
34 #include "proto.h" |
34 #include "proto.h" |
35 |
35 |
36 GameCFGWidget::GameCFGWidget(QWidget* parent) : |
36 GameCFGWidget::GameCFGWidget(QWidget* parent) : |
37 QGroupBox(parent) |
37 QGroupBox(parent) |
38 , mainLayout(this) |
38 , mainLayout(this) |
39 , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}") |
39 , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}") |
40 { |
40 { |
41 mainLayout.setMargin(0); |
41 mainLayout.setMargin(0); |
42 // mainLayout.setSizeConstraint(QLayout::SetMinimumSize); |
42 // mainLayout.setSizeConstraint(QLayout::SetMinimumSize); |
43 |
43 |
44 pMapContainer = new HWMapContainer(this); |
44 pMapContainer = new HWMapContainer(this); |
57 GBoxOptionsLayout->addWidget(Scripts, 1, 1); |
57 GBoxOptionsLayout->addWidget(Scripts, 1, 1); |
58 |
58 |
59 Scripts->addItem("Normal"); |
59 Scripts->addItem("Normal"); |
60 Scripts->insertSeparator(1); |
60 Scripts->insertSeparator(1); |
61 |
61 |
62 for (int i = 0; i < scriptList->size(); ++i) { |
62 for (int i = 0; i < scriptList->size(); ++i) |
|
63 { |
63 QString script = (*scriptList)[i].remove(".lua", Qt::CaseInsensitive); |
64 QString script = (*scriptList)[i].remove(".lua", Qt::CaseInsensitive); |
64 QList<QVariant> scriptInfo; |
65 QList<QVariant> scriptInfo; |
65 scriptInfo.push_back(script); |
66 scriptInfo.push_back(script); |
66 QFile scriptCfgFile(HWDataManager::instance().findFileForRead( |
67 QFile scriptCfgFile(HWDataManager::instance().findFileForRead( |
67 QString("Scripts/Multiplayer/%2.cfg").arg(script))); |
68 QString("Scripts/Multiplayer/%2.cfg").arg(script))); |
68 if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) { |
69 if (scriptCfgFile.exists() && scriptCfgFile.open(QFile::ReadOnly)) |
|
70 { |
69 QString scheme; |
71 QString scheme; |
70 QString weapons; |
72 QString weapons; |
71 QTextStream input(&scriptCfgFile); |
73 QTextStream input(&scriptCfgFile); |
72 input >> scheme; |
74 input >> scheme; |
73 input >> weapons; |
75 input >> weapons; |
102 connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int))); |
104 connect(GameSchemes, SIGNAL(currentIndexChanged(int)), this, SLOT(schemeChanged(int))); |
103 |
105 |
104 SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Scheme"), SchemeWidget), 0, 0); |
106 SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Scheme"), SchemeWidget), 0, 0); |
105 |
107 |
106 QPixmap pmEdit(":/res/edit.png"); |
108 QPixmap pmEdit(":/res/edit.png"); |
107 |
109 |
108 QPushButton * goToSchemePage = new QPushButton(SchemeWidget); |
110 QPushButton * goToSchemePage = new QPushButton(SchemeWidget); |
109 goToSchemePage->setToolTip(tr("Edit schemes")); |
111 goToSchemePage->setToolTip(tr("Edit schemes")); |
110 goToSchemePage->setIconSize(pmEdit.size()); |
112 goToSchemePage->setIconSize(pmEdit.size()); |
111 goToSchemePage->setIcon(pmEdit); |
113 goToSchemePage->setIcon(pmEdit); |
112 goToSchemePage->setMaximumWidth(pmEdit.width() + 6); |
114 goToSchemePage->setMaximumWidth(pmEdit.width() + 6); |
299 bool illegal = ammo.size() != cDefaultAmmoStore->size(); |
302 bool illegal = ammo.size() != cDefaultAmmoStore->size(); |
300 if (illegal) |
303 if (illegal) |
301 QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); |
304 QMessageBox::critical(this, tr("Error"), tr("Illegal ammo scheme")); |
302 |
305 |
303 int pos = WeaponsName->findText(name); |
306 int pos = WeaponsName->findText(name); |
304 if ((pos == -1) || illegal) { // prevent from overriding schemes with bad ones |
307 if ((pos == -1) || illegal) // prevent from overriding schemes with bad ones |
|
308 { |
305 WeaponsName->addItem(name, ammo); |
309 WeaponsName->addItem(name, ammo); |
306 WeaponsName->setCurrentIndex(WeaponsName->count() - 1); |
310 WeaponsName->setCurrentIndex(WeaponsName->count() - 1); |
307 } else { |
311 } |
|
312 else |
|
313 { |
308 WeaponsName->setItemData(pos, ammo); |
314 WeaponsName->setItemData(pos, ammo); |
309 WeaponsName->setCurrentIndex(pos); |
315 WeaponsName->setCurrentIndex(pos); |
310 } |
316 } |
311 } |
317 } |
312 |
318 |
333 void GameCFGWidget::setParam(const QString & param, const QStringList & slValue) |
339 void GameCFGWidget::setParam(const QString & param, const QStringList & slValue) |
334 { |
340 { |
335 if (slValue.size() == 1) |
341 if (slValue.size() == 1) |
336 { |
342 { |
337 QString value = slValue[0]; |
343 QString value = slValue[0]; |
338 if (param == "MAP") { |
344 if (param == "MAP") |
|
345 { |
339 pMapContainer->setMap(value); |
346 pMapContainer->setMap(value); |
340 return; |
347 return; |
341 } |
348 } |
342 if (param == "SEED") { |
349 if (param == "SEED") |
|
350 { |
343 pMapContainer->setSeed(value); |
351 pMapContainer->setSeed(value); |
344 if (!seedRegexp.exactMatch(value)) { |
352 if (!seedRegexp.exactMatch(value)) |
|
353 { |
345 pMapContainer->seedEdit->setVisible(true); |
354 pMapContainer->seedEdit->setVisible(true); |
346 } |
355 } |
347 return; |
356 return; |
348 } |
357 } |
349 if (param == "THEME") { |
358 if (param == "THEME") |
|
359 { |
350 pMapContainer->setTheme(value); |
360 pMapContainer->setTheme(value); |
351 return; |
361 return; |
352 } |
362 } |
353 if (param == "TEMPLATE") { |
363 if (param == "TEMPLATE") |
|
364 { |
354 pMapContainer->setTemplateFilter(value.toUInt()); |
365 pMapContainer->setTemplateFilter(value.toUInt()); |
355 return; |
366 return; |
356 } |
367 } |
357 if (param == "MAPGEN") { |
368 if (param == "MAPGEN") |
|
369 { |
358 pMapContainer->setMapgen((MapGenerator)value.toUInt()); |
370 pMapContainer->setMapgen((MapGenerator)value.toUInt()); |
359 return; |
371 return; |
360 } |
372 } |
361 if (param == "MAZE_SIZE") { |
373 if (param == "MAZE_SIZE") |
|
374 { |
362 pMapContainer->setMazeSize(value.toUInt()); |
375 pMapContainer->setMazeSize(value.toUInt()); |
363 return; |
376 return; |
364 } |
377 } |
365 if (param == "SCRIPT") { |
378 if (param == "SCRIPT") |
|
379 { |
366 Scripts->setCurrentIndex(Scripts->findText(value)); |
380 Scripts->setCurrentIndex(Scripts->findText(value)); |
367 return; |
381 return; |
368 } |
382 } |
369 if (param == "DRAWNMAP") { |
383 if (param == "DRAWNMAP") |
|
384 { |
370 pMapContainer->setDrawnMapData(qUncompress(QByteArray::fromBase64(slValue[0].toLatin1()))); |
385 pMapContainer->setDrawnMapData(qUncompress(QByteArray::fromBase64(slValue[0].toLatin1()))); |
371 return; |
386 return; |
372 } |
387 } |
373 } |
388 } |
374 |
389 |
375 if (slValue.size() == 2) |
390 if (slValue.size() == 2) |
376 { |
391 { |
377 if (param == "AMMO") { |
392 if (param == "AMMO") |
|
393 { |
378 setNetAmmo(slValue[0], slValue[1]); |
394 setNetAmmo(slValue[0], slValue[1]); |
379 return; |
395 return; |
380 } |
396 } |
381 } |
397 } |
382 |
398 |
387 QString seed = slValue[3]; |
403 QString seed = slValue[3]; |
388 if (!seedRegexp.exactMatch(seed)) |
404 if (!seedRegexp.exactMatch(seed)) |
389 pMapContainer->seedEdit->setVisible(true); |
405 pMapContainer->seedEdit->setVisible(true); |
390 |
406 |
391 pMapContainer->setAllMapParameters( |
407 pMapContainer->setAllMapParameters( |
392 slValue[0], |
408 slValue[0], |
393 (MapGenerator)slValue[1].toUInt(), |
409 (MapGenerator)slValue[1].toUInt(), |
394 slValue[2].toUInt(), |
410 slValue[2].toUInt(), |
395 seed, |
411 seed, |
396 slValue[4].toUInt() |
412 slValue[4].toUInt() |
397 ); |
413 ); |
398 return; |
414 return; |
399 } |
415 } |
400 } |
416 } |
401 |
417 |
402 qWarning("Got bad config param from net"); |
418 qWarning("Got bad config param from net"); |
403 } |
419 } |
404 |
420 |
405 void GameCFGWidget::ammoChanged(int index) |
421 void GameCFGWidget::ammoChanged(int index) |
406 { |
422 { |
407 if (index >= 0) { |
423 if (index >= 0) |
|
424 { |
408 emit paramChanged( |
425 emit paramChanged( |
409 "AMMO", |
426 "AMMO", |
410 QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString() |
427 QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString() |
411 ); |
428 ); |
412 } |
429 } |
487 for(int i = 0; i < size; ++i) |
504 for(int i = 0; i < size; ++i) |
488 sl << schemeData(i).toString(); |
505 sl << schemeData(i).toString(); |
489 |
506 |
490 emit paramChanged("SCHEME", sl); |
507 emit paramChanged("SCHEME", sl); |
491 |
508 |
492 if (isEnabled() && bindEntries->isEnabled() && bindEntries->isChecked()) { |
509 if (isEnabled() && bindEntries->isEnabled() && bindEntries->isChecked()) |
|
510 { |
493 QString schemeName = GameSchemes->itemText(index); |
511 QString schemeName = GameSchemes->itemText(index); |
494 for (int i = 0; i < WeaponsName->count(); i++) { |
512 for (int i = 0; i < WeaponsName->count(); i++) |
495 QString weapName = WeaponsName->itemText(i); |
513 { |
496 int res = QString::compare(weapName, schemeName, Qt::CaseSensitive); |
514 QString weapName = WeaponsName->itemText(i); |
497 if (0 == res) { |
515 int res = QString::compare(weapName, schemeName, Qt::CaseSensitive); |
498 WeaponsName->setCurrentIndex(i); |
516 if (0 == res) |
499 emit ammoChanged(i); |
517 { |
500 break; |
518 WeaponsName->setCurrentIndex(i); |
501 } |
519 emit ammoChanged(i); |
|
520 break; |
|
521 } |
502 } |
522 } |
503 } |
523 } |
504 } |
524 } |
505 |
525 |
506 void GameCFGWidget::scriptChanged(int index) |
526 void GameCFGWidget::scriptChanged(int index) |