YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
PokemonTeamWidget.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Graphics/Gui/WidgetBorder.hpp
"
2
#include "
YAPOG/Game/Pokemon/PokemonInfo.hpp
"
3
#include "
YAPOG/Graphics/Gui/HorizontalLayout.hpp
"
4
#include "
YAPOG/Graphics/Gui/VerticalLayout.hpp
"
5
#include "
YAPOG/Graphics/Gui/GridMenu.hpp
"
6
#include "
YAPOG/Graphics/Gui/PictureBox.hpp
"
7
#include "
YAPOG/System/StringHelper.hpp
"
8
#include "
YAPOG/Graphics/Texture.hpp
"
9
#include "
YAPOG/Audio/AudioManager.hpp
"
10
11
#include "
Gui/PokemonTeamWidget.hpp
"
12
#include "
Gui/PokemonInfoBox.hpp
"
13
14
#include "Pokemon/PokemonTeam.hpp"
15
16
namespace
ycl
17
{
18
PokemonTeamWidget::PokemonTeamWidget
(
const
PokemonTeam
& team)
19
: state_ (nullptr)
20
, menu_ (nullptr)
21
, team_ (team)
22
, pokemonInfoBoxes_ ()
23
, index_ (0)
24
, pokemonInfoWidget_ ()
25
{
26
27
}
28
29
PokemonTeamWidget::~PokemonTeamWidget
()
30
{
31
}
32
33
void
PokemonTeamWidget::Init
()
34
{
35
SetBackground
(*
new
yap::WidgetBackground
(
36
"Pictures/TeamManager/Partyfond.png"
,
true
));
37
38
yap::Label
*
state_
=
new
yap::Label
(
"Choisir un POKéMON."
);
39
40
yap::Texture
* t =
new
yap::Texture
();
41
t->
LoadFromFile
(
"WindowSkins/BasicSkin/Global/TopBorder.png"
);
42
yap::Texture
* tr =
new
yap::Texture
();
43
tr->
LoadFromFile
(
"WindowSkins/BasicSkin/Global/TopRightCorner.png"
);
44
yap::Texture
* r =
new
yap::Texture
();
45
r->
LoadFromFile
(
"WindowSkins/BasicSkin/Global/RightBorder.png"
);
46
yap::Texture
* br =
new
yap::Texture
();
47
br->
LoadFromFile
(
"WindowSkins/BasicSkin/Global/BottomRightCorner.png"
);
48
yap::Texture
* b =
new
yap::Texture
();
49
b->
LoadFromFile
(
"WindowSkins/BasicSkin/Global/BottomBorder.png"
);
50
yap::Texture
* bl =
new
yap::Texture
();
51
bl->
LoadFromFile
(
"WindowSkins/BasicSkin/Global/BottomLeftCorner.png"
);
52
yap::Texture
* l =
new
yap::Texture
();
53
l->
LoadFromFile
(
"WindowSkins/BasicSkin/Global/LeftBorder.png"
);
54
yap::Texture
* tl =
new
yap::Texture
();
55
tl->
LoadFromFile
(
"WindowSkins/BasicSkin/Global/TopLeftCorner.png"
);
56
57
yap::WidgetBorder
* stateBorder =
58
new
yap::WidgetBorder
(*t, *tr, *r, *br, *b, *bl, *l, *tl,
true
);
59
60
state_->
SetSize
(
yap::Vector2
(250, 64));
61
62
state_->
SetBackground
(*
new
yap::WidgetBackground
(
"Test/White.png"
,
true
));
63
state_->
SetPadding
(
yap::Padding
(32, 0, 5, 32));
64
AddChild
(*state_);
65
state_->
SetPosition
(
GetSize
() - state_->
GetSize
() -
yap::Vector2
(15, 15));
66
state_->
SetBorder
(*stateBorder);
67
68
69
for
(
int
i = 0; i <
team_
.
GetPokemonCount
(); i++)
70
{
71
PokemonInfoBox
* box =
nullptr
;
72
73
if
(i == 0)
74
{
75
box =
new
PokemonInfoBox
(
true
,
team_
.
GetPokemon
(i));
76
box->
SetPosition
(
GetPosition
() +
yap::Vector2
(39, 101));
77
}
78
else
79
{
80
box =
new
PokemonInfoBox
(
false
,
team_
.
GetPokemon
(i));
81
box->
SetPosition
(
GetPosition
() +
yap::Vector2
(364, 41 + 90 * (i - 1)));
82
}
83
84
pokemonInfoBoxes_
.
Add
(box);
85
86
AddChild
(*box);
87
}
88
89
AddChild
(
pokemonInfoWidget_
);
90
91
pokemonInfoWidget_
.
Init
();
92
pokemonInfoWidget_
.
Close
();
93
94
pokemonInfoBoxes_
[
index_
]->SetIsSelected (
true
);
95
}
96
97
bool
PokemonTeamWidget::IsFocusable
()
const
98
{
99
return
true
;
100
}
101
102
bool
PokemonTeamWidget::HandleOnEvent
(
const
yap::GuiEvent
& guiEvent)
103
{
104
if
(
pokemonInfoBoxes_
.
Count
() == 0)
105
return
false
;
106
107
if
(guiEvent.type == sf::Event::KeyPressed)
108
{
109
if
(guiEvent.key.code ==
sf::Keyboard::Up
)
110
{
111
// Play a sound
112
yap::AudioManager::Instance
().
PlaySound
(
"SE/Select.wav"
);
113
114
pokemonInfoBoxes_
[
index_
]->SetIsSelected (
false
);
115
116
if
(
index_
== 0)
117
index_
=
pokemonInfoBoxes_
.
Count
() - 1;
118
else
119
index_
--;
120
121
if
(
pokemonInfoWidget_
.
IsVisible
())
122
{
123
pokemonInfoWidget_
.
Close
();
124
team_
.
GetPokemon
(
index_
).
PlayCry
();
125
pokemonInfoWidget_
.
SetPokemon
(&
team_
.
GetPokemon
(
index_
));
126
pokemonInfoWidget_
.
Open
();
127
}
128
129
pokemonInfoBoxes_
[
index_
]->SetIsSelected (
true
);
130
131
return
true
;
132
}
133
134
if
(guiEvent.key.code ==
sf::Keyboard::Down
)
135
{
136
// Play a sound
137
yap::AudioManager::Instance
().
PlaySound
(
"SE/Select.wav"
);
138
139
pokemonInfoBoxes_
[
index_
]->SetIsSelected (
false
);
140
141
index_
= (
index_
+ 1) %
pokemonInfoBoxes_
.
Count
();
142
143
if
(
pokemonInfoWidget_
.
IsVisible
())
144
{
145
pokemonInfoWidget_
.
Close
();
146
team_
.
GetPokemon
(
index_
).
PlayCry
();
147
pokemonInfoWidget_
.
SetPokemon
(&
team_
.
GetPokemon
(
index_
));
148
pokemonInfoWidget_
.
Open
();
149
}
150
151
pokemonInfoBoxes_
[
index_
]->SetIsSelected (
true
);
152
153
return
true
;
154
}
155
156
if
(guiEvent.key.code ==
sf::Keyboard::Left
)
157
{
158
// Play a sound
159
yap::AudioManager::Instance
().
PlaySound
(
"SE/Select.wav"
);
160
161
if
(
index_
!= 0)
162
{
163
pokemonInfoBoxes_
[
index_
]->SetIsSelected (
false
);
164
index_
= 0;
165
pokemonInfoBoxes_
[
index_
]->SetIsSelected (
true
);
166
}
167
168
return
true
;
169
}
170
171
if
(guiEvent.key.code ==
sf::Keyboard::Right
)
172
{
173
// Play a sound
174
yap::AudioManager::Instance
().
PlaySound
(
"SE/Select.wav"
);
175
176
if
(
index_
== 0)
177
{
178
pokemonInfoBoxes_
[
index_
]->SetIsSelected (
false
);
179
index_
++;
180
pokemonInfoBoxes_
[
index_
]->SetIsSelected (
true
);
181
}
182
183
return
true
;
184
}
185
186
if
(guiEvent.key.code == sf::Keyboard::Return)
187
{
188
// Play a sound
189
yap::AudioManager::Instance
().
PlaySound
(
"SE/Choose.wav"
);
190
team_
.
GetPokemon
(
index_
).
PlayCry
();
191
pokemonInfoWidget_
.
SetPokemon
(&
team_
.
GetPokemon
(
index_
));
192
pokemonInfoWidget_
.
Open
();
193
194
return
true
;
195
}
196
197
if
(guiEvent.key.code == sf::Keyboard::Escape)
198
{
199
Close
();
200
201
return
true
;
202
}
203
}
204
205
return
false
;
206
}
207
208
yap::Vector2
PokemonTeamWidget::HandleGetSize
()
const
209
{
210
return
yap::Vector2
(800, 600);
211
}
212
213
void
PokemonTeamWidget::HandleMove
(
const
yap::Vector2
& offset)
214
{
215
216
}
217
void
PokemonTeamWidget::HandleScale
(
const
yap::Vector2
& factor)
218
{
219
220
}
221
222
void
PokemonTeamWidget::HandleDraw
(
yap::IDrawingContext
& context)
223
{
224
}
225
226
void
PokemonTeamWidget::HandleShow
(
bool
isVisible)
227
{
228
}
229
230
void
PokemonTeamWidget::HandleChangeColor
(
const
sf::Color& color)
231
{
232
}
233
void
PokemonTeamWidget::HandleUpdate
(
const
yap::Time
& dt)
234
{
235
}
236
237
}
// namespace ycl
YAPOG.Client
src
Gui
PokemonTeamWidget.cpp
Generated on Mon Sep 17 2012 22:24:22 for YAPOG by
1.8.1.1