1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-03 14:52:11 +02:00
vcmi/mapeditor/mapsettings/mapsettings.cpp

113 lines
3.6 KiB
C++
Raw Permalink Normal View History

2023-09-05 03:26:38 +04:00
/*
* mapsettings.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "mapsettings.h"
#include "ui_mapsettings.h"
#include "mainwindow.h"
#include "../../lib/CArtHandler.h"
2023-09-05 03:26:38 +04:00
#include "../../lib/CSkillHandler.h"
#include "../../lib/entities/hero/CHeroHandler.h"
2023-09-05 03:26:38 +04:00
#include "../../lib/spells/CSpellHandler.h"
MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
QDialog(parent),
ui(new Ui::MapSettings),
controller(ctrl)
{
ui->setupUi(this);
setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
2023-09-05 03:26:38 +04:00
assert(controller.map());
2024-12-07 22:31:08 +01:00
controller.settingsDialog = this;
2023-09-05 03:26:38 +04:00
show();
for(auto const & objectPtr : LIBRARY->skillh->objects)
2023-09-05 03:26:38 +04:00
{
auto * item = new QListWidgetItem(QString::fromStdString(objectPtr->getNameTranslated()));
item->setData(Qt::UserRole, QVariant::fromValue(objectPtr->getIndex()));
2023-09-05 03:26:38 +04:00
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(controller.map()->allowedAbilities.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
2023-09-05 03:26:38 +04:00
ui->listAbilities->addItem(item);
}
for(auto const & objectPtr : LIBRARY->spellh->objects)
2023-09-05 03:26:38 +04:00
{
auto * item = new QListWidgetItem(QString::fromStdString(objectPtr->getNameTranslated()));
item->setData(Qt::UserRole, QVariant::fromValue(objectPtr->getIndex()));
2023-09-05 03:26:38 +04:00
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(controller.map()->allowedSpells.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
2023-09-05 03:26:38 +04:00
ui->listSpells->addItem(item);
}
for(auto const & objectPtr : LIBRARY->arth->objects)
2023-09-05 03:26:38 +04:00
{
auto * item = new QListWidgetItem(QString::fromStdString(objectPtr->getNameTranslated()));
item->setData(Qt::UserRole, QVariant::fromValue(objectPtr->getIndex()));
2023-09-05 03:26:38 +04:00
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(controller.map()->allowedArtifact.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
2023-09-05 03:26:38 +04:00
ui->listArts->addItem(item);
}
for(auto const & objectPtr : LIBRARY->heroh->objects)
2023-09-05 03:26:38 +04:00
{
auto * item = new QListWidgetItem(QString::fromStdString(objectPtr->getNameTranslated()));
item->setData(Qt::UserRole, QVariant::fromValue(objectPtr->getIndex()));
2023-09-05 03:26:38 +04:00
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(controller.map()->allowedHeroes.count(objectPtr->getId()) ? Qt::Checked : Qt::Unchecked);
2023-09-05 03:26:38 +04:00
ui->listHeroes->addItem(item);
}
ui->general->initialize(controller);
ui->mods->initialize(controller);
ui->victory->initialize(controller);
ui->lose->initialize(controller);
ui->events->initialize(controller);
ui->rumors->initialize(controller);
2023-09-05 03:26:38 +04:00
}
MapSettings::~MapSettings()
{
2024-12-07 22:31:08 +01:00
controller.settingsDialog = nullptr;
2023-09-05 03:26:38 +04:00
delete ui;
}
void MapSettings::on_pushButton_clicked()
{
auto updateMapArray = [](const QListWidget * widget, auto & arr)
2023-09-05 03:26:38 +04:00
{
arr.clear();
for(int i = 0; i < widget->count(); ++i)
2023-09-05 03:26:38 +04:00
{
auto * item = widget->item(i);
if (item->checkState() == Qt::Checked)
arr.emplace(i);
2023-09-05 03:26:38 +04:00
}
};
updateMapArray(ui->listAbilities, controller.map()->allowedAbilities);
updateMapArray(ui->listSpells, controller.map()->allowedSpells);
updateMapArray(ui->listArts, controller.map()->allowedArtifact);
updateMapArray(ui->listHeroes, controller.map()->allowedHeroes);
controller.map()->triggeredEvents.clear();
ui->general->update();
ui->mods->update();
ui->victory->update();
ui->lose->update();
ui->events->update();
ui->rumors->update();
2023-09-05 03:26:38 +04:00
controller.commitChangeWithoutRedraw();
close();
}