YAPOG  0.0.1
Yet Another Pokemon Online Game
BattleInfoWidget.cpp
Go to the documentation of this file.
10 
12 
13 namespace ycl
14 {
15  const sf::Color BattleInfoWidget::
16  DEFAULT_HP_COLOR_GOOD = sf::Color (110, 250, 170);
17  const sf::Color BattleInfoWidget::
18  DEFAULT_HP_COLOR_MEDIUM = sf::Color (250, 225, 50);
19  const sf::Color BattleInfoWidget::
20  DEFAULT_HP_COLOR_BAD = sf::Color (250, 90, 60);
21 
22  const float BattleInfoWidget::MAX_HP_BAR_SIZE = 145.f;
23 
25  : nameLabel_ ()
26  , levelLabel_ ()
27  , battleInfoBox_ (
28  widgetPadding,
29  yap::Padding (),
30  false)
31  , firstLine_ (yap::Padding (0, 0, 0, 2), yap::Padding (), false)
32  , nameBox_ (
33  yap::Padding (0, 0, 7, 0),
34  yap::Padding (),
35  false)
36  , levelAndGenderBox_ (yap::Padding (), yap::Padding (0, 10, 0, 0), false)
37  , levelBox_ (yap::Padding (), yap::Padding (), false)
38  , genderBox_ (yap::Padding (0, 0, 4, 0), yap::Padding (), false)
39  , hpBarPictureBox_ (new yap::PictureBox ())
40  , hpBarContent_ (new yap::PictureBox ())
41  , genderPictureBox_ (new yap::PictureBox ())
42  {
43  }
44 
46  {
47  nameLabel_.ChangeColor (sf::Color::Black);
48  levelLabel_.ChangeColor (sf::Color::Black);
49 
50  hpBarContent_->SetPicture (new yap::Sprite ("Pictures/Battle/HPBarContent.png"));
51  hpBarPictureBox_->SetPicture (new yap::Sprite ("Pictures/Battle/HPBattleBar.png"));
52 
55  hpBarContent_->GetSize ().y));
57 
59 
60  // Sizes
61  firstLine_.SetSize (yap::Vector2 (253, 35));
62  nameBox_.SetSize (yap::Vector2 (175, 35));
65  levelBox_.SetSize (yap::Vector2 (53, 35));
67  genderBox_.SetSize (yap::Vector2 (12, 35));
68 
69  // First line
71  levelBox_.AddChild (levelLabel_, yap::LayoutBox::Align::RIGHT);
72  genderBox_.AddChild (*genderPictureBox_, yap::LayoutBox::Align::BOTTOM);
73 
76 
79 
80  // Second line
82  hpBarContent_->Move (yap::Vector2 (45.f, 6.f));
83 
84  // Add to the global box
85  battleInfoBox_.AddChild (firstLine_, yap::LayoutBox::Align::LEFT);
86  battleInfoBox_.AddChild (*hpBarPictureBox_, yap::LayoutBox::Align::RIGHT);
87 
90  /*
91  nameBox_.SetBorder (*new yap::WidgetBorder ("Test/red.png"));
92  nameLabel_.SetBorder (*new yap::WidgetBorder ("Test/blue.png"));
93  levelLabel_.SetBorder (*new yap::WidgetBorder ("Test/yellow.png"));
94  hpBarPictureBox_->SetBorder (*new yap::WidgetBorder ("Test/green.png"));
95  battleInfoBox_.SetBorder (*new yap::WidgetBorder ("Test/black.png"));
96  levelAndGenderBox_.SetBorder (*new yap::WidgetBorder ("Test/grey.png"));
97  */
99 
100  this->AddChild (battleInfoBox_);
101  }
102 
104  {
105  /*
107  int red = (-1.4f) * value + 250;
109  int green = 2 * value + 50;
111  int blue = 1.2f * value + 50;
112 
113  hpBarContent_->ChangeColor (sf::Color (
114  yap::MathHelper::Clamp (red, 0, 255),
115  yap::MathHelper::Clamp (green, 0, 255),
116  yap::MathHelper::Clamp (blue, 0, 255)));
117  */
118 
119  if (value <= 25)
121  else if (value <= 50)
123  else
125  }
126 
128  {
129  float size = MAX_HP_BAR_SIZE * ((float)value / 100);
130 
132  size,
133  hpBarContent_->GetSize ().y));
134  }
135 
137  {
138  nameLabel_.SetText (value);
139  }
140 
141  void BattleInfoWidget::SetLevel (int value)
142  {
144  }
145 
146  void BattleInfoWidget::SetGender (const yap::Gender& value)
147  {
148  switch (value)
149  {
150  case yap::Gender::Female:
151  genderPictureBox_->SetPicture (new yap::Sprite ("Pictures/Battle/FemaleIcon.png"));
152  break;
153  case yap::Gender::Male:
154  genderPictureBox_->SetPicture (new yap::Sprite ("Pictures/Battle/MaleIcon.png"));
155  break;
156  default:
157  genderPictureBox_->SetPicture (new yap::Sprite ("Pictures/Battle/MaleIcon.png"));
158  break;
159  }
160  }
161 
163  {
164  }
165 
167  {
168  return battleInfoBox_.GetSize ();
169  }
170 }