1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
/*
* scenelayer.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../lib/int3.h"
class MapSceneBase;
class MapScene;
class CGObjectInstance;
class MapController;
class CMap;
class MapHandler;
class AbstractLayer : public QObject
{
Q_OBJECT
public:
AbstractLayer(MapSceneBase * s);
virtual void update() = 0;
void show(bool show);
void redraw();
void initialize(MapController & controller);
protected:
MapSceneBase * scene;
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
{
Q_OBJECT
public:
GridLayer(MapSceneBase * s);
void update() override;
};
class PassabilityLayer: public AbstractLayer
{
Q_OBJECT
public:
PassabilityLayer(MapSceneBase * s);
void update() override;
};
class SelectionTerrainLayer: public AbstractLayer
{
Q_OBJECT
public:
SelectionTerrainLayer(MapSceneBase* s);
void update() override;
void draw();
void select(const int3 & tile);
void erase(const int3 & tile);
void clear();
const std::set<int3> & selection() const;
signals:
void selectionMade(bool anythingSlected);
private:
std::set<int3> area, areaAdd, areaErase;
void onSelection();
};
class TerrainLayer: public AbstractLayer
{
Q_OBJECT
public:
TerrainLayer(MapSceneBase * s);
void update() override;
void draw(bool onlyDirty = true);
void setDirty(const int3 & tile);
private:
std::set<int3> dirty;
};
class ObjectsLayer: public AbstractLayer
{
Q_OBJECT
public:
ObjectsLayer(MapSceneBase * s);
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 *> objDirty;
std::set<int3> dirty;
};
class SelectionObjectsLayer: public AbstractLayer
{
Q_OBJECT
public:
enum SelectionMode
{
NOTHING, SELECTION, MOVEMENT
};
SelectionObjectsLayer(MapSceneBase* s);
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);
void deselectObject(CGObjectInstance *);
bool isSelected(const CGObjectInstance *) const;
std::set<CGObjectInstance*> getSelection() const;
void clear();
QPoint shift;
CGObjectInstance * newObject;
//FIXME: magic number
SelectionMode selectionMode = SelectionMode::NOTHING;
signals:
void selectionMade(bool anythingSlected);
private:
std::set<CGObjectInstance *> selectedObjects;
void onSelection();
};
class MinimapLayer: public AbstractLayer
{
public:
MinimapLayer(MapSceneBase * s);
void update() override;
};
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;
};
|