1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Refactor abstract settings to have map controller

This commit is contained in:
nordsoft 2023-09-11 19:16:24 +02:00
parent 3024aaae30
commit 1ac886ca71
15 changed files with 172 additions and 123 deletions

View File

@ -10,6 +10,7 @@
#include "StdInc.h"
#include "abstractsettings.h"
#include "../mapcontroller.h"
#include "../../lib/mapObjects/CGHeroInstance.h"
#include "../../lib/mapObjects/CGCreature.h"
#include "../../lib/CTownHandler.h"
@ -82,6 +83,11 @@ AbstractSettings::AbstractSettings(QWidget *parent)
}
void AbstractSettings::initialize(MapController & c)
{
controller = &c;
}
std::string AbstractSettings::getTownName(const CMap & map, int objectIdx)
{
std::string name;

View File

@ -20,6 +20,8 @@ QString expiredDate(int date);
int3 posFromJson(const JsonNode & json);
std::vector<JsonNode> linearJsonArray(const JsonNode & json);
class MapController;
class AbstractSettings : public QWidget
{
Q_OBJECT
@ -27,8 +29,8 @@ public:
explicit AbstractSettings(QWidget *parent = nullptr);
virtual ~AbstractSettings() = default;
virtual void initialize(const CMap & map) = 0;
virtual void update(CMap & map) = 0;
virtual void initialize(MapController & controller);
virtual void update() = 0;
static std::string getTownName(const CMap & map, int objectIdx);
static std::string getHeroName(const CMap & map, int objectIdx);
@ -37,7 +39,7 @@ public:
static JsonNode conditionToJson(const EventCondition & event);
template<class T>
std::vector<int> getObjectIndexes(const CMap & map) const
static std::vector<int> getObjectIndexes(const CMap & map)
{
std::vector<int> result;
for(int i = 0; i < map.objects.size(); ++i)
@ -49,7 +51,7 @@ public:
}
template<class T>
int getObjectByPos(const CMap & map, const int3 & pos)
static int getObjectByPos(const CMap & map, const int3 & pos)
{
for(int i = 0; i < map.objects.size(); ++i)
{
@ -62,6 +64,7 @@ public:
return -1;
}
signals:
protected:
MapController * controller = nullptr;
};

View File

@ -11,6 +11,7 @@
#include "eventsettings.h"
#include "timedevent.h"
#include "ui_eventsettings.h"
#include "../mapcontroller.h"
#include "../../lib/mapping/CMapDefines.h"
#include "../../lib/constants/NumericConstants.h"
#include "../../lib/constants/StringConstants.h"
@ -73,9 +74,10 @@ EventSettings::~EventSettings()
delete ui;
}
void EventSettings::initialize(const CMap & map)
void EventSettings::initialize(MapController & c)
{
for(const auto & event : map.events)
AbstractSettings::initialize(c);
for(const auto & event : controller->map()->events)
{
auto * item = new QListWidgetItem(QString::fromStdString(event.name));
item->setData(Qt::UserRole, toVariant(event));
@ -83,13 +85,13 @@ void EventSettings::initialize(const CMap & map)
}
}
void EventSettings::update(CMap & map)
void EventSettings::update()
{
map.events.clear();
controller->map()->events.clear();
for(int i = 0; i < ui->eventsList->count(); ++i)
{
const auto * item = ui->eventsList->item(i);
map.events.push_back(eventFromVariant(item->data(Qt::UserRole)));
controller->map()->events.push_back(eventFromVariant(item->data(Qt::UserRole)));
}
}

View File

@ -23,8 +23,8 @@ public:
explicit EventSettings(QWidget *parent = nullptr);
~EventSettings();
void initialize(const CMap & map) override;
void update(CMap & map) override;
void initialize(MapController & map) override;
void update() override;
private slots:
void on_timedEventAdd_clicked();

View File

@ -10,6 +10,7 @@
#include "StdInc.h"
#include "generalsettings.h"
#include "ui_generalsettings.h"
#include "../mapcontroller.h"
GeneralSettings::GeneralSettings(QWidget *parent) :
AbstractSettings(parent),
@ -23,15 +24,16 @@ GeneralSettings::~GeneralSettings()
delete ui;
}
void GeneralSettings::initialize(const CMap & map)
void GeneralSettings::initialize(MapController & c)
{
ui->mapNameEdit->setText(tr(map.name.c_str()));
ui->mapDescriptionEdit->setPlainText(tr(map.description.c_str()));
ui->heroLevelLimit->setValue(map.levelLimit);
ui->heroLevelLimitCheck->setChecked(map.levelLimit);
AbstractSettings::initialize(c);
ui->mapNameEdit->setText(tr(controller->map()->name.c_str()));
ui->mapDescriptionEdit->setPlainText(tr(controller->map()->description.c_str()));
ui->heroLevelLimit->setValue(controller->map()->levelLimit);
ui->heroLevelLimitCheck->setChecked(controller->map()->levelLimit);
//set difficulty
switch(map.difficulty)
switch(controller->map()->difficulty)
{
case 0:
ui->diffRadio1->setChecked(true);
@ -55,21 +57,21 @@ void GeneralSettings::initialize(const CMap & map)
};
}
void GeneralSettings::update(CMap & map)
void GeneralSettings::update()
{
map.name = ui->mapNameEdit->text().toStdString();
map.description = ui->mapDescriptionEdit->toPlainText().toStdString();
controller->map()->name = ui->mapNameEdit->text().toStdString();
controller->map()->description = ui->mapDescriptionEdit->toPlainText().toStdString();
if(ui->heroLevelLimitCheck->isChecked())
map.levelLimit = ui->heroLevelLimit->value();
controller->map()->levelLimit = ui->heroLevelLimit->value();
else
map.levelLimit = 0;
controller->map()->levelLimit = 0;
//set difficulty
if(ui->diffRadio1->isChecked()) map.difficulty = 0;
if(ui->diffRadio2->isChecked()) map.difficulty = 1;
if(ui->diffRadio3->isChecked()) map.difficulty = 2;
if(ui->diffRadio4->isChecked()) map.difficulty = 3;
if(ui->diffRadio5->isChecked()) map.difficulty = 4;
if(ui->diffRadio1->isChecked()) controller->map()->difficulty = 0;
if(ui->diffRadio2->isChecked()) controller->map()->difficulty = 1;
if(ui->diffRadio3->isChecked()) controller->map()->difficulty = 2;
if(ui->diffRadio4->isChecked()) controller->map()->difficulty = 3;
if(ui->diffRadio5->isChecked()) controller->map()->difficulty = 4;
}
void GeneralSettings::on_heroLevelLimitCheck_toggled(bool checked)

