26{
27 clear();
28
29 this->addWidget(std::make_unique<WText>("<h2>Hall of fame</h2>"));
30
32
33 std::string yourScore;
34 if (ranking == 1)
35 yourScore = "Congratulations! You are currently leading the pack.";
36 else {
37 yourScore = "You are currently ranked number "
38 + asString(ranking).toUTF8()
39 + ". Almost there !";
40 }
41
42 WText *score = this->addWidget(std::make_unique<WText>("<p>" + yourScore + "</p>"));
43 score->addStyleClass("score");
44
46
47 WTable *table = this->addWidget(std::make_unique<WTable>());
48
49 table->elementAt(0, 0)->addWidget(std::make_unique<WText>("Rank"));
50 table->elementAt(0, 1)->addWidget(std::make_unique<WText>("User"));
51 table->elementAt(0, 2)->addWidget(std::make_unique<WText>("Games"));
52 table->elementAt(0, 3)->addWidget(std::make_unique<WText>("Score"));
53 table->elementAt(0, 4)->addWidget(std::make_unique<WText>("Last game"));
54 table->setHeaderCount(1);
55
56 int formerScore = -1;
57 int rank = 0;
58 for (auto& user : top) {
59
60 if (user.score != formerScore) {
61 formerScore = user.score;
62 ++rank;
63 }
64
65 int row = table->rowCount();
66 table->elementAt(row, 0)->addWidget(std::make_unique<WText>(asString(rank)));
67 table->elementAt(row, 1)->addWidget(std::make_unique<WText>(user.name));
68 table->elementAt(row, 2)->addWidget(std::make_unique<WText>(asString(user.gamesPlayed)));
69 table->elementAt(row, 3)->addWidget(std::make_unique<WText>(asString(user.score)));
70 if (!user.lastGame.isNull())
71 table->elementAt(row, 4)->addWidget(std::make_unique<WText>(user.lastGame.timeTo(WDateTime::currentDateTime())
72 + " ago"));
73 else
74 table->elementAt(row, 4)->addWidget(std::make_unique<WText>("---"));
75
77 table->rowAt(row)->setId("self");
78 }
79
80 WText *fineprint = this->addWidget(std::make_unique<WText>(tr("highscore.info")));
81 fineprint->addStyleClass("fineprint");
82}
std::vector< User > topUsers(int limit)
std::string userName() const