From 3430edba2285126a01a6a875219fe8eb24ebe836 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Mon, 5 Sep 2022 06:18:38 +0400 Subject: [PATCH] Few more fixes --- mapeditor/mainwindow.cpp | 17 ++++++++++++++--- mapeditor/mainwindow.h | 1 + mapeditor/mapcontroller.cpp | 19 ++++++++++++++++--- mapeditor/mapcontroller.h | 3 ++- mapeditor/playersettings.cpp | 5 +++-- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 867784657..25250c188 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -58,7 +58,8 @@ void init() MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - ui(new Ui::MainWindow) + ui(new Ui::MainWindow), + controller(this) { ui->setupUi(this); @@ -156,13 +157,22 @@ void MainWindow::reloadMap(int level) //sceneMini->addPixmap(minimap); } +void MainWindow::mapChanged() +{ + unsaved = true; + setWindowTitle(filename + "* - VCMI Map Editor"); +} + void MainWindow::initializeMap(bool isNew) { unsaved = isNew; if(isNew) + { filename.clear(); - - setWindowTitle(filename + "* - VCMI Map Editor"); + setWindowTitle("* - VCMI Map Editor"); + } + else + setWindowTitle(filename + " - VCMI Map Editor"); mapLevel = 0; ui->mapView->setScene(controller.scene(mapLevel)); @@ -171,6 +181,7 @@ void MainWindow::initializeMap(bool isNew) //enable settings ui->actionMapSettings->setEnabled(true); + ui->actionPlayers_settings->setEnabled(true); } void MainWindow::on_actionOpen_triggered() diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index 2936ce489..242719702 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -83,6 +83,7 @@ public slots: void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected); void loadInspector(CGObjectInstance * obj); + void mapChanged(); private: void preparePreview(const QModelIndex &index, bool createNew); diff --git a/mapeditor/mapcontroller.cpp b/mapeditor/mapcontroller.cpp index b707f1c6b..afcb768fd 100644 --- a/mapeditor/mapcontroller.cpp +++ b/mapeditor/mapcontroller.cpp @@ -14,7 +14,7 @@ #include "inspector.h" -MapController::MapController() +MapController::MapController(MainWindow * m): main(m) { _scenes[0].reset(new MapScene(0)); _scenes[1].reset(new MapScene(1)); @@ -42,8 +42,8 @@ MapScene * MapController::scene(int level) void MapController::setMap(std::unique_ptr cmap) { _map = std::move(cmap); - //_scenes[0].reset(new MapScene(0)); - //_scenes[1].reset(new MapScene(1)); + _scenes[0].reset(new MapScene(0)); + _scenes[1].reset(new MapScene(1)); resetMapHandler(); sceneForceUpdate(); } @@ -83,6 +83,8 @@ void MapController::commitTerrainChange(int level, const Terrain & terrain) for(auto & t : v) _scenes[level]->terrainView.setDirty(t); _scenes[level]->terrainView.draw(); + + main->mapChanged(); } void MapController::commitObjectErase(int level) @@ -95,6 +97,8 @@ void MapController::commitObjectErase(int level) _scenes[level]->selectionObjectsView.clear(); resetMapHandler(); _scenes[level]->updateViews(); + + main->mapChanged(); } bool MapController::discardObject(int level) const @@ -144,6 +148,8 @@ void MapController::commitObstacleFill(int level) resetMapHandler(); _scenes[level]->updateViews(); + + main->mapChanged(); } void MapController::commitObjectChange(int level) @@ -151,12 +157,15 @@ void MapController::commitObjectChange(int level) resetMapHandler(); _scenes[level]->objectsView.draw(); _scenes[level]->selectionObjectsView.draw(); + + main->mapChanged(); } void MapController::commitChangeWithoutRedraw() { //DO NOT REDRAW + main->mapChanged(); } void MapController::commitObjectShiftOrCreate(int level) @@ -188,6 +197,8 @@ void MapController::commitObjectShiftOrCreate(int level) resetMapHandler(); _scenes[level]->updateViews(); + + main->mapChanged(); } void MapController::commitObjectCreate(int level) @@ -197,4 +208,6 @@ void MapController::commitObjectCreate(int level) return; _map->getEditManager()->insertObject(newObj); Initializer init(newObj); + + main->mapChanged(); } diff --git a/mapeditor/mapcontroller.h b/mapeditor/mapcontroller.h index e90c7ac2e..a89b6b377 100644 --- a/mapeditor/mapcontroller.h +++ b/mapeditor/mapcontroller.h @@ -10,7 +10,7 @@ class MainWindow; class MapController { public: - MapController(); + MapController(MainWindow *); MapController(const MapController &) = delete; MapController(const MapController &&) = delete; ~MapController(); @@ -40,6 +40,7 @@ public: private: std::unique_ptr _map; std::unique_ptr _mapHandler; + MainWindow * main; mutable std::array, 2> _scenes; }; diff --git a/mapeditor/playersettings.cpp b/mapeditor/playersettings.cpp index 5e5b119af..2a49e14b3 100644 --- a/mapeditor/playersettings.cpp +++ b/mapeditor/playersettings.cpp @@ -2,6 +2,7 @@ #include "playersettings.h" #include "ui_playersettings.h" #include "playerparams.h" +#include "mainwindow.h" PlayerSettings::PlayerSettings(CMapHeader & mapHeader, QWidget *parent) : QDialog(parent), @@ -35,8 +36,7 @@ PlayerSettings::~PlayerSettings() void PlayerSettings::on_playersCount_currentIndexChanged(int index) { - assert(index + 2 == paramWidgets.size()); - assert(index + 2 < header.players.size()); + assert(index + 2 <= header.players.size()); for(int i = 0; i < index + 2; ++i) { @@ -69,6 +69,7 @@ void PlayerSettings::on_pushButton_clicked() header.players[w->playerColor] = w->playerInfo; } + static_cast(parent())->controller.commitChangeWithoutRedraw(); close(); }