-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChooseUpgradeButton.cpp
67 lines (55 loc) · 1.41 KB
/
ChooseUpgradeButton.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "ChooseUpgradeButton.h"
#include "Logger.h"
#include "Game.h"
#include "PowerUpEventDispatcher.h"
void ChooseUpgradeButton::Init(std::string name, Render::TEXTURE_ID textureID, int x, int y, int width, int height, int spriteFrame)
{
InitSelectable(x, y, width, height);
UIImage::Init(name, textureID, x, y, width, height, spriteFrame);
m_btnText.Initialize(Render::TEXTURE_ID::BM_FONT_PIXEL,
"CHOOSE", Render::Pivot::CENTER, x + 80, y+15);
m_btnText.SetSpacing(14);
m_btnText.SetSize(24);
Game::CurrentScene->Add(this);
Game::CurrentScene->Add(&m_btnText);
m_shouldUpdate = true;
}
void ChooseUpgradeButton::CleanUp()
{
m_shouldUpdate = false;
Game::CurrentScene->Remove(this);
Game::CurrentScene->Remove(&m_btnText);
m_callback = nullptr;
}
void ChooseUpgradeButton::Update()
{
if (!m_shouldUpdate) return;
UpdateSelectable();
m_btnText.Update();
}
void ChooseUpgradeButton::OnMouseLeftClick()
{
if (m_cardSelectedValue < 0) return;
ChooseUpgrade();
}
void ChooseUpgradeButton::SetSelectedCard(PowerUpType type)
{
m_cardSelectedValue = type;
}
void ChooseUpgradeButton::SetCallBack(CallbackFunction callback)
{
m_callback = callback;
}
void ChooseUpgradeButton::TriggerCallBack()
{
if (m_callback)
{
m_callback();
}
}
void ChooseUpgradeButton::ChooseUpgrade()
{
if (m_cardSelectedValue < 0) return;
TriggerCallBack();
PowerUpEventDispatcher::Trigger(PowerUpEvent{ m_cardSelectedValue });
}