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

177 lines
3.0 KiB
C
Raw Normal View History

2022-09-05 02:19:21 +02:00
#ifndef SCENELAYER_H
#define SCENELAYER_H
#include "../lib/int3.h"
2022-09-05 12:10:39 +02:00
class MapSceneBase;
2022-09-05 02:19:21 +02:00
class MapScene;
class CGObjectInstance;
class MapController;
class CMap;
class MapHandler;
2022-09-06 13:20:11 +02:00
class AbstractLayer : public QObject
2022-09-05 02:19:21 +02:00
{
2022-09-06 13:20:11 +02:00
Q_OBJECT
2022-09-05 02:19:21 +02:00
public:
2022-09-05 12:10:39 +02:00
AbstractLayer(MapSceneBase * s);
2022-09-05 02:19:21 +02:00
virtual void update() = 0;
void show(bool show);
void redraw();
void initialize(MapController & controller);
protected:
2022-09-05 12:10:39 +02:00
MapSceneBase * scene;
2022-09-05 02:19:21 +02:00
CMap * map = nullptr;
MapHandler * handler = nullptr;
bool isShown = false;
std::unique_ptr<QPixmap> pixmap;
QPixmap emptyPixmap;
private:
std::unique_ptr<QGraphicsPixmapItem> item;
};
class GridLayer: public AbstractLayer
{
2022-09-06 13:20:11 +02:00
Q_OBJECT
2022-09-05 02:19:21 +02:00
public:
2022-09-05 12:10:39 +02:00
GridLayer(MapSceneBase * s);
2022-09-05 02:19:21 +02:00
void update() override;
};
class PassabilityLayer: public AbstractLayer
{
2022-09-06 13:20:11 +02:00
Q_OBJECT
2022-09-05 02:19:21 +02:00
public:
2022-09-05 12:10:39 +02:00
PassabilityLayer(MapSceneBase * s);
2022-09-05 02:19:21 +02:00
void update() override;
};
class SelectionTerrainLayer: public AbstractLayer
{
2022-09-06 13:20:11 +02:00
Q_OBJECT
2022-09-05 02:19:21 +02:00
public:
2022-09-06 13:20:11 +02:00
SelectionTerrainLayer(MapSceneBase* s);
2022-09-05 02:19:21 +02:00
void update() override;
void draw();
void select(const int3 & tile);
void erase(const int3 & tile);
void clear();
const std::set<int3> & selection() const;
2022-09-06 13:20:11 +02:00
signals:
void selectionMade(bool anythingSlected);
2022-09-05 02:19:21 +02:00
private:
std::set<int3> area, areaAdd, areaErase;
2022-09-06 13:20:11 +02:00
void onSelection();
2022-09-05 02:19:21 +02:00
};
class TerrainLayer: public AbstractLayer
{
2022-09-06 13:20:11 +02:00
Q_OBJECT
2022-09-05 02:19:21 +02:00
public:
2022-09-05 12:10:39 +02:00
TerrainLayer(MapSceneBase * s);
2022-09-05 02:19:21 +02:00
void update() override;
void draw(bool onlyDirty = true);
void setDirty(const int3 & tile);
private:
std::set<int3> dirty;
};
class ObjectsLayer: public AbstractLayer
{
2022-09-06 13:20:11 +02:00
Q_OBJECT
2022-09-05 02:19:21 +02:00
public:
2022-09-05 12:10:39 +02:00
ObjectsLayer(MapSceneBase * s);
2022-09-05 02:19:21 +02:00
void update() override;
void draw(bool onlyDirty = true); //TODO: implement dirty
void setDirty(int x, int y);
void setDirty(const CGObjectInstance * object);
private:
std::set<const CGObjectInstance *> dirty;
};
class SelectionObjectsLayer: public AbstractLayer
{
2022-09-06 13:20:11 +02:00
Q_OBJECT
2022-09-05 02:19:21 +02:00
public:
2022-09-06 13:20:11 +02:00
SelectionObjectsLayer(MapSceneBase* s);
2022-09-05 02:19:21 +02:00
void update() override;
void draw();
CGObjectInstance * selectObjectAt(int x, int y) const;
void selectObjects(int x1, int y1, int x2, int y2);
void selectObject(CGObjectInstance *, bool inform = true);
2022-09-05 02:19:21 +02:00
bool isSelected(const CGObjectInstance *) const;
std::set<CGObjectInstance*> getSelection() const;
void moveSelection(int x, int y);
void clear();
QPoint shift;
CGObjectInstance * newObject;
2022-09-06 13:20:11 +02:00
//FIXME: magic number
2022-09-05 02:19:21 +02:00
int selectionMode = 0; //0 - nothing, 1 - selection, 2 - movement
2022-09-06 13:20:11 +02:00
signals:
void selectionMade(bool anythingSlected);
2022-09-05 02:19:21 +02:00
private:
std::set<CGObjectInstance *> selectedObjects;
2022-09-06 13:20:11 +02:00
void onSelection();
2022-09-05 02:19:21 +02:00
};
2022-09-05 12:10:39 +02:00
class MinimapLayer: public AbstractLayer
{
public:
MinimapLayer(MapSceneBase * s);
void update() override;
};
2022-09-05 14:28:47 +02:00
class MinimapViewLayer: public AbstractLayer
{
public:
MinimapViewLayer(MapSceneBase * s);
void setViewport(int x, int y, int w, int h);
void draw();
void update() override;
int viewportX() const {return x;}
int viewportY() const {return y;}
int viewportWidth() const {return w;}
int viewportHeight() const {return h;}
private:
int x = 0, y = 0, w = 1, h = 1;
};
2022-09-05 02:19:21 +02:00
#endif // SCENELAYER_H