-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUi.hpp
116 lines (100 loc) · 2.71 KB
/
Ui.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
/*
* File: Ui.hpp
* Author: iMer
*
* Created on 7. Dezember 2014, 00:05
*/
#ifndef LD31_UI_HPP
#define LD31_UI_HPP
#include <unordered_map>
#include <Engine/Node.hpp>
#include <Engine/Text.hpp>
#include <Engine/Factory.hpp>
#include <sstream>
#include "Cannon.hpp"
#include <Engine/Button.hpp>
class Ui : public engine::Node {
public:
class Slot : public engine::SpriteNode {
protected:
bool m_selected;
uint32_t m_count;
std::string m_projectile;
engine::Node* m_icon;
public:
Slot(engine::Scene* scene);
virtual ~Slot();
void SetCount(uint32_t count) {
Node* text = GetChildByID("count");
if (text && text->GetType() == engine::NT_TEXT) {
std::ostringstream ss;
ss << count;
static_cast<engine::Text*> (text)->SetText(ss.str());
}
m_count = count;
UpdateAnimation();
}
void SetIcon(std::string file) {
if (m_icon) {
m_icon->Delete();
}
m_icon = engine::Factory::CreateChildFromFile(file, this);
// ensure it's rendered before the text
m_children.remove(m_icon);
m_children.push_front(m_icon);
}
uint32_t GetCount() const {
return m_count;
}
void SetProjectile(std::string projectile) {
m_projectile = projectile;
}
std::string GetProjectile() const {
return m_projectile;
}
void SetSelected(bool selected) {
m_selected = selected;
UpdateAnimation();
}
bool IsSelected() const {
return m_selected;
}
void UpdateAnimation() {
if (m_selected){
if (m_count > 0){
PlayAnimation("selected");
} else {
PlayAnimation("selected_empty");
}
}else{
if (m_count > 0){
PlayAnimation("default");
} else {
PlayAnimation("empty");
}
}
}
};
protected:
std::unordered_map<uint8_t, Slot*> m_slots;
uint8_t m_currentSlot;
engine::Text* m_score;
engine::Button* m_next;
bool m_updateSelect;
bool m_init;
public:
Ui(engine::Scene* scene);
virtual ~Ui();
virtual bool initialize(Json::Value& root);
Slot* GetCurrentSlot();
engine::Text* GetScore() const {
return m_score;
}
engine::Button* GetNext() const {
return m_next;
}
protected:
virtual void OnUpdate(sf::Time interval);
bool Select();
};
#endif /* LD31_UI_HPP */