1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00
vcmi/mapeditor/maphandler.h

107 lines
3.5 KiB
C
Raw Normal View History

2022-08-30 00:44:02 +02:00
#ifndef MAPHANDLER_H
#define MAPHANDLER_H
#include "StdInc.h"
#include "../lib/mapping/CMap.h"
#include "Animation.h"
#include <QImage>
2022-08-30 02:15:54 +02:00
#include <QPixmap>
2022-08-30 04:38:24 +02:00
#include <QRect>
class CGObjectInstance;
class CGBoat;
2022-08-30 15:08:33 +02:00
class PlayerColor;
2022-08-30 04:38:24 +02:00
struct TileObject
2022-08-30 04:38:24 +02:00
{
2022-09-01 15:08:03 +02:00
CGObjectInstance *obj;
2022-08-30 04:38:24 +02:00
QRect rect;
TileObject(CGObjectInstance *obj_, QRect rect_);
~TileObject();
2022-08-30 04:38:24 +02:00
};
using TileObjects = std::vector<TileObject>; //pointers to objects being on this tile with rects to be easier to blit this tile on screen
2022-08-30 00:44:02 +02:00
class MapHandler
{
public:
2022-08-30 04:38:24 +02:00
struct AnimBitmapHolder
{
std::shared_ptr<QImage> objBitmap; // main object bitmap
std::shared_ptr<QImage> flagBitmap; // flag bitmap for the object (probably only for heroes and boats with heroes)
AnimBitmapHolder(std::shared_ptr<QImage> objBitmap_ = nullptr, std::shared_ptr<QImage> flagBitmap_ = nullptr)
: objBitmap(objBitmap_),
flagBitmap(flagBitmap_)
{}
};
private:
int index(int x, int y, int z) const;
int index(const int3 &) const;
2022-08-30 04:38:24 +02:00
std::shared_ptr<QImage> findFlagBitmapInternal(std::shared_ptr<Animation> animation, int anim, int group, ui8 dir, bool moving) const;
std::shared_ptr<QImage> findFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor * color, int group) const;
2022-08-30 04:38:24 +02:00
AnimBitmapHolder findObjectBitmap(const CGObjectInstance * obj, int anim) const;
2022-08-30 00:44:02 +02:00
//FIXME: unique_ptr should be enough, but fails to compile in MSVS 2013
2022-08-30 02:48:44 +02:00
typedef std::map<std::string, std::shared_ptr<Animation>> TFlippedAnimations; //[type, rotation]
typedef std::map<std::string, std::vector<std::shared_ptr<QImage>>> TFlippedCache;//[type, view type, rotation]
2022-08-30 00:44:02 +02:00
TFlippedAnimations terrainAnimations;//[terrain type, rotation]
TFlippedCache terrainImages;//[terrain type, view type, rotation]
2022-08-30 00:44:02 +02:00
TFlippedAnimations roadAnimations;//[road type, rotation]
TFlippedCache roadImages;//[road type, view type, rotation]
2022-08-30 00:44:02 +02:00
TFlippedAnimations riverAnimations;//[river type, rotation]
TFlippedCache riverImages;//[river type, view type, rotation]
std::vector<TileObjects> ttiles; //informations about map tiles
int3 sizes; //map size (x = width, y = height, z = number of levels)
const CMap * map;
enum class EMapCacheType : char
{
TERRAIN, OBJECTS, ROADS, RIVERS, FOW, HEROES, HERO_FLAGS, FRAME, AFTER_LAST
};
void initObjectRects();
void initTerrainGraphics();
QRgb getTileColor(int x, int y, int z);
public:
MapHandler();
~MapHandler() = default;
void reset(const CMap * Map);
void updateWater();
2022-09-01 03:51:29 +02:00
void drawTerrainTile(QPainter & painter, int x, int y, int z);
2022-08-30 04:38:24 +02:00
/// draws a river segment on current tile
void drawRiver(QPainter & painter, int x, int y, int z);
2022-08-30 04:38:24 +02:00
/// draws a road segment on current tile
void drawRoad(QPainter & painter, int x, int y, int z);
void invalidate(int x, int y, int z); //invalidates all objects in particular tile
void invalidate(CGObjectInstance *); //invalidates object rects
void invalidate(const std::vector<int3> &); //invalidates all tiles
std::vector<int3> geTilesUnderObject(CGObjectInstance *) const;
2022-08-30 04:38:24 +02:00
/// draws all objects on current tile (higher-level logic, unlike other draw*** methods)
2022-09-01 03:51:29 +02:00
void drawObjects(QPainter & painter, int x, int y, int z);
void drawObject(QPainter & painter, const TileObject & object);
void drawObjectAt(QPainter & painter, const CGObjectInstance * object, int x, int y);
std::vector<TileObject> & getObjects(int x, int y, int z);
2022-08-30 02:15:54 +02:00
void drawMinimapTile(QPainter & painter, int x, int y, int z);
2022-08-30 00:44:02 +02:00
static bool compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b);
};
#endif // MAPHANDLER_H