View File

@ -23,8 +23,8 @@ public:
explicit GeneralSettings(QWidget *parent = nullptr);
~GeneralSettings();
void initialize(const CMap & map) override;
void update(CMap & map) override;
void initialize(MapController & map) override;
void update() override;
private slots:
void on_heroLevelLimitCheck_toggled(bool checked);

View File

@ -10,7 +10,7 @@
#include "StdInc.h"
#include "loseconditions.h"
#include "ui_loseconditions.h"
#include "../mapcontroller.h"
#include "../lib/CGeneralTextHandler.h"
LoseConditions::LoseConditions(QWidget *parent) :
@ -25,12 +25,12 @@ LoseConditions::~LoseConditions()
delete ui;
}
void LoseConditions::initialize(const CMap & map)
void LoseConditions::initialize(MapController & c)
{
mapPointer = &map;
AbstractSettings::initialize(c);
//loss messages
ui->defeatMessageEdit->setText(QString::fromStdString(map.defeatMessage.toString()));
ui->defeatMessageEdit->setText(QString::fromStdString(controller->map()->defeatMessage.toString()));
//loss conditions
const std::array<std::string, 5> conditionStringsLose = {
@ -47,7 +47,7 @@ void LoseConditions::initialize(const CMap & map)
}
ui->standardLoseCheck->setChecked(false);
for(auto & ev : map.triggeredEvents)
for(auto & ev : controller->map()->triggeredEvents)
{
if(ev.effect.type == EventEffect::DEFEAT)
{
@ -68,7 +68,7 @@ void LoseConditions::initialize(const CMap & map)
{
ui->loseComboBox->setCurrentIndex(1);
assert(loseTypeWidget);
int townIdx = getObjectByPos<const CGTownInstance>(*mapPointer, posFromJson(json["position"]));
int townIdx = getObjectByPos<const CGTownInstance>(*controller->map(), posFromJson(json["position"]));
if(townIdx >= 0)
{
auto idx = loseTypeWidget->findData(townIdx);
@ -79,7 +79,7 @@ void LoseConditions::initialize(const CMap & map)
{
ui->loseComboBox->setCurrentIndex(2);
assert(loseTypeWidget);
int heroIdx = getObjectByPos<const CGHeroInstance>(*mapPointer, posFromJson(json["position"]));
int heroIdx = getObjectByPos<const CGHeroInstance>(*controller->map(), posFromJson(json["position"]));
if(heroIdx >= 0)
{
auto idx = loseTypeWidget->findData(heroIdx);
@ -114,10 +114,10 @@ void LoseConditions::initialize(const CMap & map)
}
}
void LoseConditions::update(CMap & map)
void LoseConditions::update()
{
//loss messages
map.defeatMessage = MetaString::createFromRawString(ui->defeatMessageEdit->text().toStdString());
controller->map()->defeatMessage = MetaString::createFromRawString(ui->defeatMessageEdit->text().toStdString());
//loss conditions
EventCondition defeatCondition(EventCondition::DAYS_WITHOUT_TOWN);
@ -135,9 +135,9 @@ void LoseConditions::update(CMap & map)
//DEFEAT
if(ui->loseComboBox->currentIndex() == 0)
{
map.triggeredEvents.push_back(standardDefeat);
map.defeatIconIndex = 3;
map.defeatMessage = MetaString::createFromTextID("core.lcdesc.0");
controller->map()->triggeredEvents.push_back(standardDefeat);
controller->map()->defeatIconIndex = 3;
controller->map()->defeatMessage = MetaString::createFromTextID("core.lcdesc.0");
}
else
{
@ -148,7 +148,7 @@ void LoseConditions::update(CMap & map)
specialDefeat.identifier = "specialDefeat";
specialDefeat.description.clear(); // TODO: display in quest window
map.defeatIconIndex = lossCondition;
controller->map()->defeatIconIndex = lossCondition;
switch(lossCondition)
{
@ -158,11 +158,11 @@ void LoseConditions::update(CMap & map)
cond.objectType = Obj::TOWN;
assert(loseTypeWidget);
int townIdx = loseTypeWidget->currentData().toInt();
cond.position = map.objects[townIdx]->pos;
cond.position = controller->map()->objects[townIdx]->pos;
noneOf.expressions.push_back(cond);
specialDefeat.onFulfill.appendTextID("core.genrltxt.251");
specialDefeat.trigger = EventExpression(noneOf);
map.defeatMessage = MetaString::createFromTextID("core.lcdesc.1");
controller->map()->defeatMessage = MetaString::createFromTextID("core.lcdesc.1");
break;
}
@ -172,11 +172,11 @@ void LoseConditions::update(CMap & map)
cond.objectType = Obj::HERO;
assert(loseTypeWidget);
int townIdx = loseTypeWidget->currentData().toInt();
cond.position = map.objects[townIdx]->pos;
cond.position = controller->map()->objects[townIdx]->pos;
noneOf.expressions.push_back(cond);
specialDefeat.onFulfill.appendTextID("core.genrltxt.253");
specialDefeat.trigger = EventExpression(noneOf);
map.defeatMessage = MetaString::createFromTextID("core.lcdesc.2");
controller->map()->defeatMessage = MetaString::createFromTextID("core.lcdesc.2");
break;
}
@ -186,7 +186,7 @@ void LoseConditions::update(CMap & map)
cond.value = expiredDate(loseValueWidget->text());
specialDefeat.onFulfill.appendTextID("core.genrltxt.254");
specialDefeat.trigger = EventExpression(cond);
map.defeatMessage = MetaString::createFromTextID("core.lcdesc.3");
controller->map()->defeatMessage = MetaString::createFromTextID("core.lcdesc.3");
break;
}
@ -210,9 +210,9 @@ void LoseConditions::update(CMap & map)
if(ui->standardLoseCheck->isChecked())
{
map.triggeredEvents.push_back(standardDefeat);
controller->map()->triggeredEvents.push_back(standardDefeat);
}
map.triggeredEvents.push_back(specialDefeat);
controller->map()->triggeredEvents.push_back(specialDefeat);
}
}
@ -222,9 +222,11 @@ void LoseConditions::on_loseComboBox_currentIndexChanged(int index)
delete loseTypeWidget;
delete loseValueWidget;
delete loseSelectWidget;
delete pickObjectButton;
loseTypeWidget = nullptr;
loseValueWidget = nullptr;
loseSelectWidget = nullptr;
pickObjectButton = nullptr;
if(index == 0)
{
@ -240,16 +242,22 @@ void LoseConditions::on_loseComboBox_currentIndexChanged(int index)
case 0: { //EventCondition::CONTROL (Obj::TOWN)
loseTypeWidget = new QComboBox;
ui->loseParamsLayout->addWidget(loseTypeWidget);
for(int i : getObjectIndexes<const CGTownInstance>(*mapPointer))
loseTypeWidget->addItem(tr(getTownName(*mapPointer, i).c_str()), QVariant::fromValue(i));
for(int i : getObjectIndexes<const CGTownInstance>(*controller->map()))
loseTypeWidget->addItem(tr(getTownName(*controller->map(), i).c_str()), QVariant::fromValue(i));
pickObjectButton = new QToolButton;
connect(pickObjectButton, &QToolButton::clicked, this, &LoseConditions::onObjectSelect);
ui->loseParamsLayout->addWidget(pickObjectButton);
break;
}
case 1: { //EventCondition::CONTROL (Obj::HERO)
loseTypeWidget = new QComboBox;
ui->loseParamsLayout->addWidget(loseTypeWidget);
for(int i : getObjectIndexes<const CGHeroInstance>(*mapPointer))
loseTypeWidget->addItem(tr(getHeroName(*mapPointer, i).c_str()), QVariant::fromValue(i));
for(int i : getObjectIndexes<const CGHeroInstance>(*controller->map()))
loseTypeWidget->addItem(tr(getHeroName(*controller->map(), i).c_str()), QVariant::fromValue(i));
pickObjectButton = new QToolButton;
connect(pickObjectButton, &QToolButton::clicked, this, &LoseConditions::onObjectSelect);
ui->loseParamsLayout->addWidget(pickObjectButton);
break;
}
@ -269,3 +277,12 @@ void LoseConditions::on_loseComboBox_currentIndexChanged(int index)
}
}
void LoseConditions::onObjectSelect()
{
}
void LoseConditions::onObjectPicked(const CGObjectInstance * obj)
{
}

View File

@ -23,18 +23,22 @@ public:
explicit LoseConditions(QWidget *parent = nullptr);
~LoseConditions();
void initialize(const CMap & map) override;
void update(CMap & map) override;
void initialize(MapController & map) override;
void update() override;
public slots:
void onObjectSelect();
void onObjectPicked(const CGObjectInstance *);
private slots:
void on_loseComboBox_currentIndexChanged(int index);
private:
Ui::LoseConditions *ui;
const CMap * mapPointer = nullptr;
QComboBox * loseTypeWidget = nullptr;
QComboBox * loseSelectWidget = nullptr;
QLineEdit * loseValueWidget = nullptr;
QToolButton * pickObjectButton = nullptr;
};

View File

@ -63,12 +63,12 @@ MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
ui->listHeroes->addItem(item);
}
ui->general->initialize(*controller.map());
ui->mods->initialize(*controller.map());
ui->victory->initialize(*controller.map());
ui->lose->initialize(*controller.map());
ui->events->initialize(*controller.map());
ui->rumors->initialize(*controller.map());
ui->general->initialize(controller);
ui->mods->initialize(controller);
ui->victory->initialize(controller);
ui->lose->initialize(controller);
ui->events->initialize(controller);
ui->rumors->initialize(controller);
}
MapSettings::~MapSettings()
@ -94,12 +94,12 @@ void MapSettings::on_pushButton_clicked()
controller.map()->triggeredEvents.clear();
ui->general->update(*controller.map());
ui->mods->update(*controller.map());
ui->victory->update(*controller.map());
ui->lose->update(*controller.map());
ui->events->update(*controller.map());
ui->rumors->update(*controller.map());
ui->general->update();
ui->mods->update();
ui->victory->update();
ui->lose->update();
ui->events->update();
ui->rumors->update();
controller.commitChangeWithoutRedraw();

