1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00

Editor for map name and description

This commit is contained in:
nordsoft 2022-09-04 20:16:36 +04:00
parent 8e953c223e
commit 49a6422d20
12 changed files with 181 additions and 97 deletions

View File

@ -17,6 +17,7 @@ set(editor_SRCS
objectbrowser.cpp objectbrowser.cpp
inspector.cpp inspector.cpp
mapsettings.cpp mapsettings.cpp
playersettings.cpp
) )
set(editor_HEADERS set(editor_HEADERS
@ -37,6 +38,7 @@ set(editor_HEADERS
objectbrowser.h objectbrowser.h
inspector.h inspector.h
mapsettings.h mapsettings.h
playersettings.h
) )
set(editor_FORMS set(editor_FORMS
@ -44,6 +46,7 @@ set(editor_FORMS
windownewmap.ui windownewmap.ui
generatorprogress.ui generatorprogress.ui
mapsettings.ui mapsettings.ui
playersettings.ui
) )
assign_source_group(${editor_SRCS} ${editor_HEADERS} VCMI_launcher.rc) assign_source_group(${editor_SRCS} ${editor_HEADERS} VCMI_launcher.rc)

View File

@ -28,6 +28,7 @@
#include "windownewmap.h" #include "windownewmap.h"
#include "objectbrowser.h" #include "objectbrowser.h"
#include "inspector.h" #include "inspector.h"
#include "mapsettings.h"
static CBasicLogConfigurator * logConfig; static CBasicLogConfigurator * logConfig;
@ -203,6 +204,9 @@ void MainWindow::setMap(bool isNew)
mapLevel = 0; mapLevel = 0;
ui->mapView->setScene(scenes[mapLevel]); ui->mapView->setScene(scenes[mapLevel]);
//enable settings
ui->actionMapSettings->setEnabled(true);
} }
void MainWindow::on_actionOpen_triggered() void MainWindow::on_actionOpen_triggered()
@ -822,3 +826,8 @@ void MainWindow::on_inspectorWidget_itemChanged(QTableWidgetItem *item)
inspector.setProperty(param, item->text()); inspector.setProperty(param, item->text());
} }
void MainWindow::on_actionMapSettings_triggered()
{
auto mapSettingsDialog = new MapSettings(this);
}

View File

@ -81,6 +81,8 @@ private slots:
void on_inspectorWidget_itemChanged(QTableWidgetItem *item); void on_inspectorWidget_itemChanged(QTableWidgetItem *item);
void on_actionMapSettings_triggered();
public slots: public slots:
void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected); void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected);

View File

@ -63,7 +63,14 @@
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="actionSave_as"/> <addaction name="actionSave_as"/>
</widget> </widget>
<widget class="QMenu" name="menuMap">
<property name="title">
<string>Map</string>
</property>
<addaction name="actionMapSettings"/>
</widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menuMap"/>
</widget> </widget>
<widget class="QToolBar" name="toolBar"> <widget class="QToolBar" name="toolBar">
<property name="windowTitle"> <property name="windowTitle">
@ -652,6 +659,9 @@
<string>Terrains</string> <string>Terrains</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -665,7 +675,11 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<layout class="QVBoxLayout" name="terrainLayout"/> <layout class="QVBoxLayout" name="terrainLayout">
<property name="spacing">
<number>1</number>
</property>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -792,6 +806,17 @@
<string>Grid</string> <string>Grid</string>
</property> </property>
</action> </action>
<action name="actionMapSettings">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>General</string>
</property>
<property name="toolTip">
<string>Map title and description</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -1,14 +1,41 @@
#include "mapsettings.h" #include "mapsettings.h"
#include "ui_mapsettings.h" #include "ui_mapsettings.h"
#include "mainwindow.h"
MapSettings::MapSettings(QWidget *parent) : MapSettings::MapSettings(MainWindow *parent) :
QDialog(parent), QDialog(static_cast<QWidget*>(parent)),
ui(new Ui::MapSettings) ui(new Ui::MapSettings),
main(parent)
{ {
ui->setupUi(this); ui->setupUi(this);
assert(main);
assert(main->getMap());
ui->mapNameEdit->setText(QString::fromStdString(main->getMap()->name));
ui->mapDescriptionEdit->setPlainText(QString::fromStdString(main->getMap()->description));
show();
//ui8 difficulty;
//ui8 levelLimit;
//std::string victoryMessage;
//std::string defeatMessage;
//ui16 victoryIconIndex;
//ui16 defeatIconIndex;
//std::vector<PlayerInfo> players; /// The default size of the vector is PlayerColor::PLAYER_LIMIT.
} }
MapSettings::~MapSettings() MapSettings::~MapSettings()
{ {
delete ui; delete ui;
} }
void MapSettings::on_pushButton_clicked()
{
main->getMap()->name = ui->mapNameEdit->text().toStdString();
main->getMap()->description = ui->mapDescriptionEdit->toPlainText().toStdString();
close();
}

View File

@ -7,16 +7,21 @@ namespace Ui {
class MapSettings; class MapSettings;
} }
class MainWindow;
class MapSettings : public QDialog class MapSettings : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit MapSettings(QWidget *parent = nullptr); explicit MapSettings(MainWindow *parent = nullptr);
~MapSettings(); ~MapSettings();
private slots:
void on_pushButton_clicked();
private: private:
Ui::MapSettings *ui; Ui::MapSettings *ui;
MainWindow * main;
}; };
#endif // MAPSETTINGS_H #endif // MAPSETTINGS_H

