Wt examples  3.3.0
Public Member Functions | Private Attributes | List of all members
HighScoresWidget Class Reference

#include <HighScoresWidget.h>

Inheritance diagram for HighScoresWidget:
Inheritance graph
[legend]

Public Member Functions

 HighScoresWidget (Session *session, Wt::WContainerWidget *parent=0)
 
void update ()
 

Private Attributes

Sessionsession_
 

Additional Inherited Members

- Protected Member Functions inherited from Wt::WWidget
virtual void enableAjax ()=0
 
virtual void propagateSetEnabled (bool enabled)=0
 
virtual void render (WFlags< RenderFlag > flags)
 

Detailed Description

Definition at line 15 of file HighScoresWidget.h.

Constructor & Destructor Documentation

HighScoresWidget::HighScoresWidget ( Session session,
Wt::WContainerWidget parent = 0 
)

Definition at line 18 of file HighScoresWidget.C.

19  :
20  WContainerWidget(parent),
21  session_(session)
22 {
23  setContentAlignment(AlignCenter);
24  setStyleClass("highscores");
}

Member Function Documentation

void HighScoresWidget::update ( )

Definition at line 26 of file HighScoresWidget.C.

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

Member Data Documentation

Session* HighScoresWidget::session_
private

Definition at line 22 of file HighScoresWidget.h.


The documentation for this class was generated from the following files:
Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1