-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeaderBoard.cpp
More file actions
124 lines (114 loc) · 3.39 KB
/
Copy pathLeaderBoard.cpp
File metadata and controls
124 lines (114 loc) · 3.39 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
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "LeaderBoard.h"
void LeaderBoard::initKeybinds()
{
std::ifstream ifs("Config/LeaderboardKeybinds.ini.txt");
if (ifs.is_open()) {
std::string key = "", key2 = "";
while (ifs >> key >> key2) {
this->keybinds[key] = this->supportedKeys->at(key2);
}
}
ifs.close();
}
void LeaderBoard::initFonts()
{
if (!this->font.loadFromFile("Fonts/Minecraft.ttf")) {
throw("ERROR::Leaderboard::COULD NOT LOAD FONT");
}
}
void LeaderBoard::initBackground()
{
this->background.setSize(sf::Vector2f(static_cast<float>(this->window->getSize().x), static_cast<float>(this->window->getSize().y)));
if (!this->backgroundTexture.loadFromFile("Resources/BackGround/Mainmenu.jpg")) {
throw("ERROR::Leaderboard::COULD NOT LOAD BACKGROUND TEXTURE");
}
this->background.setTexture(&backgroundTexture);
}
void LeaderBoard::initGUI()
{
this->textures["UI_texture"].loadFromFile("Resources/UI/panel_Example1.png");
this->leaderboard = new gui::textbox(600, 100, 400, 100, sf::Color(255, 255, 255, 255),
"Leader Board",
&this->font, 50, sf::Color::Black, &this->textures["UI_texture"], false
);
this->textures["BTN"].loadFromFile("Resources/UI/Btn.png");
this->quitBTN = new gui::Button(650, 750, 300.f, 75.f,
&this->font, "Quit", 30,
sf::Color::Black, sf::Color::Black, sf::Color::Black,
sf::Color(255, 255, 255, 255), sf::Color(255, 255, 255, 220), sf::Color(20, 20, 20, 200),
sf::Color::Transparent, sf::Color::Transparent, sf::Color::Transparent,
&this->textures["BTN"]);
this->squre.setTexture(&this->textures["UI_texture"]);
this->squre.setPosition(100, 100);
this->squre.setSize(sf::Vector2f(1400, 700));
}
void LeaderBoard::initScore()
{
std::ifstream ifs("Config/LeaderBoardScore.txt");
if (ifs.is_open()) {
std::string name;
unsigned int score;
for (int i = 0; i < 5; i++) {
if (!(ifs >> name >> score)) return;
this->playerscore[i] = new gui::textbox(300, 200+i*100, 1000, 100, sf::Color::Transparent,
std::to_string(i+1) + "." + name + " Score:" + std::to_string(score),
&this->font, 30, sf::Color::Black
);
}
}
ifs.close();
}
LeaderBoard::LeaderBoard(sf::RenderWindow* window, std::map<std::string, int>* supportedKeys, std::stack<State*>* states)
: State(window, supportedKeys, states)
{
this->initKeybinds();
this->initFonts();
this->initBackground();
this->initGUI();
this->initBackground();
this->initScore();
pfirefly = new pFirefly(50);
}
LeaderBoard::~LeaderBoard()
{
delete this->leaderboard;
for (int i = 0; i < 5; i++)
delete this->playerscore[i];
}
void LeaderBoard::UpdateInput(const float& deltaTime)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key(this->keybinds.at("CLOSE"))) && this->getKeytime()) {
this->endState();
}
}
void LeaderBoard::UpdateGUI(const float& deltaTime)
{
//button
this->quitBTN->Update(this->mousePosView);
if (this->quitBTN->isPressed()) {
this->endState();
}
}
void LeaderBoard::Update(const float& deltaTime)
{
this->UpdateMousePositions();
this->UpdateKeytime(deltaTime);
this->UpdateInput(deltaTime);
this->UpdateGUI(deltaTime);
pfirefly->Update(deltaTime);
}
void LeaderBoard::Render(sf::RenderTarget* target)
{
if (!target) {
target = this->window;
}
target->draw(this->background);
pfirefly->Render(target);
target->draw(this->squre);
this->leaderboard->Render(*target);
for (int i = 0; i < 5; i++) {
if(this->playerscore[i])
this->playerscore[i]->Render(*target);
}
this->quitBTN->Render(*target);
}