-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopUpText.cpp
More file actions
111 lines (92 loc) · 2.19 KB
/
Copy pathPopUpText.cpp
File metadata and controls
111 lines (92 loc) · 2.19 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
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
#include "headers.h"
#include "PopUpText.h"
PopUpText::PopUpText(float delay)
{
m_popUpTimer = new Timer{ delay };
m_textFont = new sf::Font{};
if(!m_textFont->loadFromFile("Fonts/PixellettersFull.ttf"))
{
std::cout << "ERROR::POPUPTEXT::Font could not load\n";
}
m_popUpText = new sf::Text{};
m_popUpText->setFont(*m_textFont);
m_popUpText->setString("");
m_popUpText->setCharacterSize(100.0f);
m_isTextShown = false;
m_smoothPooping = true;
}
PopUpText::~PopUpText()
{
delete m_textFont;
delete m_popUpText;
delete m_popUpTimer;
}
void PopUpText::update(float& timePerFrame)
{
m_popUpTimer->update(timePerFrame);
if (m_popUpTimer->getElapsedTime() > m_popUpTimer->getTimeMAX())
{
m_isTextShown = false;
}
else
{
if (m_smoothPooping == true)
{
sf::Color textColor{ m_popUpText->getFillColor() };
if (textColor.a < 255)
{
textColor.a += (int)100 * timePerFrame + 1;
m_popUpText->setFillColor(textColor);
if (textColor.a >= 255)
{
m_popUpText->setFillColor(sf::Color{ 255,255,255,255 });
}
}
}
else
{
m_popUpText->setFillColor(sf::Color{ 255,255,255,255 });
}
}
if (m_isTextShown == false)
{
this->hideText(timePerFrame);
}
}
void PopUpText::render(sf::RenderTarget* target)
{
if (m_popUpText->getFillColor() != sf::Color{255, 255, 255, 0})
{
target->draw(*m_popUpText);
}
}
void PopUpText::showText(std::string textToShow, float delay, bool showSmoothly)
{
m_popUpText->setString(textToShow);
m_popUpText->setFillColor(sf::Color{ 255,255,255,0 });
m_popUpTimer->setMAXtime(delay);
m_popUpTimer->restart(0.0f);
m_isTextShown = true;
m_smoothPooping = showSmoothly;
m_popUpText->setPosition(
Constants::WindowWidth / 2.0f - m_popUpText->getGlobalBounds().width / 2.0f,
Constants::WindowHeigth / 2.0f - m_popUpText->getGlobalBounds().height / 2.0f
);
}
void PopUpText::hideText(float& timePerFrame)
{
sf::Color textColor{ m_popUpText->getFillColor() };
if (textColor.a > 0)
{
textColor.a -= (int)100 * timePerFrame + 1;
m_popUpText->setFillColor(textColor);
if (textColor.a <= 40)
{
m_popUpText->setFillColor(sf::Color{ 255,255,255,0 });
}
}
}
const bool& PopUpText::isTextShown()
{
return m_isTextShown;
}