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
|
|
|
|
2022-09-06 03:46:22 +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),
|
2022-09-06 03:46:22 +02:00
|
|
|
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;
|
2022-09-06 03:46:22 +02:00
|
|
|
for(auto & p : controller.map()->players)
|
2022-09-04 20:01:49 +02:00
|
|
|
{
|
|
|
|
if(p.canAnyonePlay())
|
|
|
|
{
|
2022-09-06 03:46:22 +02:00
|
|
|
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);
|
2022-09-09 00:59:49 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2022-09-06 03:46:22 +02:00
|
|
|
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;
|
|
|
|
|
2022-09-06 03:46:22 +02:00
|
|
|
auto & p = controller.map()->players[i];
|
2022-09-04 20:01:49 +02:00
|
|
|
p.canComputerPlay = true;
|
2022-09-06 03:46:22 +02:00
|
|
|
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)
|
|
|
|
{
|
2022-09-06 03:46:22 +02:00
|
|
|
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)
|
|
|
|
{
|
2022-09-06 03:46:22 +02:00
|
|
|
controller.map()->players[w->playerColor] = w->playerInfo;
|
2022-09-04 20:01:49 +02:00
|
|
|
}
|
2022-09-04 20:29:56 +02:00
|
|
|
|
2022-09-06 03:46:22 +02:00
|
|
|
controller.commitChangeWithoutRedraw();
|
2022-09-04 20:29:56 +02:00
|
|
|
close();
|
2022-09-04 20:01:49 +02:00
|
|
|
}
|
|
|
|
|