View File

@ -35,9 +35,9 @@ ModSettings::~ModSettings()
delete ui;
}
void ModSettings::initialize(const CMap & map)
void ModSettings::initialize(MapController & c)
{
mapPointer = &map;
AbstractSettings::initialize(c);
//mods management
//collect all active mods
@ -50,7 +50,7 @@ void ModSettings::initialize(const CMap & map)
auto item = new QTreeWidgetItem(parent, {QString::fromStdString(modInfo.name), QString::fromStdString(modInfo.version.toString())});
item->setData(0, Qt::UserRole, QVariant(QString::fromStdString(modInfo.identifier)));
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(0, map.mods.count(modInfo.identifier) ? Qt::Checked : Qt::Unchecked);
item->setCheckState(0, controller->map()->mods.count(modInfo.identifier) ? Qt::Checked : Qt::Unchecked);
//set parent check
if(parent && item->checkState(0) == Qt::Checked)
parent->setCheckState(0, Qt::Checked);
@ -96,7 +96,7 @@ void ModSettings::initialize(const CMap & map)
ui->treeMods->blockSignals(false);
}
void ModSettings::update(CMap & map)
void ModSettings::update()
{
//Mod management
auto widgetAction = [&](QTreeWidgetItem * item)
@ -104,11 +104,11 @@ void ModSettings::update(CMap & map)
if(item->checkState(0) == Qt::Checked)
{
auto modName = item->data(0, Qt::UserRole).toString().toStdString();
map.mods[modName] = VLC->modh->getModInfo(modName).version;
controller->map()->mods[modName] = VLC->modh->getModInfo(modName).version;
}
};
map.mods.clear();
controller->map()->mods.clear();
for (int i = 0; i < ui->treeMods->topLevelItemCount(); ++i)
{
QTreeWidgetItem *item = ui->treeMods->topLevelItem(i);
@ -134,7 +134,7 @@ void ModSettings::updateModWidgetBasedOnMods(const ModCompatibilityInfo & mods)
void ModSettings::on_modResolution_map_clicked()
{
updateModWidgetBasedOnMods(MapController::modAssessmentMap(*mapPointer));
updateModWidgetBasedOnMods(MapController::modAssessmentMap(*controller->map()));
}

View File

@ -23,8 +23,8 @@ public:
explicit ModSettings(QWidget *parent = nullptr);
~ModSettings();
void initialize(const CMap & map) override;
void update(CMap & map) override;
void initialize(MapController & map) override;
void update() override;
private slots:
void on_modResolution_map_clicked();
@ -38,5 +38,4 @@ private:
private:
Ui::ModSettings *ui;
const CMap * mapPointer = nullptr;
};

