Wt examples  3.3.5
Public Member Functions | Private Member Functions | Private Attributes
HangmanGame Class Reference

#include <HangmanGame.h>

List of all members.

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_
HangmanWidgetgame_
HighScoresWidgetscores_
Wt::WContainerWidget * links_
Wt::WAnchor * backToGameAnchor_
Wt::WAnchor * scoresAnchor_
Session session_

Detailed Description

Definition at line 24 of file HangmanGame.h.


Constructor & Destructor Documentation

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();
}

Member Function Documentation

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.

{
  if (session_.login().loggedIn()) {  
    links_->show();
    handleInternalPath(WApplication::instance()->internalPath());
  } else {
    mainStack_->clear();
    game_ = 0;
    scores_ = 0;
    links_->hide();
  }
}
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");
}

Member Data Documentation

Wt::WAnchor* HangmanGame::backToGameAnchor_ [private]

Definition at line 36 of file HangmanGame.h.

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.

Definition at line 34 of file HangmanGame.h.

Wt::WAnchor* HangmanGame::scoresAnchor_ [private]

Definition at line 37 of file HangmanGame.h.

Definition at line 39 of file HangmanGame.h.


The documentation for this class was generated from the following files:

Generated on Wed Mar 23 2016 for the C++ Web Toolkit (Wt) by doxygen 1.7.6.1