1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Object movement visualization works somehow

This commit is contained in:
nordsoft 2022-09-01 18:07:36 +04:00
parent 6290274371
commit 8a2864b788
4 changed files with 67 additions and 0 deletions

View File

@ -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);
}*/
}
}
}

View File

@ -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<TerrainTileObject> & getObjects(int x, int y, int z);
//void drawObject(SDL_Surface * targetSurf, std::shared_ptr<IImage> source, SDL_Rect * sourceRect, bool moving) const;
//void drawHeroFlag(SDL_Surface * targetSurf, std::shared_ptr<IImage> source, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const;

View File

@ -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<MapScene*>(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<CGObjectInstance *> SelectionObjectsView::selectObjects(int x1, int y1,
void SelectionObjectsView::clear()
{
selectedObjects.clear();
shift.setX(0);
shift.setY(0);
}

View File

@ -136,8 +136,11 @@ public:
CGObjectInstance * selectObjectAt(int x, int y);
std::set<CGObjectInstance *> selectObjects(int x1, int y1, int x2, int y2);
void moveSelection(int x, int y);
void clear();
QPoint shift;
private:
std::set<CGObjectInstance *> selectedObjects;
};