-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHexModel.hpp
132 lines (110 loc) · 3.79 KB
/
HexModel.hpp
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
#ifndef HEXMODEL_HPP
#define HEXMODEL_HPP
#include <QObject>
#include <QPair>
#include <QMap>
#include "RegionModel.hpp"
// Hex borders.
static const int DRAW_NO_BORDER = 0;
static const int DRAW_UPPER_LEFT_BORDER = 1;
static const int DRAW_UPPER_CENTER_BORDER = 2;
static const int DRAW_UPPER_RIGHT_BORDER = 4;
static const int DRAW_LOWER_RIGHT_BORDER = 8;
static const int DRAW_LOWER_CENTER_BORDER = 16;
static const int DRAW_LOWER_LEFT_BORDER = 32;
class HexModel : public QObject
{
Q_OBJECT
signals:
void hexModelUpdated(int x, int y);
void hexTriggered(Qt::MouseButton button, int x, int y);
private:
// Save
int xPos;
int yPos;
int region; // -1, if it isn't associated with any region.
bool enable;
bool selected;
bool active;
bool bad;
int visibleBorders;
int representativeBorders;
// Initilized
QMap<int, HexModel *> adjacentHexes; // Int represents the border of this hex on which the hex borders on.
// Save
bool regionNumberShown;
bool frontier;
bool sea;
QString basePixmap;
bool representativeHex;
// Derive later.
RegionModel *regionModel; // Set, only if representativeHex = true.
public:
HexModel(int xPos = -1, int yPos = -1, bool enable = true, int visibleBorders = DRAW_NO_BORDER, QObject *parent = 0);
void addVisibleBorders(int visibleBorders);
void removeVisibleBorders(int visibleBorders);
void toggleFrontier();
void updateHex();
public:
// Get-Methods
bool isEnabled() const;
int getVisibleBorders() const;
int getRepresentativeBorders() const;
int x() const;
int y() const;
int getRegion() const;
QMap<int, HexModel *> getAdjacentHexes() const;
QSet<HexModel *> getAdjacentSeaHexes() const;
bool showRegionNumber() const;
bool isFrontier() const;
bool isSea() const;
QString getBasePixmap() const;
bool isRepresentativeHex() const;
bool isSelected() const;
bool isActive() const;
bool activeIsBad() const;
// Set-Methods
void setEnable(bool enable);
void setVisibleBorders(int visibleBorders);
// Has to be at most 6 hexes.
void setAdjacentHexes(QMap<int, HexModel *> &adjacentHexes);
void triggerHex(Qt::MouseButton button);
void setRegion(int region);
void unsetRegion();
void setRegionModel(RegionModel *regionModel);
void unsetRegionModel();
void setRegionNumberShown(bool show);
void setFrontier(bool frontier);
void setSea(bool sea);
void setBasePixmap(const QString &basePixmap);
void setRepresentativeHex(bool representative, RegionModel *regionModel);
void setSelected(bool selected);
void setActive(bool active, bool isBad = true);
// Ref-Methods
RegionModel *refRegionModel();
private:
// Return the draw border constant of this hex. Remember: You can convert it to the opposite side with oppositeBorder().
int borderAdjacentTo(HexModel *hexModel) const;
void privateAddVisibleBorders(int visibleBorders);
void privateRemoveVisibleBorders(int visibleBorders);
public:
// Serialization
void serialize(QDataStream &writer) const;
void deserialize(QDataStream &reader);
};
inline int oppositeBorder(int visibleBorder)
{
int result = 0;
switch(visibleBorder)
{
case DRAW_UPPER_LEFT_BORDER: result = DRAW_LOWER_RIGHT_BORDER; break;
case DRAW_UPPER_CENTER_BORDER: result = DRAW_LOWER_CENTER_BORDER; break;
case DRAW_UPPER_RIGHT_BORDER: result = DRAW_LOWER_LEFT_BORDER; break;
case DRAW_LOWER_RIGHT_BORDER: result = DRAW_UPPER_LEFT_BORDER; break;
case DRAW_LOWER_CENTER_BORDER: result = DRAW_UPPER_CENTER_BORDER; break;
case DRAW_LOWER_LEFT_BORDER: result = DRAW_UPPER_RIGHT_BORDER; break;
default: break;
}
return result;
}
#endif // HEXMODEL_HPP