1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Customize colors and teams

This commit is contained in:
nordsoft 2023-04-21 03:17:13 +04:00 committed by Nordsoft91
parent bd1105e2b7
commit 1899dd97c7
4 changed files with 109 additions and 58 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -50,67 +50,45 @@
<string/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QComboBox" name="teamId">
<item>
<property name="text">
<string>No team</string>
</property>
</item>
</widget>
<item row="4" column="0">
<widget class="QComboBox" name="teamId"/>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="radioHuman">
<property name="text">
<string>Human/CPU</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radioCpu">
<property name="text">
<string>CPU only</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Team</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Main town</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QCheckBox" name="randomFaction">
<property name="text">
<string>Random faction</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QCheckBox" name="generateHero">
<property name="text">
<string>Generate hero at main</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mainTown">
<item>
<property name="text">
<string>(default)</string>
</property>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="randomFaction">
<property name="text">
<string>Random faction</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Team</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="radioCpu">
<property name="text">
<string>CPU only</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radioHuman">
<property name="text">
<string>Human/CPU</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="4">
<widget class="QListWidget" name="allowedFactions">
<property name="enabled">
<bool>true</bool>
@ -132,6 +110,32 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="mainTown">
<item>
<property name="text">
<string>(default)</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Main town</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="playerColorCombo"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -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<int> 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]);