1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Support teams in map editor

This commit is contained in:
nordsoft
2023-04-22 18:47:25 +04:00
committed by Nordsoft91
parent 1899dd97c7
commit bab84309a5
3 changed files with 195 additions and 134 deletions

View File

@ -31,6 +31,28 @@ WindowNewMap::WindowNewMap(QWidget *parent) :
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
setWindowModality(Qt::ApplicationModal); setWindowModality(Qt::ApplicationModal);
for(auto * combo : {ui->humanCombo, ui->cpuCombo, ui->humanTeamsCombo, ui->cpuTeamsCombo})
combo->clear();
//prepare human players combo box
for(int i = 0; i <= PlayerColor::PLAYER_LIMIT_I; ++i)
{
ui->humanCombo->addItem(!i ? randomString : QString::number(players.at(i)));
ui->humanCombo->setItemData(i, QVariant(players.at(i)));
ui->cpuCombo->addItem(!i ? randomString : QString::number(cpuPlayers.at(i)));
ui->cpuCombo->setItemData(i, QVariant(cpuPlayers.at(i)));
ui->humanTeamsCombo->addItem(!i ? randomString : QString::number(cpuPlayers.at(i)));
ui->humanTeamsCombo->setItemData(i, QVariant(cpuPlayers.at(i)));
ui->cpuTeamsCombo->addItem(!i ? randomString : QString::number(cpuPlayers.at(i)));
ui->cpuTeamsCombo->setItemData(i, QVariant(cpuPlayers.at(i)));
}
for(auto * combo : {ui->humanCombo, ui->cpuCombo, ui->humanTeamsCombo, ui->cpuTeamsCombo})
combo->setCurrentIndex(0);
loadUserSettings(); loadUserSettings();
@ -87,8 +109,17 @@ void WindowNewMap::loadUserSettings()
{ {
ui->cpuCombo->setCurrentIndex(cpuPlayers.toInt()); ui->cpuCombo->setCurrentIndex(cpuPlayers.toInt());
} }
//TODO: teams when implemented auto teams = s.value(newMapHumanTeams);
if(teams.isValid())
{
ui->humanTeamsCombo->setCurrentIndex(teams.toInt());
}
auto cputeams = s.value(newMapCpuTeams);
if(cputeams.isValid())
{
ui->cpuTeamsCombo->setCurrentIndex(cputeams.toInt());
}
auto waterContent = s.value(newMapWaterContent); auto waterContent = s.value(newMapWaterContent);
if (waterContent.isValid()) if (waterContent.isValid())
{ {
@ -150,7 +181,8 @@ void WindowNewMap::saveUserSettings()
s.setValue(newMapPlayers,ui->humanCombo->currentIndex()); s.setValue(newMapPlayers,ui->humanCombo->currentIndex());
s.setValue(newMapCpuPlayers,ui->cpuCombo->currentIndex()); s.setValue(newMapCpuPlayers,ui->cpuCombo->currentIndex());
//TODO: teams when implemented s.setValue(newMapHumanTeams, ui->humanTeamsCombo->currentIndex());
s.setValue(newMapCpuTeams, ui->cpuTeamsCombo->currentIndex());
EWaterContent::EWaterContent water = EWaterContent::RANDOM; EWaterContent::EWaterContent water = EWaterContent::RANDOM;
if(ui->waterOpt1->isChecked()) if(ui->waterOpt1->isChecked())
@ -272,16 +304,8 @@ void WindowNewMap::on_okButton_clicked()
void WindowNewMap::on_sizeCombo_activated(int index) void WindowNewMap::on_sizeCombo_activated(int index)
{ {
std::map<int, std::pair<int, int>> sizes ui->widthTxt->setText(QString::number(mapSizes.at(index).first));
{ ui->heightTxt->setText(QString::number(mapSizes.at(index).second));
{0, {36, 36}},
{1, {72, 72}},
{2, {108, 108}},
{3, {144, 144}},
};
ui->widthTxt->setText(QString::number(sizes[index].first));
ui->heightTxt->setText(QString::number(sizes[index].second));
} }
@ -295,12 +319,11 @@ void WindowNewMap::on_twoLevelCheck_stateChanged(int arg1)
void WindowNewMap::on_humanCombo_activated(int index) void WindowNewMap::on_humanCombo_activated(int index)
{ {
int humans = players.at(index); int humans = ui->humanCombo->currentData().toInt();
if(humans > playerLimit) if(humans > PlayerColor::PLAYER_LIMIT_I)
{ {
humans = playerLimit; humans = PlayerColor::PLAYER_LIMIT_I;
ui->humanCombo->setCurrentIndex(humans); ui->humanCombo->setCurrentIndex(humans);
return;
} }
mapGenOptions.setPlayerCount(humans); mapGenOptions.setPlayerCount(humans);
@ -309,24 +332,23 @@ void WindowNewMap::on_humanCombo_activated(int index)
if(teams > humans - 1) if(teams > humans - 1)
{ {
teams = humans - 1; teams = humans - 1;
//TBD ui->humanTeamsCombo->setCurrentIndex(teams + 1); //skip one element because first is random
} }
int cpu = mapGenOptions.getCompOnlyPlayerCount(); int cpu = mapGenOptions.getCompOnlyPlayerCount();
if(cpu > playerLimit - humans) if(cpu > PlayerColor::PLAYER_LIMIT_I - humans)
{ {
cpu = playerLimit - humans; cpu = PlayerColor::PLAYER_LIMIT_I - humans;
ui->cpuCombo->setCurrentIndex(cpu + 1); ui->cpuCombo->setCurrentIndex(cpu + 1); //skip one element because first is random
} }
int cpuTeams = mapGenOptions.getCompOnlyTeamCount(); //comp only players - 1 int cpuTeams = mapGenOptions.getCompOnlyTeamCount(); //comp only players - 1
if(cpuTeams > cpu - 1) if(cpuTeams > cpu - 1)
{ {
cpuTeams = cpu - 1; cpuTeams = cpu - 1;
//TBD ui->cpuTeamsCombo->setCurrentIndex(cpuTeams + 1); //skip one element because first is random
} }
//void setMapTemplate(const CRmgTemplate * value);
updateTemplateList(); updateTemplateList();
} }
@ -334,15 +356,22 @@ void WindowNewMap::on_humanCombo_activated(int index)
void WindowNewMap::on_cpuCombo_activated(int index) void WindowNewMap::on_cpuCombo_activated(int index)
{ {
int humans = mapGenOptions.getPlayerCount(); int humans = mapGenOptions.getPlayerCount();
int cpu = cpuPlayers.at(index); int cpu = ui->cpuCombo->currentData().toInt();
if(cpu > playerLimit - humans) if(cpu > PlayerColor::PLAYER_LIMIT_I - humans)
{ {
cpu = playerLimit - humans; cpu = PlayerColor::PLAYER_LIMIT_I - humans;
ui->cpuCombo->setCurrentIndex(cpu + 1); ui->cpuCombo->setCurrentIndex(cpu + 1); //skip one element because first is random
return; }
mapGenOptions.setCompOnlyPlayerCount(cpu);
int cpuTeams = mapGenOptions.getCompOnlyTeamCount(); //comp only players - 1
if(cpuTeams > cpu - 1)
{
cpuTeams = cpu - 1;
ui->cpuTeamsCombo->setCurrentIndex(cpuTeams + 1); //skip one element because first is random
} }
mapGenOptions.setCompOnlyPlayerCount(cpu);
updateTemplateList(); updateTemplateList();
} }
@ -417,3 +446,33 @@ void WindowNewMap::on_checkSeed_toggled(bool checked)
ui->lineSeed->setEnabled(checked); ui->lineSeed->setEnabled(checked);
} }
void WindowNewMap::on_humanTeamsCombo_activated(int index)
{
int humans = mapGenOptions.getPlayerCount();
int teams = ui->humanTeamsCombo->currentData().toInt();
if(teams >= humans)
{
teams = humans - 1;
ui->humanTeamsCombo->setCurrentIndex(teams + 1); //skip one element because first is random
}
mapGenOptions.setTeamCount(teams);
updateTemplateList();
}
void WindowNewMap::on_cpuTeamsCombo_activated(int index)
{
int cpu = mapGenOptions.getCompOnlyPlayerCount();
int teams = ui->cpuTeamsCombo->currentData().toInt();
if(teams >= cpu)
{
teams = cpu - 1;
ui->cpuTeamsCombo->setCurrentIndex(teams + 1); //skip one element because first is random
}
mapGenOptions.setCompOnlyTeamCount(teams);
updateTemplateList();
}

