1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/mapeditor/inspector/artifactwidget.cpp

64 lines
2.0 KiB
C++

/*
* herosspellwidget.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 "artifactWidget.h"
#include "ui_artifactWidget.h"
#include "inspector.h"
#include "../../lib/ArtifactUtils.h"
#include "../../lib/constants/StringConstants.h"
ArtifactWidget::ArtifactWidget(CArtifactFittingSet & fittingSet, QWidget * parent) :
QDialog(parent),
ui(new Ui::ArtifactWidget),
fittingSet(fittingSet)
{
ui->setupUi(this);
connect(ui->saveButton, &QPushButton::clicked, this, [this]()
{
emit saveArtifact(ui->artifact->currentData().toInt(), ArtifactPosition(ui->possiblePositions->currentData().toInt()));
close();
});
connect(ui->cancelButton, &QPushButton::clicked, this, &ArtifactWidget::close);
connect(ui->possiblePositions, static_cast<void(QComboBox::*) (int)> (&QComboBox::currentIndexChanged), this, &ArtifactWidget::fillArtifacts);
std::vector<ArtifactPosition> possiblePositions;
for(const auto & slot : ArtifactUtils::allWornSlots())
{
if(fittingSet.isPositionFree(slot))
{
ui->possiblePositions->addItem(QString::fromStdString(NArtifactPosition::namesHero[slot.num]), slot.num);
}
}
ui->possiblePositions->addItem(QString::fromStdString(NArtifactPosition::backpack), ArtifactPosition::BACKPACK_START);
fillArtifacts();
}
void ArtifactWidget::fillArtifacts()
{
ui->artifact->clear();
auto currentSlot = ui->possiblePositions->currentData().toInt();
for (const auto& art : VLC->arth->getDefaultAllowed())
{
auto artifact = art.toArtifact();
// forbid spell scroll for now as require special handling
if (artifact->canBePutAt(&fittingSet, currentSlot, true) && artifact->getId() != ArtifactID::SPELL_SCROLL) {
ui->artifact->addItem(QString::fromStdString(artifact->getNameTranslated()), QVariant::fromValue(artifact->getIndex()));
}
}
}
ArtifactWidget::~ArtifactWidget()
{
delete ui;
}