-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTip.cpp
55 lines (38 loc) · 1011 Bytes
/
Tip.cpp
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
//
// Created by iMer on 16.04.2016.
//
#include "Tip.hpp"
#include <Engine/Scene.hpp>
#include <Engine/Text.hpp>
#include <limits>
Tip::Tip(engine::Scene* scene): SpriteNode(scene), m_clearTimer(std::numeric_limits<float>::infinity()) {
}
Tip::~Tip() {
}
bool Tip::initialize(Json::Value& root) {
if (!engine::SpriteNode::initialize(root)) {
return false;
}
m_text = root.get("tip", "someone [IMER] forgot to put text for the tip.. mmmh").asString();
return true;
}
void Tip::Show() {
engine::Node* t = m_scene->GetUi()->GetChildByID("tip");
if (t) {
static_cast<engine::Text*>(t)->SetText(m_text);
}
m_clearTimer = 15;
}
void Tip::OnUpdate(sf::Time interval) {
m_clearTimer -= interval.asSeconds();
if (m_clearTimer < 0) {
m_clearTimer = std::numeric_limits<float>::infinity();
engine::Node* t = m_scene->GetUi()->GetChildByID("tip");
if (t) {
engine::Text* text = static_cast<engine::Text*>(t);
if (text->GetText() == m_text) {
text->SetText("");
}
}
}
}