Peoplemon  0.1.0
Peoplemon 3 game source documentation
StorageGrid.cpp
Go to the documentation of this file.
2 
4 #include <Core/Resources.hpp>
6 
7 namespace game
8 {
9 namespace menu
10 {
11 StorageGrid::StorageGrid(bl::engine::Engine& engine)
12 : engine(engine) {
13  background.create(engine);
14  background.getOverlayScaler().setFixedScissor(
15  sf::IntRect(BoxPosition.x, BoxPosition.y, BoxSize.x, BoxSize.y));
16  background.getTransform().setPosition(BoxPosition);
17 }
18 
19 void StorageGrid::activate(bl::ecs::Entity parent) { background.setParent(parent); }
20 
22  for (auto& ppl : peoplemon) { ppl.removeFromScene(); }
23  peoplemon.clear();
24 }
25 
26 void StorageGrid::notifyOffset(float offset) {
27  background.getTransform().setPosition(BoxPosition.x + offset, BoxPosition.y);
28 }
29 
30 void StorageGrid::update(const std::vector<core::pplmn::StoredPeoplemon>& box) {
31  deactivate();
32 
33  for (const auto& ppl : box) {
34  auto& rp = peoplemon.emplace_back();
35  rp.create(engine,
36  engine.renderer().texturePool().getOrLoadTexture(
37  core::pplmn::Peoplemon::thumbnailImage(ppl.peoplemon.id())));
38  rp.scaleToSize({StorageCursor::TileSize(), StorageCursor::TileSize()});
39  rp.getTransform().setPosition(glm::vec2(ppl.position.x, ppl.position.y) *
41  rp.setParent(background);
42  rp.addToScene(engine.renderer().getObserver().getCurrentOverlay(),
43  bl::rc::UpdateSpeed::Static);
44  }
45 }
46 
47 } // namespace menu
48 } // namespace game
Parent namespace for all functionality unique to the game.
static std::string thumbnailImage(Id id)
Returns the path of the image to render as the peoplemon thumbnail.
Definition: Peoplemon.cpp:211
static float TileSize()
Returns the size of a square on the grid.
void notifyOffset(float offset)
Applies the given offset to the grid position. Used for sliding in and out.
Definition: StorageGrid.cpp:26
void deactivate()
Removes the content from the scene and releases entities.
Definition: StorageGrid.cpp:21
void activate(bl::ecs::Entity background)
Sets the parent of the grid rectangle to the background.
Definition: StorageGrid.cpp:19
void update(const std::vector< core::pplmn::StoredPeoplemon > &box)
Updates the set of peoplemon to render.
Definition: StorageGrid.cpp:30
static constexpr glm::vec2 BoxPosition
Definition: StorageGrid.hpp:22
static constexpr glm::vec2 BoxSize
Definition: StorageGrid.hpp:23
StorageGrid(bl::engine::Engine &engine)
Initializes the grid to be empty.
Definition: StorageGrid.cpp:11