mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-05 13:04:54 +02:00
Merge pull request #4608 from godric3/map-editor-fix-event-regressions
Map editor fix event regressions
This commit is contained in:
commit
72819d5fe3
@ -13,6 +13,7 @@
|
||||
#include "towneventdialog.h"
|
||||
#include "ui_towneventdialog.h"
|
||||
#include "mapeditorroles.h"
|
||||
#include "../mapsettings/eventsettings.h"
|
||||
#include "../../lib/entities/building/CBuilding.h"
|
||||
#include "../../lib/entities/faction/CTownHandler.h"
|
||||
#include "../../lib/constants/NumericConstants.h"
|
||||
@ -63,9 +64,10 @@ TownEventDialog::~TownEventDialog()
|
||||
|
||||
void TownEventDialog::initPlayers()
|
||||
{
|
||||
auto playerList = params.value("players").toList();
|
||||
for (int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
|
||||
{
|
||||
bool isAffected = (1 << i) & params.value("players").toInt();
|
||||
bool isAffected = playerList.contains(toQString(PlayerColor(i)));
|
||||
auto * item = new QListWidgetItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[i]));
|
||||
item->setData(MapEditorRoles::PlayerIDRole, QVariant::fromValue(i));
|
||||
item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked);
|
||||
@ -155,7 +157,12 @@ void TownEventDialog::initCreatures()
|
||||
{
|
||||
auto creatures = params.value("creatures").toList();
|
||||
auto * ctown = town.town;
|
||||
for (int i = 0; i < GameConstants::CREATURES_PER_TOWN; ++i)
|
||||
if (!ctown)
|
||||
ui->creaturesTable->setRowCount(GameConstants::CREATURES_PER_TOWN);
|
||||
else
|
||||
ui->creaturesTable->setRowCount(ctown->creatures.size());
|
||||
|
||||
for (int i = 0; i < ui->creaturesTable->rowCount(); ++i)
|
||||
{
|
||||
QString creatureNames;
|
||||
if (!ctown)
|
||||
@ -208,12 +215,12 @@ void TownEventDialog::on_TownEventDialog_finished(int result)
|
||||
|
||||
QVariant TownEventDialog::playersToVariant()
|
||||
{
|
||||
int players = 0;
|
||||
QVariantList players;
|
||||
for (int i = 0; i < ui->playersAffected->count(); ++i)
|
||||
{
|
||||
auto * item = ui->playersAffected->item(i);
|
||||
if (item->checkState() == Qt::Checked)
|
||||
players |= 1 << i;
|
||||
players.push_back(toQString(PlayerColor(i)));
|
||||
}
|
||||
return QVariant::fromValue(players);
|
||||
}
|
||||
@ -239,7 +246,7 @@ QVariantList TownEventDialog::buildingsToVariant()
|
||||
QVariantList TownEventDialog::creaturesToVariant()
|
||||
{
|
||||
QVariantList creaturesList;
|
||||
for (int i = 0; i < GameConstants::CREATURES_PER_TOWN; ++i)
|
||||
for (int i = 0; i < ui->creaturesTable->rowCount(); ++i)
|
||||
{
|
||||
auto * item = static_cast<QSpinBox *>(ui->creaturesTable->cellWidget(i, 1));
|
||||
creaturesList.push_back(item->value());
|
||||
|
@ -16,11 +16,16 @@
|
||||
#include "../../lib/constants/NumericConstants.h"
|
||||
#include "../../lib/constants/StringConstants.h"
|
||||
|
||||
QString toQString(const PlayerColor & player)
|
||||
{
|
||||
return QString::fromStdString(player.toString());
|
||||
}
|
||||
|
||||
QVariant toVariant(const std::set<PlayerColor> & players)
|
||||
{
|
||||
QVariantList result;
|
||||
for(auto const id : players)
|
||||
result.push_back(QString::fromStdString(id.toString()));
|
||||
result.push_back(toQString(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace Ui {
|
||||
class EventSettings;
|
||||
}
|
||||
|
||||
QString toQString(const PlayerColor & player);
|
||||
QVariant toVariant(const TResources & resources);
|
||||
QVariant toVariant(const std::set<PlayerColor> & players);
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "StdInc.h"
|
||||
#include "timedevent.h"
|
||||
#include "ui_timedevent.h"
|
||||
#include "eventsettings.h"
|
||||
#include "../../lib/constants/EntityIdentifiers.h"
|
||||
#include "../../lib/constants/StringConstants.h"
|
||||
|
||||
@ -30,9 +31,10 @@ TimedEvent::TimedEvent(QListWidgetItem * t, QWidget *parent) :
|
||||
ui->eventFirstOccurrence->setValue(params.value("firstOccurrence").toInt());
|
||||
ui->eventRepeatAfter->setValue(params.value("nextOccurrence").toInt());
|
||||
|
||||
auto playerList = params.value("players").toList();
|
||||
for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
|
||||
{
|
||||
bool isAffected = (1 << i) & params.value("players").toInt();
|
||||
bool isAffected = playerList.contains(toQString(PlayerColor(i)));
|
||||
auto * item = new QListWidgetItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[i]));
|
||||
item->setData(Qt::UserRole, QVariant::fromValue(i));
|
||||
item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked);
|
||||
@ -69,12 +71,12 @@ void TimedEvent::on_TimedEvent_finished(int result)
|
||||
descriptor["firstOccurrence"] = QVariant::fromValue(ui->eventFirstOccurrence->value());
|
||||
descriptor["nextOccurrence"] = QVariant::fromValue(ui->eventRepeatAfter->value());
|
||||
|
||||
int players = 0;
|
||||
QVariantList players;
|
||||
for(int i = 0; i < ui->playersAffected->count(); ++i)
|
||||
{
|
||||
auto * item = ui->playersAffected->item(i);
|
||||
if(item->checkState() == Qt::Checked)
|
||||
players |= 1 << i;
|
||||
players.push_back(toQString(PlayerColor(i)));
|
||||
}
|
||||
descriptor["players"] = QVariant::fromValue(players);
|
||||
|
||||
|
@ -110,7 +110,7 @@ void NewTurnProcessor::handleTownEvents(const CGTownInstance * town)
|
||||
|
||||
for (si32 i=0;i<event.creatures.size();i++) //creature growths
|
||||
{
|
||||
if (!town->creatures.at(i).second.empty() && event.creatures.at(i) > 0)//there is dwelling
|
||||
if (i < town->creatures.size() && !town->creatures.at(i).second.empty() && event.creatures.at(i) > 0)//there is dwelling
|
||||
{
|
||||
sac.creatures[i].first += event.creatures.at(i);
|
||||
iw.components.emplace_back(ComponentType::CREATURE, town->creatures.at(i).second.back(), event.creatures.at(i));
|
||||
|
Loading…
x
Reference in New Issue
Block a user