View File

@ -10,6 +10,7 @@
#include "StdInc.h"
#include "rumorsettings.h"
#include "ui_rumorsettings.h"
#include "../mapcontroller.h"
RumorSettings::RumorSettings(QWidget *parent) :
AbstractSettings(parent),
@ -23,9 +24,10 @@ RumorSettings::~RumorSettings()
delete ui;
}
void RumorSettings::initialize(const CMap & map)
void RumorSettings::initialize(MapController & c)
{
for(auto & rumor : map.rumors)
AbstractSettings::initialize(c);
for(auto & rumor : controller->map()->rumors)
{
auto * item = new QListWidgetItem(QString::fromStdString(rumor.name));
item->setData(Qt::UserRole, QVariant(QString::fromStdString(rumor.text)));
@ -34,15 +36,15 @@ void RumorSettings::initialize(const CMap & map)
}
}
void RumorSettings::update(CMap & map)
void RumorSettings::update()
{
map.rumors.clear();
controller->map()->rumors.clear();
for(int i = 0; i < ui->rumors->count(); ++i)
{
Rumor rumor;
rumor.name = ui->rumors->item(i)->text().toStdString();
rumor.text = ui->rumors->item(i)->data(Qt::UserRole).toString().toStdString();
map.rumors.push_back(rumor);
controller->map()->rumors.push_back(rumor);
}
}

