1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00

Implemented properties for some object types, player settings supported

This commit is contained in:
nordsoft 2022-09-06 05:46:22 +04:00
parent dcef991b84
commit 667f05843a
10 changed files with 399 additions and 127 deletions

View File

@ -2,6 +2,9 @@
#include "../Global.h" #include "../Global.h"
#define VCMI_EDITOR_VERSION "0.1"
#define VCMI_EDITOR_NAME "VCMI Map Editor"
#include <QtWidgets> #include <QtWidgets>
#include <QStringList> #include <QStringList>
#include <QSet> #include <QSet>

View File

@ -1,45 +1,32 @@
#include "StdInc.h" #include "StdInc.h"
#include "inspector.h" #include "inspector.h"
#include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/mapObjects/CGTownInstance.h"
#include "../lib/mapObjects/MiscObjects.h"
#include "../lib/CArtHandler.h" #include "../lib/CArtHandler.h"
#include "../lib/spells/CSpellHandler.h" #include "../lib/spells/CSpellHandler.h"
#include "../lib/CRandomGenerator.h" #include "../lib/CRandomGenerator.h"
#include "../lib/mapObjects/CObjectClassesHandler.h"
void Inspector::setProperty(const QString & key, const QVariant & value) //===============IMPLEMENT OBJECT INITIALIZATION FUNCTIONS================
Initializer::Initializer(CGObjectInstance * o)
{ {
if(!obj) ///IMPORTANT! initialize order should be from base objects to derived objects
return; INIT_OBJ_TYPE(CGResource);
INIT_OBJ_TYPE(CGArtifact);
setProperty(dynamic_cast<CGTownInstance*>(obj), key, value); INIT_OBJ_TYPE(CArmedInstance);
//updateProperties(); INIT_OBJ_TYPE(CGMine);
INIT_OBJ_TYPE(CGTownInstance);
} }
void Inspector::setProperty(CGTownInstance * object, const QString & key, const QVariant & value) void initialize(CArmedInstance * o)
{ {
if(!object) if(!o) return;
return;
if(key == "Owner")
{
PlayerColor owner(value.toString().toInt());
if(value == "NEUTRAL")
owner = PlayerColor::NEUTRAL;
if(value == "UNFLAGGABLE")
owner = PlayerColor::UNFLAGGABLE;
object->tempOwner = owner;
return;
}
}
CGTownInstance * initialize(CGTownInstance * o)
{
if(!o)
return nullptr;
o->tempOwner = PlayerColor::NEUTRAL; o->tempOwner = PlayerColor::NEUTRAL;
}
void initialize(CGTownInstance * o)
{
if(!o) return;
o->builtBuildings.insert(BuildingID::FORT); o->builtBuildings.insert(BuildingID::FORT);
o->builtBuildings.insert(BuildingID::DEFAULT); o->builtBuildings.insert(BuildingID::DEFAULT);
@ -48,13 +35,11 @@ CGTownInstance * initialize(CGTownInstance * o)
if(!spell->isSpecial() && !spell->isCreatureAbility()) if(!spell->isSpecial() && !spell->isCreatureAbility())
o->possibleSpells.push_back(spell->id); o->possibleSpells.push_back(spell->id);
} }
return o;
} }
CGArtifact * initialize(CGArtifact * o) void initialize(CGArtifact * o)
{ {
if(!o) if(!o) return;
return nullptr;
if(o->ID == Obj::SPELL_SCROLL) if(o->ID == Obj::SPELL_SCROLL)
{ {
@ -69,66 +54,161 @@ CGArtifact * initialize(CGArtifact * o)
auto a = CArtifactInstance::createScroll(*RandomGeneratorUtil::nextItem(out, CRandomGenerator::getDefault())); auto a = CArtifactInstance::createScroll(*RandomGeneratorUtil::nextItem(out, CRandomGenerator::getDefault()));
o->storedArtifact = a; o->storedArtifact = a;
} }
}
void initialize(CGMine * o)
{
if(!o) return;
return o; o->producedResource = Res::ERes(o->subID);
o->producedQuantity = o->defaultResProduction();
} }
Initializer::Initializer(CGObjectInstance * o) void initialize(CGResource * o)
{ {
initialize(dynamic_cast<CGTownInstance*>(o)); if(!o) return;
initialize(dynamic_cast<CGArtifact*>(o));
o->amount = CGResource::RANDOM_AMOUNT;
} }
Inspector::Inspector(CGObjectInstance * o, QTableWidget * t): obj(o), table(t) //===============IMPLEMENT PROPERTIES SETUP===============================
void Inspector::updateProperties(CArmedInstance * o)
{ {
/* if(!o) return;
/// Position of bottom-right corner of object on map
int3 pos; addProperty("Owner", o->tempOwner);
/// Type of object, e.g. town, hero, creature. }
Obj ID;
/// Subtype of object, depends on type
si32 subID;
/// Current owner of an object (when below PLAYER_LIMIT)
PlayerColor tempOwner;
/// Index of object in map's list of objects
ObjectInstanceID id;
/// Defines appearance of object on map (animation, blocked tiles, blit order, etc)
ObjectTemplate appearance;
/// If true hero can visit this object only from neighbouring tiles and can't stand on this object
bool blockVisit;
std::string instanceName; void Inspector::updateProperties(CGTownInstance * o)
std::string typeName; {
std::string subTypeName;*/ if(!o) return;
addProperty("Owner", o->tempOwner, false);
addProperty("Town name", o->name, false);
}
void Inspector::updateProperties(CGArtifact * o)
{
if(!o) return;
}
void Inspector::updateProperties(CGMine * o)
{
if(!o) return;
addProperty("Owner", o->tempOwner, false);
addProperty("Resource", o->producedResource);
addProperty("Productivity", o->producedQuantity, false);
}
void Inspector::updateProperties(CGResource * o)
{
if(!o) return;
addProperty("Amount", o->amount, false);
} }
void Inspector::updateProperties() void Inspector::updateProperties()
{ {
if(!obj) if(!obj)
return; return;
table->setRowCount(0); //cleanup table
addProperty("Indentifier", obj); addProperty("Indentifier", obj);
addProperty("ID", obj->ID.getNum()); addProperty("ID", obj->ID.getNum());
addProperty("SubID", obj->subID); addProperty("SubID", obj->subID);
addProperty("InstanceName", obj->instanceName); addProperty("InstanceName", obj->instanceName);
addProperty("TypeName", obj->typeName); addProperty("TypeName", obj->typeName);
addProperty("SubTypeName", obj->subTypeName); addProperty("SubTypeName", obj->subTypeName);
addProperty("Owner", obj->tempOwner, false);
auto factory = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID); auto factory = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID);
addProperty("IsStatic", factory->isStaticObject()); addProperty("IsStatic", factory->isStaticObject());
UPDATE_OBJ_PROPERTIES(CArmedInstance);
UPDATE_OBJ_PROPERTIES(CGTownInstance);
UPDATE_OBJ_PROPERTIES(CGArtifact);
UPDATE_OBJ_PROPERTIES(CGMine);
UPDATE_OBJ_PROPERTIES(CGResource);
table->show(); table->show();
} }
//===============IMPLEMENT PROPERTY UPDATE================================
void Inspector::setProperty(const QString & key, const QVariant & value)
{
if(!obj)
return;
SET_PROPERTIES(CArmedInstance);
SET_PROPERTIES(CGTownInstance);
SET_PROPERTIES(CGArtifact);
SET_PROPERTIES(CGMine);
SET_PROPERTIES(CGResource);
}
void Inspector::setProperty(CArmedInstance * object, const QString & key, const QVariant & value)
{
if(!object)
return;
if(key == "Owner")
{
PlayerColor owner(value.toString().toInt());
if(value == "NEUTRAL")
owner = PlayerColor::NEUTRAL;
if(value == "UNFLAGGABLE")
owner = PlayerColor::UNFLAGGABLE;
object->tempOwner = owner;
return;
}
}
void Inspector::setProperty(CGTownInstance * object, const QString & key, const QVariant & value)
{
if(!object)
return;
if(key == "Town name")
object->name = value.toString().toStdString();
}
void Inspector::setProperty(CGMine * object, const QString & key, const QVariant & value)
{
if(!object)
return;
if(key == "Productivity")
object->producedQuantity = value.toString().toInt();
}
void Inspector::setProperty(CGArtifact * object, const QString & key, const QVariant & value)
{
if(!object)
return;
}
void Inspector::setProperty(CGResource * object, const QString & key, const QVariant & value)
{
if(!object)
return;
if(key == "Amount")
object->amount = value.toString().toInt();
}
//===============IMPLEMENT PROPERTY VALUE TYPE============================
QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value) QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value)
{ {
using NumericPointer = unsigned long long; using NumericPointer = unsigned long long;
static_assert(sizeof(CGObjectInstance *) == sizeof(NumericPointer), static_assert(sizeof(CGObjectInstance *) == sizeof(NumericPointer),
"Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int"); "Compilied for 64 bit arcitecture. Use NumericPointer = unsigned int");
return new QTableWidgetItem(QString::number(reinterpret_cast<NumericPointer>(value))); return new QTableWidgetItem(QString::number(reinterpret_cast<NumericPointer>(value)));
} }
QTableWidgetItem * Inspector::addProperty(unsigned int value)
{
return new QTableWidgetItem(QString::number(value));
}
QTableWidgetItem * Inspector::addProperty(int value) QTableWidgetItem * Inspector::addProperty(int value)
{ {
return new QTableWidgetItem(QString::number(value)); return new QTableWidgetItem(QString::number(value));
@ -165,6 +245,47 @@ QTableWidgetItem * Inspector::addProperty(const PlayerColor & value)
return new QTableWidgetItem(str); return new QTableWidgetItem(str);
} }
QTableWidgetItem * Inspector::addProperty(const Res::ERes & value)
{
QString str;
switch (value) {
case Res::ERes::WOOD:
str = "WOOD";
break;
case Res::ERes::ORE:
str = "ORE";
break;
case Res::ERes::SULFUR:
str = "SULFUR";
break;
case Res::ERes::GEMS:
str = "GEMS";
break;
case Res::ERes::MERCURY:
str = "MERCURY";
break;
case Res::ERes::CRYSTAL:
str = "CRYSTAL";
break;
case Res::ERes::GOLD:
str = "GOLD";
break;
default:
break;
}
return new QTableWidgetItem(str);
}
//========================================================================
Inspector::Inspector(CGObjectInstance * o, QTableWidget * t): obj(o), table(t)
{
}
/*
* Delegates
*/
QWidget * PlayerColorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const QWidget * PlayerColorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
if (index.data().canConvert<int>()) if (index.data().canConvert<int>())

