17 getSignal(Item::Selected).willAlwaysCall(std::bind(&BagItemButton::onSelect,
this));
18 getSignal(Item::Deselected).willAlwaysCall(std::bind(&BagItemButton::onDeselect,
this));
24 label.getSection().setString(
"Exit");
25 qty.getSection().setString(
"");
26 label.getTransform().setPosition(
27 {txtr->size().x * 0.5f - label.getLocalBounds().width * 0.5f,
28 txtr->size().y * 0.5f - label.getLocalBounds().height * 0.5f -
29 label.getLocalBounds().top * 0.5f});
33 qty.getSection(1).setString(std::to_string(item.
qty));
34 label.getTransform().setPosition(
35 8.f, txtr->size().y * 0.5f - label.getLocalBounds().height * 0.5f);
36 qty.getTransform().setPosition(txtr->size().x * 0.75f,
37 txtr->size().y * 0.5f - qty.getLocalBounds().height * 0.5f -
38 qty.getLocalBounds().top * 0.5f);
41 label.getSection().setCharacterSize(22);
42 while (label.getLocalBounds().width > txtr->size().x * 0.75f - 8.f) {
43 label.getSection().setCharacterSize(label.getSection().getCharacterSize() - 1);
44 if (label.getSection().getCharacterSize() <= 8) {
45 BL_LOG_WARN <<
"Item name too long to fit: "
46 << label.getSection().getString().toAnsiString();
55 txtr = engine.renderer().texturePool().getOrLoadTexture(
57 background.create(engine, txtr);
60 label.setParent(background);
64 qty.addSection(
"", 18, sf::Color(10, 10, 60));
65 qty.setParent(background);
71 background.addToScene(overlay, bl::rc::UpdateSpeed::Static);
72 label.addToScene(overlay, bl::rc::UpdateSpeed::Static);
73 qty.addToScene(overlay, bl::rc::UpdateSpeed::Static);
82 void BagItemButton::onSelect() { background.setColor(sf::Color(40, 230, 140)); }
84 void BagItemButton::onDeselect() {
86 sf::Color(240, 40, 40));
Parent namespace for all functionality unique to the game.
static const std::string & getName(item::Id item)
Returns the name of the given item.
Simple struct representing a set of items in the bag.
item::Id id
The item in the bag.
unsigned int qty
How many of the item are in the bag.
static const sf::VulkanFont & MenuFont()
static const std::string & MenuImagePath()
Represents a button for a quantity of items in the bag.
void update(const core::player::Bag::Item &item)
Updates the text labels from the given item.
const core::player::Bag::Item & getItem() const
Returns the item this button is representing.
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 void draw(bl::rc::scene::CodeScene::RenderContext &ctx) override
Renders the item.
std::shared_ptr< BagItemButton > Ptr
Pointer to the menu item.
static Ptr create(const core::player::Bag::Item &item)
Creates a new item button.
virtual glm::vec2 getSize() const override
Returns the size the button takes up.
virtual void doSceneRemove() override
Called when the item should be removed from the overlay.
virtual bl::ecs::Entity getEntity() const override
Returns the entity (or top level entity) of the item.
virtual void doSceneAdd(bl::rc::Scene *overlay) override
Called when the item should be added to the overlay.