View File

@ -23,8 +23,8 @@ public:
explicit RumorSettings(QWidget *parent = nullptr);
~RumorSettings();
void initialize(const CMap & map) override;
void update(CMap & map) override;
void initialize(MapController & map) override;
void update() override;
private slots:
void on_message_textChanged();

View File

@ -10,7 +10,7 @@
#include "StdInc.h"
#include "victoryconditions.h"
#include "ui_victoryconditions.h"
#include "../mapcontroller.h"
#include "../lib/CGeneralTextHandler.h"
#include "../lib/constants/StringConstants.h"
@ -23,12 +23,12 @@ VictoryConditions::VictoryConditions(QWidget *parent) :
ui->setupUi(this);
}
void VictoryConditions::initialize(const CMap & map)
void VictoryConditions::initialize(MapController & c)
{
mapPointer = &map;
AbstractSettings::initialize(c);
//victory message
ui->victoryMessageEdit->setText(QString::fromStdString(map.victoryMessage.toString()));
ui->victoryMessageEdit->setText(QString::fromStdString(controller->map()->victoryMessage.toString()));
//victory conditions
const std::array<std::string, 8> conditionStringsWin = {
@ -49,7 +49,7 @@ void VictoryConditions::initialize(const CMap & map)
ui->standardVictoryCheck->setChecked(false);
ui->onlyForHumansCheck->setChecked(false);
for(auto & ev : map.triggeredEvents)
for(auto & ev : controller->map()->triggeredEvents)
{
if(ev.effect.type == EventEffect::VICTORY)
{
@ -98,7 +98,7 @@ void VictoryConditions::initialize(const CMap & map)
assert(victorySelectWidget);
auto idx = victoryTypeWidget->findData(int(json["objectType"].Integer()));
victoryTypeWidget->setCurrentIndex(idx);
int townIdx = getObjectByPos<const CGTownInstance>(*mapPointer, posFromJson(json["position"]));
int townIdx = getObjectByPos<const CGTownInstance>(*controller->map(), posFromJson(json["position"]));
if(townIdx >= 0)
{
auto idx = victorySelectWidget->findData(townIdx);
@ -112,7 +112,7 @@ void VictoryConditions::initialize(const CMap & map)
assert(victoryTypeWidget);
if(json["objectType"].Integer() == Obj::TOWN)
{
int townIdx = getObjectByPos<const CGTownInstance>(*mapPointer, posFromJson(json["position"]));
int townIdx = getObjectByPos<const CGTownInstance>(*controller->map(), posFromJson(json["position"]));
if(townIdx >= 0)
{
auto idx = victoryTypeWidget->findData(townIdx);
@ -128,7 +128,7 @@ void VictoryConditions::initialize(const CMap & map)
assert(victoryTypeWidget);
if(json["objectType"].Integer() == Obj::HERO)
{
int heroIdx = getObjectByPos<const CGHeroInstance>(*mapPointer, posFromJson(json["position"]));
int heroIdx = getObjectByPos<const CGHeroInstance>(*controller->map(), posFromJson(json["position"]));
if(heroIdx >= 0)
{
auto idx = victoryTypeWidget->findData(heroIdx);
@ -144,7 +144,7 @@ void VictoryConditions::initialize(const CMap & map)
assert(victoryTypeWidget);
assert(victorySelectWidget);
victoryTypeWidget->setCurrentIndex(json["objectType"].Integer());
int townIdx = getObjectByPos<const CGTownInstance>(*mapPointer, posFromJson(json["position"]));
int townIdx = getObjectByPos<const CGTownInstance>(*controller->map(), posFromJson(json["position"]));
if(townIdx >= 0)
{
auto idx = victorySelectWidget->findData(townIdx);
@ -164,10 +164,10 @@ void VictoryConditions::initialize(const CMap & map)
}
}
void VictoryConditions::update(CMap & map)
void VictoryConditions::update()
{
//victory messages
map.victoryMessage = MetaString::createFromRawString(ui->victoryMessageEdit->text().toStdString());
controller->map()->victoryMessage = MetaString::createFromRawString(ui->victoryMessageEdit->text().toStdString());
//victory conditions
EventCondition victoryCondition(EventCondition::STANDARD_WIN);
@ -184,9 +184,9 @@ void VictoryConditions::update(CMap & map)
//VICTORY
if(ui->victoryComboBox->currentIndex() == 0)
{
map.triggeredEvents.push_back(standardVictory);
map.victoryIconIndex = 11;
map.victoryMessage = MetaString::createFromTextID("core.vcdesc.0");
controller->map()->triggeredEvents.push_back(standardVictory);
controller->map()->victoryIconIndex = 11;
controller->map()->victoryMessage = MetaString::createFromTextID("core.vcdesc.0");
}
else
{
@ -197,8 +197,8 @@ void VictoryConditions::update(CMap & map)
specialVictory.identifier = "specialVictory";
specialVictory.description.clear(); // TODO: display in quest window
map.victoryIconIndex = vicCondition;
map.victoryMessage = MetaString::createFromTextID("core.vcdesc." + std::to_string(vicCondition + 1));
controller->map()->victoryIconIndex = vicCondition;
controller->map()->victoryMessage = MetaString::createFromTextID("core.vcdesc." + std::to_string(vicCondition + 1));
switch(vicCondition)
{
@ -240,7 +240,7 @@ void VictoryConditions::update(CMap & map)
cond.objectType = victoryTypeWidget->currentData().toInt();
int townIdx = victorySelectWidget->currentData().toInt();
if(townIdx > -1)
cond.position = map.objects[townIdx]->pos;
cond.position = controller->map()->objects[townIdx]->pos;
specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.283");
specialVictory.onFulfill.appendTextID("core.genrltxt.282");
specialVictory.trigger = EventExpression(cond);
@ -252,7 +252,7 @@ void VictoryConditions::update(CMap & map)
assert(victoryTypeWidget);
cond.objectType = Obj::TOWN;
int townIdx = victoryTypeWidget->currentData().toInt();
cond.position = map.objects[townIdx]->pos;
cond.position = controller->map()->objects[townIdx]->pos;
specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.250");
specialVictory.onFulfill.appendTextID("core.genrltxt.249");
specialVictory.trigger = EventExpression(cond);
@ -264,7 +264,7 @@ void VictoryConditions::update(CMap & map)
assert(victoryTypeWidget);
cond.objectType = Obj::HERO;
int heroIdx = victoryTypeWidget->currentData().toInt();
cond.position = map.objects[heroIdx]->pos;
cond.position = controller->map()->objects[heroIdx]->pos;
specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.253");
specialVictory.onFulfill.appendTextID("core.genrltxt.252");
specialVictory.trigger = EventExpression(cond);
@ -277,7 +277,7 @@ void VictoryConditions::update(CMap & map)
cond.objectType = victoryTypeWidget->currentData().toInt();
int townIdx = victorySelectWidget->currentData().toInt();
if(townIdx > -1)
cond.position = map.objects[townIdx]->pos;
cond.position = controller->map()->objects[townIdx]->pos;
specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.293");
specialVictory.onFulfill.appendTextID("core.genrltxt.292");
specialVictory.trigger = EventExpression(cond);
@ -300,11 +300,11 @@ void VictoryConditions::update(CMap & map)
// if normal victory allowed - add one more quest
if(ui->standardVictoryCheck->isChecked())
{
map.victoryMessage.appendRawString(" / ");
map.victoryMessage.appendTextID("core.vcdesc.0");
map.triggeredEvents.push_back(standardVictory);
controller->map()->victoryMessage.appendRawString(" / ");
controller->map()->victoryMessage.appendTextID("core.vcdesc.0");
controller->map()->triggeredEvents.push_back(standardVictory);
}
map.triggeredEvents.push_back(specialVictory);
controller->map()->triggeredEvents.push_back(specialVictory);
}
}
@ -339,7 +339,7 @@ void VictoryConditions::on_victoryComboBox_currentIndexChanged(int index)
case 0: { //EventCondition::HAVE_ARTIFACT
victoryTypeWidget = new QComboBox;
ui->victoryParamsLayout->addWidget(victoryTypeWidget);
for(int i = 0; i < mapPointer->allowedArtifact.size(); ++i)
for(int i = 0; i < controller->map()->allowedArtifact.size(); ++i)
victoryTypeWidget->addItem(QString::fromStdString(VLC->arth->objects[i]->getNameTranslated()), QVariant::fromValue(i));
break;
}
@ -383,37 +383,37 @@ void VictoryConditions::on_victoryComboBox_currentIndexChanged(int index)
victorySelectWidget = new QComboBox;
ui->victoryParamsLayout->addWidget(victorySelectWidget);
victorySelectWidget->addItem("Any town", QVariant::fromValue(-1));
for(int i : getObjectIndexes<const CGTownInstance>(*mapPointer))
victorySelectWidget->addItem(getTownName(*mapPointer, i).c_str(), QVariant::fromValue(i));
for(int i : getObjectIndexes<const CGTownInstance>(*controller->map()))
victorySelectWidget->addItem(getTownName(*controller->map(), i).c_str(), QVariant::fromValue(i));
break;
}
case 4: { //EventCondition::CONTROL (Obj::TOWN)
victoryTypeWidget = new QComboBox;
ui->victoryParamsLayout->addWidget(victoryTypeWidget);
for(int i : getObjectIndexes<const CGTownInstance>(*mapPointer))
victoryTypeWidget->addItem(tr(getTownName(*mapPointer, i).c_str()), QVariant::fromValue(i));
for(int i : getObjectIndexes<const CGTownInstance>(*controller->map()))
victoryTypeWidget->addItem(tr(getTownName(*controller->map(), i).c_str()), QVariant::fromValue(i));
break;
}
case 5: { //EventCondition::DESTROY (Obj::HERO)
victoryTypeWidget = new QComboBox;
ui->victoryParamsLayout->addWidget(victoryTypeWidget);
for(int i : getObjectIndexes<const CGHeroInstance>(*mapPointer))
victoryTypeWidget->addItem(tr(getHeroName(*mapPointer, i).c_str()), QVariant::fromValue(i));
for(int i : getObjectIndexes<const CGHeroInstance>(*controller->map()))
victoryTypeWidget->addItem(tr(getHeroName(*controller->map(), i).c_str()), QVariant::fromValue(i));
break;
}
case 6: { //EventCondition::TRANSPORT (Obj::ARTEFACT)
victoryTypeWidget = new QComboBox;
ui->victoryParamsLayout->addWidget(victoryTypeWidget);
for(int i = 0; i < mapPointer->allowedArtifact.size(); ++i)
for(int i = 0; i < controller->map()->allowedArtifact.size(); ++i)
victoryTypeWidget->addItem(QString::fromStdString(VLC->arth->objects[i]->getNameTranslated()), QVariant::fromValue(i));
victorySelectWidget = new QComboBox;
ui->victoryParamsLayout->addWidget(victorySelectWidget);
for(int i : getObjectIndexes<const CGTownInstance>(*mapPointer))
victorySelectWidget->addItem(tr(getTownName(*mapPointer, i).c_str()), QVariant::fromValue(i));
for(int i : getObjectIndexes<const CGTownInstance>(*controller->map()))
victorySelectWidget->addItem(tr(getTownName(*controller->map(), i).c_str()), QVariant::fromValue(i));
break;
}
@ -433,3 +433,13 @@ void VictoryConditions::on_victoryComboBox_currentIndexChanged(int index)
}
}
void VictoryConditions::onObjectSelect()
{
}
void VictoryConditions::onObjectPicked(const CGObjectInstance * obj)
{
}

View File

@ -23,17 +23,21 @@ public:
explicit VictoryConditions(QWidget *parent = nullptr);
~VictoryConditions();
void initialize(const CMap & map) override;
void update(CMap & map) override;
void initialize(MapController & map) override;
void update() override;
public slots:
void onObjectSelect();
void onObjectPicked(const CGObjectInstance *);
private slots:
void on_victoryComboBox_currentIndexChanged(int index);
private:
Ui::VictoryConditions *ui;
const CMap * mapPointer = nullptr;
QComboBox * victoryTypeWidget = nullptr;
QComboBox * victorySelectWidget = nullptr;
QLineEdit * victoryValueWidget = nullptr;
QToolButton * pickObjectButton = nullptr;
};