View File

@ -28,11 +28,13 @@ class WindowNewMap : public QDialog
const QString newMapGenerateRandom = "NewMapWindow/GenerateRandom"; const QString newMapGenerateRandom = "NewMapWindow/GenerateRandom";
const QString newMapPlayers = "NewMapWindow/Players"; //map index const QString newMapPlayers = "NewMapWindow/Players"; //map index
const QString newMapCpuPlayers = "NewMapWindow/CpuPlayers"; //map index const QString newMapCpuPlayers = "NewMapWindow/CpuPlayers"; //map index
const QString newMapHumanTeams = "NewMapWindow/HumanTeams"; //map index
const QString newMapCpuTeams = "NewMapWindow/CpuTeams"; //map index
const QString newMapWaterContent = "NewMapWindow/WaterContent"; const QString newMapWaterContent = "NewMapWindow/WaterContent";
const QString newMapMonsterStrength = "NewMapWindow/MonsterStrength"; const QString newMapMonsterStrength = "NewMapWindow/MonsterStrength";
const QString newMapTemplate = "NewMapWindow/Template"; const QString newMapTemplate = "NewMapWindow/Template";
const int playerLimit = 8; const QString randomString = "Random";
const std::map<int, int> players const std::map<int, int> players
{ {
@ -59,6 +61,14 @@ class WindowNewMap : public QDialog
{7, 6}, {7, 6},
{8, 7} {8, 7}
}; };
const std::map<int, std::pair<int, int>> mapSizes
{
{0, {36, 36}},
{1, {72, 72}},
{2, {108, 108}},
{3, {144, 144}},
};
public: public:
explicit WindowNewMap(QWidget *parent = nullptr); explicit WindowNewMap(QWidget *parent = nullptr);
@ -87,6 +97,10 @@ private slots:
void on_checkSeed_toggled(bool checked); void on_checkSeed_toggled(bool checked);
void on_humanTeamsCombo_activated(int index);
void on_cpuTeamsCombo_activated(int index);
private: private:
void updateTemplateList(); void updateTemplateList();