View File

@ -6,56 +6,94 @@
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include "../lib/int3.h" #include "../lib/int3.h"
#include "../lib/GameConstants.h" #include "../lib/GameConstants.h"
#include "../lib/mapObjects/MapObjects.h"
#include "../lib/ResourceSet.h"
class CGObjectInstance; #define DECLARE_OBJ_TYPE(x) void initialize(x*);
class CGTownInstance; #define DECLARE_OBJ_PROPERTY_METHODS(x) \
void updateProperties(x*); \
void setProperty(x*, const QString &, const QVariant &);
class Initializer #define INIT_OBJ_TYPE(x) initialize(dynamic_cast<x*>(o))
{ #define UPDATE_OBJ_PROPERTIES(x) updateProperties(dynamic_cast<x*>(obj))
public: #define SET_PROPERTIES(x) setProperty(dynamic_cast<x*>(obj), key, value)
Initializer(CGObjectInstance *);
}; //===============DECLARE MAP OBJECTS======================================
DECLARE_OBJ_TYPE(CArmedInstance);
DECLARE_OBJ_TYPE(CGTownInstance);
DECLARE_OBJ_TYPE(CGArtifact);
DECLARE_OBJ_TYPE(CGMine);
DECLARE_OBJ_TYPE(CGResource);
class Inspector class Inspector
{ {
protected:
//===============DECLARE PROPERTIES SETUP=================================
DECLARE_OBJ_PROPERTY_METHODS(CArmedInstance);
DECLARE_OBJ_PROPERTY_METHODS(CGTownInstance);
DECLARE_OBJ_PROPERTY_METHODS(CGArtifact);
DECLARE_OBJ_PROPERTY_METHODS(CGMine);
DECLARE_OBJ_PROPERTY_METHODS(CGResource);
//===============DECLARE PROPERTY VALUE TYPE==============================
QTableWidgetItem * addProperty(unsigned int value);
QTableWidgetItem * addProperty(int value);
QTableWidgetItem * addProperty(const std::string & value);
QTableWidgetItem * addProperty(const QString & value);
QTableWidgetItem * addProperty(const int3 & value);
QTableWidgetItem * addProperty(const PlayerColor & value);
QTableWidgetItem * addProperty(const Res::ERes & value);
QTableWidgetItem * addProperty(bool value);
QTableWidgetItem * addProperty(CGObjectInstance * value);
//===============END OF DECLARATION=======================================
public: public:
Inspector(CGObjectInstance *, QTableWidget *); Inspector(CGObjectInstance *, QTableWidget *);
void setProperty(const QString & key, const QVariant & value); void setProperty(const QString & key, const QVariant & value);
void updateProperties(); void updateProperties();
protected: protected:
QTableWidgetItem * addProperty(int value);
QTableWidgetItem * addProperty(const std::string & value);
QTableWidgetItem * addProperty(const QString & value);
QTableWidgetItem * addProperty(const int3 & value);
QTableWidgetItem * addProperty(const PlayerColor & value);
QTableWidgetItem * addProperty(bool value);
QTableWidgetItem * addProperty(CGObjectInstance * value);
void setProperty(CGTownInstance * obj, const QString & key, const QVariant & value);
template<class T> template<class T>
void addProperty(const QString & key, const T & value, bool restricted = true) void addProperty(const QString & key, const T & value, bool restricted = true)
{ {
auto * itemKey = new QTableWidgetItem(key);
auto * itemValue = addProperty(value); auto * itemValue = addProperty(value);
itemKey->setFlags(Qt::NoItemFlags);
if(restricted) if(restricted)
itemValue->setFlags(Qt::NoItemFlags); itemValue->setFlags(Qt::NoItemFlags);
if(table->rowCount() < row + 1) QTableWidgetItem * itemKey = nullptr;
if(keyItems.contains(key))
{
itemKey = keyItems[key];
table->setItem(table->row(itemKey), 1, itemValue);
}
else
{
itemKey = new QTableWidgetItem(key);
itemKey->setFlags(Qt::NoItemFlags);
keyItems[key] = itemKey;
table->setRowCount(row + 1); table->setRowCount(row + 1);
table->setItem(row, 0, itemKey); table->setItem(row, 0, itemKey);
table->setItem(row, 1, itemValue); table->setItem(row, 1, itemValue);
++row; ++row;
}
} }
protected: protected:
int row = 0; int row = 0;
QTableWidget * table; QTableWidget * table;
CGObjectInstance * obj; CGObjectInstance * obj;
QMap<QString, QTableWidgetItem*> keyItems;
};
class Initializer
{
public:
Initializer(CGObjectInstance *);
}; };
class PlayerColorDelegate : public QStyledItemDelegate class PlayerColorDelegate : public QStyledItemDelegate

