YAPOG  0.0.1
Yet Another Pokemon Online Game
PokemonStatsInfoWidget.cpp
Go to the documentation of this file.
11 
13 #include "Pokemon/Pokemon.hpp"
14 
15 namespace ycl
16 {
18  : hp_ (nullptr)
19  , attack_ (nullptr)
20  , defense_ (nullptr)
21  , specialAttack_ (nullptr)
22  , specialDefense_ (nullptr)
23  , speed_ (nullptr)
24  , experiencePointLabel_ (nullptr)
25  , experiencePoint_ (nullptr)
26  , nextLevelPointLabel_ (nullptr)
27  , nextLevelPoint_ (nullptr)
28  , type1_ (nullptr)
29  , type2_ (nullptr)
30  , mainLayout_ (nullptr)
31  , firstLine_ (nullptr)
32  , firstLinePartRight_ (nullptr)
33  , hpLayout_ (nullptr)
34  , statsLayout_ (nullptr)
35  , experienceLayout_ (nullptr)
36  , experiencePointLayout_ (nullptr)
37  , experiencePointLabelLayout_ (nullptr)
38  , experiencePointNumberLayout_ (nullptr)
39  , nextLevelPointLayout_ (nullptr)
40  , nextLevelPointLabelLayout_ (nullptr)
41  , nextLevelPointNumberLayout_ (nullptr)
42  , capacityAndExperienceGlobalLayout_ (nullptr)
43  , capacityAndExperienceLayout_ (nullptr)
44  , capacityLayout_ (nullptr)
45  , experienceBarLayout_ (nullptr)
46  , pokemonFrontInfoWidget_ ()
47  , experienceBarWidget_ ()
48  {
49  // Labels
50  hp_ = new yap::Label ();
51  attack_ = new yap::Label ();
52  defense_ = new yap::Label ();
53  specialAttack_ = new yap::Label ();
54  specialDefense_ = new yap::Label ();
55  speed_ = new yap::Label ();
56 
57  experiencePointLabel_ = new yap::Label ("Points:");
59  nextLevelPointLabel_ = new yap::Label ("N. suivant:");
60  nextLevelPoint_ = new yap::Label ();
61 
62  // PictureBoxes
63  type1_ = new yap::PictureBox ();
64  type2_ = new yap::PictureBox ();
65 
66  // Layouts
68  yap::Padding (), yap::Padding (), false);
69 
71  yap::Padding (), yap::Padding (), false);
72 
74  yap::Padding (0, 8, 0, 20), yap::Padding (0, 0, 26, 0), false);
75 
77  yap::Padding (), yap::Padding (), false);
78 
80  yap::Padding (), yap::Padding (0, 0, 9, 0), false);
81 
83  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
87  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
89  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
93  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
95  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
96 
98  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
100  new yap::HorizontalLayout (yap::Padding (), yap::Padding (), false);
101  capacityLayout_ =
102  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
104  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
105  }
106 
108  {
109  // Init widgets
112 
114  "Pictures/TeamManager/PokemonStatsInfoBackground.png", true));
115 
116  type1_->SetPicture (
117  new yap::Sprite ("Pictures/Types/0.png"));
118 
119  type2_->SetPicture (
120  new yap::Sprite ("Pictures/Types/0.png"));
121 
122  // Sizes
124  firstLine_->SetSize (yap::Vector2 (800, 328));
126 
127  hpLayout_->SetSize (yap::Vector2 (238, 41));
128  statsLayout_->SetSize (yap::Vector2 (135, 236));
129 
130  experienceLayout_->SetSize (yap::Vector2 (792, 100));
137 
140  capacityLayout_ ->SetSize (yap::Vector2 (284, 46));
142 
143  // Set the labels text size
144  hp_->SetTextSize (40);
145  attack_->SetTextSize (40);
146  defense_->SetTextSize (40);
149  speed_->SetTextSize (40);
150 
155 
156  // Hierarchy construction
157  hpLayout_->AddChild (*hp_);
158 
164 
165  firstLinePartRight_->AddChild (*hpLayout_, yap::LayoutBox::Align::RIGHT);
166  firstLinePartRight_->AddChild (*statsLayout_, yap::LayoutBox::Align::RIGHT);
167 
168  firstLine_->AddChild (pokemonFrontInfoWidget_, yap::LayoutBox::Align::TOP);
169  firstLine_->AddChild (*firstLinePartRight_, yap::LayoutBox::Align::TOP);
170 
173 
176 
178  *experiencePointLabelLayout_, yap::LayoutBox::Align::LEFT);
180  *experiencePointNumberLayout_, yap::LayoutBox::Align::RIGHT);
181 
183  *nextLevelPointLabelLayout_, yap::LayoutBox::Align::LEFT);
185  *nextLevelPointNumberLayout_, yap::LayoutBox::Align::RIGHT);
186 
188  *experiencePointLayout_, yap::LayoutBox::Align::RIGHT);
190  *nextLevelPointLayout_, yap::LayoutBox::Align::RIGHT);
191 
192  experienceBarLayout_->AddChild (experienceBarWidget_, yap::LayoutBox::Align::RIGHT);
193 
194  capacityAndExperienceLayout_->AddChild (*capacityLayout_, yap::LayoutBox::Align::RIGHT);
195  capacityAndExperienceLayout_->AddChild (*experienceBarLayout_, yap::LayoutBox::Align::RIGHT);
196 
198  *capacityAndExperienceLayout_, yap::LayoutBox::Align::RIGHT);
199 
200  mainLayout_->AddChild (*firstLine_, yap::LayoutBox::Align::LEFT);
201  mainLayout_->AddChild (*experienceLayout_, yap::LayoutBox::Align::LEFT);
202  mainLayout_->AddChild (*capacityAndExperienceGlobalLayout_, yap::LayoutBox::Align::LEFT);
203 
204  // Borders
205  /*
206  mainLayout_->SetBorder (*new yap::WidgetBorder ("Test/grey.png"));
207  firstLine_->SetBorder (*new yap::WidgetBorder ("Test/red.png"));
208  firstLinePartRight_->SetBorder (*new yap::WidgetBorder ("Test/blue.png"));
209  hpLayout_->SetBorder (*new yap::WidgetBorder ("Test/brown.png"));
210  statsLayout_->SetBorder (*new yap::WidgetBorder ("Test/black.png"));
211 
212  experienceLayout_->SetBorder (*new yap::WidgetBorder ("Test/grey.png"));
213  experiencePointLayout_->SetBorder (*new yap::WidgetBorder ("Test/red.png"));
214  experiencePointNumberLayout_->SetBorder (*new yap::WidgetBorder ("Test/yellow.png"));
215  experiencePointLabelLayout_->SetBorder (*new yap::WidgetBorder ("Test/green.png"));
216 
217  capacityAndExperienceGlobalLayout_->SetBorder (*new yap::WidgetBorder ("Test/green.png"));
218  capacityAndExperienceLayout_->SetBorder (*new yap::WidgetBorder ("Test/grey.png"));
219  capacityLayout_->SetBorder (*new yap::WidgetBorder ("Test/red.png"));
220  experienceBarLayout_->SetBorder (*new yap::WidgetBorder ("Test/yellow.png"));
221  */
222 
224 
226  }
227 
229  {
232 
233  // Labels
234  hp_->SetText (
236  (pokemon.GetStats ().GetHitPoint ().GetCurrentValue ())
237  + "/" +
239  (pokemon.GetStats ().GetHitPoint ().GetValue ()));
240 
241  attack_->SetText (
243  (pokemon.GetStats ().GetAttack ().GetValue ()));
244 
245  defense_->SetText (
247  (pokemon.GetStats ().GetDefense ().GetValue ()));
248 
251  (pokemon.GetStats ().GetSpecialAttack ().GetValue ()));
252 
255  (pokemon.GetStats ().GetSpecialDefense ().GetValue ()));
256 
257  speed_->SetText (
259  (pokemon.GetStats ().GetSpeed ().GetValue ()));
260 
263  static_cast<int>(pokemon.GetTotalExperience ())));
264 
267  static_cast<int>(pokemon.GetExperienceToNextLevel ())));
268 
269  type1_->SetPicture (pokemon.GetType1Icon ().Clone ());
270  type2_->SetPicture (pokemon.GetType2Icon ().Clone ());
271 
272  // Refresh layouts to center labels
273  hpLayout_->Refresh ();
274  statsLayout_->Refresh ();
277  }
278 
281  /*
282  void PokemonStatsInfoWidget::SetDefaultColor (const sf::Color& color)
283  {}
284  void PokemonStatsInfoWidget::AddDrawable (yap::IDrawable& drawable)
285  {}
286  void PokemonStatsInfoWidget::AddChild (yap::IWidget& child)
287  {}
288  yap::IWidget& PokemonStatsInfoWidget::GetRoot () const
289  { return GetRoot (); }
290  yap::WidgetBorder* PokemonStatsInfoWidget::GetBorder () const
291  { return GetBorder (); }
292  void PokemonStatsInfoWidget::SetParent (yap::IWidget& parent)
293  {}
294  void PokemonStatsInfoWidget::SetPadding (const yap::Padding& padding)
295  {}
296  void PokemonStatsInfoWidget::SetBackground (yap::WidgetBackground& background)
297  {}
298  void PokemonStatsInfoWidget::SetBorder (yap::WidgetBorder& border, yap::uint width)
299  {}
300  void PokemonStatsInfoWidget::Refresh ()
301  {}
302  */
304  {
305  return false;
306  }
307  /*
308  void PokemonStatsInfoWidget::SetFocused (bool state)
309  {}
310  void PokemonStatsInfoWidget::SetEnable (bool enable)
311  {}
312  void PokemonStatsInfoWidget::Open ()
313  {}
314  void PokemonStatsInfoWidget::Close ()
315  {}
316  */
318 
320  {
321  }
322 
324  {
325  }
326 
328  {
329  }
330 
332  {
333  }
334 
335  void PokemonStatsInfoWidget::HandleChangeColor (const sf::Color& color)
336  {
337  }
338 
340  {
341  }
342 
343 } // namespace ycl