-
Notifications
You must be signed in to change notification settings - Fork 1
/
scene_if.h
117 lines (86 loc) · 3.51 KB
/
scene_if.h
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
#ifndef SCENE_IF_H
#define SCENE_IF_H
#include <QList>
#include <QPainter>
#include <QCursor>
#include "gameitem.h"
#include "scaler.h"
#define MAX_COLS 16
#define MAX_ROWS 16
class BaseItem;
struct PlaceInfo
{
PlaceInfo() : item(0), place(NoPlace)
{
}
inline bool hasItem() const { return item; }
inline bool empty() const { return !(place & PlaceConcrete); }
inline bool freePlaceForItem() const { return !item && (place & PlaceConcrete); }
inline bool itemCanBeAppeared() const { return freePlaceForItem() && (place & ItemAppear); }
inline bool itemCanBeCreated() const { return freePlaceForItem() && (place & ItemStart); }
inline bool itemCanBeMoved() const { return item && !(place & Blocks) && (item->isIdle() || item->isSelected()); }
inline bool itemCanBeHighlighted() const { return item && (item->isIdle() || item->isSelected()); }
inline bool hasTarget() const { return place & Targets; }
inline bool hasBlock() const { return place & Blocks; }
inline bool isProcessed() const { return place & Processed; }
inline void setProcessed() { place |= Processed; }
inline void setUnprocessed() { place &= ~Processed; }
GameItem *item;
quint32 place;
};
class IScene
{
public:
IScene();
~IScene() {}
void createPixmapPopup(int x, int y, int dx, int dy, const QPixmap &pm, int steps);
void createScorePopup(int x, int y, int score);
void createStaticPopup(QRect rect, const QString &text, int textFlags,
const QFont &font, QColor color = Qt::white,
qreal opacity = 1, int staysteps = 0, int steps = 10,
int dx = 0, int dy = 0);
inline void showHint(const QString &hint) {hintText = hint;}
inline void removeHint() { if (!hintText.isEmpty()) hintText = ""; }
void drawTransRect(QPainter &p, const QRect &r,
QColor borderColor = Qt::white, QColor bgColor = Qt::black,
qreal opacity = 0.3);
inline int col2x(int val) const { return val*X56+DX(xoff); }
inline int row2y(int val) const { return val*Y56+DY(yoff); }
inline int item_col2x(int val) const { return val*X56+DX(xoff+4); }
inline int item_row2y(int val) const { return val*Y56+DY(yoff+4); }
inline const PlaceInfo* data() const { return field; }
inline PlaceInfo& data(int r, int c) { return field[(r << 4) | c]; }
inline int numRows() const { return rows; }
inline int numCols() const { return cols; }
inline const QList<int>& gameItems() { return activeItems; }
inline const QPixmap& itemPixmap(int id) const { return allItems.at(id); }
inline int randomItemId() { return activeItems.at(qrand() % activeItems.count()); }
void removeAndCountItem(int row, int col);
void removeAndCountItemOnly(int row, int col); // only for small hammer
void removeBlock(PlaceInfo &pi, int row, int col);
void removeTarget(PlaceInfo &pi, int row, int col);
void addTime(int time);
void setDefaultGameCursor();
void restoreCursor();
protected:
void drawTextHint(QPainter &p);
QList<BaseItem*> tempItems;
QCursor lastCursor;
PlaceInfo field[MAX_ROWS*MAX_COLS];
int rows, cols;
int xoff, yoff;
int time;
int bonus, bonus_time;
int targets;
int score;
int level, max_level;
QPixmap concrete;
QPixmap block1, block2;
QPixmap target1, target2;
QPixmap bgpicture;
QList<int> activeItems;
QList<QPixmap> allItems;
QString hintText;
};
extern IScene * scene;
#endif // SCENE_IF_H