View File

@ -62,6 +62,7 @@ MainWindow::MainWindow(QWidget *parent) :
controller(this) controller(this)
{ {
ui->setupUi(this); ui->setupUi(this);
setTitle();
// Set current working dir to executable folder. // Set current working dir to executable folder.
// This is important on Mac for relative paths to work inside DMG. // This is important on Mac for relative paths to work inside DMG.
@ -158,22 +159,24 @@ void MainWindow::reloadMap(int level)
//sceneMini->addPixmap(minimap); //sceneMini->addPixmap(minimap);
} }
void MainWindow::setTitle()
{
QString title = QString("%1%2 - %3 (v%4)").arg(filename, unsaved ? "*" : "", VCMI_EDITOR_NAME, VCMI_EDITOR_VERSION);
setWindowTitle(title);
}
void MainWindow::mapChanged() void MainWindow::mapChanged()
{ {
unsaved = true; unsaved = true;
setWindowTitle(filename + "* - VCMI Map Editor"); setTitle();
} }
void MainWindow::initializeMap(bool isNew) void MainWindow::initializeMap(bool isNew)
{ {
unsaved = isNew; unsaved = isNew;
if(isNew) if(isNew)
{
filename.clear(); filename.clear();
setWindowTitle("* - VCMI Map Editor"); setTitle();
}
else
setWindowTitle(filename + " - VCMI Map Editor");
mapLevel = 0; mapLevel = 0;
ui->mapView->setScene(controller.scene(mapLevel)); ui->mapView->setScene(controller.scene(mapLevel));
@ -239,7 +242,7 @@ void MainWindow::saveMap()
} }
unsaved = false; unsaved = false;
setWindowTitle(filename + " - VCMI Map Editor"); setTitle();
} }
void MainWindow::on_actionSave_as_triggered() void MainWindow::on_actionSave_as_triggered()
@ -793,7 +796,7 @@ void MainWindow::on_actionMapSettings_triggered()
void MainWindow::on_actionPlayers_settings_triggered() void MainWindow::on_actionPlayers_settings_triggered()
{ {
auto settingsDialog = new PlayerSettings(*controller.map(), this); auto settingsDialog = new PlayerSettings(controller, this);
settingsDialog->setWindowModality(Qt::WindowModal); settingsDialog->setWindowModality(Qt::WindowModal);
settingsDialog->setModal(true); settingsDialog->setModal(true);
} }

