YAPOG  0.0.1
Yet Another Pokemon Online Game
LoginScreen.cpp
Go to the documentation of this file.
1 #include "YAPOG/Graphics/Gui/GuiManager.hpp"
5 
7 #include "Gui/GameMainMenu.hpp"
8 #include "Client/Session.hpp"
9 
10 namespace ycl
11 {
13 
15  : BaseScreen (DEFAULT_NAME, context)
16  , loginWidget_ ()
17  {
18  loginWidget_.Init ();
19  }
20 
22  {
23  }
24 
26  {
28 
29  session_.OnLoginValidation += [this] (
30  Session& sender,
31  const yap::EmptyEventArgs& args)
32  {
33  nextScreen_ = "Gameplay";
34  };
35 
36  session_.OnLoginError += [this] (
37  Session& sender,
38  const yap::EmptyEventArgs& args)
39  {
40  loginWidget_.SetErrorText ("Failed to login !");
41  };
42 
43  yap::PictureBox* bg = new yap::PictureBox ();
44 
45  yap::RandomHelper* random;
46  int nb = random->GetNext (0, 4242) % 5;
47  switch (nb)
48  {
49  case 0:
50  bg->SetPicture (
51  new yap::Sprite ("WindowSkins/BasicSkin/Background/mew.jpg"));
52  break;
53  case 1:
54  bg->SetPicture (
55  new yap::Sprite ("WindowSkins/BasicSkin/Background/fete.jpg"));
56  break;
57  case 2:
58  bg->SetPicture (
59  new yap::Sprite ("WindowSkins/BasicSkin/Background/rondoudou.jpg"));
60  break;
61  case 3:
62  bg->SetPicture (
63  new yap::Sprite ("WindowSkins/BasicSkin/Background/dresseur.jpg"));
64  break;
65  case 4:
66  bg->SetPicture (
67  new yap::Sprite ("WindowSkins/BasicSkin/Background/ronflex.gif"));
68  break;
69  default:
70  bg->SetPicture (
71  new yap::Sprite ("WindowSkins/BasicSkin/Background/ronflex.gif"));
72  break;
73  }
74  bg->SetSize (yap::Vector2 (800, 600));
75  guiManager_->AddChild (*bg);
77  }
78 
80  const yap::Time& dt,
81  yap::IDrawingContext& context)
82  {
83  BaseScreen::HandleRun (dt, context);
84  }
85 
87  {
88  if (guiEvent.type == sf::Event::KeyPressed)
89  {
90  if (guiEvent.key.code == sf::Keyboard::Escape)
91  {
92  nextScreen_ = "MainMenu";
93  return true;
94  }
95 
96  if (guiEvent.key.code == sf::Keyboard::Return)
97  {
100 
101  session_.Login (login, password);
102 
103  return true;
104  }
105 
106  }
107  return false;
108  }
109 
111  {
115  }
116 
117 } // namespace ycl