|
Wt examples
3.3.0
|
#include <HangmanGame.h>

Public Member Functions | |
| HangmanGame (Wt::WContainerWidget *parent=0) | |
| void | handleInternalPath (const std::string &internalPath) |
Private Member Functions | |
| void | onAuthEvent () |
| void | showGame () |
| void | showHighScores () |
Private Attributes | |
| Wt::WStackedWidget * | mainStack_ |
| HangmanWidget * | game_ |
| HighScoresWidget * | scores_ |
| Wt::WContainerWidget * | links_ |
| Wt::WAnchor * | backToGameAnchor_ |
| Wt::WAnchor * | scoresAnchor_ |
| Session | session_ |
Definition at line 24 of file HangmanGame.h.
| HangmanGame::HangmanGame | ( | Wt::WContainerWidget * | parent = 0 | ) |
Definition at line 21 of file HangmanGame.C.
: WContainerWidget(parent), game_(0), scores_(0) { session_.login().changed().connect(this, &HangmanGame::onAuthEvent); Auth::AuthModel *authModel = new Auth::AuthModel(Session::auth(), session_.users(), this); authModel->addPasswordAuth(&Session::passwordAuth()); authModel->addOAuth(Session::oAuth()); Auth::AuthWidget *authWidget = new Auth::AuthWidget(session_.login()); authWidget->setModel(authModel); authWidget->setRegistrationEnabled(true); WText *title = new WText("<h1>A Witty game: Hangman</h1>"); addWidget(title); addWidget(authWidget); mainStack_ = new WStackedWidget(); mainStack_->setStyleClass("gamestack"); addWidget(mainStack_); links_ = new WContainerWidget(); links_->setStyleClass("links"); links_->hide(); addWidget(links_); backToGameAnchor_ = new WAnchor("/play", "Gaming Grounds", links_); backToGameAnchor_->setLink(WLink(WLink::InternalPath, "/play")); scoresAnchor_ = new WAnchor("/highscores", "Highscores", links_); scoresAnchor_->setLink(WLink(WLink::InternalPath, "/highscores")); WApplication::instance()->internalPathChanged() .connect(this, &HangmanGame::handleInternalPath); authWidget->processEnvironment(); }
| void HangmanGame::handleInternalPath | ( | const std::string & | internalPath | ) |
Definition at line 76 of file HangmanGame.C.
{
if (session_.login().loggedIn()) {
if (internalPath == "/play")
showGame();
else if (internalPath == "/highscores")
showHighScores();
else
WApplication::instance()->setInternalPath("/play", true);
}
}
| void HangmanGame::onAuthEvent | ( | ) | [private] |
Definition at line 63 of file HangmanGame.C.
| void HangmanGame::showGame | ( | ) | [private] |
Definition at line 100 of file HangmanGame.C.
{
if (!game_) {
game_ = new HangmanWidget(session_.userName(), mainStack_);
game_->scoreUpdated().connect(&session_, &Session::addToScore);
}
mainStack_->setCurrentWidget(game_);
backToGameAnchor_->addStyleClass("selected-link");
scoresAnchor_->removeStyleClass("selected-link");
}
| void HangmanGame::showHighScores | ( | ) | [private] |
Definition at line 88 of file HangmanGame.C.
{
if (!scores_)
scores_ = new HighScoresWidget(&session_, mainStack_);
mainStack_->setCurrentWidget(scores_);
scores_->update();
backToGameAnchor_->removeStyleClass("selected-link");
scoresAnchor_->addStyleClass("selected-link");
}
Wt::WAnchor* HangmanGame::backToGameAnchor_ [private] |
Definition at line 36 of file HangmanGame.h.
HangmanWidget* HangmanGame::game_ [private] |
Definition at line 33 of file HangmanGame.h.
Wt::WContainerWidget* HangmanGame::links_ [private] |
Definition at line 35 of file HangmanGame.h.
Wt::WStackedWidget* HangmanGame::mainStack_ [private] |
Definition at line 32 of file HangmanGame.h.
HighScoresWidget* HangmanGame::scores_ [private] |
Definition at line 34 of file HangmanGame.h.
Wt::WAnchor* HangmanGame::scoresAnchor_ [private] |
Definition at line 37 of file HangmanGame.h.
Session HangmanGame::session_ [private] |
Definition at line 39 of file HangmanGame.h.
1.7.5.1