mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-11 01:10:26 +02:00
Customize colors and teams
This commit is contained in:
@ -12,6 +12,7 @@
|
|||||||
#include "playerparams.h"
|
#include "playerparams.h"
|
||||||
#include "ui_playerparams.h"
|
#include "ui_playerparams.h"
|
||||||
#include "../lib/CTownHandler.h"
|
#include "../lib/CTownHandler.h"
|
||||||
|
#include "../lib/StringConstants.h"
|
||||||
|
|
||||||
PlayerParams::PlayerParams(MapController & ctrl, int playerId, QWidget *parent) :
|
PlayerParams::PlayerParams(MapController & ctrl, int playerId, QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
@ -19,10 +20,27 @@ PlayerParams::PlayerParams(MapController & ctrl, int playerId, QWidget *parent)
|
|||||||
controller(ctrl)
|
controller(ctrl)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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;
|
playerColor = playerId;
|
||||||
assert(controller.map()->players.size() > playerColor);
|
assert(controller.map()->players.size() > playerColor);
|
||||||
playerInfo = controller.map()->players[playerColor];
|
playerInfo = controller.map()->players[playerColor];
|
||||||
|
ui->teamId->setCurrentIndex(playerInfo.team == TeamID::NO_TEAM ? 0 : playerInfo.team.getNum() + 1);
|
||||||
|
|
||||||
//load factions
|
//load factions
|
||||||
for(auto idx : VLC->townh->getAllowedFactions())
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,10 @@ private slots:
|
|||||||
|
|
||||||
void allowedFactionsCheck(QListWidgetItem *);
|
void allowedFactionsCheck(QListWidgetItem *);
|
||||||
|
|
||||||
|
void on_teamId_activated(int index);
|
||||||
|
|
||||||
|
void on_playerColorCombo_activated(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::PlayerParams *ui;
|
Ui::PlayerParams *ui;
|
||||||
|
|
||||||
|
@ -50,67 +50,45 @@
|
|||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="3" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QComboBox" name="teamId">
|
<widget class="QComboBox" name="teamId"/>
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>No team</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="4" column="1">
|
||||||
<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">
|
|
||||||
<widget class="QCheckBox" name="generateHero">
|
<widget class="QCheckBox" name="generateHero">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Generate hero at main</string>
|
<string>Generate hero at main</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="4" column="2">
|
||||||
<widget class="QComboBox" name="mainTown">
|
<widget class="QCheckBox" name="randomFaction">
|
||||||
<item>
|
<property name="text">
|
||||||
<property name="text">
|
<string>Random faction</string>
|
||||||
<string>(default)</string>
|
</property>
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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">
|
<widget class="QListWidget" name="allowedFactions">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
@ -132,6 +110,32 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -24,11 +24,11 @@ PlayerSettings::PlayerSettings(MapController & ctrl, QWidget *parent) :
|
|||||||
|
|
||||||
int players = 0;
|
int players = 0;
|
||||||
const int minAllowedPlayers = 1;
|
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());
|
ui->playersLayout->addWidget(paramWidgets.back());
|
||||||
++players;
|
++players;
|
||||||
}
|
}
|
||||||
@ -51,22 +51,29 @@ void PlayerSettings::on_playersCount_currentIndexChanged(int index)
|
|||||||
{
|
{
|
||||||
const auto selectedPlayerCount = index + 1;
|
const auto selectedPlayerCount = index + 1;
|
||||||
assert(selectedPlayerCount <= controller.map()->players.size());
|
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)
|
for(int i = 0; i < selectedPlayerCount; ++i)
|
||||||
{
|
{
|
||||||
if(i < paramWidgets.size())
|
if(i < paramWidgets.size())
|
||||||
|
{
|
||||||
|
availableColors.erase(paramWidgets[i]->playerColor);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto & p = controller.map()->players[i];
|
assert(!availableColors.empty());
|
||||||
|
auto plColor = *availableColors.begin();
|
||||||
|
auto & p = controller.map()->players[plColor];
|
||||||
p.canComputerPlay = true;
|
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());
|
ui->playersLayout->addWidget(paramWidgets.back());
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(!paramWidgets.empty());
|
assert(!paramWidgets.empty());
|
||||||
for(int i = paramWidgets.size() - 1; i >= selectedPlayerCount; --i)
|
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.canComputerPlay = false;
|
||||||
p.canHumanPlay = false;
|
p.canHumanPlay = false;
|
||||||
ui->playersLayout->removeWidget(paramWidgets[i]);
|
ui->playersLayout->removeWidget(paramWidgets[i]);
|
||||||
|
Reference in New Issue
Block a user