-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaderboard.cpp
50 lines (42 loc) · 1.14 KB
/
leaderboard.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
#include "leaderboard.h"
#include <QtDebug>
Leaderboard::Leaderboard(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
{
setVisible(0);
setAttribute(Qt::WA_TransparentForMouseEvents);
// setGeometry(0, 0, 300, 100);
setGraphicsEffect(effect);
effect->setOpacity(0.7);
setLayout(gridLayout);
gridLayout->setAlignment(Qt::AlignCenter);
gridLayout->addWidget(&lNr, 0, 0);
gridLayout->addWidget(&lPlayer, 0, 1);
gridLayout->addWidget(&lKills, 0, 2);
gridLayout->addWidget(&lDeaths, 0, 3);
}
void Leaderboard::addNewHero(HeroStats *hS)
{
heroes.push_back(hS);
LeaderboardSlot * leaderboardSlot = new LeaderboardSlot(this, hS);
leaderboardSlots.push_back(leaderboardSlot);
sortHeroes();
update();
}
void Leaderboard::update()
{
sortHeroes();
updateSlots();
}
void Leaderboard::sortHeroes()
{
std::sort(heroes.begin(), heroes.end(), [](HeroStats * lhs, HeroStats * rhs)
{
return lhs->getKills() > rhs->getKills();
});
}
void Leaderboard::updateSlots()
{
for (auto i = 0; i < leaderboardSlots.size(); i++)
leaderboardSlots[i]->setHeroStats(heroes[i]);
}