View File

@ -97,6 +97,7 @@ private:
void addGroupIntoCatalog(const std::string & groupName, bool staticOnly, int ID); void addGroupIntoCatalog(const std::string & groupName, bool staticOnly, int ID);
void changeBrushState(int idx); void changeBrushState(int idx);
void setTitle();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;

View File

@ -1,21 +1,68 @@
#include "StdInc.h" #include "StdInc.h"
#include "playerparams.h" #include "playerparams.h"
#include "ui_playerparams.h" #include "ui_playerparams.h"
#include "../lib/CTownHandler.h"
PlayerParams::PlayerParams(const CMapHeader & mapHeader, int playerId, QWidget *parent) : PlayerParams::PlayerParams(MapController & ctrl, int playerId, QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::PlayerParams) ui(new Ui::PlayerParams),
controller(ctrl)
{ {
ui->setupUi(this); ui->setupUi(this);
playerColor = playerId; playerColor = playerId;
assert(mapHeader.players.size() > playerColor); assert(controller.map()->players.size() > playerColor);
playerInfo = mapHeader.players[playerColor]; playerInfo = controller.map()->players[playerColor];
//load factions
for(auto idx : VLC->townh->getAllowedFactions())
{
CFaction * faction = VLC->townh->objects.at(idx);
auto * item = new QListWidgetItem(QString::fromStdString(faction->name));
item->setData(Qt::UserRole, QVariant::fromValue(idx));
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
ui->allowedFactions->addItem(item);
if(playerInfo.allowedFactions.count(idx))
item->setCheckState(Qt::Checked);
else
item->setCheckState(Qt::Unchecked);
}
QObject::connect(ui->allowedFactions, SIGNAL(itemChanged(QListWidgetItem*)),
this, SLOT(allowedFactionsCheck(QListWidgetItem*)));
if(playerInfo.canComputerPlay) //load checks
ui->radioCpu->setChecked(true); bool canHumanPlay = playerInfo.canHumanPlay; //need variable to restore after signal received
if(playerInfo.canHumanPlay) playerInfo.canComputerPlay = true; //computer always can play
ui->radioCpu->setChecked(true);
if(canHumanPlay)
ui->radioHuman->setChecked(true); ui->radioHuman->setChecked(true);
if(playerInfo.isFactionRandom)
ui->randomFaction->setChecked(true);
if(playerInfo.generateHeroAtMainTown)
ui->generateHero->setChecked(true);
//load towns
int foundMainTown = -1;
for(int i = 0; i < controller.map()->towns.size(); ++i)
{
auto town = controller.map()->towns[i];
if(town->getOwner().getNum() == playerColor)
{
if(playerInfo.hasMainTown && playerInfo.posOfMainTown == town->pos)
foundMainTown = i;
ui->mainTown->addItem(QString::fromStdString(town->getObjectName()), QVariant::fromValue(i));
}
}
if(foundMainTown > -1)
{
ui->mainTown->setCurrentIndex(foundMainTown + 1);
}
else
{
playerInfo.hasMainTown = false;
playerInfo.posOfMainTown = int3(-1, -1, -1);
}
ui->playerColor->setTitle(QString("PlayerID: %1").arg(playerId)); ui->playerColor->setTitle(QString("PlayerID: %1").arg(playerId));
show(); show();
@ -39,3 +86,40 @@ void PlayerParams::on_radioCpu_toggled(bool checked)
playerInfo.canHumanPlay = false; playerInfo.canHumanPlay = false;
} }
void PlayerParams::on_generateHero_stateChanged(int arg1)
{
playerInfo.generateHeroAtMainTown = ui->generateHero->isChecked();
}
void PlayerParams::on_randomFaction_stateChanged(int arg1)
{
playerInfo.isFactionRandom = ui->randomFaction->isChecked();
}
void PlayerParams::allowedFactionsCheck(QListWidgetItem * item)
{
if(item->checkState() == Qt::Checked)
playerInfo.allowedFactions.insert(item->data(Qt::UserRole).toInt());
else
playerInfo.allowedFactions.erase(item->data(Qt::UserRole).toInt());
}
void PlayerParams::on_mainTown_activated(int index)
{
if(index == 0) //default
{
playerInfo.hasMainTown = false;
playerInfo.posOfMainTown = int3(-1, -1, -1);
}
else
{
auto town = controller.map()->towns.at(ui->mainTown->currentData().toInt());
playerInfo.hasMainTown = true;
playerInfo.posOfMainTown = town->pos;
}
}

