mapsettings.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * mapsettings.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "mapsettings.h"
  12. #include "ui_mapsettings.h"
  13. #include "mainwindow.h"
  14. #include "../../lib/CSkillHandler.h"
  15. #include "../../lib/entities/artifact/CArtHandler.h"
  16. #include "../../lib/entities/hero/CHeroHandler.h"
  17. #include "../../lib/spells/CSpellHandler.h"
  18. MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
  19. QDialog(parent),
  20. ui(new Ui::MapSettings),
  21. controller(ctrl)
  22. {
  23. ui->setupUi(this);
  24. setWindowModality(Qt::WindowModal);
  25. setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
  26. assert(controller.map());
  27. controller.settingsDialog = this;
  28. for(auto const & objectPtr : LIBRARY->skillh->objects)
  29. {
  30. auto * item = new QListWidgetItem(QString::fromStdString(objectPtr->getNameTranslated()));
  31. item->setData(Qt::UserRole, QVariant::fromValue(objectPtr->getIndex()));
  32. item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
  33. item->setCheckState(controller.map()->allowedAbilities.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
  34. ui->listAbilities->addItem(item);
  35. }
  36. for(auto const & objectPtr : LIBRARY->spellh->objects)
  37. {
  38. auto * item = new QListWidgetItem(QString::fromStdString(objectPtr->getNameTranslated()));
  39. item->setData(Qt::UserRole, QVariant::fromValue(objectPtr->getIndex()));
  40. item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
  41. item->setCheckState(controller.map()->allowedSpells.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
  42. ui->listSpells->addItem(item);
  43. }
  44. for(auto const & objectPtr : LIBRARY->arth->objects)
  45. {
  46. auto * item = new QListWidgetItem(QString::fromStdString(objectPtr->getNameTranslated()));
  47. item->setData(Qt::UserRole, QVariant::fromValue(objectPtr->getIndex()));
  48. item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
  49. item->setCheckState(controller.map()->allowedArtifact.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
  50. ui->listArts->addItem(item);
  51. }
  52. for(auto const & objectPtr : LIBRARY->heroh->objects)
  53. {
  54. auto * item = new QListWidgetItem(QString::fromStdString(objectPtr->getNameTranslated()));
  55. item->setData(Qt::UserRole, QVariant::fromValue(objectPtr->getIndex()));
  56. item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
  57. item->setCheckState(controller.map()->allowedHeroes.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
  58. ui->listHeroes->addItem(item);
  59. }
  60. ui->general->initialize(controller);
  61. ui->mods->initialize(controller);
  62. ui->victory->initialize(controller);
  63. ui->lose->initialize(controller);
  64. ui->events->initialize(controller);
  65. ui->rumors->initialize(controller);
  66. }
  67. MapSettings::~MapSettings()
  68. {
  69. controller.settingsDialog = nullptr;
  70. delete ui;
  71. }
  72. ModSettings * MapSettings::getModSettings()
  73. {
  74. return ui->mods;
  75. }
  76. void MapSettings::on_pushButton_clicked()
  77. {
  78. auto updateMapArray = [](const QListWidget * widget, auto & arr)
  79. {
  80. arr.clear();
  81. for(int i = 0; i < widget->count(); ++i)
  82. {
  83. auto * item = widget->item(i);
  84. if (item->checkState() == Qt::Checked)
  85. arr.emplace(i);
  86. }
  87. };
  88. updateMapArray(ui->listAbilities, controller.map()->allowedAbilities);
  89. updateMapArray(ui->listSpells, controller.map()->allowedSpells);
  90. updateMapArray(ui->listArts, controller.map()->allowedArtifact);
  91. updateMapArray(ui->listHeroes, controller.map()->allowedHeroes);
  92. controller.map()->triggeredEvents.clear();
  93. ui->general->update();
  94. ui->mods->update();
  95. ui->victory->update();
  96. ui->lose->update();
  97. ui->events->update();
  98. ui->rumors->update();
  99. controller.commitChangeWithoutRedraw();
  100. close();
  101. }