-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextTagSystem.h
150 lines (115 loc) · 2.58 KB
/
TextTagSystem.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
144
145
146
147
148
149
#pragma once
#include "State.h"
enum class TagTypes
{
Default = 0,
Negative,
Positive,
Experience,
Environmental
};
class TextTagSystem
{
private:
// Nested class:
class TextTag
{
private:
// Variables:
sf::Text text;
float dirX;
float dirY;
float lifetime;
float speed;
public:
// Constructors and Distructor:
TextTag
(
float x, float y,
float dir_x, float dir_y,
sf::Font& font, std::string str,
sf::Color color,
unsigned int char_size,
float lifetime, float speed
)
{
this->text.setFont(font);
this->text.setPosition(x, y);
this->text.setFillColor(color);
this->text.setCharacterSize(char_size);
this->text.setString(str);
this->dirX = dir_x;
this->dirY = dir_y;
this->lifetime = lifetime;
this->speed = speed;
}
TextTag
(
TextTag* tag,
float x, float y,
std::string str
)
{
this->text = tag->text;
this->text.setString(str);
this->text.setPosition(x, y);
this->dirX = tag->dirX;
this->dirY = tag->dirY;
this->lifetime = tag->lifetime;
this->speed = tag->speed;
}
~TextTag()
{
}
//Accessors:
inline const bool isExpired() const { return this->lifetime <= 0.f; }
// Functions:
void update(const float& dt)
{
if (this->lifetime > 0.f)
{
// Updating lifetime
this->lifetime -= 100.f * dt;
// Moving tag
this->text.move(this->dirX * this->speed * dt, this->dirY * this->speed * dt);
}
}
void render(sf::RenderTarget& target)
{
target.draw(this->text);
}
};
// Variables:
sf::Font font;
// std::map<const int, TextTag*> textTagTemplates;
std::map<const TagTypes, TextTag*> tagTemplates;
std::vector<TextTag*> tags;
StateData* stateData;
// private: Functions:
void initVariables();
void initFont(const std::string file_path);
void initTagTemplates();
public:
// Constructors and Distructor:
TextTagSystem(StateData* state_data, const std::string font_file_path);
virtual ~TextTagSystem();
// Functions:
// void addTextTag(const int tag_type);
void addTextTag
(
const TagTypes tag_type, const float x, const float y,
const std::string str, const std::string prefix = "", const std::string postfix = ""
);
void addTextTag
(
const TagTypes tag_type, const float x, const float y, const int int_value,
const std::string prefix = "", const std::string postfix = ""
);
void addTextTag
(
const TagTypes tag_type, const float x, const float y, const float float_value,
const std::string prefix = "", const std::string postfix = ""
);
void update(const float& dt);
void render(sf::RenderTarget& target);
};