View File

@ -3,6 +3,7 @@
#include <QWidget> #include <QWidget>
#include "../lib/mapping/CMap.h" #include "../lib/mapping/CMap.h"
#include "mapcontroller.h"
namespace Ui { namespace Ui {
class PlayerParams; class PlayerParams;
@ -13,7 +14,7 @@ class PlayerParams : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit PlayerParams(const CMapHeader & mapHeader, int playerId, QWidget *parent = nullptr); explicit PlayerParams(MapController & controller, int playerId, QWidget *parent = nullptr);
~PlayerParams(); ~PlayerParams();
PlayerInfo playerInfo; PlayerInfo playerInfo;
@ -24,8 +25,18 @@ private slots:
void on_radioCpu_toggled(bool checked); void on_radioCpu_toggled(bool checked);
void on_mainTown_activated(int index);
void on_generateHero_stateChanged(int arg1);
void on_randomFaction_stateChanged(int arg1);
void allowedFactionsCheck(QListWidgetItem *);
private: private:
Ui::PlayerParams *ui; Ui::PlayerParams *ui;
MapController & controller;
}; };
#endif // PLAYERPARAMS_H #endif // PLAYERPARAMS_H

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>505</width> <width>505</width>
<height>146</height> <height>160</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -101,23 +101,34 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2" rowspan="2"> <item row="1" column="1">
<widget class="QComboBox" name="mainTown">
<item>
<property name="text">
<string>(default)</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<widget class="QListWidget" name="allowedFactions"> <widget class="QListWidget" name="allowedFactions">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding"> <sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
</widget> <property name="focusPolicy">
</item> <enum>Qt::ClickFocus</enum>
<item row="1" column="1"> </property>
<widget class="QComboBox" name="mainTown"/> <property name="editTriggers">
</item> <set>QAbstractItemView::NoEditTriggers</set>
<item row="0" column="2"> </property>
<widget class="QCheckBox" name="checkBox"> <property name="selectionMode">
<property name="text"> <enum>QAbstractItemView::NoSelection</enum>
<string>All factions allowed</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -4,20 +4,20 @@
#include "playerparams.h" #include "playerparams.h"
#include "mainwindow.h" #include "mainwindow.h"
PlayerSettings::PlayerSettings(CMapHeader & mapHeader, QWidget *parent) : PlayerSettings::PlayerSettings(MapController & ctrl, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::PlayerSettings), ui(new Ui::PlayerSettings),
header(mapHeader) controller(ctrl)
{ {
ui->setupUi(this); ui->setupUi(this);
show(); show();
int players = 0; int players = 0;
for(auto & p : header.players) for(auto & p : controller.map()->players)
{ {
if(p.canAnyonePlay()) if(p.canAnyonePlay())
{ {
paramWidgets.push_back(new PlayerParams(header, players)); paramWidgets.push_back(new PlayerParams(controller, players));
ui->playersLayout->addWidget(paramWidgets.back()); ui->playersLayout->addWidget(paramWidgets.back());
++players; ++players;
} }
@ -36,23 +36,23 @@ PlayerSettings::~PlayerSettings()
void PlayerSettings::on_playersCount_currentIndexChanged(int index) void PlayerSettings::on_playersCount_currentIndexChanged(int index)
{ {
assert(index + 2 <= header.players.size()); assert(index + 2 <= controller.map()->players.size());
for(int i = 0; i < index + 2; ++i) for(int i = 0; i < index + 2; ++i)
{ {
if(i < paramWidgets.size()) if(i < paramWidgets.size())
continue; continue;
auto & p = header.players[i]; auto & p = controller.map()->players[i];
p.canComputerPlay = true; p.canComputerPlay = true;
paramWidgets.push_back(new PlayerParams(header, i)); paramWidgets.push_back(new PlayerParams(controller, i));
ui->playersLayout->addWidget(paramWidgets.back()); ui->playersLayout->addWidget(paramWidgets.back());
} }
assert(!paramWidgets.empty()); assert(!paramWidgets.empty());
for(int i = paramWidgets.size() - 1; i >= index + 2; --i) for(int i = paramWidgets.size() - 1; i >= index + 2; --i)
{ {
auto & p = header.players[i]; auto & p = controller.map()->players[i];
p.canComputerPlay = false; p.canComputerPlay = false;
p.canHumanPlay = false; p.canHumanPlay = false;
ui->playersLayout->removeWidget(paramWidgets[i]); ui->playersLayout->removeWidget(paramWidgets[i]);
@ -66,10 +66,10 @@ void PlayerSettings::on_pushButton_clicked()
{ {
for(auto * w : paramWidgets) for(auto * w : paramWidgets)
{ {
header.players[w->playerColor] = w->playerInfo; controller.map()->players[w->playerColor] = w->playerInfo;
} }
static_cast<MainWindow*>(parent())->controller.commitChangeWithoutRedraw(); controller.commitChangeWithoutRedraw();
close(); close();
} }

View File

@ -14,7 +14,7 @@ class PlayerSettings : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit PlayerSettings(CMapHeader & mapHeader, QWidget *parent = nullptr); explicit PlayerSettings(MapController & controller, QWidget *parent = nullptr);
~PlayerSettings(); ~PlayerSettings();
private slots: private slots:
@ -27,8 +27,8 @@ private:
Ui::PlayerSettings *ui; Ui::PlayerSettings *ui;
std::vector<PlayerParams*> paramWidgets; std::vector<PlayerParams*> paramWidgets;
CMapHeader & header; MapController & controller;
}; };
#endif // PLAYERSETTINGS_H #endif // PLAYERSETTINGS_H