diff --git a/mapeditor/CMakeLists.txt b/mapeditor/CMakeLists.txt index ddda34ba0..11b348696 100644 --- a/mapeditor/CMakeLists.txt +++ b/mapeditor/CMakeLists.txt @@ -17,6 +17,7 @@ set(editor_SRCS objectbrowser.cpp inspector.cpp mapsettings.cpp + playersettings.cpp ) set(editor_HEADERS @@ -37,6 +38,7 @@ set(editor_HEADERS objectbrowser.h inspector.h mapsettings.h + playersettings.h ) set(editor_FORMS @@ -44,6 +46,7 @@ set(editor_FORMS windownewmap.ui generatorprogress.ui mapsettings.ui + playersettings.ui ) assign_source_group(${editor_SRCS} ${editor_HEADERS} VCMI_launcher.rc) diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index efb45b907..ef40b0cc9 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -28,6 +28,7 @@ #include "windownewmap.h" #include "objectbrowser.h" #include "inspector.h" +#include "mapsettings.h" static CBasicLogConfigurator * logConfig; @@ -203,6 +204,9 @@ void MainWindow::setMap(bool isNew) mapLevel = 0; ui->mapView->setScene(scenes[mapLevel]); + + //enable settings + ui->actionMapSettings->setEnabled(true); } void MainWindow::on_actionOpen_triggered() @@ -822,3 +826,8 @@ void MainWindow::on_inspectorWidget_itemChanged(QTableWidgetItem *item) inspector.setProperty(param, item->text()); } +void MainWindow::on_actionMapSettings_triggered() +{ + auto mapSettingsDialog = new MapSettings(this); +} + diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index 4dcba78bb..4bcc03972 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -81,6 +81,8 @@ private slots: void on_inspectorWidget_itemChanged(QTableWidgetItem *item); + void on_actionMapSettings_triggered(); + public slots: void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected); diff --git a/mapeditor/mainwindow.ui b/mapeditor/mainwindow.ui index fda479d21..4173be7a3 100644 --- a/mapeditor/mainwindow.ui +++ b/mapeditor/mainwindow.ui @@ -63,7 +63,14 @@ + + + Map + + + + @@ -652,6 +659,9 @@ Terrains + + 1 + 0 @@ -665,7 +675,11 @@ 0 - + + + 1 + + @@ -792,6 +806,17 @@ Grid + + + false + + + General + + + Map title and description + + diff --git a/mapeditor/mapsettings.cpp b/mapeditor/mapsettings.cpp index e458e8930..8448344cf 100644 --- a/mapeditor/mapsettings.cpp +++ b/mapeditor/mapsettings.cpp @@ -1,14 +1,41 @@ #include "mapsettings.h" #include "ui_mapsettings.h" +#include "mainwindow.h" -MapSettings::MapSettings(QWidget *parent) : - QDialog(parent), - ui(new Ui::MapSettings) +MapSettings::MapSettings(MainWindow *parent) : + QDialog(static_cast(parent)), + ui(new Ui::MapSettings), + main(parent) { 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 players; /// The default size of the vector is PlayerColor::PLAYER_LIMIT. } MapSettings::~MapSettings() { delete ui; } + +void MapSettings::on_pushButton_clicked() +{ + main->getMap()->name = ui->mapNameEdit->text().toStdString(); + main->getMap()->description = ui->mapDescriptionEdit->toPlainText().toStdString(); + close(); +} diff --git a/mapeditor/mapsettings.h b/mapeditor/mapsettings.h index 6ef31ae2b..4bda47063 100644 --- a/mapeditor/mapsettings.h +++ b/mapeditor/mapsettings.h @@ -7,16 +7,21 @@ namespace Ui { class MapSettings; } +class MainWindow; class MapSettings : public QDialog { Q_OBJECT public: - explicit MapSettings(QWidget *parent = nullptr); + explicit MapSettings(MainWindow *parent = nullptr); ~MapSettings(); +private slots: + void on_pushButton_clicked(); + private: Ui::MapSettings *ui; + MainWindow * main; }; #endif // MAPSETTINGS_H diff --git a/mapeditor/mapsettings.ui b/mapeditor/mapsettings.ui index 97fa1b14f..442ded00c 100644 --- a/mapeditor/mapsettings.ui +++ b/mapeditor/mapsettings.ui @@ -2,6 +2,9 @@ MapSettings + + Qt::ApplicationModal + 0 @@ -21,8 +24,18 @@ + + + + Ok + + + + + + - + @@ -31,70 +44,6 @@ - - - - Players amount - - - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - 1 - - - - - 2 - - - - - 3 - - - - - 4 - - - - - 5 - - - - - 6 - - - - - 7 - - - - - 8 - - - - diff --git a/mapeditor/playersettings.cpp b/mapeditor/playersettings.cpp new file mode 100644 index 000000000..2d4c2e2df --- /dev/null +++ b/mapeditor/playersettings.cpp @@ -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; +} diff --git a/mapeditor/playersettings.h b/mapeditor/playersettings.h new file mode 100644 index 000000000..73a4a7d1d --- /dev/null +++ b/mapeditor/playersettings.h @@ -0,0 +1,22 @@ +#ifndef PLAYERSETTINGS_H +#define PLAYERSETTINGS_H + +#include + +namespace Ui { +class PlayerSettings; +} + +class PlayerSettings : public QDialog +{ + Q_OBJECT + +public: + explicit PlayerSettings(QWidget *parent = nullptr); + ~PlayerSettings(); + +private: + Ui::PlayerSettings *ui; +}; + +#endif // PLAYERSETTINGS_H diff --git a/mapeditor/playersettings.ui b/mapeditor/playersettings.ui new file mode 100644 index 000000000..dc62aaf6e --- /dev/null +++ b/mapeditor/playersettings.ui @@ -0,0 +1,18 @@ + + PlayerSettings + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + diff --git a/mapeditor/windownewmap.cpp b/mapeditor/windownewmap.cpp index 253bd111b..da0d177e0 100644 --- a/mapeditor/windownewmap.cpp +++ b/mapeditor/windownewmap.cpp @@ -4,6 +4,8 @@ #include "../lib/rmg/CRmgTemplate.h" #include "../lib/rmg/CMapGenerator.h" #include "../lib/VCMI_Lib.h" +#include "../lib/mapping/CMapEditManager.h" +#include "../lib/CGeneralTextHandler.h" #include "windownewmap.h" #include "ui_windownewmap.h" @@ -40,9 +42,25 @@ void WindowNewMap::on_cancelButton_clicked() 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 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() @@ -69,35 +87,30 @@ void WindowNewMap::on_okButtong_clicked() mapGenOptions.setWaterContent(water); mapGenOptions.setMonsterStrength(monster); - CMapGenerator generator(mapGenOptions); - - //TODO: fix water and roads - generator.disableModificator("RoadPlacer"); - generator.disableModificator("RiverPlacer"); - - auto progressBarWnd = new GeneratorProgress(generator, this); - progressBarWnd->show(); - + if(ui->randomMapCheck->isChecked()) { - std::thread generate(&::generateRandomMap, std::ref(generator), static_cast(parent()), !ui->randomMapCheck->isChecked()); - progressBarWnd->update(); - generate.join(); + CMapGenerator generator(mapGenOptions); + //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(parent())); + progressBarWnd->update(); + generate.join(); + } + } + else + { + generateEmptyMap(mapGenOptions, static_cast(parent())); } static_cast(parent())->setMap(true); close(); } -void WindowNewMap::generateEmptyMap() -{ - -} - -void WindowNewMap::generateRandomMap() -{ - -} - void WindowNewMap::on_sizeCombo_activated(int index) { std::map> sizes diff --git a/mapeditor/windownewmap.h b/mapeditor/windownewmap.h index 485a8eadd..c35b8524e 100644 --- a/mapeditor/windownewmap.h +++ b/mapeditor/windownewmap.h @@ -39,9 +39,6 @@ private slots: private: - void generateEmptyMap(); - void generateRandomMap(); - void updateTemplateList(); private: