mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-18 17:40:48 +02:00
Show objects layer
This commit is contained in:
parent
ec2204715a
commit
facc29b6d7
@ -331,18 +331,20 @@ MapHandler::AnimBitmapHolder MapHandler::findObjectBitmap(const CGObjectInstance
|
|||||||
return MapHandler::AnimBitmapHolder(bitmap);
|
return MapHandler::AnimBitmapHolder(bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<TerrainTileObject> & MapHandler::getObjects(int x, int y, int z)
|
||||||
|
{
|
||||||
|
return ttiles[z * (sizes.x * sizes.y) + y * sizes.x + x].objects;
|
||||||
|
}
|
||||||
|
|
||||||
void MapHandler::drawObjects(QPainter & painter, int x, int y, int z)
|
void MapHandler::drawObjects(QPainter & painter, int x, int y, int z)
|
||||||
{
|
{
|
||||||
auto & objects = ttiles[z * (sizes.x * sizes.y) + y * sizes.x + x].objects;
|
for(auto & object : getObjects(x, y, z))
|
||||||
for(auto & object : objects)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
//if(object.visi)
|
|
||||||
const CGObjectInstance * obj = object.obj;
|
const CGObjectInstance * obj = object.obj;
|
||||||
if (!obj)
|
if (!obj)
|
||||||
{
|
{
|
||||||
logGlobal->error("Stray map object that isn't fading");
|
logGlobal->error("Stray map object that isn't fading");
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t animationFrame = 0;
|
uint8_t animationFrame = 0;
|
||||||
@ -350,9 +352,11 @@ void MapHandler::drawObjects(QPainter & painter, int x, int y, int z)
|
|||||||
auto objData = findObjectBitmap(obj, animationFrame);
|
auto objData = findObjectBitmap(obj, animationFrame);
|
||||||
if (objData.objBitmap)
|
if (objData.objBitmap)
|
||||||
{
|
{
|
||||||
QRect srcRect(object.rect.x() + x * 32, object.rect.y() + y * 32, tileSize, tileSize);
|
auto pos = obj->getPosition();
|
||||||
|
QRect srcRect(object.rect.x() + pos.x * 32, object.rect.y() + pos.y * 32, tileSize, tileSize);
|
||||||
|
|
||||||
painter.drawImage(x * 32 - object.rect.x(), y * 32 - object.rect.y(), *objData.objBitmap);
|
painter.drawImage(QPoint(x * 32, y * 32), *objData.objBitmap, object.rect);
|
||||||
|
//painter.drawImage(pos.x * 32 - object.rect.x(), pos.y * 32 - object.rect.y(), *objData.objBitmap);
|
||||||
//drawObject(targetSurf, objData.objBitmap, &srcRect, objData.isMoving);
|
//drawObject(targetSurf, objData.objBitmap, &srcRect, objData.isMoving);
|
||||||
if (objData.flagBitmap)
|
if (objData.flagBitmap)
|
||||||
{
|
{
|
||||||
@ -371,3 +375,40 @@ void MapHandler::drawObjects(QPainter & painter, int x, int y, int z)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapHandler::drawObject(QPainter & painter, const TerrainTileObject & object)
|
||||||
|
{
|
||||||
|
//if(object.visi)
|
||||||
|
const CGObjectInstance * obj = object.obj;
|
||||||
|
if (!obj)
|
||||||
|
{
|
||||||
|
logGlobal->error("Stray map object that isn't fading");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t animationFrame = 0;
|
||||||
|
|
||||||
|
auto objData = findObjectBitmap(obj, animationFrame);
|
||||||
|
if (objData.objBitmap)
|
||||||
|
{
|
||||||
|
auto pos = obj->getPosition();
|
||||||
|
QRect srcRect(object.rect.x() + pos.x * 32, object.rect.y() + pos.y * 32, tileSize, tileSize);
|
||||||
|
|
||||||
|
painter.drawImage(pos.x * 32 - object.rect.x(), pos.y * 32 - object.rect.y(), *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);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -93,6 +93,8 @@ public:
|
|||||||
//void drawRoad(const TerrainTile & tinfo, const TerrainTile * tinfoUpper) const;
|
//void drawRoad(const TerrainTile & tinfo, const TerrainTile * tinfoUpper) const;
|
||||||
/// draws all objects on current tile (higher-level logic, unlike other draw*** methods)
|
/// draws all objects on current tile (higher-level logic, unlike other draw*** methods)
|
||||||
void drawObjects(QPainter & painter, int x, int y, int z);
|
void drawObjects(QPainter & painter, int x, int y, int z);
|
||||||
|
void drawObject(QPainter & painter, const TerrainTileObject & object);
|
||||||
|
const 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 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;
|
//void drawHeroFlag(SDL_Surface * targetSurf, std::shared_ptr<IImage> source, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const;
|
||||||
|
|
||||||
|
@ -102,6 +102,7 @@ MapScene::MapScene(MainWindow *parent, int l):
|
|||||||
passabilityView(parent, this),
|
passabilityView(parent, this),
|
||||||
selectionTerrainView(parent, this),
|
selectionTerrainView(parent, this),
|
||||||
terrainView(parent, this),
|
terrainView(parent, this),
|
||||||
|
objectsView(parent, this),
|
||||||
main(parent),
|
main(parent),
|
||||||
level(l)
|
level(l)
|
||||||
{
|
{
|
||||||
@ -109,12 +110,15 @@ MapScene::MapScene(MainWindow *parent, int l):
|
|||||||
|
|
||||||
void MapScene::updateViews()
|
void MapScene::updateViews()
|
||||||
{
|
{
|
||||||
|
//sequence is important because it defines rendering order
|
||||||
terrainView.update();
|
terrainView.update();
|
||||||
|
objectsView.update();
|
||||||
gridView.update();
|
gridView.update();
|
||||||
passabilityView.update();
|
passabilityView.update();
|
||||||
selectionTerrainView.update();
|
selectionTerrainView.update();
|
||||||
|
|
||||||
terrainView.show(true);
|
terrainView.show(true);
|
||||||
|
objectsView.show(true);
|
||||||
selectionTerrainView.show(true);
|
selectionTerrainView.show(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,6 +334,8 @@ void TerrainView::draw(bool onlyDirty)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
auto map = main->getMap();
|
auto map = main->getMap();
|
||||||
|
if(!map)
|
||||||
|
return;
|
||||||
|
|
||||||
QPainter painter(pixmap.get());
|
QPainter painter(pixmap.get());
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||||
@ -366,5 +372,75 @@ void TerrainView::draw(bool onlyDirty)
|
|||||||
main->getMapHandler()->drawTerrainTile(painter, i, j, scene->level);
|
main->getMapHandler()->drawTerrainTile(painter, i, j, scene->level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dirty.clear();
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectsView::ObjectsView(MainWindow * m, MapScene * s): BasicView(m, s)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectsView::update()
|
||||||
|
{
|
||||||
|
auto map = main->getMap();
|
||||||
|
if(!map)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pixmap.reset(new QPixmap(map->width * 32, map->height * 32));
|
||||||
|
pixmap->fill(QColor(0, 0, 0, 0));
|
||||||
|
draw(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectsView::draw(bool onlyDirty)
|
||||||
|
{
|
||||||
|
if(!pixmap)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto map = main->getMap();
|
||||||
|
if(!map)
|
||||||
|
return;
|
||||||
|
|
||||||
|
pixmap->fill(QColor(0, 0, 0, 0));
|
||||||
|
QPainter painter(pixmap.get());
|
||||||
|
//painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||||
|
std::set<const CGObjectInstance *> drawen;
|
||||||
|
|
||||||
|
|
||||||
|
for(int j = 0; j < map->height; ++j)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < map->width; ++i)
|
||||||
|
{
|
||||||
|
main->getMapHandler()->drawObjects(painter, i, j, scene->level);
|
||||||
|
/*auto & objects = main->getMapHandler()->getObjects(i, j, scene->level);
|
||||||
|
for(auto & object : objects)
|
||||||
|
{
|
||||||
|
if(!object.obj || drawen.count(object.obj))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!onlyDirty || dirty.count(object.obj))
|
||||||
|
{
|
||||||
|
main->getMapHandler()->drawObject(painter, object);
|
||||||
|
drawen.insert(object.obj);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dirty.clear();
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectsView::setDirty(int x, int y)
|
||||||
|
{
|
||||||
|
auto & objects = main->getMapHandler()->getObjects(x, y, scene->level);
|
||||||
|
for(auto & object : objects)
|
||||||
|
{
|
||||||
|
if(object.obj)
|
||||||
|
dirty.insert(object.obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectsView::setDirty(const CGObjectInstance * object)
|
||||||
|
{
|
||||||
|
dirty.insert(object);
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "../lib/int3.h"
|
#include "../lib/int3.h"
|
||||||
|
|
||||||
class int3;
|
class int3;
|
||||||
|
class CGObjectInstance;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
class MapScene;
|
class MapScene;
|
||||||
|
|
||||||
@ -108,6 +109,22 @@ private:
|
|||||||
std::set<int3> dirty;
|
std::set<int3> dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ObjectsView: public BasicView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ObjectsView(MainWindow * m, MapScene * s);
|
||||||
|
|
||||||
|
void update() override;
|
||||||
|
|
||||||
|
void draw(bool onlyDirty = true);
|
||||||
|
|
||||||
|
void setDirty(int x, int y);
|
||||||
|
void setDirty(const CGObjectInstance * object);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::set<const CGObjectInstance *> dirty;
|
||||||
|
};
|
||||||
|
|
||||||
class MapScene : public QGraphicsScene
|
class MapScene : public QGraphicsScene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -119,6 +136,7 @@ public:
|
|||||||
PassabilityView passabilityView;
|
PassabilityView passabilityView;
|
||||||
SelectionTerrainView selectionTerrainView;
|
SelectionTerrainView selectionTerrainView;
|
||||||
TerrainView terrainView;
|
TerrainView terrainView;
|
||||||
|
ObjectsView objectsView;
|
||||||
|
|
||||||
const int level;
|
const int level;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user