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

660 lines
21 KiB
C++
Raw Normal View History

2022-10-08 22:32:02 +02:00
/*
* rewardswidget.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
*
*/
2022-10-16 12:22:34 +02:00
#include "StdInc.h"
2022-09-18 01:23:17 +02:00
#include "rewardswidget.h"
#include "ui_rewardswidget.h"
#include "../lib/VCMI_Lib.h"
#include "../lib/CSkillHandler.h"
#include "../lib/spells/CSpellHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CCreatureHandler.h"
#include "../lib/constants/StringConstants.h"
2023-05-24 01:05:59 +02:00
#include "../lib/mapping/CMap.h"
2023-09-16 05:34:27 +02:00
#include "../lib/rewardable/Configuration.h"
#include "../lib/rewardable/Limiter.h"
#include "../lib/rewardable/Reward.h"
#include "../lib/mapObjects/CGPandoraBox.h"
#include "../lib/mapObjects/CQuest.h"
2022-09-18 01:23:17 +02:00
2023-09-16 05:34:27 +02:00
RewardsWidget::RewardsWidget(const CMap & m, CRewardableObject & p, QWidget *parent) :
2022-09-18 01:23:17 +02:00
QDialog(parent),
map(m),
2023-09-16 05:34:27 +02:00
object(p),
2022-09-18 01:23:17 +02:00
ui(new Ui::RewardsWidget)
{
ui->setupUi(this);
2023-09-16 05:34:27 +02:00
//fill core elements
for(const auto & s : Rewardable::VisitModeString)
ui->visitMode->addItem(QString::fromStdString(s));
2022-10-16 01:20:24 +02:00
2023-09-16 05:34:27 +02:00
for(const auto & s : Rewardable::SelectModeString)
ui->selectMode->addItem(QString::fromStdString(s));
2023-09-19 18:20:22 +02:00
for(auto s : {"AUTO", "MODAL", "INFO"})
2023-09-16 05:34:27 +02:00
ui->windowMode->addItem(QString::fromStdString(s));
ui->lDayOfWeek->addItem(tr("None"));
for(int i = 1; i <= 7; ++i)
ui->lDayOfWeek->addItem(tr("Day %1").arg(i));
//fill resources
ui->rResources->setRowCount(GameConstants::RESOURCE_QUANTITY - 1);
ui->lResources->setRowCount(GameConstants::RESOURCE_QUANTITY - 1);
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY - 1; ++i)
{
for(auto * w : {ui->rResources, ui->lResources})
{
auto * item = new QTableWidgetItem(QString::fromStdString(GameConstants::RESOURCE_NAMES[i]));
item->setData(Qt::UserRole, QVariant::fromValue(i));
w->setItem(i, 0, item);
w->setCellWidget(i, 1, new QSpinBox);
}
}
//fill artifacts
for(int i = 0; i < map.allowedArtifact.size(); ++i)
{
for(auto * w : {ui->rArtifacts, ui->lArtifacts})
{
auto * item = new QListWidgetItem(QString::fromStdString(VLC->artifacts()->getByIndex(i)->getNameTranslated()));
item->setData(Qt::UserRole, QVariant::fromValue(i));
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked);
if(!map.allowedArtifact[i])
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
w->addItem(item);
}
}
//fill spells
for(int i = 0; i < map.allowedSpells.size(); ++i)
{
for(auto * w : {ui->rSpells, ui->lSpells})
{
auto * item = new QListWidgetItem(QString::fromStdString(VLC->spells()->getByIndex(i)->getNameTranslated()));
item->setData(Qt::UserRole, QVariant::fromValue(i));
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Unchecked);
if(!map.allowedSpells[i])
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
w->addItem(item);
}
//spell cast
if(VLC->spells()->getByIndex(i)->isAdventure())
{
ui->castSpell->addItem(QString::fromStdString(VLC->spells()->getByIndex(i)->getNameTranslated()));
ui->castSpell->setItemData(ui->castSpell->count() - 1, QVariant::fromValue(i));
}
}
//fill skills
ui->rSkills->setRowCount(map.allowedAbilities.size());
ui->lSkills->setRowCount(map.allowedAbilities.size());
for(int i = 0; i < map.allowedAbilities.size(); ++i)
{
for(auto * w : {ui->rSkills, ui->lSkills})
{
auto * item = new QTableWidgetItem(QString::fromStdString(VLC->skills()->getByIndex(i)->getNameTranslated()));
item->setData(Qt::UserRole, QVariant::fromValue(i));
auto * widget = new QComboBox;
for(auto & s : NSecondarySkill::levels)
widget->addItem(QString::fromStdString(s));
if(!map.allowedAbilities[i])
{
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
widget->setEnabled(false);
}
w->setItem(i, 0, item);
w->setCellWidget(i, 1, widget);
}
}
//fill creatures
for(auto & creature : VLC->creh->objects)
{
for(auto * w : {ui->rCreatureId, ui->lCreatureId})
{
w->addItem(QString::fromStdString(creature->getNameSingularTranslated()));
w->setItemData(w->count() - 1, creature->getIndex());
}
}
//fill spell cast
for(auto & s : NSecondarySkill::levels)
ui->castLevel->addItem(QString::fromStdString(s));
on_castSpellCheck_toggled(false);
//fill bonuses
for(auto & s : bonusDurationMap)
ui->bonusDuration->addItem(QString::fromStdString(s.first));
for(auto & s : bonusNameMap)
ui->bonusType->addItem(QString::fromStdString(s.first));
//set default values
if(dynamic_cast<CGPandoraBox*>(&object))
{
ui->visitMode->setCurrentIndex(vstd::find_pos(Rewardable::VisitModeString, "once"));
ui->visitMode->setEnabled(false);
2023-09-17 18:02:24 +02:00
ui->selectMode->setCurrentIndex(vstd::find_pos(Rewardable::SelectModeString, "selectFirst"));
2023-09-16 05:34:27 +02:00
ui->selectMode->setEnabled(false);
ui->windowMode->setEnabled(false);
ui->canRefuse->setEnabled(false);
}
2023-09-17 18:02:24 +02:00
if(auto * e = dynamic_cast<CGEvent*>(&object))
{
ui->selectMode->setEnabled(true);
if(!e->removeAfterVisit)
ui->visitMode->setCurrentIndex(vstd::find_pos(Rewardable::VisitModeString, "unlimited"));
}
2023-09-16 05:34:27 +02:00
if(dynamic_cast<CGSeerHut*>(&object))
{
ui->visitMode->setCurrentIndex(vstd::find_pos(Rewardable::VisitModeString, "once"));
ui->visitMode->setEnabled(false);
ui->windowMode->setEnabled(false);
ui->canRefuse->setChecked(true);
ui->canRefuse->setEnabled(false);
}
//hide elements
ui->eventInfoGroup->hide();
2022-10-16 01:20:24 +02:00
}
2022-09-18 01:23:17 +02:00
RewardsWidget::~RewardsWidget()
{
delete ui;
}
2023-09-16 05:34:27 +02:00
void RewardsWidget::obtainData()
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
//common parameters
ui->visitMode->setCurrentIndex(object.configuration.visitMode);
ui->selectMode->setCurrentIndex(object.configuration.selectMode);
ui->windowMode->setCurrentIndex(int(object.configuration.infoWindowType));
ui->onSelectText->setText(QString::fromStdString(object.configuration.onSelect.toString()));
ui->canRefuse->setChecked(object.configuration.canRefuse);
//reset parameters
ui->resetPeriod->setValue(object.configuration.resetParameters.period);
ui->resetVisitors->setChecked(object.configuration.resetParameters.visitors);
ui->resetRewards->setChecked(object.configuration.resetParameters.rewards);
ui->visitInfoList->clear();
for([[maybe_unused]] auto & a : object.configuration.info)
ui->visitInfoList->addItem(tr("Reward %1").arg(ui->visitInfoList->count() + 1));
if(ui->visitInfoList->currentItem())
loadCurrentVisitInfo(ui->visitInfoList->currentRow());
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
bool RewardsWidget::commitChanges()
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
//common parameters
object.configuration.visitMode = ui->visitMode->currentIndex();
object.configuration.selectMode = ui->selectMode->currentIndex();
object.configuration.infoWindowType = EInfoWindowMode(ui->windowMode->currentIndex());
2023-09-17 22:19:45 +02:00
if(ui->onSelectText->text().isEmpty())
object.configuration.onSelect.clear();
else
object.configuration.onSelect = MetaString::createFromRawString(ui->onSelectText->text().toStdString());
2023-09-16 05:34:27 +02:00
object.configuration.canRefuse = ui->canRefuse->isChecked();
//reset parameters
object.configuration.resetParameters.period = ui->resetPeriod->value();
object.configuration.resetParameters.visitors = ui->resetVisitors->isChecked();
object.configuration.resetParameters.rewards = ui->resetRewards->isChecked();
2022-09-18 01:23:17 +02:00
2023-09-16 05:34:27 +02:00
if(ui->visitInfoList->currentItem())
saveCurrentVisitInfo(ui->visitInfoList->currentRow());
2022-09-18 01:23:17 +02:00
2023-09-16 05:34:27 +02:00
return true;
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
void RewardsWidget::saveCurrentVisitInfo(int index)
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
auto & vinfo = object.configuration.info.at(index);
2023-09-17 13:03:42 +02:00
vinfo.visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
2023-09-17 22:19:45 +02:00
if(ui->rewardMessage->text().isEmpty())
vinfo.message.clear();
else
vinfo.message = MetaString::createFromRawString(ui->rewardMessage->text().toStdString());
2023-09-16 05:34:27 +02:00
vinfo.reward.heroLevel = ui->rHeroLevel->value();
vinfo.reward.heroExperience = ui->rHeroExperience->value();
vinfo.reward.manaDiff = ui->rManaDiff->value();
vinfo.reward.manaPercentage = ui->rManaPercentage->value();
vinfo.reward.manaOverflowFactor = ui->rOverflowFactor->value();
vinfo.reward.movePoints = ui->rMovePoints->value();
vinfo.reward.movePercentage = ui->rMovePercentage->value();
vinfo.reward.removeObject = ui->removeObject->isChecked();
2023-09-16 05:52:23 +02:00
vinfo.reward.primary.resize(4);
2023-09-16 05:34:27 +02:00
vinfo.reward.primary[0] = ui->rAttack->value();
vinfo.reward.primary[1] = ui->rDefence->value();
vinfo.reward.primary[2] = ui->rPower->value();
vinfo.reward.primary[3] = ui->rKnowledge->value();
for(int i = 0; i < ui->rResources->rowCount(); ++i)
{
if(auto * widget = qobject_cast<QSpinBox*>(ui->rResources->cellWidget(i, 1)))
vinfo.reward.resources[i] = widget->value();
}
vinfo.reward.artifacts.clear();
for(int i = 0; i < ui->rArtifacts->count(); ++i)
{
if(ui->rArtifacts->item(i)->checkState() == Qt::Checked)
vinfo.reward.artifacts.push_back(VLC->artifacts()->getByIndex(i)->getId());
}
vinfo.reward.spells.clear();
for(int i = 0; i < ui->rSpells->count(); ++i)
{
if(ui->rSpells->item(i)->checkState() == Qt::Checked)
vinfo.reward.spells.push_back(VLC->spells()->getByIndex(i)->getId());
}
vinfo.reward.secondary.clear();
for(int i = 0; i < ui->rSkills->rowCount(); ++i)
{
if(auto * widget = qobject_cast<QComboBox*>(ui->rSkills->cellWidget(i, 1)))
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
if(widget->currentIndex() > 0)
vinfo.reward.secondary[VLC->skills()->getByIndex(i)->getId()] = widget->currentIndex();
2022-09-18 01:23:17 +02:00
}
}
2022-10-16 01:20:24 +02:00
2023-09-16 05:34:27 +02:00
vinfo.reward.creatures.clear();
for(int i = 0; i < ui->rCreatures->rowCount(); ++i)
{
int index = ui->rCreatures->item(i, 0)->data(Qt::UserRole).toInt();
if(auto * widget = qobject_cast<QSpinBox*>(ui->rCreatures->cellWidget(i, 1)))
if(widget->value())
vinfo.reward.creatures.emplace_back(VLC->creatures()->getByIndex(index)->getId(), widget->value());
}
vinfo.reward.spellCast.first = SpellID::NONE;
if(ui->castSpellCheck->isChecked())
{
vinfo.reward.spellCast.first = VLC->spells()->getByIndex(ui->castSpell->itemData(ui->castSpell->currentIndex()).toInt())->getId();
vinfo.reward.spellCast.second = ui->castLevel->currentIndex();
}
vinfo.reward.bonuses.clear();
for(int i = 0; i < ui->bonuses->rowCount(); ++i)
{
auto dur = bonusDurationMap.at(ui->bonuses->item(i, 0)->text().toStdString());
auto typ = bonusNameMap.at(ui->bonuses->item(i, 1)->text().toStdString());
auto val = ui->bonuses->item(i, 2)->data(Qt::UserRole).toInt();
vinfo.reward.bonuses.emplace_back(dur, typ, BonusSource::OBJECT, val, object.id);
}
vinfo.limiter.dayOfWeek = ui->lDayOfWeek->currentIndex();
vinfo.limiter.daysPassed = ui->lDaysPassed->value();
vinfo.limiter.heroLevel = ui->lHeroLevel->value();
vinfo.limiter.heroExperience = ui->lHeroExperience->value();
vinfo.limiter.manaPoints = ui->lManaPoints->value();
vinfo.limiter.manaPercentage = ui->lManaPercentage->value();
2023-09-16 05:52:23 +02:00
vinfo.limiter.primary.resize(4);
2023-09-16 05:34:27 +02:00
vinfo.limiter.primary[0] = ui->lAttack->value();
vinfo.limiter.primary[1] = ui->lDefence->value();
vinfo.limiter.primary[2] = ui->lPower->value();
vinfo.limiter.primary[3] = ui->lKnowledge->value();
for(int i = 0; i < ui->lResources->rowCount(); ++i)
{
if(auto * widget = qobject_cast<QSpinBox*>(ui->lResources->cellWidget(i, 1)))
vinfo.limiter.resources[i] = widget->value();
}
vinfo.limiter.artifacts.clear();
for(int i = 0; i < ui->lArtifacts->count(); ++i)
2022-10-16 01:20:24 +02:00
{
2023-09-16 05:34:27 +02:00
if(ui->lArtifacts->item(i)->checkState() == Qt::Checked)
vinfo.limiter.artifacts.push_back(VLC->artifacts()->getByIndex(i)->getId());
}
vinfo.limiter.spells.clear();
for(int i = 0; i < ui->lSpells->count(); ++i)
{
if(ui->lSpells->item(i)->checkState() == Qt::Checked)
vinfo.limiter.spells.push_back(VLC->spells()->getByIndex(i)->getId());
}
vinfo.limiter.secondary.clear();
for(int i = 0; i < ui->lSkills->rowCount(); ++i)
{
if(auto * widget = qobject_cast<QComboBox*>(ui->lSkills->cellWidget(i, 1)))
{
2023-09-16 05:34:27 +02:00
if(widget->currentIndex() > 0)
vinfo.limiter.secondary[VLC->skills()->getByIndex(i)->getId()] = widget->currentIndex();
}
2023-09-16 05:34:27 +02:00
}
vinfo.limiter.creatures.clear();
for(int i = 0; i < ui->lCreatures->rowCount(); ++i)
{
int index = ui->lCreatures->item(i, 0)->data(Qt::UserRole).toInt();
if(auto * widget = qobject_cast<QSpinBox*>(ui->lCreatures->cellWidget(i, 1)))
if(widget->value())
vinfo.reward.creatures.emplace_back(VLC->creatures()->getByIndex(index)->getId(), widget->value());
2022-10-16 01:20:24 +02:00
}
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
void RewardsWidget::loadCurrentVisitInfo(int index)
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
for(auto * w : {ui->rArtifacts, ui->rSpells, ui->lArtifacts, ui->lSpells})
for(int i = 0; i < w->count(); ++i)
w->item(i)->setCheckState(Qt::Unchecked);
for(auto * w : {ui->rSkills, ui->lSkills})
for(int i = 0; i < w->rowCount(); ++i)
if(auto * widget = qobject_cast<QComboBox*>(ui->rSkills->cellWidget(i, 1)))
widget->setCurrentIndex(0);
ui->rCreatures->setRowCount(0);
ui->lCreatures->setRowCount(0);
ui->bonuses->setRowCount(0);
const auto & vinfo = object.configuration.info.at(index);
ui->rewardMessage->setText(QString::fromStdString(vinfo.message.toString()));
ui->rHeroLevel->setValue(vinfo.reward.heroLevel);
ui->rHeroExperience->setValue(vinfo.reward.heroExperience);
ui->rManaDiff->setValue(vinfo.reward.manaDiff);
ui->rManaPercentage->setValue(vinfo.reward.manaPercentage);
ui->rOverflowFactor->setValue(vinfo.reward.manaOverflowFactor);
ui->rMovePoints->setValue(vinfo.reward.movePoints);
ui->rMovePercentage->setValue(vinfo.reward.movePercentage);
ui->removeObject->setChecked(vinfo.reward.removeObject);
ui->rAttack->setValue(vinfo.reward.primary[0]);
ui->rDefence->setValue(vinfo.reward.primary[1]);
ui->rPower->setValue(vinfo.reward.primary[2]);
ui->rKnowledge->setValue(vinfo.reward.primary[3]);
for(int i = 0; i < ui->rResources->rowCount(); ++i)
{
if(auto * widget = qobject_cast<QSpinBox*>(ui->rResources->cellWidget(i, 1)))
widget->setValue(vinfo.reward.resources[i]);
}
for(auto i : vinfo.reward.artifacts)
ui->rArtifacts->item(VLC->artifacts()->getById(i)->getIndex())->setCheckState(Qt::Checked);
for(auto i : vinfo.reward.spells)
ui->rArtifacts->item(VLC->spells()->getById(i)->getIndex())->setCheckState(Qt::Checked);
for(auto & i : vinfo.reward.secondary)
{
int index = VLC->skills()->getById(i.first)->getIndex();
if(auto * widget = qobject_cast<QComboBox*>(ui->rSkills->cellWidget(index, 1)))
widget->setCurrentIndex(i.second);
}
for(auto & i : vinfo.reward.creatures)
{
int index = i.type->getIndex();
ui->rCreatureId->setCurrentIndex(index);
ui->rCreatureAmount->setValue(i.count);
onCreatureAdd(ui->rCreatures, ui->rCreatureId, ui->rCreatureAmount);
}
ui->castSpellCheck->setChecked(vinfo.reward.spellCast.first != SpellID::NONE);
if(ui->castSpellCheck->isChecked())
{
int index = VLC->spells()->getById(vinfo.reward.spellCast.first)->getIndex();
ui->castSpell->setCurrentIndex(index);
ui->castLevel->setCurrentIndex(vinfo.reward.spellCast.second);
}
for(auto & i : vinfo.reward.bonuses)
{
auto dur = vstd::findKey(bonusDurationMap, i.duration);
for(int i = 0; i < ui->bonusDuration->count(); ++i)
{
if(ui->bonusDuration->itemText(i) == QString::fromStdString(dur))
{
ui->bonusDuration->setCurrentIndex(i);
break;
}
}
2022-09-18 01:23:17 +02:00
2023-09-16 05:34:27 +02:00
auto typ = vstd::findKey(bonusNameMap, i.type);
for(int i = 0; i < ui->bonusType->count(); ++i)
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
if(ui->bonusType->itemText(i) == QString::fromStdString(typ))
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
ui->bonusType->setCurrentIndex(i);
break;
2022-09-18 01:23:17 +02:00
}
}
2023-09-16 05:34:27 +02:00
ui->bonusValue->setValue(i.val);
on_bonusAdd_clicked();
}
ui->lDayOfWeek->setCurrentIndex(vinfo.limiter.dayOfWeek);
ui->lDaysPassed->setValue(vinfo.limiter.daysPassed);
ui->lHeroLevel->setValue(vinfo.limiter.heroLevel);
ui->lHeroExperience->setValue(vinfo.limiter.heroExperience);
ui->lManaPoints->setValue(vinfo.limiter.manaPoints);
ui->lManaPercentage->setValue(vinfo.limiter.manaPercentage);
ui->lAttack->setValue(vinfo.reward.primary[0]);
ui->lDefence->setValue(vinfo.reward.primary[1]);
ui->lPower->setValue(vinfo.reward.primary[2]);
ui->lKnowledge->setValue(vinfo.reward.primary[3]);
for(int i = 0; i < ui->lResources->rowCount(); ++i)
{
if(auto * widget = qobject_cast<QSpinBox*>(ui->lResources->cellWidget(i, 1)))
widget->setValue(vinfo.limiter.resources[i]);
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
for(auto i : vinfo.limiter.artifacts)
ui->lArtifacts->item(VLC->artifacts()->getById(i)->getIndex())->setCheckState(Qt::Checked);
for(auto i : vinfo.limiter.spells)
ui->lArtifacts->item(VLC->spells()->getById(i)->getIndex())->setCheckState(Qt::Checked);
for(auto & i : vinfo.limiter.secondary)
{
int index = VLC->skills()->getById(i.first)->getIndex();
if(auto * widget = qobject_cast<QComboBox*>(ui->lSkills->cellWidget(index, 1)))
widget->setCurrentIndex(i.second);
}
for(auto & i : vinfo.limiter.creatures)
{
int index = i.type->getIndex();
ui->lCreatureId->setCurrentIndex(index);
ui->lCreatureAmount->setValue(i.count);
onCreatureAdd(ui->lCreatures, ui->lCreatureId, ui->lCreatureAmount);
}
}
void RewardsWidget::onCreatureAdd(QTableWidget * listWidget, QComboBox * comboWidget, QSpinBox * spinWidget)
{
QTableWidgetItem * item = nullptr;
QSpinBox * widget = nullptr;
for(int i = 0; i < listWidget->rowCount(); ++i)
2022-10-16 01:20:24 +02:00
{
2023-09-16 05:34:27 +02:00
if(auto * cname = listWidget->item(i, 0))
2022-10-16 01:20:24 +02:00
{
2023-09-16 05:34:27 +02:00
if(cname->data(Qt::UserRole).toInt() == comboWidget->currentData().toInt())
{
item = cname;
widget = qobject_cast<QSpinBox*>(listWidget->cellWidget(i, 1));
break;
}
2022-10-16 01:20:24 +02:00
}
}
2023-09-16 05:34:27 +02:00
if(!item)
{
listWidget->setRowCount(listWidget->rowCount() + 1);
item = new QTableWidgetItem(comboWidget->currentText());
listWidget->setItem(listWidget->rowCount() - 1, 0, item);
}
item->setData(Qt::UserRole, comboWidget->currentData());
if(!widget)
{
widget = new QSpinBox;
widget->setRange(spinWidget->minimum(), spinWidget->maximum());
listWidget->setCellWidget(listWidget->rowCount() - 1, 1, widget);
}
widget->setValue(spinWidget->value());
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
void RewardsWidget::on_addVisitInfo_clicked()
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
ui->visitInfoList->addItem(tr("Reward %1").arg(ui->visitInfoList->count() + 1));
object.configuration.info.emplace_back();
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
void RewardsWidget::on_removeVisitInfo_clicked()
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
int index = ui->visitInfoList->currentRow();
object.configuration.info.erase(std::next(object.configuration.info.begin(), index));
ui->visitInfoList->blockSignals(true);
delete ui->visitInfoList->currentItem();
ui->visitInfoList->blockSignals(false);
on_visitInfoList_itemSelectionChanged();
2023-09-17 18:02:24 +02:00
if(ui->visitInfoList->currentItem())
loadCurrentVisitInfo(ui->visitInfoList->currentRow());
2023-09-16 05:34:27 +02:00
}
void RewardsWidget::on_selectMode_currentIndexChanged(int index)
{
ui->onSelectText->setEnabled(index == vstd::find_pos(Rewardable::SelectModeString, "selectPlayer"));
}
void RewardsWidget::on_resetPeriod_valueChanged(int arg1)
{
ui->resetRewards->setEnabled(arg1);
ui->resetVisitors->setEnabled(arg1);
}
void RewardsWidget::on_visitInfoList_itemSelectionChanged()
{
if(ui->visitInfoList->currentItem() == nullptr)
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
ui->eventInfoGroup->hide();
return;
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
ui->eventInfoGroup->show();
}
void RewardsWidget::on_visitInfoList_currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous)
{
if(previous)
saveCurrentVisitInfo(ui->visitInfoList->row(previous));
2023-09-16 05:59:16 +02:00
if(current)
loadCurrentVisitInfo(ui->visitInfoList->currentRow());
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
void RewardsWidget::on_rCreatureAdd_clicked()
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
onCreatureAdd(ui->rCreatures, ui->rCreatureId, ui->rCreatureAmount);
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
void RewardsWidget::on_rCreatureRemove_clicked()
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
std::set<int, std::greater<int>> rowsToRemove;
for(auto * i : ui->rCreatures->selectedItems())
rowsToRemove.insert(i->row());
for(auto i : rowsToRemove)
ui->rCreatures->removeRow(i);
}
void RewardsWidget::on_lCreatureAdd_clicked()
{
onCreatureAdd(ui->lCreatures, ui->lCreatureId, ui->lCreatureAmount);
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
void RewardsWidget::on_lCreatureRemove_clicked()
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
std::set<int, std::greater<int>> rowsToRemove;
for(auto * i : ui->lCreatures->selectedItems())
rowsToRemove.insert(i->row());
for(auto i : rowsToRemove)
ui->lCreatures->removeRow(i);
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
void RewardsWidget::on_castSpellCheck_toggled(bool checked)
{
ui->castSpell->setEnabled(checked);
ui->castLevel->setEnabled(checked);
}
2022-09-18 01:23:17 +02:00
2023-09-16 05:34:27 +02:00
void RewardsWidget::on_bonusAdd_clicked()
2022-09-18 01:23:17 +02:00
{
2023-09-16 05:34:27 +02:00
auto * itemType = new QTableWidgetItem(ui->bonusType->currentText());
auto * itemDur = new QTableWidgetItem(ui->bonusDuration->currentText());
auto * itemVal = new QTableWidgetItem(QString::number(ui->bonusValue->value()));
itemVal->setData(Qt::UserRole, ui->bonusValue->value());
2022-09-18 01:23:17 +02:00
2023-09-16 05:34:27 +02:00
ui->bonuses->setRowCount(ui->bonuses->rowCount() + 1);
ui->bonuses->setItem(ui->bonuses->rowCount() - 1, 0, itemDur);
ui->bonuses->setItem(ui->bonuses->rowCount() - 1, 1, itemType);
ui->bonuses->setItem(ui->bonuses->rowCount() - 1, 2, itemVal);
}
void RewardsWidget::on_bonusRemove_clicked()
{
std::set<int, std::greater<int>> rowsToRemove;
for(auto * i : ui->bonuses->selectedItems())
rowsToRemove.insert(i->row());
2022-09-18 01:23:17 +02:00
2023-09-16 05:34:27 +02:00
for(auto i : rowsToRemove)
ui->bonuses->removeRow(i);
2022-09-18 01:23:17 +02:00
}
2023-09-16 05:34:27 +02:00
2022-10-16 01:20:24 +02:00
void RewardsDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
2022-09-18 01:23:17 +02:00
{
if(auto * ed = qobject_cast<RewardsWidget *>(editor))
{
ed->obtainData();
}
else
{
QStyledItemDelegate::setEditorData(editor, index);
}
}
2022-10-16 01:20:24 +02:00
void RewardsDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
2022-09-18 01:23:17 +02:00
{
if(auto * ed = qobject_cast<RewardsWidget *>(editor))
{
2023-09-10 22:05:57 +02:00
ed->commitChanges();
2022-09-18 01:23:17 +02:00
}
else
{
QStyledItemDelegate::setModelData(editor, model, index);
}
}
2022-10-16 01:20:24 +02:00
2023-09-16 05:34:27 +02:00
RewardsDelegate::RewardsDelegate(const CMap & m, CRewardableObject & t): map(m), object(t)
2022-10-16 01:20:24 +02:00
{
}
2023-09-16 05:34:27 +02:00
QWidget * RewardsDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
2022-10-16 01:20:24 +02:00
{
2023-09-16 05:34:27 +02:00
return new RewardsWidget(map, object, parent);
2022-10-16 01:20:24 +02:00
}