1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/mapeditor/playersettings.cpp

78 lines
1.6 KiB
C++
Raw Normal View History

2022-09-04 20:01:49 +02:00
#include "StdInc.h"
2022-09-04 18:16:36 +02:00
#include "playersettings.h"
#include "ui_playersettings.h"
2022-09-04 20:01:49 +02:00
#include "playerparams.h"
2022-09-05 04:18:38 +02:00
#include "mainwindow.h"
2022-09-04 18:16:36 +02:00
PlayerSettings::PlayerSettings(MapController & ctrl, QWidget *parent) :
2022-09-04 18:16:36 +02:00
QDialog(parent),
2022-09-04 20:01:49 +02:00
ui(new Ui::PlayerSettings),
controller(ctrl)
2022-09-04 18:16:36 +02:00
{
ui->setupUi(this);
2022-09-04 20:01:49 +02:00
show();
int players = 0;
for(auto & p : controller.map()->players)
2022-09-04 20:01:49 +02:00
{
if(p.canAnyonePlay())
{
paramWidgets.push_back(new PlayerParams(controller, players));
2022-09-04 20:01:49 +02:00
ui->playersLayout->addWidget(paramWidgets.back());
++players;
}
}
if(players < 2)
ui->playersCount->setCurrentText("");
else
ui->playersCount->setCurrentIndex(players - 2);
setAttribute(Qt::WA_DeleteOnClose);
2022-09-04 18:16:36 +02:00
}
PlayerSettings::~PlayerSettings()
{
delete ui;
}
2022-09-04 20:01:49 +02:00
void PlayerSettings::on_playersCount_currentIndexChanged(int index)
{
assert(index + 2 <= controller.map()->players.size());
2022-09-04 20:01:49 +02:00
for(int i = 0; i < index + 2; ++i)
{
if(i < paramWidgets.size())
continue;
auto & p = controller.map()->players[i];
2022-09-04 20:01:49 +02:00
p.canComputerPlay = true;
paramWidgets.push_back(new PlayerParams(controller, i));
2022-09-04 20:01:49 +02:00
ui->playersLayout->addWidget(paramWidgets.back());
}
assert(!paramWidgets.empty());
for(int i = paramWidgets.size() - 1; i >= index + 2; --i)
{
auto & p = controller.map()->players[i];
2022-09-04 20:01:49 +02:00
p.canComputerPlay = false;
p.canHumanPlay = false;
ui->playersLayout->removeWidget(paramWidgets[i]);
delete paramWidgets[i];
paramWidgets.pop_back();
}
}
void PlayerSettings::on_pushButton_clicked()
{
for(auto * w : paramWidgets)
{
controller.map()->players[w->playerColor] = w->playerInfo;
2022-09-04 20:01:49 +02:00
}
2022-09-04 20:29:56 +02:00
controller.commitChangeWithoutRedraw();
2022-09-04 20:29:56 +02:00
close();
2022-09-04 20:01:49 +02:00
}