2022-08-31 20:05:57 +02:00
|
|
|
#ifndef MAPVIEW_H
|
|
|
|
#define MAPVIEW_H
|
|
|
|
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
#include <QGraphicsView>
|
2022-09-01 03:51:29 +02:00
|
|
|
#include "../lib/int3.h"
|
2022-08-31 20:05:57 +02:00
|
|
|
|
2022-09-01 03:51:29 +02:00
|
|
|
class int3;
|
2022-08-31 20:05:57 +02:00
|
|
|
class MainWindow;
|
|
|
|
class MapScene;
|
|
|
|
|
|
|
|
class BasicView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicView(MainWindow * m, MapScene * s);
|
|
|
|
|
|
|
|
virtual void update() = 0;
|
|
|
|
|
|
|
|
void show(bool show);
|
2022-09-01 03:51:29 +02:00
|
|
|
void redraw();
|
2022-08-31 20:05:57 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
MainWindow * main;
|
|
|
|
MapScene * scene;
|
|
|
|
bool isShown = false;
|
|
|
|
|
|
|
|
std::unique_ptr<QPixmap> pixmap;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<QGraphicsPixmapItem> item;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MapView : public QGraphicsView
|
|
|
|
{
|
2022-09-01 03:51:29 +02:00
|
|
|
public:
|
|
|
|
enum class SelectionTool
|
|
|
|
{
|
|
|
|
None, Brush, Brush2, Brush4, Area, Lasso
|
|
|
|
};
|
|
|
|
|
2022-08-31 20:05:57 +02:00
|
|
|
public:
|
|
|
|
MapView(QWidget *parent);
|
|
|
|
|
|
|
|
void setMain(MainWindow * m);
|
|
|
|
|
2022-09-01 03:51:29 +02:00
|
|
|
SelectionTool selectionTool;
|
|
|
|
|
2022-08-31 20:05:57 +02:00
|
|
|
public slots:
|
|
|
|
void mouseMoveEvent(QMouseEvent * mouseEvent) override;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MainWindow * main;
|
2022-09-01 03:51:29 +02:00
|
|
|
|
|
|
|
QPointF mouseStart;
|
|
|
|
int3 tileStart;
|
|
|
|
int3 tilePrev;
|
|
|
|
bool pressedOnSelected;
|
2022-08-31 20:05:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class GridView: public BasicView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GridView(MainWindow * m, MapScene * s);
|
|
|
|
|
|
|
|
void update() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PassabilityView: public BasicView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PassabilityView(MainWindow * m, MapScene * s);
|
|
|
|
|
|
|
|
void update() override;
|
|
|
|
};
|
|
|
|
|
2022-09-01 03:51:29 +02:00
|
|
|
class SelectionTerrainView: public BasicView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SelectionTerrainView(MainWindow * m, MapScene * s);
|
|
|
|
|
|
|
|
void update() override;
|
|
|
|
|
|
|
|
void draw();
|
|
|
|
void select(const int3 & tile);
|
|
|
|
void erase(const int3 & tile);
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
const std::set<int3> & selection() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::set<int3> area, areaAdd, areaErase;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TerrainView: public BasicView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TerrainView(MainWindow * m, MapScene * s);
|
|
|
|
|
|
|
|
void update() override;
|
|
|
|
|
|
|
|
void draw(bool onlyDirty = true);
|
|
|
|
void setDirty(const int3 & tile);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::set<int3> dirty;
|
|
|
|
};
|
|
|
|
|
2022-08-31 20:05:57 +02:00
|
|
|
class MapScene : public QGraphicsScene
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MapScene(MainWindow *parent, int l);
|
|
|
|
|
2022-09-01 03:51:29 +02:00
|
|
|
void updateViews();
|
2022-08-31 20:05:57 +02:00
|
|
|
|
|
|
|
GridView gridView;
|
|
|
|
PassabilityView passabilityView;
|
2022-09-01 03:51:29 +02:00
|
|
|
SelectionTerrainView selectionTerrainView;
|
|
|
|
TerrainView terrainView;
|
2022-08-31 20:05:57 +02:00
|
|
|
|
|
|
|
const int level;
|
|
|
|
|
|
|
|
private:
|
|
|
|
MainWindow * main;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MAPVIEW_H
|