YAPOG  0.0.1
Yet Another Pokemon Online Game
PokemonTeamWidget.cpp
Go to the documentation of this file.
10 
12 #include "Gui/PokemonInfoBox.hpp"
13 
14 #include "Pokemon/PokemonTeam.hpp"
15 
16 namespace ycl
17 {
19  : state_ (nullptr)
20  , menu_ (nullptr)
21  , team_ (team)
22  , pokemonInfoBoxes_ ()
23  , index_ (0)
24  , pokemonInfoWidget_ ()
25  {
26 
27  }
28 
30  {
31  }
32 
34  {
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 
90 
93 
94  pokemonInfoBoxes_[index_]->SetIsSelected (true);
95  }
96 
98  {
99  return true;
100  }
101 
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 
122  {
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 
144  {
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");
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 
209  {
210  return yap::Vector2 (800, 600);
211  }
212 
214  {
215 
216  }
218  {
219 
220  }
221 
223  {
224  }
225 
226  void PokemonTeamWidget::HandleShow (bool isVisible)
227  {
228  }
229 
230  void PokemonTeamWidget::HandleChangeColor (const sf::Color& color)
231  {
232  }
234  {
235  }
236 
237 } // namespace ycl