From 8a2864b788c64f7d2b3d69cc816041de71f28cfd Mon Sep 17 00:00:00 2001 From: nordsoft Date: Thu, 1 Sep 2022 18:07:36 +0400 Subject: [PATCH] Object movement visualization works somehow --- mapeditor/maphandler.cpp | 34 ++++++++++++++++++++++++++++++++++ mapeditor/maphandler.h | 1 + mapeditor/mapview.cpp | 29 +++++++++++++++++++++++++++++ mapeditor/mapview.h | 3 +++ 4 files changed, 67 insertions(+) diff --git a/mapeditor/maphandler.cpp b/mapeditor/maphandler.cpp index 8c608680e..0cb86a55b 100644 --- a/mapeditor/maphandler.cpp +++ b/mapeditor/maphandler.cpp @@ -412,3 +412,37 @@ void MapHandler::drawObject(QPainter & painter, const TerrainTileObject & object } } } + + +void MapHandler::drawObjectAt(QPainter & painter, const CGObjectInstance * obj, int x, int y) +{ + if (!obj) + { + logGlobal->error("Stray map object that isn't fading"); + return; + } + + uint8_t animationFrame = 0; + + auto objData = findObjectBitmap(obj, animationFrame); + if (objData.objBitmap) + { + painter.drawImage(QPoint((x - obj->getWidth()) * 32, (y - obj->getHeight()) * 32), *objData.objBitmap); + + //drawObject(targetSurf, objData.objBitmap, &srcRect, objData.isMoving); + if (objData.flagBitmap) + { + /*if (objData.isMoving) + { + srcRect.y += FRAMES_PER_MOVE_ANIM_GROUP * 2 - tileSize; + Rect dstRect(realPos.x, realPos.y - tileSize / 2, tileSize, tileSize); + drawHeroFlag(targetSurf, objData.flagBitmap, &srcRect, &dstRect, true); + } + else if (obj->pos.x == pos.x && obj->pos.y == pos.y) + { + Rect dstRect(realPos.x - 2 * tileSize, realPos.y - tileSize, 3 * tileSize, 2 * tileSize); + drawHeroFlag(targetSurf, objData.flagBitmap, nullptr, &dstRect, false); + }*/ + } + } +} diff --git a/mapeditor/maphandler.h b/mapeditor/maphandler.h index 37d3af41d..ed5d1d3d2 100644 --- a/mapeditor/maphandler.h +++ b/mapeditor/maphandler.h @@ -94,6 +94,7 @@ public: /// draws all objects on current tile (higher-level logic, unlike other draw*** methods) void drawObjects(QPainter & painter, int x, int y, int z); void drawObject(QPainter & painter, const TerrainTileObject & object); + void drawObjectAt(QPainter & painter, const CGObjectInstance * object, int x, int y); std::vector & getObjects(int x, int y, int z); //void drawObject(SDL_Surface * targetSurf, std::shared_ptr source, SDL_Rect * sourceRect, bool moving) const; //void drawHeroFlag(SDL_Surface * targetSurf, std::shared_ptr source, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const; diff --git a/mapeditor/mapview.cpp b/mapeditor/mapview.cpp index 81dcf7c67..1dfe6e22f 100644 --- a/mapeditor/mapview.cpp +++ b/mapeditor/mapview.cpp @@ -53,6 +53,12 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent) } sc->selectionTerrainView.draw(); break; + + case MapView::SelectionTool::None: + auto sh = tile - tileStart; + sc->selectionObjectsView.shift = QPoint(sh.x, sh.y); + sc->selectionObjectsView.draw(); + break; } } @@ -106,6 +112,18 @@ void MapView::mousePressEvent(QMouseEvent *event) void MapView::mouseReleaseEvent(QMouseEvent *event) { this->update(); + + auto * sc = static_cast(scene()); + if(!sc) + return; + + switch(selectionTool) + { + case MapView::SelectionTool::None: + sc->selectionObjectsView.shift = QPoint(0, 0); + sc->selectionObjectsView.draw(); + break; + } } MapScene::MapScene(MainWindow *parent, int l): @@ -500,7 +518,16 @@ void SelectionObjectsView::draw() bbox.setBottomRight(bottomRight); } + painter.setOpacity(1.0); painter.drawRect(bbox.x() * 32, bbox.y() * 32, bbox.width() * 32, bbox.height() * 32); + + //show translation + if(shift.x() || shift.y()) + { + painter.setOpacity(0.5); + auto newPos = QPoint(obj->getPosition().x, obj->getPosition().y) + shift; + main->getMapHandler()->drawObjectAt(painter, obj, newPos.x(), newPos.y()); + } } redraw(); @@ -565,4 +592,6 @@ std::set SelectionObjectsView::selectObjects(int x1, int y1, void SelectionObjectsView::clear() { selectedObjects.clear(); + shift.setX(0); + shift.setY(0); } diff --git a/mapeditor/mapview.h b/mapeditor/mapview.h index e074db954..ae1423d25 100644 --- a/mapeditor/mapview.h +++ b/mapeditor/mapview.h @@ -136,8 +136,11 @@ public: CGObjectInstance * selectObjectAt(int x, int y); std::set selectObjects(int x1, int y1, int x2, int y2); + void moveSelection(int x, int y); void clear(); + QPoint shift; + private: std::set selectedObjects; };