mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Support teams in map editor
This commit is contained in:
parent
1899dd97c7
commit
bab84309a5
@ -31,6 +31,28 @@ WindowNewMap::WindowNewMap(QWidget *parent) :
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
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();
|
||||
|
||||
@ -87,8 +109,17 @@ void WindowNewMap::loadUserSettings()
|
||||
{
|
||||
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);
|
||||
if (waterContent.isValid())
|
||||
{
|
||||
@ -150,7 +181,8 @@ void WindowNewMap::saveUserSettings()
|
||||
|
||||
s.setValue(newMapPlayers,ui->humanCombo->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;
|
||||
if(ui->waterOpt1->isChecked())
|
||||
@ -272,16 +304,8 @@ void WindowNewMap::on_okButton_clicked()
|
||||
|
||||
void WindowNewMap::on_sizeCombo_activated(int index)
|
||||
{
|
||||
std::map<int, std::pair<int, int>> sizes
|
||||
{
|
||||
{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));
|
||||
ui->widthTxt->setText(QString::number(mapSizes.at(index).first));
|
||||
ui->heightTxt->setText(QString::number(mapSizes.at(index).second));
|
||||
}
|
||||
|
||||
|
||||
@ -295,12 +319,11 @@ void WindowNewMap::on_twoLevelCheck_stateChanged(int arg1)
|
||||
|
||||
void WindowNewMap::on_humanCombo_activated(int index)
|
||||
{
|
||||
int humans = players.at(index);
|
||||
if(humans > playerLimit)
|
||||
int humans = ui->humanCombo->currentData().toInt();
|
||||
if(humans > PlayerColor::PLAYER_LIMIT_I)
|
||||
{
|
||||
humans = playerLimit;
|
||||
humans = PlayerColor::PLAYER_LIMIT_I;
|
||||
ui->humanCombo->setCurrentIndex(humans);
|
||||
return;
|
||||
}
|
||||
|
||||
mapGenOptions.setPlayerCount(humans);
|
||||
@ -309,24 +332,23 @@ void WindowNewMap::on_humanCombo_activated(int index)
|
||||
if(teams > humans - 1)
|
||||
{
|
||||
teams = humans - 1;
|
||||
//TBD
|
||||
ui->humanTeamsCombo->setCurrentIndex(teams + 1); //skip one element because first is random
|
||||
}
|
||||
|
||||
int cpu = mapGenOptions.getCompOnlyPlayerCount();
|
||||
if(cpu > playerLimit - humans)
|
||||
if(cpu > PlayerColor::PLAYER_LIMIT_I - humans)
|
||||
{
|
||||
cpu = playerLimit - humans;
|
||||
ui->cpuCombo->setCurrentIndex(cpu + 1);
|
||||
cpu = PlayerColor::PLAYER_LIMIT_I - humans;
|
||||
ui->cpuCombo->setCurrentIndex(cpu + 1); //skip one element because first is random
|
||||
}
|
||||
|
||||
int cpuTeams = mapGenOptions.getCompOnlyTeamCount(); //comp only players - 1
|
||||
if(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();
|
||||
}
|
||||
|
||||
@ -334,15 +356,22 @@ void WindowNewMap::on_humanCombo_activated(int index)
|
||||
void WindowNewMap::on_cpuCombo_activated(int index)
|
||||
{
|
||||
int humans = mapGenOptions.getPlayerCount();
|
||||
int cpu = cpuPlayers.at(index);
|
||||
if(cpu > playerLimit - humans)
|
||||
int cpu = ui->cpuCombo->currentData().toInt();
|
||||
if(cpu > PlayerColor::PLAYER_LIMIT_I - humans)
|
||||
{
|
||||
cpu = playerLimit - humans;
|
||||
ui->cpuCombo->setCurrentIndex(cpu + 1);
|
||||
return;
|
||||
cpu = PlayerColor::PLAYER_LIMIT_I - humans;
|
||||
ui->cpuCombo->setCurrentIndex(cpu + 1); //skip one element because first is random
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -417,3 +446,33 @@ void WindowNewMap::on_checkSeed_toggled(bool 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();
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,13 @@ class WindowNewMap : public QDialog
|
||||
const QString newMapGenerateRandom = "NewMapWindow/GenerateRandom";
|
||||
const QString newMapPlayers = "NewMapWindow/Players"; //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 newMapMonsterStrength = "NewMapWindow/MonsterStrength";
|
||||
const QString newMapTemplate = "NewMapWindow/Template";
|
||||
|
||||
const int playerLimit = 8;
|
||||
|
||||
const QString randomString = "Random";
|
||||
|
||||
const std::map<int, int> players
|
||||
{
|
||||
@ -59,6 +61,14 @@ class WindowNewMap : public QDialog
|
||||
{7, 6},
|
||||
{8, 7}
|
||||
};
|
||||
|
||||
const std::map<int, std::pair<int, int>> mapSizes
|
||||
{
|
||||
{0, {36, 36}},
|
||||
{1, {72, 72}},
|
||||
{2, {108, 108}},
|
||||
{3, {144, 144}},
|
||||
};
|
||||
|
||||
public:
|
||||
explicit WindowNewMap(QWidget *parent = nullptr);
|
||||
@ -87,6 +97,10 @@ private slots:
|
||||
|
||||
void on_checkSeed_toggled(bool checked);
|
||||
|
||||
void on_humanTeamsCombo_activated(int index);
|
||||
|
||||
void on_cpuTeamsCombo_activated(int index);
|
||||
|
||||
private:
|
||||
|
||||
void updateTemplateList();
|
||||
|
@ -213,59 +213,60 @@
|
||||
<height>68</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,1">
|
||||
<item row="0" column="3">
|
||||
<widget class="QComboBox" name="humanTeamsCombo">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>48</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="currentText">
|
||||
<string notr="true">0</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0">
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cpuCombo">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Random</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">0</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QComboBox" name="cpuTeamsCombo">
|
||||
<property name="currentText">
|
||||
<string notr="true">0</string>
|
||||
</property>
|
||||
<item>
|
||||
<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>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<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>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Human/Computer</string>
|
||||
<string>Computer only</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -330,87 +331,74 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<item row="0" column="0">
|
||||
<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">
|
||||
<string>Computer only</string>
|
||||
<string>Human/Computer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<item row="0" column="3">
|
||||
<widget class="QComboBox" name="humanTeamsCombo">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="cpuCombo">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Random</string>
|
||||
</property>
|
||||
</item>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="currentText">
|
||||
<string notr="true">0</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">0</string>
|
||||
</property>
|
||||
</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>
|
||||
<property name="text">
|
||||
<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>
|
||||
<string notr="true">0</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Computer teams</string>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
Loading…
Reference in New Issue
Block a user