mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Added new rewardable widget
This commit is contained in:
parent
4f76eb3fce
commit
991a755a1f
@ -67,6 +67,7 @@ Initializer::Initializer(CGObjectInstance * o, const PlayerColor & pl) : default
|
||||
INIT_OBJ_TYPE(CGHeroInstance);
|
||||
INIT_OBJ_TYPE(CGSignBottle);
|
||||
INIT_OBJ_TYPE(CGLighthouse);
|
||||
//INIT_OBJ_TYPE(CRewardableObject);
|
||||
//INIT_OBJ_TYPE(CGPandoraBox);
|
||||
//INIT_OBJ_TYPE(CGEvent);
|
||||
//INIT_OBJ_TYPE(CGSeerHut);
|
||||
@ -375,14 +376,19 @@ void Inspector::updateProperties(CGCreature * o)
|
||||
//addProperty("Resources reward", o->resources); //TODO: implement in setProperty
|
||||
}
|
||||
|
||||
void Inspector::updateProperties(CRewardableObject * o)
|
||||
{
|
||||
if(!o) return;
|
||||
|
||||
auto * delegate = new RewardsDelegate(*map, *o);
|
||||
addProperty("Reward", PropertyEditorPlaceholder(), delegate, false);
|
||||
}
|
||||
|
||||
void Inspector::updateProperties(CGPandoraBox * o)
|
||||
{
|
||||
if(!o) return;
|
||||
|
||||
addProperty("Message", o->message, new MessageDelegate, false);
|
||||
|
||||
auto * delegate = new RewardsPandoraDelegate(*map, *o);
|
||||
addProperty("Reward", PropertyEditorPlaceholder(), delegate, false);
|
||||
}
|
||||
|
||||
void Inspector::updateProperties(CGEvent * o)
|
||||
@ -413,11 +419,6 @@ void Inspector::updateProperties(CGSeerHut * o)
|
||||
auto * delegate = new QuestDelegate(*map, *o);
|
||||
addProperty("Quest", PropertyEditorPlaceholder(), delegate, false);
|
||||
}
|
||||
|
||||
{ //Reward
|
||||
auto * delegate = new RewardsSeerhutDelegate(*map, *o);
|
||||
addProperty("Reward", PropertyEditorPlaceholder(), delegate, false);
|
||||
}
|
||||
}
|
||||
|
||||
void Inspector::updateProperties()
|
||||
@ -458,6 +459,7 @@ void Inspector::updateProperties()
|
||||
UPDATE_OBJ_PROPERTIES(CGHeroInstance);
|
||||
UPDATE_OBJ_PROPERTIES(CGSignBottle);
|
||||
UPDATE_OBJ_PROPERTIES(CGLighthouse);
|
||||
UPDATE_OBJ_PROPERTIES(CRewardableObject);
|
||||
UPDATE_OBJ_PROPERTIES(CGPandoraBox);
|
||||
UPDATE_OBJ_PROPERTIES(CGEvent);
|
||||
UPDATE_OBJ_PROPERTIES(CGSeerHut);
|
||||
@ -503,6 +505,7 @@ void Inspector::setProperty(const QString & key, const QVariant & value)
|
||||
SET_PROPERTIES(CGShipyard);
|
||||
SET_PROPERTIES(CGSignBottle);
|
||||
SET_PROPERTIES(CGLighthouse);
|
||||
SET_PROPERTIES(CRewardableObject);
|
||||
SET_PROPERTIES(CGPandoraBox);
|
||||
SET_PROPERTIES(CGEvent);
|
||||
SET_PROPERTIES(CGSeerHut);
|
||||
@ -518,6 +521,11 @@ void Inspector::setProperty(CGLighthouse * o, const QString & key, const QVarian
|
||||
if(!o) return;
|
||||
}
|
||||
|
||||
void Inspector::setProperty(CRewardableObject * o, const QString & key, const QVariant & value)
|
||||
{
|
||||
if(!o) return;
|
||||
}
|
||||
|
||||
void Inspector::setProperty(CGPandoraBox * o, const QString & key, const QVariant & value)
|
||||
{
|
||||
if(!o) return;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "../lib/GameConstants.h"
|
||||
#include "../lib/mapObjects/CGCreature.h"
|
||||
#include "../lib/mapObjects/MapObjects.h"
|
||||
#include "../lib/mapObjects/CRewardableObject.h"
|
||||
#include "../lib/ResourceSet.h"
|
||||
|
||||
#define DECLARE_OBJ_TYPE(x) void initialize(x*);
|
||||
@ -45,6 +46,7 @@ public:
|
||||
DECLARE_OBJ_TYPE(CGCreature);
|
||||
DECLARE_OBJ_TYPE(CGSignBottle);
|
||||
DECLARE_OBJ_TYPE(CGLighthouse);
|
||||
//DECLARE_OBJ_TYPE(CRewardableObject);
|
||||
//DECLARE_OBJ_TYPE(CGEvent);
|
||||
//DECLARE_OBJ_TYPE(CGPandoraBox);
|
||||
//DECLARE_OBJ_TYPE(CGSeerHut);
|
||||
@ -73,6 +75,7 @@ protected:
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGCreature);
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGSignBottle);
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGLighthouse);
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CRewardableObject);
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGPandoraBox);
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGEvent);
|
||||
DECLARE_OBJ_PROPERTY_METHODS(CGSeerHut);
|
||||
|
@ -17,31 +17,153 @@
|
||||
#include "../lib/CCreatureHandler.h"
|
||||
#include "../lib/constants/StringConstants.h"
|
||||
#include "../lib/mapping/CMap.h"
|
||||
#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"
|
||||
|
||||
RewardsWidget::RewardsWidget(const CMap & m, CGPandoraBox & p, QWidget *parent) :
|
||||
RewardsWidget::RewardsWidget(const CMap & m, CRewardableObject & p, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
map(m),
|
||||
pandora(&p),
|
||||
seerhut(nullptr),
|
||||
object(p),
|
||||
ui(new Ui::RewardsWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
for(auto & type : rewardTypes)
|
||||
ui->rewardType->addItem(QString::fromStdString(type));
|
||||
}
|
||||
|
||||
RewardsWidget::RewardsWidget(const CMap & m, CGSeerHut & p, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
map(m),
|
||||
pandora(nullptr),
|
||||
seerhut(&p),
|
||||
ui(new Ui::RewardsWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
//fill core elements
|
||||
for(const auto & s : Rewardable::VisitModeString)
|
||||
ui->visitMode->addItem(QString::fromStdString(s));
|
||||
|
||||
for(auto & type : rewardTypes)
|
||||
ui->rewardType->addItem(QString::fromStdString(type));
|
||||
for(const auto & s : Rewardable::SelectModeString)
|
||||
ui->selectMode->addItem(QString::fromStdString(s));
|
||||
|
||||
for(const std::string & s : {"AUTO", "MODAL", "INFO"})
|
||||
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);
|
||||
ui->selectMode->setCurrentIndex(vstd::find_pos(Rewardable::SelectModeString, "selectAll"));
|
||||
ui->selectMode->setEnabled(false);
|
||||
ui->windowMode->setEnabled(false);
|
||||
ui->canRefuse->setEnabled(false);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
RewardsWidget::~RewardsWidget()
|
||||
@ -49,364 +171,440 @@ RewardsWidget::~RewardsWidget()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QList<QString> RewardsWidget::getListForType(RewardType typeId)
|
||||
{
|
||||
assert(typeId < rewardTypes.size());
|
||||
QList<QString> result;
|
||||
|
||||
switch (typeId) {
|
||||
case RewardType::RESOURCE:
|
||||
//to convert string to index WOOD = 0, MERCURY, ORE, SULFUR, CRYSTAL, GEMS, GOLD, MITHRIL,
|
||||
result.append("Wood");
|
||||
result.append("Mercury");
|
||||
result.append("Ore");
|
||||
result.append("Sulfur");
|
||||
result.append("Crystals");
|
||||
result.append("Gems");
|
||||
result.append("Gold");
|
||||
break;
|
||||
|
||||
case RewardType::PRIMARY_SKILL:
|
||||
for(auto s : NPrimarySkill::names)
|
||||
result.append(QString::fromStdString(s));
|
||||
break;
|
||||
|
||||
case RewardType::SECONDARY_SKILL:
|
||||
for(int i = 0; i < map.allowedAbilities.size(); ++i)
|
||||
{
|
||||
if(map.allowedAbilities[i])
|
||||
result.append(QString::fromStdString(VLC->skills()->getByIndex(i)->getNameTranslated()));
|
||||
}
|
||||
break;
|
||||
|
||||
case RewardType::ARTIFACT:
|
||||
for(int i = 0; i < map.allowedArtifact.size(); ++i)
|
||||
{
|
||||
if(map.allowedArtifact[i])
|
||||
result.append(QString::fromStdString(VLC->artifacts()->getByIndex(i)->getNameTranslated()));
|
||||
}
|
||||
break;
|
||||
|
||||
case RewardType::SPELL:
|
||||
for(int i = 0; i < map.allowedSpells.size(); ++i)
|
||||
{
|
||||
if(map.allowedSpells[i])
|
||||
result.append(QString::fromStdString(VLC->spells()->getByIndex(i)->getNameTranslated()));
|
||||
}
|
||||
break;
|
||||
|
||||
case RewardType::CREATURE:
|
||||
for(auto creature : VLC->creh->objects)
|
||||
{
|
||||
result.append(QString::fromStdString(creature->getNameSingularTranslated()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void RewardsWidget::on_rewardType_activated(int index)
|
||||
{
|
||||
ui->rewardList->clear();
|
||||
ui->rewardList->setEnabled(true);
|
||||
assert(index < rewardTypes.size());
|
||||
|
||||
auto l = getListForType(RewardType(index));
|
||||
if(l.empty())
|
||||
ui->rewardList->setEnabled(false);
|
||||
|
||||
for(auto & s : l)
|
||||
ui->rewardList->addItem(s);
|
||||
}
|
||||
|
||||
void RewardsWidget::obtainData()
|
||||
{
|
||||
if(pandora)
|
||||
{
|
||||
if(pandora->gainedExp > 0)
|
||||
addReward(RewardType::EXPERIENCE, 0, pandora->gainedExp);
|
||||
if(pandora->manaDiff)
|
||||
addReward(RewardType::MANA, 0, pandora->manaDiff);
|
||||
if(pandora->moraleDiff)
|
||||
addReward(RewardType::MORALE, 0, pandora->moraleDiff);
|
||||
if(pandora->luckDiff)
|
||||
addReward(RewardType::LUCK, 0, pandora->luckDiff);
|
||||
if(pandora->resources.nonZero())
|
||||
{
|
||||
for(ResourceSet::nziterator resiter(pandora->resources); resiter.valid(); ++resiter)
|
||||
addReward(RewardType::RESOURCE, resiter->resType, resiter->resVal);
|
||||
}
|
||||
for(int idx = 0; idx < pandora->primskills.size(); ++idx)
|
||||
{
|
||||
if(pandora->primskills[idx])
|
||||
addReward(RewardType::PRIMARY_SKILL, idx, pandora->primskills[idx]);
|
||||
}
|
||||
assert(pandora->abilities.size() == pandora->abilityLevels.size());
|
||||
for(int idx = 0; idx < pandora->abilities.size(); ++idx)
|
||||
{
|
||||
addReward(RewardType::SECONDARY_SKILL, pandora->abilities[idx].getNum(), pandora->abilityLevels[idx]);
|
||||
}
|
||||
for(auto art : pandora->artifacts)
|
||||
{
|
||||
addReward(RewardType::ARTIFACT, art.getNum(), 1);
|
||||
}
|
||||
for(auto spell : pandora->spells)
|
||||
{
|
||||
addReward(RewardType::SPELL, spell.getNum(), 1);
|
||||
}
|
||||
for(int i = 0; i < pandora->creatures.Slots().size(); ++i)
|
||||
{
|
||||
if(auto c = pandora->creatures.getCreature(SlotID(i)))
|
||||
addReward(RewardType::CREATURE, c->getId(), pandora->creatures.getStackCount(SlotID(i)));
|
||||
}
|
||||
}
|
||||
//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);
|
||||
|
||||
if(seerhut)
|
||||
{
|
||||
for(auto & i : seerhut->configuration.info)
|
||||
{
|
||||
if(i.reward.heroExperience)
|
||||
addReward(RewardType::EXPERIENCE, 0, i.reward.heroExperience);
|
||||
if(i.reward.manaDiff)
|
||||
addReward(RewardType::MANA, 0, i.reward.manaDiff);
|
||||
for(auto & a : i.reward.artifacts)
|
||||
addReward(RewardType::ARTIFACT, a.getNum(), 0);
|
||||
for(auto & a : i.reward.creatures)
|
||||
addReward(RewardType::CREATURE, a.getType()->getId().getNum(), a.getCount());
|
||||
}
|
||||
/*switch(seerhut->rewardType)
|
||||
{
|
||||
case CGSeerHut::ERewardType::EXPERIENCE:
|
||||
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::MANA_POINTS:
|
||||
addReward(RewardType::MANA, 0, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::MORALE_BONUS:
|
||||
addReward(RewardType::MORALE, 0, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::LUCK_BONUS:
|
||||
addReward(RewardType::LUCK, 0, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::RESOURCES:
|
||||
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::PRIMARY_SKILL:
|
||||
addReward(RewardType::PRIMARY_SKILL, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::SECONDARY_SKILL:
|
||||
addReward(RewardType::SECONDARY_SKILL, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::ARTIFACT:
|
||||
addReward(RewardType::ARTIFACT, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::SPELL:
|
||||
addReward(RewardType::SPELL, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
case CGSeerHut::ERewardType::CREATURE:
|
||||
addReward(RewardType::CREATURE, seerhut->rID, seerhut->rVal);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
//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());
|
||||
}
|
||||
|
||||
bool RewardsWidget::commitChanges()
|
||||
{
|
||||
bool haveRewards = false;
|
||||
if(pandora)
|
||||
//common parameters
|
||||
object.configuration.visitMode = ui->visitMode->currentIndex();
|
||||
object.configuration.selectMode = ui->selectMode->currentIndex();
|
||||
object.configuration.infoWindowType = EInfoWindowMode(ui->windowMode->currentIndex());
|
||||
object.configuration.onSelect = MetaString::createFromRawString(ui->onSelectText->text().toStdString());
|
||||
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();
|
||||
|
||||
if(ui->visitInfoList->currentItem())
|
||||
saveCurrentVisitInfo(ui->visitInfoList->currentRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RewardsWidget::saveCurrentVisitInfo(int index)
|
||||
{
|
||||
auto & vinfo = object.configuration.info.at(index);
|
||||
vinfo.message = MetaString::createFromRawString(ui->rewardMessage->text().toStdString());
|
||||
|
||||
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();
|
||||
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)
|
||||
{
|
||||
pandora->abilities.clear();
|
||||
pandora->abilityLevels.clear();
|
||||
pandora->primskills.resize(GameConstants::PRIMARY_SKILLS, 0);
|
||||
pandora->resources = ResourceSet();
|
||||
pandora->artifacts.clear();
|
||||
pandora->spells.clear();
|
||||
pandora->creatures.clearSlots();
|
||||
|
||||
for(int row = 0; row < rewards; ++row)
|
||||
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)))
|
||||
{
|
||||
haveRewards = true;
|
||||
int typeId = ui->rewardsTable->item(row, 0)->data(Qt::UserRole).toInt();
|
||||
int listId = ui->rewardsTable->item(row, 1) ? ui->rewardsTable->item(row, 1)->data(Qt::UserRole).toInt() : 0;
|
||||
int amount = ui->rewardsTable->item(row, 2)->data(Qt::UserRole).toInt();
|
||||
switch(typeId)
|
||||
if(widget->currentIndex() > 0)
|
||||
vinfo.reward.secondary[VLC->skills()->getByIndex(i)->getId()] = widget->currentIndex();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
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)
|
||||
{
|
||||
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)))
|
||||
{
|
||||
if(widget->currentIndex() > 0)
|
||||
vinfo.limiter.secondary[VLC->skills()->getByIndex(i)->getId()] = widget->currentIndex();
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
void RewardsWidget::loadCurrentVisitInfo(int index)
|
||||
{
|
||||
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))
|
||||
{
|
||||
case RewardType::EXPERIENCE:
|
||||
pandora->gainedExp = amount;
|
||||
break;
|
||||
|
||||
case RewardType::MANA:
|
||||
pandora->manaDiff = amount;
|
||||
break;
|
||||
|
||||
case RewardType::MORALE:
|
||||
pandora->moraleDiff = amount;
|
||||
break;
|
||||
|
||||
case RewardType::LUCK:
|
||||
pandora->luckDiff = amount;
|
||||
break;
|
||||
|
||||
case RewardType::RESOURCE:
|
||||
pandora->resources[listId] = amount;
|
||||
break;
|
||||
|
||||
case RewardType::PRIMARY_SKILL:
|
||||
pandora->primskills[listId] = amount;
|
||||
break;
|
||||
|
||||
case RewardType::SECONDARY_SKILL:
|
||||
pandora->abilities.push_back(SecondarySkill(listId));
|
||||
pandora->abilityLevels.push_back(amount);
|
||||
break;
|
||||
|
||||
case RewardType::ARTIFACT:
|
||||
pandora->artifacts.push_back(ArtifactID(listId));
|
||||
break;
|
||||
|
||||
case RewardType::SPELL:
|
||||
pandora->spells.push_back(SpellID(listId));
|
||||
break;
|
||||
|
||||
case RewardType::CREATURE:
|
||||
auto slot = pandora->creatures.getFreeSlot();
|
||||
if(slot != SlotID() && amount > 0)
|
||||
pandora->creatures.addToSlot(slot, CreatureID(listId), amount);
|
||||
break;
|
||||
ui->bonusDuration->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(seerhut)
|
||||
{
|
||||
seerhut->configuration.info.clear();
|
||||
for(int row = 0; row < rewards; ++row)
|
||||
|
||||
auto typ = vstd::findKey(bonusNameMap, i.type);
|
||||
for(int i = 0; i < ui->bonusType->count(); ++i)
|
||||
{
|
||||
seerhut->configuration.info.emplace_back();
|
||||
seerhut->configuration.info.back().visitType = Rewardable::EEventType::EVENT_FIRST_VISIT;
|
||||
Rewardable::Reward & reward = seerhut->configuration.info.back().reward;
|
||||
haveRewards = true;
|
||||
int typeId = ui->rewardsTable->item(row, 0)->data(Qt::UserRole).toInt();
|
||||
int listId = ui->rewardsTable->item(row, 1) ? ui->rewardsTable->item(row, 1)->data(Qt::UserRole).toInt() : 0;
|
||||
int amount = ui->rewardsTable->item(row, 2)->data(Qt::UserRole).toInt();
|
||||
switch (typeId) {
|
||||
case RewardType::EXPERIENCE:
|
||||
reward.heroExperience = amount;
|
||||
break;
|
||||
|
||||
case RewardType::ARTIFACT:
|
||||
reward.artifacts.push_back(listId);
|
||||
break;
|
||||
|
||||
case RewardType::CREATURE:
|
||||
reward.creatures.emplace_back(listId, amount);
|
||||
|
||||
default:
|
||||
break;
|
||||
if(ui->bonusType->itemText(i) == QString::fromStdString(typ))
|
||||
{
|
||||
ui->bonusType->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if(auto * cname = listWidget->item(i, 0))
|
||||
{
|
||||
if(cname->data(Qt::UserRole).toInt() == comboWidget->currentData().toInt())
|
||||
{
|
||||
item = cname;
|
||||
widget = qobject_cast<QSpinBox*>(listWidget->cellWidget(i, 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return haveRewards;
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
void RewardsWidget::on_rewardList_activated(int index)
|
||||
void RewardsWidget::on_addVisitInfo_clicked()
|
||||
{
|
||||
ui->rewardAmount->setText(QStringLiteral("1"));
|
||||
ui->visitInfoList->addItem(tr("Reward %1").arg(ui->visitInfoList->count() + 1));
|
||||
object.configuration.info.emplace_back();
|
||||
}
|
||||
|
||||
void RewardsWidget::addReward(RewardsWidget::RewardType typeId, int listId, int amount)
|
||||
|
||||
void RewardsWidget::on_removeVisitInfo_clicked()
|
||||
{
|
||||
//for seerhut there could be the only one reward
|
||||
if(!pandora && seerhut && rewards)
|
||||
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();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
ui->eventInfoGroup->hide();
|
||||
return;
|
||||
|
||||
ui->rewardsTable->setRowCount(++rewards);
|
||||
|
||||
auto itemType = new QTableWidgetItem(QString::fromStdString(rewardTypes[typeId]));
|
||||
itemType->setData(Qt::UserRole, typeId);
|
||||
ui->rewardsTable->setItem(rewards - 1, 0, itemType);
|
||||
|
||||
auto l = getListForType(typeId);
|
||||
if(!l.empty())
|
||||
{
|
||||
auto itemCurr = new QTableWidgetItem(getListForType(typeId)[listId]);
|
||||
itemCurr->setData(Qt::UserRole, listId);
|
||||
ui->rewardsTable->setItem(rewards - 1, 1, itemCurr);
|
||||
}
|
||||
|
||||
QString am = QString::number(amount);
|
||||
switch(ui->rewardType->currentIndex())
|
||||
{
|
||||
case 6:
|
||||
if(amount <= 1)
|
||||
am = "Basic";
|
||||
if(amount == 2)
|
||||
am = "Advanced";
|
||||
if(amount >= 3)
|
||||
am = "Expert";
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 8:
|
||||
am = "";
|
||||
amount = 1;
|
||||
break;
|
||||
}
|
||||
auto itemCount = new QTableWidgetItem(am);
|
||||
itemCount->setData(Qt::UserRole, amount);
|
||||
ui->rewardsTable->setItem(rewards - 1, 2, itemCount);
|
||||
ui->eventInfoGroup->show();
|
||||
loadCurrentVisitInfo(ui->visitInfoList->currentRow());
|
||||
}
|
||||
|
||||
void RewardsWidget::on_visitInfoList_currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous)
|
||||
{
|
||||
if(previous)
|
||||
saveCurrentVisitInfo(ui->visitInfoList->row(previous));
|
||||
}
|
||||
|
||||
|
||||
void RewardsWidget::on_buttonAdd_clicked()
|
||||
void RewardsWidget::on_rCreatureAdd_clicked()
|
||||
{
|
||||
addReward(RewardType(ui->rewardType->currentIndex()), ui->rewardList->currentIndex(), ui->rewardAmount->text().toInt());
|
||||
onCreatureAdd(ui->rCreatures, ui->rCreatureId, ui->rCreatureAmount);
|
||||
}
|
||||
|
||||
|
||||
void RewardsWidget::on_buttonRemove_clicked()
|
||||
void RewardsWidget::on_rCreatureRemove_clicked()
|
||||
{
|
||||
auto currentRow = ui->rewardsTable->currentRow();
|
||||
if(currentRow != -1)
|
||||
{
|
||||
ui->rewardsTable->removeRow(currentRow);
|
||||
--rewards;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RewardsWidget::on_buttonClear_clicked()
|
||||
{
|
||||
ui->rewardsTable->clear();
|
||||
rewards = 0;
|
||||
}
|
||||
|
||||
|
||||
void RewardsWidget::on_rewardsTable_itemSelectionChanged()
|
||||
{
|
||||
/*auto type = ui->rewardsTable->item(ui->rewardsTable->currentRow(), 0);
|
||||
ui->rewardType->setCurrentIndex(type->data(Qt::UserRole).toInt());
|
||||
ui->rewardType->activated(ui->rewardType->currentIndex());
|
||||
std::set<int, std::greater<int>> rowsToRemove;
|
||||
for(auto * i : ui->rCreatures->selectedItems())
|
||||
rowsToRemove.insert(i->row());
|
||||
|
||||
type = ui->rewardsTable->item(ui->rewardsTable->currentRow(), 1);
|
||||
ui->rewardList->setCurrentIndex(type->data(Qt::UserRole).toInt());
|
||||
ui->rewardList->activated(ui->rewardList->currentIndex());
|
||||
|
||||
type = ui->rewardsTable->item(ui->rewardsTable->currentRow(), 2);
|
||||
ui->rewardAmount->setText(QString::number(type->data(Qt::UserRole).toInt()));*/
|
||||
for(auto i : rowsToRemove)
|
||||
ui->rCreatures->removeRow(i);
|
||||
}
|
||||
|
||||
|
||||
void RewardsWidget::on_lCreatureAdd_clicked()
|
||||
{
|
||||
onCreatureAdd(ui->lCreatures, ui->lCreatureId, ui->lCreatureAmount);
|
||||
}
|
||||
|
||||
|
||||
void RewardsWidget::on_lCreatureRemove_clicked()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
void RewardsWidget::on_castSpellCheck_toggled(bool checked)
|
||||
{
|
||||
ui->castSpell->setEnabled(checked);
|
||||
ui->castLevel->setEnabled(checked);
|
||||
}
|
||||
|
||||
void RewardsWidget::on_bonusAdd_clicked()
|
||||
{
|
||||
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());
|
||||
|
||||
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());
|
||||
|
||||
for(auto i : rowsToRemove)
|
||||
ui->bonuses->removeRow(i);
|
||||
}
|
||||
|
||||
|
||||
void RewardsDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
if(auto * ed = qobject_cast<RewardsWidget *>(editor))
|
||||
@ -431,20 +629,11 @@ void RewardsDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, c
|
||||
}
|
||||
}
|
||||
|
||||
RewardsPandoraDelegate::RewardsPandoraDelegate(const CMap & m, CGPandoraBox & t): map(m), pandora(t), RewardsDelegate()
|
||||
RewardsDelegate::RewardsDelegate(const CMap & m, CRewardableObject & t): map(m), object(t)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget * RewardsPandoraDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
QWidget * RewardsDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return new RewardsWidget(map, pandora, parent);
|
||||
}
|
||||
|
||||
RewardsSeerhutDelegate::RewardsSeerhutDelegate(const CMap & m, CGSeerHut & t): map(m), seerhut(t), RewardsDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
QWidget * RewardsSeerhutDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return new RewardsWidget(map, seerhut, parent);
|
||||
return new RewardsWidget(map, object, parent);
|
||||
}
|
||||
|
@ -10,88 +10,77 @@
|
||||
#pragma once
|
||||
#include "../StdInc.h"
|
||||
#include <QDialog>
|
||||
#include "../lib/mapObjects/CGPandoraBox.h"
|
||||
#include "../lib/mapObjects/CQuest.h"
|
||||
#include "../lib/mapObjects/CRewardableObject.h"
|
||||
|
||||
namespace Ui {
|
||||
class RewardsWidget;
|
||||
}
|
||||
|
||||
const std::array<std::string, 10> rewardTypes{"Experience", "Mana", "Morale", "Luck", "Resource", "Primary skill", "Secondary skill", "Artifact", "Spell", "Creature"};
|
||||
|
||||
class RewardsWidget : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum RewardType
|
||||
{
|
||||
EXPERIENCE = 0, MANA, MORALE, LUCK, RESOURCE, PRIMARY_SKILL, SECONDARY_SKILL, ARTIFACT, SPELL, CREATURE
|
||||
};
|
||||
|
||||
explicit RewardsWidget(const CMap &, CGPandoraBox &, QWidget *parent = nullptr);
|
||||
explicit RewardsWidget(const CMap &, CGSeerHut &, QWidget *parent = nullptr);
|
||||
explicit RewardsWidget(const CMap &, CRewardableObject &, QWidget *parent = nullptr);
|
||||
~RewardsWidget();
|
||||
|
||||
void obtainData();
|
||||
bool commitChanges();
|
||||
|
||||
private slots:
|
||||
void on_rewardType_activated(int index);
|
||||
void on_addVisitInfo_clicked();
|
||||
|
||||
void on_rewardList_activated(int index);
|
||||
void on_removeVisitInfo_clicked();
|
||||
|
||||
void on_buttonAdd_clicked();
|
||||
void on_selectMode_currentIndexChanged(int index);
|
||||
|
||||
void on_buttonRemove_clicked();
|
||||
void on_resetPeriod_valueChanged(int arg1);
|
||||
|
||||
void on_buttonClear_clicked();
|
||||
void on_visitInfoList_itemSelectionChanged();
|
||||
|
||||
void on_rewardsTable_itemSelectionChanged();
|
||||
void on_visitInfoList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
|
||||
|
||||
void on_rCreatureAdd_clicked();
|
||||
|
||||
void on_rCreatureRemove_clicked();
|
||||
|
||||
void on_lCreatureAdd_clicked();
|
||||
|
||||
void on_lCreatureRemove_clicked();
|
||||
|
||||
void on_castSpellCheck_toggled(bool checked);
|
||||
|
||||
void on_bonusAdd_clicked();
|
||||
|
||||
void on_bonusRemove_clicked();
|
||||
|
||||
private:
|
||||
void addReward(RewardType typeId, int listId, int amount);
|
||||
QList<QString> getListForType(RewardType typeId);
|
||||
|
||||
void saveCurrentVisitInfo(int index);
|
||||
void loadCurrentVisitInfo(int index);
|
||||
|
||||
void onCreatureAdd(QTableWidget * listWidget, QComboBox * comboWidget, QSpinBox * spinWidget);
|
||||
|
||||
Ui::RewardsWidget *ui;
|
||||
CGPandoraBox * pandora;
|
||||
CGSeerHut * seerhut;
|
||||
CRewardableObject & object;
|
||||
const CMap & map;
|
||||
int rewards = 0;
|
||||
};
|
||||
|
||||
class RewardsDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RewardsDelegate(const CMap &, CRewardableObject &);
|
||||
|
||||
using QStyledItemDelegate::QStyledItemDelegate;
|
||||
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
class RewardsPandoraDelegate : public RewardsDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RewardsPandoraDelegate(const CMap &, CGPandoraBox &);
|
||||
|
||||
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
|
||||
private:
|
||||
CGPandoraBox & pandora;
|
||||
const CMap & map;
|
||||
};
|
||||
|
||||
class RewardsSeerhutDelegate : public RewardsDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RewardsSeerhutDelegate(const CMap &, CGSeerHut &);
|
||||
|
||||
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
CGSeerHut & seerhut;
|
||||
CRewardableObject & object;
|
||||
const CMap & map;
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user