View File

@ -213,59 +213,60 @@
<height>68</height> <height>68</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,1"> <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
<item row="0" column="3"> <item row="1" column="1">
<widget class="QComboBox" name="humanTeamsCombo"> <widget class="QComboBox" name="cpuCombo">
<property name="minimumSize"> <item>
<size> <property name="text">
<width>48</width> <string>Random</string>
<height>0</height> </property>
</size> </item>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>16777215</height>
</size>
</property>
<property name="currentText">
<string notr="true">0</string>
</property>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">0</string> <string notr="true">0</string>
</property> </property>
</item> </item>
</widget>
</item>
<item row="1" column="3">
<widget class="QComboBox" name="cpuTeamsCombo">
<property name="currentText">
<string notr="true">0</string>
</property>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">0</string> <string notr="true">1</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">2</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">3</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">4</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">5</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">6</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">7</string>
</property> </property>
</item> </item>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_4">
<property name="minimumSize">
<size>
<width>96</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="text"> <property name="text">
<string>Human/Computer</string> <string>Computer only</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -330,87 +331,74 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_3">
<property name="minimumSize">
<size>
<width>96</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>120</width>
<height>16777215</height>
</size>
</property>
<property name="text"> <property name="text">
<string>Computer only</string> <string>Human/Computer</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="0" column="3">
<spacer name="horizontalSpacer_3"> <widget class="QComboBox" name="humanTeamsCombo">
<property name="orientation"> <property name="minimumSize">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>0</width>
<height>20</height> <height>0</height>
</size> </size>
</property> </property>
</spacer> <property name="maximumSize">
</item> <size>
<item row="1" column="1"> <width>16777215</width>
<widget class="QComboBox" name="cpuCombo"> <height>16777215</height>
<item> </size>
<property name="text"> </property>
<string>Random</string> <property name="currentText">
</property> <string notr="true">0</string>
</item> </property>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">0</string> <string notr="true">0</string>
</property> </property>
</item> </item>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Human teams</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QComboBox" name="cpuTeamsCombo">
<property name="currentText">
<string notr="true">0</string>
</property>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">1</string> <string notr="true">0</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">2</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">3</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">4</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">5</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">6</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">7</string>
</property> </property>
</item> </item>
</widget> </widget>
</item> </item>
<item row="1" column="4"> <item row="1" column="2">
<spacer name="horizontalSpacer_4"> <widget class="QLabel" name="label_7">
<property name="orientation"> <property name="text">
<enum>Qt::Horizontal</enum> <string>Computer teams</string>
</property> </property>
<property name="sizeHint" stdset="0"> </widget>
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>