From ec2204715a6468583accc8c2b84968b451f325fc Mon Sep 17 00:00:00 2001 From: nordsoft Date: Thu, 1 Sep 2022 15:04:34 +0400 Subject: [PATCH] Redering order was fixed --- mapeditor/mapview.cpp | 53 ++++++++++++++++++++++---------------- mapeditor/mapview.h | 1 + mapeditor/windownewmap.cpp | 7 +++++ 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/mapeditor/mapview.cpp b/mapeditor/mapview.cpp index b9235f517..70bd58791 100644 --- a/mapeditor/mapview.cpp +++ b/mapeditor/mapview.cpp @@ -105,7 +105,6 @@ MapScene::MapScene(MainWindow *parent, int l): main(parent), level(l) { - } void MapScene::updateViews() @@ -114,6 +113,9 @@ void MapScene::updateViews() gridView.update(); passabilityView.update(); selectionTerrainView.update(); + + terrainView.show(true); + selectionTerrainView.show(true); } BasicView::BasicView(MainWindow * m, MapScene * s): main(m), scene(s) @@ -129,14 +131,24 @@ void BasicView::show(bool show) if(show) { - if(item) - scene->addItem(item.get()); + if(pixmap) + { + if(item) + item->setPixmap(*pixmap); + else + item.reset(scene->addPixmap(*pixmap)); + } else - item.reset(scene->addPixmap(*pixmap)); + { + if(item) + item->setPixmap(emptyPixmap); + else + item.reset(scene->addPixmap(emptyPixmap)); + } } else { - scene->removeItem(item.get()); + item->setPixmap(emptyPixmap); } isShown = show; @@ -145,11 +157,18 @@ void BasicView::show(bool show) void BasicView::redraw() { if(item) - scene->removeItem(item.get()); - - if(isShown) { - item.reset(scene->addPixmap(*pixmap)); + if(pixmap && isShown) + item->setPixmap(*pixmap); + else + item->setPixmap(emptyPixmap); + } + else + { + if(pixmap && isShown) + item.reset(scene->addPixmap(*pixmap)); + else + item.reset(scene->addPixmap(emptyPixmap)); } } @@ -163,8 +182,6 @@ void GridView::update() if(!map) return; - show(false); - pixmap.reset(new QPixmap(map->width * 32, map->height * 32)); pixmap->fill(QColor(0, 0, 0, 0)); QPainter painter(pixmap.get()); @@ -179,7 +196,7 @@ void GridView::update() painter.drawLine(i * 32, 0, i * 32, map->height * 32 - 1); } - show(isShown); + redraw(); } PassabilityView::PassabilityView(MainWindow * m, MapScene * s): BasicView(m, s) @@ -192,8 +209,6 @@ void PassabilityView::update() if(!map) return; - show(false); - pixmap.reset(new QPixmap(map->width * 32, map->height * 32)); pixmap->fill(QColor(0, 0, 0, 0)); @@ -213,7 +228,7 @@ void PassabilityView::update() } } - show(isShown); + redraw(); } SelectionTerrainView::SelectionTerrainView(MainWindow * m, MapScene * s): BasicView(m, s) @@ -226,8 +241,6 @@ void SelectionTerrainView::update() if(!map) return; - show(false); - area.clear(); areaAdd.clear(); areaErase.clear(); @@ -235,7 +248,7 @@ void SelectionTerrainView::update() pixmap.reset(new QPixmap(map->width * 32, map->height * 32)); pixmap->fill(QColor(0, 0, 0, 0)); - show(true); //always visible + redraw(); } void SelectionTerrainView::draw() @@ -302,12 +315,8 @@ void TerrainView::update() if(!map) return; - show(false); - pixmap.reset(new QPixmap(map->width * 32, map->height * 32)); draw(false); - - show(true); //always visible } void TerrainView::setDirty(const int3 & tile) diff --git a/mapeditor/mapview.h b/mapeditor/mapview.h index cddf24382..c1ff64118 100644 --- a/mapeditor/mapview.h +++ b/mapeditor/mapview.h @@ -25,6 +25,7 @@ protected: bool isShown = false; std::unique_ptr pixmap; + QPixmap emptyPixmap; private: std::unique_ptr item; diff --git a/mapeditor/windownewmap.cpp b/mapeditor/windownewmap.cpp index d69264be2..06bc59c52 100644 --- a/mapeditor/windownewmap.cpp +++ b/mapeditor/windownewmap.cpp @@ -21,6 +21,13 @@ WindowNewMap::WindowNewMap(QWidget *parent) : setWindowModality(Qt::ApplicationModal); show(); + + //setup initial parameters + mapGenOptions.setWidth(ui->widthTxt->text().toInt()); + mapGenOptions.setHeight(ui->heightTxt->text().toInt()); + bool twoLevel = ui->twoLevelCheck->isChecked(); + mapGenOptions.setHasTwoLevels(twoLevel); + updateTemplateList(); } WindowNewMap::~WindowNewMap()