Repository navigation
Expand file tree
/
Copy pathui.cpp
More file actions
83 lines (74 loc) · 1.76 KB
/
Copy pathui.cpp
File metadata and controls
83 lines (74 loc) · 1.76 KB
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
#include <managers.h>
bool flagHover = false;
bool flagClick = false;
UIManager* UI;
UIManager::UIManager(){
UI = this;
}
void UIManager::updateUI(){
int size = UIElements.size();
for (int i = 0; i < size; ++i){
UIElements[i].update();
}
while (!(messageQueue.empty())){
handleMessage(dispatchMessage());
}
for (int i = 0; i < size; ++i){
UIElements[i].renderMe();
}
}
UIMessage UIManager::dispatchMessage(){
UIMessage temp = messageQueue.front();
messageQueue.pop();
return temp;
}
void UIManager::pushMessage(UIMessage msg){
messageQueue.push(msg);
}
void UIManager::createElement(UIElement* element){
UIElements.push_back(*element);
}
void UIManager::handleMessage(UIMessage msg){
switch (msg.type){
case buttonClick:
switch (msg.id){
case 23137:
Entities->getEntities().push_back(new Enemy);
}
}
}
Button::Button(int x, int y, int w, int h, std::string textt, int idd){
dimensions.x = x;
dimensions.y = y;
dimensions.w = w;
dimensions.h = h;
currTexture.second = &dimensions;
text = textt;
id = idd;
type = button;
}
void Button::renderMe(){
Graphics->render(&currTexture, spriteRender);
}
void Button::update(){
if (!flagHover && Collision->pointIn(Input->getInput()->mx, Input->getInput()->my, dimensions)){
flagHover = true;
currTexture.first = textureHover;
}
if (flagHover && !(Collision->pointIn(Input->getInput()->mx, Input->getInput()->my, dimensions))){
flagHover = false;
currTexture.first = textureDefault;
}
if (flagHover && flagClick && Input->getInput()->m1){
flagClick = false;
currTexture.first = textureClick;
}
if (!flagClick && !(Input->getInput()->m1)){
flagClick = true;
currTexture.first = textureDefault;
UIMessage msg;
msg.type = buttonClick;
msg.id = this->id;
UI->pushMessage(msg);
}
}