View File

@ -2,6 +2,9 @@
<ui version="4.0"> <ui version="4.0">
<class>MapSettings</class> <class>MapSettings</class>
<widget class="QDialog" name="MapSettings"> <widget class="QDialog" name="MapSettings">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -21,8 +24,18 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLineEdit" name="mapNameEdit"/>
</item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<widget class="QPlainTextEdit" name="plainTextEdit"/> <widget class="QPlainTextEdit" name="mapDescriptionEdit"/>
</item> </item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
@ -31,70 +44,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Players amount</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="5" column="0">
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string>1</string>
</property>
</item>
<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>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -0,0 +1,14 @@
#include "playersettings.h"
#include "ui_playersettings.h"
PlayerSettings::PlayerSettings(QWidget *parent) :
QDialog(parent),
ui(new Ui::PlayerSettings)
{
ui->setupUi(this);
}
PlayerSettings::~PlayerSettings()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef PLAYERSETTINGS_H
#define PLAYERSETTINGS_H
#include <QDialog>
namespace Ui {
class PlayerSettings;
}
class PlayerSettings : public QDialog
{
Q_OBJECT
public:
explicit PlayerSettings(QWidget *parent = nullptr);
~PlayerSettings();
private:
Ui::PlayerSettings *ui;
};
#endif // PLAYERSETTINGS_H

View File

@ -0,0 +1,18 @@
<ui version="4.0">
<class>PlayerSettings</class>
<widget class="QDialog" name="PlayerSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -4,6 +4,8 @@
#include "../lib/rmg/CRmgTemplate.h" #include "../lib/rmg/CRmgTemplate.h"
#include "../lib/rmg/CMapGenerator.h" #include "../lib/rmg/CMapGenerator.h"
#include "../lib/VCMI_Lib.h" #include "../lib/VCMI_Lib.h"
#include "../lib/mapping/CMapEditManager.h"
#include "../lib/CGeneralTextHandler.h"
#include "windownewmap.h" #include "windownewmap.h"
#include "ui_windownewmap.h" #include "ui_windownewmap.h"
@ -40,9 +42,25 @@ void WindowNewMap::on_cancelButton_clicked()
close(); close();
} }
void generateRandomMap(CMapGenerator & gen, MainWindow * window, bool empty) void generateRandomMap(CMapGenerator & gen, MainWindow * window)
{ {
window->setMapRaw(gen.generate(empty)); window->setMapRaw(gen.generate());
}
void generateEmptyMap(CMapGenOptions & options, MainWindow * window)
{
std::unique_ptr<CMap> map(new CMap);
map->version = EMapFormat::VCMI;
map->width = options.getWidth();
map->height = options.getHeight();
map->twoLevel = options.getHasTwoLevels();
map->initTerrain();
map->getEditManager()->clearTerrain(&CRandomGenerator::getDefault());
map->getEditManager()->getTerrainSelection().selectRange(MapRect(int3(0, 0, 0), options.getWidth(), options.getHeight()));
map->getEditManager()->drawTerrain(Terrain("grass"), &CRandomGenerator::getDefault());
window->setMapRaw(std::move(map));
} }
void WindowNewMap::on_okButtong_clicked() void WindowNewMap::on_okButtong_clicked()
@ -69,35 +87,30 @@ void WindowNewMap::on_okButtong_clicked()
mapGenOptions.setWaterContent(water); mapGenOptions.setWaterContent(water);
mapGenOptions.setMonsterStrength(monster); mapGenOptions.setMonsterStrength(monster);
CMapGenerator generator(mapGenOptions); if(ui->randomMapCheck->isChecked())
//TODO: fix water and roads
generator.disableModificator("RoadPlacer");
generator.disableModificator("RiverPlacer");
auto progressBarWnd = new GeneratorProgress(generator, this);
progressBarWnd->show();
{ {
std::thread generate(&::generateRandomMap, std::ref(generator), static_cast<MainWindow*>(parent()), !ui->randomMapCheck->isChecked()); CMapGenerator generator(mapGenOptions);
progressBarWnd->update(); //TODO: fix water and roads
generate.join(); generator.disableModificator("RoadPlacer");
generator.disableModificator("RiverPlacer");
auto progressBarWnd = new GeneratorProgress(generator, this);
progressBarWnd->show();
{
std::thread generate(&::generateRandomMap, std::ref(generator), static_cast<MainWindow*>(parent()));
progressBarWnd->update();
generate.join();
}
}
else
{
generateEmptyMap(mapGenOptions, static_cast<MainWindow*>(parent()));
} }
static_cast<MainWindow*>(parent())->setMap(true); static_cast<MainWindow*>(parent())->setMap(true);
close(); close();
} }
void WindowNewMap::generateEmptyMap()
{
}
void WindowNewMap::generateRandomMap()
{
}
void WindowNewMap::on_sizeCombo_activated(int index) void WindowNewMap::on_sizeCombo_activated(int index)
{ {
std::map<int, std::pair<int, int>> sizes std::map<int, std::pair<int, int>> sizes

View File

@ -39,9 +39,6 @@ private slots:
private: private:
void generateEmptyMap();
void generateRandomMap();
void updateTemplateList(); void updateTemplateList();
private: private: