-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHud.h
143 lines (101 loc) · 2.46 KB
/
Hud.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
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
#pragma once
#include <QWidget>
#include <QTimer>
#include <QPainter>
#include "RigidBody.h"
#include "Definitions.h"
#include "Animator.h"
#include "Sprites.h"
class ClickableObject {
public:
virtual bool processClick() = 0;
};
class BaseGUI : public RigidBody, public ClickableObject {
protected:
bool show = true;
Animator anim;
std::vector<BaseGUI*> children;
TexManager::TexID id;
public:
void setShow(bool value) {
show = value;
//std::cout << "Setting show " << value << "\n";
}
void restartAnimation() {
anim.restartAnimation();
}
bool getShow() const { return show; }
BaseGUI(QPointF pos, TexManager::TexID id, uint ZValue = 2) : RigidBody(pos, QPointF(0,0), 1, 1 ) {
setTexture(id);
setObjectId(objects::HUD);
setZValue(ZValue);
rigiddrawscale = 0.936;
}
BaseGUI* setTexture(TexManager::TexID id) {
this->id = id;
anim.setAnimatable(TextureManager::getInstance().getAnimatable(id));
return this;
}
virtual bool processClick() {
return 0;
}
void tick(double delta) {
if(getShow())
anim.tick(delta);
}
void addChild(BaseGUI* element) {
children.push_back(element);
}
void removeChild(BaseGUI* element) {
}
QPixmap getTexture() { return anim.getCurrentPixmap(); }
void playOneShot(TexManager::TexID id) { anim.playOneShot(TextureManager::getInstance().getAnimatable(id)); }
void render(QGraphicsScene& scene, bool shouldClear) override {
if (show && !shouldClear) {
QPen qp;
qp.setColor(Qt::blue);
KA::RectF rf = getColliderRectF();
if (!pm) {
pm = scene.addPixmap(getTexture());
pm->setZValue(getZValue());
}
pm->setPixmap(getTexture());
pm->setPos(Camera::fromPercentageToScreen(QPointF(getX(), getY())));
pm->setScale(scale * rigiddrawscale * gui_scalemultiplier / scalemultiplier);
if (hitboxenabled) {
QPointF p = Camera::fromPercentageToScreen(QPointF(rf.pos.x, rf.pos.y));
if (hitbox) {
scene.removeItem(hitbox);
delete hitbox;
}
hitbox = scene.addRect(QRect(p.x(), p.y(), rf.size.x * scalefactor, rf.size.y * scalefactor), qp);
}
}
else if (pm) {
scene.removeItem(pm);
delete pm;
pm = 0;
if (hitbox) {
scene.removeItem(hitbox);
delete hitbox;
hitbox = 0;
}
}
}
};
class PauseGUI : public BaseGUI {
PauseGUI(QPointF pos, TexManager::TexID id, uint ZValue = 2) : BaseGUI(pos, id, ZValue) {
}
};
class HUD : public QWidget
{
Q_OBJECT
private:
public:
protected slots:
};
class ScoreItem
{
private:
public:
};