From ea3845e8dda6873f4f5c8556837fc8ce3efb53cc Mon Sep 17 00:00:00 2001 From: nordsoft Date: Tue, 30 Aug 2022 04:48:44 +0400 Subject: [PATCH] Fix flips for terrains --- mapeditor/mainwindow.cpp | 6 +++--- mapeditor/maphandler.cpp | 35 +++++++---------------------------- mapeditor/maphandler.h | 4 ++-- 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 0d12c932f..bce543591 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -95,7 +95,7 @@ MainWindow::~MainWindow() void MainWindow::on_actionOpen_triggered() { - /*auto filename = QFileDialog::getOpenFileName(this, tr("Open Image"), QString::fromStdString(VCMIDirs::get().userCachePath().native()), tr("Homm3 Files (*.vmap *.h3m)")); + auto filename = QFileDialog::getOpenFileName(this, tr("Open Image"), QString::fromStdString(VCMIDirs::get().userCachePath().native()), tr("Homm3 Files (*.vmap *.h3m)")); if(filename.isNull()) return; @@ -103,8 +103,8 @@ void MainWindow::on_actionOpen_triggered() QFileInfo fi(filename); std::string fname = fi.fileName().toStdString(); std::string fdir = fi.dir().path().toStdString(); - ResourceID resId("MAPS/" + fname, EResType::MAP);*/ - ResourceID resId("MAPS/SomeMap.vmap", EResType::MAP); + ResourceID resId("MAPS/" + fname, EResType::MAP); + //ResourceID resId("MAPS/SomeMap.vmap", EResType::MAP); if(!CResourceHandler::get()->existsResource(resId)) { diff --git a/mapeditor/maphandler.cpp b/mapeditor/maphandler.cpp index c90c33d68..ef21e803e 100644 --- a/mapeditor/maphandler.cpp +++ b/mapeditor/maphandler.cpp @@ -43,38 +43,15 @@ void MapHandler::initTerrainGraphics() auto loadFlipped = [](TFlippedAnimations & animation, TFlippedCache & cache, const std::map & files) { - //no rotation and basic setup for(auto & type : files) { - animation[type.first][0] = make_unique(type.second); - animation[type.first][0]->preload(); - const size_t views = animation[type.first][0]->size(0); + animation[type.first] = make_unique(type.second); + animation[type.first]->preload(); + const size_t views = animation[type.first]->size(0); cache[type.first].resize(views); for(int j = 0; j < views; j++) - cache[type.first][j][0] = animation[type.first][0]->getImage(j); - } - - for(int rotation = 1; rotation < 4; rotation++) - { - for(auto & type : files) - { - animation[type.first][rotation] = make_unique(type.second); - animation[type.first][rotation]->preload(); - const size_t views = animation[type.first][rotation]->size(0); - - for(int j = 0; j < views; j++) - { - auto image = animation[type.first][rotation]->getImage(j); - - //if(rotation == 2 || rotation == 3) - //image->horizontalFlip(); - //if(rotation == 1 || rotation == 3) - //image->verticalFlip(); - - cache[type.first][j][rotation] = image; - } - } + cache[type.first][j] = animation[type.first]->getImage(j); } }; @@ -98,7 +75,9 @@ void MapHandler::drawTerrainTile(int x, int y, const TerrainTile & tinfo) if(terrainImages.at(tinfo.terType).size() <= tinfo.terView) return; - painter.drawImage(x * tileSize, y * tileSize, *terrainImages.at(tinfo.terType)[tinfo.terView][rotation]); + bool hflip = (rotation == 1 || rotation == 3), vflip = (rotation == 2 || rotation == 3); + + painter.drawImage(x * tileSize, y * tileSize, terrainImages.at(tinfo.terType)[tinfo.terView]->mirrored(hflip, vflip)); } void MapHandler::initObjectRects() diff --git a/mapeditor/maphandler.h b/mapeditor/maphandler.h index a918dd0c7..960ae77ba 100644 --- a/mapeditor/maphandler.h +++ b/mapeditor/maphandler.h @@ -27,8 +27,8 @@ public: //terrain graphics //FIXME: unique_ptr should be enough, but fails to compile in MSVS 2013 - typedef std::map, 4>> TFlippedAnimations; //[type, rotation] - typedef std::map, 4>>> TFlippedCache;//[type, view type, rotation] + typedef std::map> TFlippedAnimations; //[type, rotation] + typedef std::map>> TFlippedCache;//[type, view type, rotation] TFlippedAnimations terrainAnimations;//[terrain type, rotation] TFlippedCache terrainImages;//[terrain type, view type, rotation]