mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
Player settings
This commit is contained in:
parent
49a6422d20
commit
d6e8d7965c
@ -18,6 +18,7 @@ set(editor_SRCS
|
||||
inspector.cpp
|
||||
mapsettings.cpp
|
||||
playersettings.cpp
|
||||
playerparams.cpp
|
||||
)
|
||||
|
||||
set(editor_HEADERS
|
||||
@ -39,6 +40,7 @@ set(editor_HEADERS
|
||||
inspector.h
|
||||
mapsettings.h
|
||||
playersettings.h
|
||||
playerparams.h
|
||||
)
|
||||
|
||||
set(editor_FORMS
|
||||
@ -47,6 +49,7 @@ set(editor_FORMS
|
||||
generatorprogress.ui
|
||||
mapsettings.ui
|
||||
playersettings.ui
|
||||
playerparams.ui
|
||||
)
|
||||
|
||||
assign_source_group(${editor_SRCS} ${editor_HEADERS} VCMI_launcher.rc)
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "objectbrowser.h"
|
||||
#include "inspector.h"
|
||||
#include "mapsettings.h"
|
||||
#include "playersettings.h"
|
||||
|
||||
static CBasicLogConfigurator * logConfig;
|
||||
|
||||
@ -831,3 +832,9 @@ void MainWindow::on_actionMapSettings_triggered()
|
||||
auto mapSettingsDialog = new MapSettings(this);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionPlayers_settings_triggered()
|
||||
{
|
||||
auto mapSettingsDialog = new PlayerSettings(*map, this);
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,8 @@ private slots:
|
||||
|
||||
void on_actionMapSettings_triggered();
|
||||
|
||||
void on_actionPlayers_settings_triggered();
|
||||
|
||||
public slots:
|
||||
|
||||
void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected);
|
||||
|
@ -68,6 +68,7 @@
|
||||
<string>Map</string>
|
||||
</property>
|
||||
<addaction name="actionMapSettings"/>
|
||||
<addaction name="actionPlayers_settings"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuMap"/>
|
||||
@ -817,6 +818,11 @@
|
||||
<string>Map title and description</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPlayers_settings">
|
||||
<property name="text">
|
||||
<string>Players settings</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
41
mapeditor/playerparams.cpp
Normal file
41
mapeditor/playerparams.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include "StdInc.h"
|
||||
#include "playerparams.h"
|
||||
#include "ui_playerparams.h"
|
||||
|
||||
PlayerParams::PlayerParams(const CMapHeader & mapHeader, int playerId, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::PlayerParams)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
playerColor = playerId;
|
||||
assert(mapHeader.players.size() > playerColor);
|
||||
playerInfo = mapHeader.players[playerColor];
|
||||
|
||||
if(playerInfo.canComputerPlay)
|
||||
ui->radioCpu->setChecked(true);
|
||||
if(playerInfo.canHumanPlay)
|
||||
ui->radioHuman->setChecked(true);
|
||||
|
||||
ui->playerColor->setTitle(QString("PlayerID: %1").arg(playerId));
|
||||
show();
|
||||
}
|
||||
|
||||
PlayerParams::~PlayerParams()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void PlayerParams::on_radioHuman_toggled(bool checked)
|
||||
{
|
||||
if(checked)
|
||||
playerInfo.canHumanPlay = true;
|
||||
}
|
||||
|
||||
|
||||
void PlayerParams::on_radioCpu_toggled(bool checked)
|
||||
{
|
||||
if(checked)
|
||||
playerInfo.canHumanPlay = false;
|
||||
}
|
||||
|
31
mapeditor/playerparams.h
Normal file
31
mapeditor/playerparams.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef PLAYERPARAMS_H
|
||||
#define PLAYERPARAMS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "../lib/mapping/CMap.h"
|
||||
|
||||
namespace Ui {
|
||||
class PlayerParams;
|
||||
}
|
||||
|
||||
class PlayerParams : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PlayerParams(const CMapHeader & mapHeader, int playerId, QWidget *parent = nullptr);
|
||||
~PlayerParams();
|
||||
|
||||
PlayerInfo playerInfo;
|
||||
int playerColor;
|
||||
|
||||
private slots:
|
||||
void on_radioHuman_toggled(bool checked);
|
||||
|
||||
void on_radioCpu_toggled(bool checked);
|
||||
|
||||
private:
|
||||
Ui::PlayerParams *ui;
|
||||
};
|
||||
|
||||
#endif // PLAYERPARAMS_H
|
131
mapeditor/playerparams.ui
Normal file
131
mapeditor/playerparams.ui
Normal file
@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PlayerParams</class>
|
||||
<widget class="QWidget" name="PlayerParams">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>505</width>
|
||||
<height>146</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>160</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="playerColor">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>160</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>GroupBox</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>
|
||||
<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">
|
||||
<widget class="QCheckBox" name="generateHero">
|
||||
<property name="text">
|
||||
<string>Generate hero at main</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2" rowspan="2">
|
||||
<widget class="QListWidget" name="allowedFactions">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="mainTown"/>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>All factions allowed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -1,14 +1,72 @@
|
||||
#include "StdInc.h"
|
||||
#include "playersettings.h"
|
||||
#include "ui_playersettings.h"
|
||||
#include "playerparams.h"
|
||||
|
||||
PlayerSettings::PlayerSettings(QWidget *parent) :
|
||||
PlayerSettings::PlayerSettings(CMapHeader & mapHeader, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::PlayerSettings)
|
||||
ui(new Ui::PlayerSettings),
|
||||
header(mapHeader)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
show();
|
||||
|
||||
int players = 0;
|
||||
for(auto & p : header.players)
|
||||
{
|
||||
if(p.canAnyonePlay())
|
||||
{
|
||||
paramWidgets.push_back(new PlayerParams(header, players));
|
||||
ui->playersLayout->addWidget(paramWidgets.back());
|
||||
++players;
|
||||
}
|
||||
}
|
||||
|
||||
if(players < 2)
|
||||
ui->playersCount->setCurrentText("");
|
||||
else
|
||||
ui->playersCount->setCurrentIndex(players - 2);
|
||||
}
|
||||
|
||||
PlayerSettings::~PlayerSettings()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void PlayerSettings::on_playersCount_currentIndexChanged(int index)
|
||||
{
|
||||
assert(index + 2 != paramWidgets.size());
|
||||
assert(index + 2 < header.players.size());
|
||||
|
||||
for(int i = 0; i < index + 2; ++i)
|
||||
{
|
||||
if(i < paramWidgets.size())
|
||||
continue;
|
||||
|
||||
auto & p = header.players[i];
|
||||
p.canComputerPlay = true;
|
||||
paramWidgets.push_back(new PlayerParams(header, i));
|
||||
ui->playersLayout->addWidget(paramWidgets.back());
|
||||
}
|
||||
|
||||
assert(!paramWidgets.empty());
|
||||
for(int i = paramWidgets.size() - 1; i >= index + 2; --i)
|
||||
{
|
||||
auto & p = header.players[i];
|
||||
p.canComputerPlay = false;
|
||||
p.canHumanPlay = false;
|
||||
ui->playersLayout->removeWidget(paramWidgets[i]);
|
||||
delete paramWidgets[i];
|
||||
paramWidgets.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PlayerSettings::on_pushButton_clicked()
|
||||
{
|
||||
for(auto * w : paramWidgets)
|
||||
{
|
||||
header.players[w->playerColor] = w->playerInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
#ifndef PLAYERSETTINGS_H
|
||||
#define PLAYERSETTINGS_H
|
||||
|
||||
#include "StdInc.h"
|
||||
#include <QDialog>
|
||||
#include "playerparams.h"
|
||||
|
||||
namespace Ui {
|
||||
class PlayerSettings;
|
||||
@ -12,11 +14,19 @@ class PlayerSettings : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PlayerSettings(QWidget *parent = nullptr);
|
||||
explicit PlayerSettings(CMapHeader & mapHeader, QWidget *parent = nullptr);
|
||||
~PlayerSettings();
|
||||
|
||||
private slots:
|
||||
|
||||
void on_playersCount_currentIndexChanged(int index);
|
||||
|
||||
private:
|
||||
Ui::PlayerSettings *ui;
|
||||
|
||||
std::vector<PlayerParams*> paramWidgets;
|
||||
|
||||
CMapHeader & header;
|
||||
};
|
||||
|
||||
#endif // PLAYERSETTINGS_H
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PlayerSettings</class>
|
||||
<widget class="QDialog" name="PlayerSettings">
|
||||
@ -5,13 +6,102 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>654</width>
|
||||
<height>283</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0" colspan="8">
|
||||
<widget class="QScrollArea" name="players">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="playerscomon">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>628</width>
|
||||
<height>187</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="playersLayout"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Players</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="playersCount">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>3</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>4</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>6</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>7</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>8</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="6" colspan="2">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Ok</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
Loading…
Reference in New Issue
Block a user