-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecent.cpp
95 lines (83 loc) · 2.26 KB
/
recent.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
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
#include "recent.h"
#include <SFML/Graphics.hpp>
#include <fstream>
#include <algorithm>
#include <iostream>
Recent::Recent()
{
background.loadFromFile("Textures/recentbg.jpg");
backSprite.setTexture(background);
backSprite.setColor(sf::Color(255, 255, 255, 100));
font.loadFromFile("Textures/DK-Lemon-Yellow-Sun.ttf");
title.setFont(font);
title.setString("Recent Matches");
title.setCharacterSize(50);
title.setFillColor(sf::Color::White);
title.setPosition(sf::Vector2f(250, 10));
header.setFont(font);
header.setString("Player\t\tTime");
header.setCharacterSize(35);
header.setFillColor(sf::Color::White);
header.setPosition(sf::Vector2f(270, 100));
cleanUp();
}
Recent::~Recent()
{
}
void Recent::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
target.draw(backSprite);
target.draw(title);
target.draw(header);
for (int i = 0; i < records.size(); i++)
{
target.draw(records.at(i));
}
}
void Recent::loadDetail()
{
if (!loaded)
{
std::ifstream fp;
std::string name;
int second;
fp.open("recent.dat");
while (!fp.eof())
{
fp >> name;
name_vec.push_back(name);
fp >> second;
sec_vec.push_back(second);
}
name_vec.pop_back();
sec_vec.pop_back();
std::reverse(name_vec.begin(), name_vec.end());
std::reverse(sec_vec.begin(), sec_vec.end());
fp.close();
int pos = 190;
if (name_vec.size() > 5)
records.resize(5);
else
records.resize(name_vec.size());
if (!name_vec.empty())
{
for (int i = 0; i < records.size(); i++)
{
records.at(i).setFont(font);
records.at(i).setString(name_vec.at(i) + "\t\t\t\t\t" + std::to_string(sec_vec.at(i)) + " sec");
records.at(i).setCharacterSize(20);
records.at(i).setFillColor(sf::Color::White);
records.at(i).setPosition(sf::Vector2f(270, pos));
pos += 50;
}
loaded = true;
}
}
}
void Recent::cleanUp()
{
records.clear();
name_vec.clear();
sec_vec.clear();
loaded = false;
}