Peoplemon  0.1.0
Peoplemon 3 game source documentation
PeopledexRow.cpp
Go to the documentation of this file.
2 
4 #include <Core/Properties.hpp>
5 #include <Core/Resources.hpp>
6 
7 namespace game
8 {
9 namespace menu
10 {
11 namespace
12 {
13 std::string toString(core::pplmn::Id ppl) {
14  std::string r = std::to_string(static_cast<int>(ppl));
15  while (r.size() < 3) { r.insert(0, "0"); }
16  return "No" + r;
17 }
18 } // namespace
19 
21  return Ptr{new PeopledexRow(ppl, dex)};
22 }
23 
24 PeopledexRow::PeopledexRow(core::pplmn::Id ppl, const core::player::Peopledex& dex)
25 : ppl(ppl)
26 , dex(dex) {
27  getSignal(Item::Selected).willAlwaysCall(std::bind(&PeopledexRow::makeActive, this));
28  getSignal(Item::Deselected).willAlwaysCall(std::bind(&PeopledexRow::makeInactive, this));
29 }
30 
31 glm::vec2 PeopledexRow::getSize() const { return bgndTxtr->size(); }
32 
33 void PeopledexRow::doCreate(bl::engine::Engine& engine) {
34  const auto intel = dex.getIntelLevel(ppl);
35  const bool caught = dex.getCaught(ppl) > 0;
36 
37  const std::string& ImgPath = core::Properties::MenuImagePath();
38  auto& jp = bl::util::FileUtil::joinPath;
39 
40  bgndTxtr = engine.renderer().texturePool().getOrLoadTexture(jp(ImgPath, "Peopledex/item.png"));
41  activeBgndTxtr =
42  engine.renderer().texturePool().getOrLoadTexture(jp(ImgPath, "Peopledex/itemActive.png"));
43  background.create(engine, bgndTxtr);
44  const float mid = static_cast<float>(bgndTxtr->size().y) * 0.5f;
45 
46  ballTxtr = engine.renderer().texturePool().getOrLoadTexture(
47  jp(core::Properties::ImagePath(), "item.png"));
48  constexpr float BallX = 26.f;
49  const float bw = static_cast<float>(ballTxtr->size().x) * 0.5f;
50  if (caught) {
51  ball.create(engine, ballTxtr);
52  ball.getTransform().setOrigin(ballTxtr->size() * 0.5f);
53  ball.getTransform().setPosition({BallX, mid});
54  ball.setParent(background);
55  }
56 
57  id.create(engine, core::Properties::MenuFont(), toString(ppl), 14, sf::Color::Black);
58  id.getTransform().setPosition(bw + BallX, mid);
59  id.getTransform().setOrigin(0.f,
60  id.getLocalBounds().height * 0.5f + id.getLocalBounds().top * 0.5f);
61  id.setParent(background);
62 
63  name.create(engine,
66  "???",
67  24,
68  sf::Color::Black);
69  name.getTransform().setOrigin(
70  0.f, name.getLocalBounds().height * 0.5f + name.getLocalBounds().top * 0.5f);
71  name.getTransform().setPosition(id.getTransform().getLocalPosition().x + 65.f, mid);
72  name.setParent(background);
73 }
74 
75 void PeopledexRow::doSceneAdd(bl::rc::Scene* overlay) {
76  background.addToScene(overlay, bl::rc::UpdateSpeed::Static);
77  id.addToScene(overlay, bl::rc::UpdateSpeed::Static);
78  name.addToScene(overlay, bl::rc::UpdateSpeed::Static);
79  if (ball.entity() != bl::ecs::InvalidEntity) {
80  ball.addToScene(overlay, bl::rc::UpdateSpeed::Static);
81  }
82 }
83 
84 void PeopledexRow::doSceneRemove() { background.removeFromScene(); }
85 
86 bl::ecs::Entity PeopledexRow::getEntity() const { return background.entity(); }
87 
88 void PeopledexRow::makeActive() { background.setTexture(activeBgndTxtr); }
89 
90 void PeopledexRow::makeInactive() { background.setTexture(bgndTxtr); }
91 
92 void PeopledexRow::draw(bl::rc::scene::CodeScene::RenderContext& ctx) {
93  background.draw(ctx);
94  id.draw(ctx);
95  name.draw(ctx);
96  if (ball.entity() != bl::ecs::InvalidEntity) { ball.draw(ctx); }
97 }
98 
99 } // namespace menu
100 } // namespace game
Id
The id of a peoplemon.
Definition: Id.hpp:16
Parent namespace for all functionality unique to the game.
static const std::string & name(Id id)
Returns the name of the given Peoplemon.
Definition: Peoplemon.cpp:126
Maintains the information required to populate the peopledex.
Definition: Peopledex.hpp:24
IntelLevel getIntelLevel(pplmn::Id peoplemon) const
Returns the level of intel on the given peoplemon.
Definition: Peopledex.cpp:42
unsigned int getCaught(pplmn::Id peoplemon) const
Returns how many of the given peoplemon have been caught.
Definition: Peopledex.cpp:26
static const sf::VulkanFont & MenuFont()
Definition: Properties.cpp:363
static const std::string & MenuImagePath()
Definition: Properties.cpp:303
static const std::string & ImagePath()
Definition: Properties.cpp:333
Item row for peoplemon in the peopledex.
virtual void doSceneRemove() override
Called when the item should be removed from the overlay.
virtual void doCreate(bl::engine::Engine &engine) override
Called at least once when the item is added to a menu. Should create required graphics primitives and...
virtual glm::vec2 getSize() const override
Returns the size that the row takes up.
virtual bl::ecs::Entity getEntity() const override
Returns the entity (or top level entity) of the item.
static Ptr create(core::pplmn::Id ppl, const core::player::Peopledex &dex)
Create a new peopledex row.
virtual void doSceneAdd(bl::rc::Scene *overlay) override
Called when the item should be added to the overlay.
std::shared_ptr< PeopledexRow > Ptr
Pointer to the row item.
virtual void draw(bl::rc::scene::CodeScene::RenderContext &ctx) override
Renders the item.