YAPOG  0.0.1
Yet Another Pokemon Online Game
PokemonInfoBox.cpp
Go to the documentation of this file.
9 
10 #include "Gui/PokemonInfoBox.hpp"
11 #include "Pokemon/Pokemon.hpp"
12 
13 namespace ycl
14 {
15  PokemonInfoBox::PokemonInfoBox (bool isMainPokemon, const Pokemon& pokemon)
16  : pokemon_ (pokemon)
17  , isMainPokemon_ (isMainPokemon)
18  , isSelected_ (false)
19  , normalBackground_ (nullptr)
20  , selectedBackground_ (nullptr)
21  , icon_ (nullptr)
22  , name_ (new yap::Label (pokemon.GetName ()))
23  , level_ (new yap::Label ())
24  , gender_ (nullptr)
25  , hpBar_ (nullptr)
26  , hpBarContent_ (nullptr)
27  , hpLabel_ (new yap::Label (
28  yap::StringHelper::ToString (
29  pokemon.GetCurrentHP ()) + " / " +
30  yap::StringHelper::ToString (pokemon.GetMaxHP ())))
31  {
32 
34  "Pictures/TeamManager/ItemBox.png", true);
35 
37  "Pictures/TeamManager/ItemBoxSelected.png", true);
38 
40 
41  icon_ = new yap::PictureBox ();
42  gender_ = new yap::PictureBox ();
44  hpBar_ = new yap::PictureBox ();
45 
46  icon_->SetPicture (&pokemon.GetIcon ());
47  gender_->SetPicture (&pokemon.GetGenderIcon ());
48  level_->SetText (
50  static_cast<int>(pokemon.GetLevel ())));
51 
52  // HP Bar
54  new yap::Sprite ("Pictures/Battle/HPTeamManagerBar.png"));
56  new yap::Sprite ("Pictures/Battle/HPBarContent.png"));
57 
58  yap::Vector2 hpBarSize =
59  yap::Vector2 (130 * ((float)pokemon.GetCurrentHP () /
60  (float)pokemon.GetMaxHP ()), hpBarContent_->GetSize ().y);
61 
62  hpBarContent_->SetSize (hpBarSize);
64  hpBarContent_->Move (yap::Vector2 (45.f, 6.f));
65 
66  if (static_cast<float> (pokemon.GetCurrentHP ()) /
67  static_cast<float> (pokemon.GetMaxHP ()) <= 0.25)
68  hpBarContent_->ChangeColor (sf::Color (250, 90, 60));
69  else if (static_cast<float> (pokemon.GetCurrentHP ()) /
70  static_cast<float> (pokemon.GetMaxHP ()) <= 0.5)
71  hpBarContent_->ChangeColor (sf::Color (250, 225, 50));
72  else
73  hpBarContent_->ChangeColor (sf::Color (110, 250, 170));
74 
75  if (isMainPokemon)
76  {
77  SetSize (yap::Vector2 (276, 173));
78 
79  yap::VerticalLayout* mainLayout =
80  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
81 
82  yap::HorizontalLayout* firstLine =
84 
85  yap::VerticalLayout* firstLineIcon =
86  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
87 
88  yap::VerticalLayout* firstLineInfo =
89  new yap::VerticalLayout (yap::Padding (0, 0, 0, 20), yap::Padding (), false);
90 
91  yap::HorizontalLayout* levelAndGender =
93 
94  yap::VerticalLayout* secondLine =
95  new yap::VerticalLayout (yap::Padding (0, 20, 0, 10), yap::Padding (), false);
96 
97  mainLayout->SetSize (GetSize ());
98 
99  firstLineInfo->SetDefaultColor (sf::Color::White);
100  levelAndGender->SetDefaultColor (sf::Color::White);
101  secondLine->SetDefaultColor (sf::Color::White);
102 
103  firstLine->SetSize (yap::Vector2 (GetSize ().x, GetSize ().y / 2));
104 
105  firstLineIcon->SetSize (icon_->GetSize ());
106  firstLineIcon->AddChild (*icon_);
107 
108  firstLineInfo->SetSize (yap::Vector2 (
109  firstLine->GetSize ().x - firstLineIcon->GetSize ().x,
110  firstLine->GetSize ().y));
111  firstLineInfo->AddChild (*name_, yap::LayoutBox::Align::BOTTOM);
112 
113  levelAndGender->AddChild (*level_);
114  levelAndGender->AddChild (*gender_);
115  firstLineInfo->AddChild (*levelAndGender);
116 
117  firstLine->AddChild (*firstLineIcon);
118  firstLine->AddChild (*firstLineInfo);
119 
120  secondLine->SetSize (yap::Vector2 (GetSize ().x, GetSize ().y / 2));
121  secondLine->AddChild (*hpBar_, yap::LayoutBox::Align::RIGHT);
122  secondLine->AddChild (*hpLabel_, yap::LayoutBox::Align::RIGHT);
123 
124  mainLayout->AddChild (*firstLine);
125  mainLayout->AddChild (*secondLine);
126 
127  /*
128  mainLayout->SetBorder (*new yap::WidgetBorder ("Test/black.png"));
129  firstLine->SetBorder (*new yap::WidgetBorder ("Test/yellow.png"));
130  secondLine->SetBorder (*new yap::WidgetBorder ("Test/green.png"));
131  firstLineInfo->SetBorder (*new yap::WidgetBorder ("Test/red.png"));
132  firstLineIcon->SetBorder (*new yap::WidgetBorder ("Test/blue.png"));
133  levelAndGender->SetBorder (*new yap::WidgetBorder ("Test/orange.png"));
134  */
135 
136  AddChild (*mainLayout);
137  }
138  else
139  {
140  SetSize (yap::Vector2 (425, 75));
141 
142  yap::HorizontalLayout* hor1 =
144 
145  yap::VerticalLayout* ver1 =
146  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
147  yap::VerticalLayout* ver2 =
148  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
149  yap::VerticalLayout* ver3 =
150  new yap::VerticalLayout (yap::Padding (), yap::Padding (), false);
151 
152  hor1->SetDefaultColor (sf::Color::White);
153 
154  ver1->SetDefaultColor (sf::Color::White);
155  ver2->SetDefaultColor (sf::Color::White);
156  ver3->SetDefaultColor (sf::Color::White);
157 
158  ver1->SetSize (yap::Vector2 (64, 64));
159  ver1->AddChild (*icon_);
160 
161  hor1->AddChild (*level_);
162  hor1->AddChild (*gender_);
163 
164  ver2->SetSize (yap::Vector2 (150, 64));
165  ver2->AddChild (*name_, yap::LayoutBox::Align::CENTER);
166  ver2->AddChild (*hor1, yap::LayoutBox::Align::CENTER);
167 
168  ver3->SetSize (yap::Vector2 (200, 64));
169  ver3->AddChild (*hpBar_, yap::LayoutBox::Align::RIGHT);
170  ver3->AddChild (*hpLabel_, yap::LayoutBox::Align::RIGHT);
171 
172  /*
173  ver1->SetBorder (*new yap::WidgetBorder ("Test/black.png"));
174  ver2->SetBorder (*new yap::WidgetBorder ("Test/yellow.png"));
175  ver3->SetBorder (*new yap::WidgetBorder ("Test/green.png"));
176  hor1->SetBorder (*new yap::WidgetBorder ("Test/red.png"));
177  */
178 
179  yap::HorizontalLayout* mainLayout =
180  new yap::HorizontalLayout (yap::Padding (), yap::Padding (), false);
181  mainLayout->SetSize (GetSize ());
182  mainLayout->SetDefaultColor (sf::Color::White);
183  mainLayout->AddChild (*ver1);
184  mainLayout->AddChild (*ver2);
185  mainLayout->AddChild (*ver3);
186 
187  AddChild (*mainLayout);
188  }
189  }
190 
192  {
193  isSelected_ = value;
194 
195  if (isSelected_)
197  else
199  }
200 
202  {
203  return false;
204  }
205 
207  {
208 
209  }
211  {
212 
213  }
215  {
216 
217  }
218  void PokemonInfoBox::HandleShow (bool isVisible)
219  {
220  }
221  void PokemonInfoBox::HandleChangeColor (const sf::Color& color)
222  {
223  }
225  {
226  }
227 
228 } // namespace ycl