diff --git a/mapeditor/playerparams.cpp b/mapeditor/playerparams.cpp index daf82e1f3..fe3aded39 100644 --- a/mapeditor/playerparams.cpp +++ b/mapeditor/playerparams.cpp @@ -12,6 +12,7 @@ #include "playerparams.h" #include "ui_playerparams.h" #include "../lib/CTownHandler.h" +#include "../lib/StringConstants.h" PlayerParams::PlayerParams(MapController & ctrl, int playerId, QWidget *parent) : QWidget(parent), @@ -19,10 +20,27 @@ PlayerParams::PlayerParams(MapController & ctrl, int playerId, QWidget *parent) controller(ctrl) { ui->setupUi(this); + + //set colors and teams + ui->teamId->addItem("No team", QVariant(TeamID::NO_TEAM)); + for(int i = 0, index = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i) + { + if(i == playerId || !controller.map()->players[i].canAnyonePlay()) + { + ui->playerColorCombo->addItem(QString::fromStdString(GameConstants::PLAYER_COLOR_NAMES[i]), QVariant(i)); + if(i == playerId) + ui->playerColorCombo->setCurrentIndex(index); + ++index; + } + + //add teams + ui->teamId->addItem(QString::number(i + 1), QVariant(i)); + } playerColor = playerId; assert(controller.map()->players.size() > playerColor); playerInfo = controller.map()->players[playerColor]; + ui->teamId->setCurrentIndex(playerInfo.team == TeamID::NO_TEAM ? 0 : playerInfo.team.getNum() + 1); //load factions for(auto idx : VLC->townh->getAllowedFactions()) @@ -148,3 +166,21 @@ void PlayerParams::on_mainTown_activated(int index) } } + +void PlayerParams::on_teamId_activated(int index) +{ + playerInfo.team = ui->teamId->currentData().toInt(); +} + + +void PlayerParams::on_playerColorCombo_activated(int index) +{ + int data = ui->playerColorCombo->currentData().toInt(); + if(data != playerColor) + { + controller.map()->players[playerColor].canHumanPlay = false; + controller.map()->players[playerColor].canComputerPlay = false; + playerColor = data; + } +} + diff --git a/mapeditor/playerparams.h b/mapeditor/playerparams.h index 6df0d39f2..6fddf1b29 100644 --- a/mapeditor/playerparams.h +++ b/mapeditor/playerparams.h @@ -42,6 +42,10 @@ private slots: void allowedFactionsCheck(QListWidgetItem *); + void on_teamId_activated(int index); + + void on_playerColorCombo_activated(int index); + private: Ui::PlayerParams *ui; diff --git a/mapeditor/playerparams.ui b/mapeditor/playerparams.ui index 5eeee8832..0bbe9b0c5 100644 --- a/mapeditor/playerparams.ui +++ b/mapeditor/playerparams.ui @@ -50,67 +50,45 @@ - - - - - No team - - - + + - - - - Human/CPU - - - - - - - CPU only - - - - - - - Team - - - - - - - Main town - - - - - - - Random faction - - - - + Generate hero at main - - - - - (default) - - + + + + Random faction + - + + + + Team + + + + + + + CPU only + + + + + + + Human/CPU + + + + true @@ -132,6 +110,32 @@ + + + + + (default) + + + + + + + + Main town + + + + + + + + + + Color + + + diff --git a/mapeditor/playersettings.cpp b/mapeditor/playersettings.cpp index 697436dad..ffe2c1f7c 100644 --- a/mapeditor/playersettings.cpp +++ b/mapeditor/playersettings.cpp @@ -24,11 +24,11 @@ PlayerSettings::PlayerSettings(MapController & ctrl, QWidget *parent) : int players = 0; const int minAllowedPlayers = 1; - for(auto & p : controller.map()->players) + for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i) { - if(p.canAnyonePlay()) + if(controller.map()->players[i].canAnyonePlay()) { - paramWidgets.push_back(new PlayerParams(controller, players)); + paramWidgets.push_back(new PlayerParams(controller, i)); ui->playersLayout->addWidget(paramWidgets.back()); ++players; } @@ -51,22 +51,29 @@ void PlayerSettings::on_playersCount_currentIndexChanged(int index) { const auto selectedPlayerCount = index + 1; assert(selectedPlayerCount <= controller.map()->players.size()); + std::set availableColors{0, 1, 2, 3, 4, 5, 6, 7}; for(int i = 0; i < selectedPlayerCount; ++i) { if(i < paramWidgets.size()) + { + availableColors.erase(paramWidgets[i]->playerColor); continue; + } - auto & p = controller.map()->players[i]; + assert(!availableColors.empty()); + auto plColor = *availableColors.begin(); + auto & p = controller.map()->players[plColor]; p.canComputerPlay = true; - paramWidgets.push_back(new PlayerParams(controller, i)); + paramWidgets.push_back(new PlayerParams(controller, plColor)); + availableColors.erase(plColor); ui->playersLayout->addWidget(paramWidgets.back()); } assert(!paramWidgets.empty()); for(int i = paramWidgets.size() - 1; i >= selectedPlayerCount; --i) { - auto & p = controller.map()->players[i]; + auto & p = controller.map()->players[paramWidgets[i]->playerColor]; p.canComputerPlay = false; p.canHumanPlay = false; ui->playersLayout->removeWidget(paramWidgets[i]);