YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
LoginScreen.cpp
Go to the documentation of this file.
1
#include
"YAPOG/Graphics/Gui/GuiManager.hpp"
2
#include "
YAPOG/Graphics/Gui/PictureBox.hpp
"
3
#include "
YAPOG/System/RandomHelper.hpp
"
4
#include "
YAPOG/Graphics/Game/Sprite/Sprite.hpp
"
5
6
#include "
GameScreen/LoginScreen.hpp
"
7
#include "
Gui/GameMainMenu.hpp
"
8
#include "
Client/Session.hpp
"
9
10
namespace
ycl
11
{
12
const
yap::ScreenType
LoginScreen::DEFAULT_NAME
=
"Login"
;
13
14
LoginScreen::LoginScreen
(
yap::IDrawingContext
& context)
15
:
BaseScreen
(DEFAULT_NAME, context)
16
, loginWidget_ ()
17
{
18
loginWidget_
.
Init
();
19
}
20
21
LoginScreen::~LoginScreen
()
22
{
23
}
24
25
void
LoginScreen::HandleInit
()
26
{
27
BaseScreen::HandleInit
();
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);
76
guiManager_
->
AddChild
(
loginWidget_
);
77
}
78
79
void
LoginScreen::HandleRun
(
80
const
yap::Time
& dt,
81
yap::IDrawingContext
& context)
82
{
83
BaseScreen::HandleRun
(dt, context);
84
}
85
86
bool
LoginScreen::HandleOnPriorityEvent
(
const
yap::GuiEvent
& guiEvent)
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
{
98
yap::String
login =
loginWidget_
.
GetLoginTextBox
().
GetContent
();
99
yap::String
password =
loginWidget_
.
GetPasswordTextBox
().
GetContent
();
100
101
session_
.
Login
(login, password);
102
103
return
true
;
104
}
105
106
}
107
return
false
;
108
}
109
110
void
LoginScreen::HandleDeactivate
()
111
{
112
loginWidget_
.
GetLoginTextBox
().
Clear
();
113
loginWidget_
.
GetPasswordTextBox
().
Clear
();
114
loginWidget_
.
SetErrorText
(
""
);
115
}
116
117
}
// namespace ycl
YAPOG.Client
src
GameScreen
LoginScreen.cpp
Generated on Mon Sep 17 2012 22:24:21 for YAPOG by
1.8.1.1