YAPOG  0.0.1
Yet Another Pokemon Online Game
TrainerCardWidget.cpp
Go to the documentation of this file.
1 #include "YAPOG/Game/ID.hpp"
11 
12 #include "Client/User.hpp"
13 #include "Client/PlayerData.hpp"
15 #include "Battle/PlayerTrainer.hpp"
16 
17 namespace ycl
18 {
20  : user_ (user)
21  , uniqueIDLabel_ (nullptr)
22  , uniqueID_ (nullptr)
23  , nameLabel_ (nullptr)
24  , name_ (nullptr)
25  , moneyLabel_ (nullptr)
26  , money_ (nullptr)
27  , pokedexLabel_ (nullptr)
28  , pokedex_ (nullptr)
29  , gameTimeLabel_ (nullptr)
30  , gameTime_ (nullptr)
31  , playerSprite_ (nullptr)
32  , mainLayout_ (nullptr)
33  , firstLine_ (nullptr)
34  , uniqueIDLayout_ (nullptr)
35  , secondLine_ (nullptr)
36  , secondLinePartLeft_ (nullptr)
37  , nameLayout_ (nullptr)
38  , playerDataLayout_ (nullptr)
39  , playerDataLabelsLayout_ (nullptr)
40  , playerDataValuesLayout_ (nullptr)
41  , secondLinePartRight_ (nullptr)
42  , playerSpriteLayout_ (nullptr)
43  {
44  // Labels
45  uniqueIDLabel_ = new yap::Label ("ID Unique:");
46  nameLabel_ = new yap::Label ("Nom:");
47  moneyLabel_ = new yap::Label ("Argent:");
48  pokedexLabel_ = new yap::Label ("Pokédex:");
49  gameTimeLabel_ = new yap::Label ("Temps de jeu:");
50 
51  uniqueID_ = new yap::Label (
53  name_ = new yap::Label (user_.GetLogin ());
54  money_ = new yap::Label ();
55  pokedex_ = new yap::Label ();
56  gameTime_ = new yap::Label ();
57 
58  // PïctureBoxes
60 
61  // Layouts
63  yap::Padding (), yap::Padding (), false);
64 
66  yap::Padding (0, 0, 21, 0), yap::Padding (), false);
67 
69  yap::Padding (40, 0, 10, 0),
70  yap::Padding (0, 50, 0, 0),
71  false);
72 
74  yap::Padding (), yap::Padding (), false);
75 
77  yap::Padding (42, 0, 0, 28), yap::Padding (), false);
78 
80  yap::Padding (), yap::Padding (), false);
82  yap::Padding (0, 0, 0, 50), yap::Padding (), false);
84  yap::Padding (), yap::Padding (0, 0, 21, 0), false);
86  yap::Padding (), yap::Padding (0, 0, 21, 0), false);
87 
89  yap::Padding (0, 0, 0, 82), yap::Padding (), false);
90 
92  yap::Padding (), yap::Padding (), false);
93  }
94 
96  {
97  }
98 
100  {
102  "Pictures/TrainerCard/Front.png", true));
103 
105  new yap::Sprite ("Pictures/PlayerBattlers/Girl0.png"));
106 
107  // Set layouts size
108  mainLayout_->SetSize (yap::Vector2 (750, 465));
109  firstLine_->SetSize (yap::Vector2 (750, 75));
110  uniqueIDLayout_->SetSize (yap::Vector2 (335, 75));
111  secondLine_->SetSize (yap::Vector2 (750, 293));
114  nameLayout_->SetSize (yap::Vector2 (360, 45));
115  playerDataLayout_->SetSize (yap::Vector2 (375, 211));
118 
119  // Set the labels text size
120  uniqueID_->SetTextSize (40);
122  name_->SetTextSize (40);
123  nameLabel_->SetTextSize (40);
124  name_->SetTextSize (40);
125  moneyLabel_->SetTextSize (40);
126  money_->SetTextSize (40);
128  pokedex_->SetTextSize (40);
130  gameTime_->SetTextSize (40);
131 
132  // Hierarchy construction
135  firstLine_->AddChild (*uniqueIDLayout_, yap::LayoutBox::Align::RIGHT);
136 
137  nameLayout_->AddChild (*nameLabel_, yap::LayoutBox::Align::LEFT);
139 
140  secondLinePartLeft_->AddChild (*nameLayout_, yap::LayoutBox::Align::LEFT);
141 
143  *moneyLabel_, yap::LayoutBox::Align::LEFT);
145  *pokedexLabel_, yap::LayoutBox::Align::LEFT);
147  *gameTimeLabel_, yap::LayoutBox::Align::LEFT);
148 
152 
155 
157  *playerDataLayout_, yap::LayoutBox::Align::LEFT);
158 
160 
163 
164  mainLayout_->AddChild (*firstLine_, yap::LayoutBox::Align::LEFT);
165  mainLayout_->AddChild (*secondLine_, yap::LayoutBox::Align::LEFT);
166 
168 
169  // Borders
170  /*
171  mainLayout_->SetBorder (*new yap::WidgetBorder ("Test/black.png"));
172  firstLine_->SetBorder (*new yap::WidgetBorder ("Test/red.png"));
173  uniqueIDLayout_->SetBorder (*new yap::WidgetBorder ("Test/yellow.png"));
174  secondLine_->SetBorder (*new yap::WidgetBorder ("Test/green.png"));
175  secondLinePartLeft_->SetBorder (*new yap::WidgetBorder ("Test/blue.png"));
176  nameLayout_->SetBorder (*new yap::WidgetBorder ("Test/grey.png"));
177  playerDataLayout_->SetBorder (*new yap::WidgetBorder ("Test/cyan.png"));
178  playerDataLabelsLayout_->SetBorder (*new yap::WidgetBorder ("Test/orange.png"));
179  playerDataValuesLayout_->SetBorder (*new yap::WidgetBorder ("Test/white.png"));
180  secondLinePartRight_->SetBorder (*new yap::WidgetBorder ("Test/brown.png"));
181  playerSpriteLayout_->SetBorder (*new yap::WidgetBorder ("Test/black.png"));
182  */
183 
185  }
186 
188  {
189  return true;
190  }
191 
193  {
194  money_->SetText (
196  user_.GetPlayerData ().GetMoney ()) + "$");
197  pokedex_->SetText (
200  gameTime_->SetText (
203 
204  // Refresh layouts
206 
207  BaseWidget::Open ();
208  }
209 
211  {
212  if (guiEvent.type == sf::Event::KeyPressed)
213  {
214  if (guiEvent.key.code == sf::Keyboard::Up)
215  {
216  return true;
217  }
218 
219  if (guiEvent.key.code == sf::Keyboard::Down)
220  {
221  return true;
222  }
223 
224  if (guiEvent.key.code == sf::Keyboard::Left)
225  {
226  return true;
227  }
228 
229  if (guiEvent.key.code == sf::Keyboard::Right)
230  {
231  return true;
232  }
233 
234  if (guiEvent.key.code == sf::Keyboard::Return)
235  {
236  return true;
237  }
238 
239  if (guiEvent.key.code == sf::Keyboard::Escape)
240  {
241  Close ();
242 
243  return true;
244  }
245  }
246 
247  return false;
248  }
249 
251  {
252  return yap::Vector2 (800, 600);
253  }
254 
256  {
257 
258  }
259 
261  {
262 
263  }
264 
266  {
267  }
268 
269  void TrainerCardWidget::HandleShow (bool isVisible)
270  {
271  }
272 
273  void TrainerCardWidget::HandleChangeColor (const sf::Color& color)
274  {
275  }
276 
278  {
279  gameTime_->SetText (
282 
283  // Refresh layouts
285  }
286 
287 } // namespace ycl