YAPOG  0.0.1
Yet Another Pokemon Online Game
PokedexWidget.cpp
Go to the documentation of this file.
12 
13 #include "Gui/PokedexWidget.hpp"
15 
16 #include "Game.hpp"
17 
18 namespace ycl
19 {
20 
22  : pokedex_ (pokedex)
23  , boxInfoContent_ (new yap::PictureBox ())
24  , menu_ (nullptr)
25  , validatedPokemon_ (nullptr)
26  , firstHLayout_ (nullptr)
27  , firstVLayout_ (nullptr)
28  , pokedexInfo_ (nullptr)
29  , pokSeen_ (nullptr)
30  , pokCaught_ (nullptr)
31  {
32  /*pokedexInfo_ = new PokedexCompositeWidget ();
33  pokedexInfo_->Init ();
34  pokedexInfo_->Close ();
35  AddChild (*pokedexInfo_);*/
36 
37  pokedex_->OnAddPokemon += [this] (yap::Pokedex& sender, const yap::EmptyEventArgs& args)
38  {
39  RefreshAfterAdd ();
40  };
41  }
42 
44  {
45  }
46 
48  {
49  SetSize (yap::Vector2 (800, 600));
50  yap::WidgetBackground* background =
51  new yap::WidgetBackground ("WindowSkins/BasicSkin/Pokedex/Background.png", true);
52  SetBackground (*background);
53 
55  yap::Padding (10, 10, 10, 10), yap::Padding (10, 10, 10, 10), false);
56  firstHLayout_->SetSize (yap::Vector2 (600, 400));
57  yap::HorizontalLayout* secondHLayout = new yap::HorizontalLayout (yap::Padding (5, 5, 5, 5), yap::Padding (5, 5, 5, 5), true);
58  yap::VerticalLayout* firstVLayout_ = new yap::VerticalLayout (yap::Padding (10, 10, 10, 10), yap::Padding (10, 10, 10, 10), true);
59 
60  yap::VerticalLayout* secondVLayout = new yap::VerticalLayout (yap::Padding (5, 5, 5, 5), yap::Padding (5, 5, 5, 5), true);
61  secondHLayout->SetDefaultColor (sf::Color::White);
62  yap::PictureBox* title = new yap::PictureBox ();
63  title->SetPicture (
64  new yap::Sprite ("WindowSkins/BasicSkin/Pokedex/Title.png"));
65 
66  yap::HorizontalLayout* boxInfo = new yap::HorizontalLayout (yap::Padding (20, 20, 20, 20), yap::Padding (20, 20, 20, 20), false);
67  yap::WidgetBackground* pokImgBackground = new yap::WidgetBackground ("WindowSkins/BasicSkin/Pokedex/PokemonBoxBackground.png", true);
68  pokImgBackground->SetFixed (true);
69  boxInfo->SetBackground (*pokImgBackground);
71  new yap::Sprite ("WindowSkins/BasicSkin/Pokedex/PokemonBoxDefault.png"));
72  boxInfo->AddChild (*boxInfoContent_);
73 
74  firstVLayout_->AddChild (*title);
75 
76  yap::WidgetBackground* menuBackground = new yap::WidgetBackground ("WindowSkins/BasicSkin/Pokedex/ListBackground.png", true);
77  menu_ = new yap::Menu (yap::Menu::Type::VERTICAL, yap::Padding (5, 5, 5, 5), yap::Padding (5, 5, 5, 5), true);
78  yap::WidgetBackground* selectedBackground = new yap::WidgetBackground ("WindowSkins/BasicSkin/Pokedex/SelectionBackground.png", true);
79  menu_->SetSelectedBackground (*selectedBackground);
80  menu_->SetSize (yap::Vector2 (firstHLayout_->GetSize ().x - firstVLayout_->GetSize ().x, firstHLayout_->GetSize ().y));
81  menu_->SetBackground (*menuBackground);
82 
83  for (int i = 1; i <= pokedex_->GetMaxIDSeen (); i++)
84  {
85  yap::MenuItem* item = new yap::MenuItem (false);
86  item->SetSize (yap::Vector2 (firstHLayout_->GetSize ().x - firstVLayout_->GetSize ().x - 10, 28));
87  const yap::PokemonInfo* current = pokedex_->GetPokemonSeenID (i);
88 
89  if (current == nullptr)
90  {
91  item->SetContent ("N." + yap::StringHelper::ToString(i) + " --------");
92  item->OnSelected +=
93  [&] (yap::MenuItem& sender, const yap::EmptyEventArgs& args)
94  {
96  new yap::Sprite (
97  "WindowSkins/BasicSkin/Pokedex/PokemonBoxDefault.png"));
98  };
99  }
100  else
101  {
102  item->SetContent ("N." + yap::StringHelper::ToString(i) + " " + current->GetName ());
103 
104  item->OnSelected +=
105  [this, current] (yap::MenuItem& sender, const yap::EmptyEventArgs& args)
106  {
108  new yap::Sprite (current->GetMaleFrontPath ()));
109  };
110  item->OnActivated +=
111  [&] (yap::MenuItem& sender, const yap::EmptyEventArgs& args)
112  {
114  //firstHLayout_->Close ();
115  //pokedexInfo_->Open ();
116  };
117  }
118  item->ChangeColor (sf::Color (0, 0, 0));
119  /*item->SetBorder (*new yap::WidgetBorder ("Test/red.png"));*/
120  menu_->AddChild (*item, yap::LayoutBox::Align::LEFT);
121 
122  }
125  pokSeen_->ChangeColor (sf::Color::White);
126  pokCaught_->ChangeColor (sf::Color::White);
127 
128  secondVLayout->AddChild (*pokSeen_);
129  secondVLayout->AddChild (*pokCaught_);
130 
131  secondHLayout->AddChild (*secondVLayout, yap::LayoutBox::Align::TOP);
132  secondHLayout->AddChild (*boxInfo);
133  secondHLayout->Refresh ();
134 
135  firstVLayout_->AddChild (*secondHLayout, yap::LayoutBox::Align::RIGHT);
136 
137  firstHLayout_->AddChild (*firstVLayout_, yap::LayoutBox::Align::TOP);
139 
141  }
142 
144  {
145  if (menu_ != nullptr)
146  menu_->Clear ();
147  else
148  return;
149 
150  if (pokedex_ != nullptr)
151  for (int i = 1; i <= pokedex_->GetMaxIDSeen (); i++)
152  {
153  yap::MenuItem* item = new yap::MenuItem (false);
154  item->SetSize (yap::Vector2 (firstHLayout_->GetSize ().x - firstVLayout_->GetSize ().x - 10, 28));
155  const yap::PokemonInfo* current = pokedex_->GetPokemonSeenID (i);
156 
157  if (current == nullptr)
158  {
159  item->SetContent ("N." + yap::StringHelper::ToString(i) + " --------");
160  item->OnSelected +=
161  [&] (yap::MenuItem& sender, const yap::EmptyEventArgs& args)
162  {
164  new yap::Sprite ("WindowSkins/BasicSkin/Pokedex/PokemonBoxDefault.png"));
165  };
166  }
167  else
168  {
169  item->SetContent ("N." + yap::StringHelper::ToString(i) + " " + current->GetName ());
170  item->OnActivated +=
171  [&] (const yap::MenuItem& sender, const yap::EmptyEventArgs& args)
172  {
174  //firstHLayout_->Close ();
175  //pokedexInfo_->Open ();
176  };
177  }
178  item->ChangeColor (sf::Color (0, 0, 0));
179  /*item->SetBorder (*new yap::WidgetBorder ("Test/red.png"));*/
180  menu_->AddChild (*item, yap::LayoutBox::Align::LEFT);
181 
182  }
185  }
187  {
188  return validatedPokemon_;
189  }
190 
192  {
193  return true;
194  }
195 
197  {
198  return yap::Vector2 (800, 600);
199  }
200 
202  {
203  }
204 
206  {
207  }
208 
210  {
211  }
212 
213  void PokedexWidget::HandleShow (bool isVisible)
214  {
215  }
216 
217  void PokedexWidget::HandleChangeColor (const sf::Color& color)
218  {
219  }
220 
222  {
223  }
224 
226  {
227  if (guiEvent.type == sf::Event::KeyPressed)
228  {
229  if (guiEvent.key.code == sf::Keyboard::Escape)
230  {
231  Close ();
232 
233  return true;
234  }
235  }
236 
237  return false;
238  }
239 } // namespace ycl