diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 0c1e8c8e2..2d553d836 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -864,7 +864,10 @@ void MainWindow::on_actionUpdate_appearance_triggered() if(QMessageBox::Yes != QMessageBox::question(this, "Update appearance", "This operation is irreversible. Do you want to continue?")) return; + controller.scene(mapLevel)->selectionTerrainView.clear(); + int errors = 0; + std::set staticObjects; for(auto * obj : controller.scene(mapLevel)->selectionObjectsView.getSelection()) { auto handler = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID); @@ -875,26 +878,46 @@ void MainWindow::on_actionUpdate_appearance_triggered() } auto terrain = controller.map()->getTile(obj->visitablePos()).terType; - auto app = handler->getOverride(terrain, obj); - if(!app) + + if(handler->isStaticObject()) { + staticObjects.insert(obj); if(obj->appearance.canBePlacedAt(terrain)) - continue; - - auto templates = handler->getTemplates(terrain); - if(templates.empty()) { - ++errors; + controller.scene(mapLevel)->selectionObjectsView.deselectObject(obj); continue; } - app = templates.front(); + + for(auto & offset : obj->appearance.getBlockedOffsets()) + controller.scene(mapLevel)->selectionTerrainView.select(obj->pos + offset); + } + else + { + auto app = handler->getOverride(terrain, obj); + if(!app) + { + if(obj->appearance.canBePlacedAt(terrain)) + continue; + + auto templates = handler->getTemplates(terrain); + if(templates.empty()) + { + ++errors; + continue; + } + app = templates.front(); + } + auto tiles = controller.mapHandler()->getTilesUnderObject(obj); + obj->appearance = app.get(); + controller.mapHandler()->invalidate(tiles); + controller.mapHandler()->invalidate(obj); + controller.scene(mapLevel)->selectionObjectsView.deselectObject(obj); } - auto tiles = controller.mapHandler()->getTilesUnderObject(obj); - obj->appearance = app.get(); - controller.mapHandler()->invalidate(tiles); - controller.mapHandler()->invalidate(obj); } controller.commitObjectChange(mapLevel); + controller.commitObjectErase(mapLevel); + controller.commitObstacleFill(mapLevel); + if(errors) QMessageBox::warning(this, "Update appearance", QString("Errors occured. %1 objects were not updated").arg(errors)); diff --git a/mapeditor/mainwindow.ui b/mapeditor/mainwindow.ui index 1da456867..78445c1f1 100644 --- a/mapeditor/mainwindow.ui +++ b/mapeditor/mainwindow.ui @@ -81,16 +81,9 @@ - - - Player - - - - @@ -902,11 +895,17 @@ + + false + Update appearance + + false + Recreate obstacles diff --git a/mapeditor/scenelayer.cpp b/mapeditor/scenelayer.cpp index d514c4a89..a0e79ac5b 100644 --- a/mapeditor/scenelayer.cpp +++ b/mapeditor/scenelayer.cpp @@ -470,6 +470,11 @@ void SelectionObjectsLayer::selectObject(CGObjectInstance * obj, bool inform /* } } +void SelectionObjectsLayer::deselectObject(CGObjectInstance * obj) +{ + selectedObjects.erase(obj); +} + bool SelectionObjectsLayer::isSelected(const CGObjectInstance * obj) const { return selectedObjects.count(const_cast(obj)); diff --git a/mapeditor/scenelayer.h b/mapeditor/scenelayer.h index 1d785db44..fc1b236ea 100644 --- a/mapeditor/scenelayer.h +++ b/mapeditor/scenelayer.h @@ -127,6 +127,7 @@ public: CGObjectInstance * selectObjectAt(int x, int y) const; void selectObjects(int x1, int y1, int x2, int y2); void selectObject(CGObjectInstance *, bool inform = true); + void deselectObject(CGObjectInstance *); bool isSelected(const CGObjectInstance *) const; std::set getSelection() const; void moveSelection(int x, int y);