14 constexpr
float GrowRate = 100.f;
15 constexpr
float HpBarWidth = 178.f;
16 constexpr
float HpBarHeight = 12.f;
27 , color(sf::Color::White) {
28 getSignal(bl::menu::Item::Selected).willAlwaysCall([
this]() {
29 image.setColor(sf::Color(170, 190, 30));
31 getSignal(bl::menu::Item::Deselected).willAlwaysCall([
this]() { image.setColor(color); });
36 if (!isSelected) { image.setColor(color); }
42 const unsigned int curHp = ppl.
currentHp();
44 const float hpPercent =
static_cast<float>(curHp) /
static_cast<float>(maxHp);
45 hpText.getSection().setString(std::to_string(curHp) +
" / " + std::to_string(maxHp));
46 hpText.getTransform().setPosition(342.f - hpText.getLocalBounds().width - 8.f, 83.f);
47 hpBarTarget = hpPercent * HpBarWidth;
53 return std::abs(hpBar.getGlobalSize().x - hpBarTarget) < 0.5f;
59 txtr = engine.renderer().texturePool().getOrLoadTexture(
61 image.create(engine, txtr);
62 image.getTransform().setDepth(-2.f);
68 sf::Color(60, 225, 200),
70 name.getTransform().setPosition(135.f, 18.f);
71 name.setParent(image);
73 const unsigned int curHp = ppl.
currentHp();
75 const float hpPercent =
static_cast<float>(curHp) /
static_cast<float>(maxHp);
76 const float hpBarWidth = hpPercent * HpBarWidth;
79 hpBar.create(engine, {100.f, 12.f});
80 hpBar.getTransform().setPosition(164.f, 70.f);
81 hpBar.setFillColor(hpColor);
82 hpBar.scaleToSize({hpBarWidth, HpBarHeight});
83 hpBar.setParent(image);
84 hpBar.getTransform().setDepth(1.f);
85 hpBarTarget = hpBarWidth;
89 std::to_string(curHp) +
" / " + std::to_string(maxHp),
92 hpText.getTransform().setPosition(342.f - hpText.getLocalBounds().width - 8.f, 83.f);
93 hpText.setParent(image);
100 sf::Color(30, 230, 160));
101 item.getTransform().setPosition(85.f, 136.f);
102 item.setParent(image);
108 sf::Color(50, 220, 250),
110 level.getTransform().setPosition(304.f, 16.f);
111 level.setParent(image);
116 faceTxtr = engine.renderer().texturePool().getOrLoadTexture(faceSrc);
117 face.create(engine, faceTxtr);
118 face.setParent(image);
120 sf::Rect<unsigned int> bounds(100000, 100000, 0, 0);
121 const auto faceRes = ImageManager::load(faceSrc);
122 const sf::Image& img = *faceRes;
123 for (
unsigned int x = 0; x < img.getSize().x; ++x) {
124 for (
unsigned int y = 0; y < img.getSize().y; ++y) {
125 if (img.getPixel(x, y) != sf::Color::Transparent) {
126 if (x < bounds.left) bounds.left = x;
127 if (x > bounds.width) bounds.width = x;
128 if (y < bounds.top) bounds.top = y;
129 if (y > bounds.height) bounds.height = y;
133 const sf::Vector2f size(bounds.width - bounds.left, bounds.height - bounds.top);
134 const sf::Vector2f dscale(95.f / size.x, 95.f / size.y);
135 const float scale = std::min(dscale.x, dscale.y);
136 face.getTransform().setOrigin(faceTxtr->size() * 0.5f);
137 face.getTransform().setScale(scale, scale);
138 face.getTransform().setPosition(71.f, 76.f);
144 image.addToScene(overlay, bl::rc::UpdateSpeed::Static);
145 face.addToScene(overlay, bl::rc::UpdateSpeed::Static);
146 hpBar.addToScene(overlay, bl::rc::UpdateSpeed::Static);
147 name.addToScene(overlay, bl::rc::UpdateSpeed::Static);
148 level.addToScene(overlay, bl::rc::UpdateSpeed::Static);
149 item.addToScene(overlay, bl::rc::UpdateSpeed::Static);
150 hpText.addToScene(overlay, bl::rc::UpdateSpeed::Static);
151 if (ailment.entity() != bl::ecs::InvalidEntity) {
152 ailment.addToScene(overlay, bl::rc::UpdateSpeed::Static);
164 if (ailment.entity() != bl::ecs::InvalidEntity) { ailment.draw(ctx); }
172 if (hpBar.getGlobalSize().x < hpBarTarget) {
173 const float nw = std::min(hpBarTarget, hpBar.getGlobalSize().x + GrowRate * dt);
174 hpBar.scaleToSize({nw, HpBarHeight});
177 else if (hpBar.getGlobalSize().x > hpBarTarget) {
178 const float nw = std::max(hpBarTarget, hpBar.getGlobalSize().x - GrowRate * dt);
179 hpBar.scaleToSize({nw, HpBarHeight});
186 if (!ailSrc.empty()) {
187 ailTxtr = enginePtr->renderer().texturePool().getOrLoadTexture(ailSrc);
188 if (ailment.entity() == bl::ecs::InvalidEntity) {
189 ailment.create(*enginePtr, ailTxtr);
190 ailment.getTransform().setPosition(135.f, 90.f);
191 ailment.setParent(image);
193 else if (ailment.getTexture().get() != ailTxtr.get()) { ailment.setTexture(ailTxtr, {}); }
194 if (overlay) { ailment.addToScene(overlay, bl::rc::UpdateSpeed::Static); }
197 if (ailment.entity() != bl::ecs::InvalidEntity) { ailment.destroy(); }
Ailment
Represents an ailment that a Peoplemon can have.
Parent namespace for all functionality unique to the game.
static const std::string & getName(item::Id item)
Returns the name of the given item.
Represents an instance of a peoplemon. Can be a wild peoplemon, trainer, or player peoplemon....
Ailment & currentAilment()
Access the current ailment of this peoplemon.
std::uint16_t & currentHp()
Access the current HP.
unsigned int currentLevel() const
Returns the current level of this peoplemon.
Stats currentStats() const
Returns the computed stats for the peoplemon. Does not take into account changes during battle.
Id id() const
Returns the id of this peoplemon.
item::Id & holdItem()
Access the current hold item of this peoplemon.
const std::string & name() const
Returns the name of this peoplemon, custom or defualt.
static std::string thumbnailImage(Id id)
Returns the path of the image to render as the peoplemon thumbnail.
static const sf::VulkanFont & MenuFont()
static std::string AilmentTexture(pplmn::Ailment ailment)
static const std::string & MenuImagePath()
static sf::Color HPBarColor(float percent)
virtual void doSceneAdd(bl::rc::Scene *overlay) override
Called when the item should be added to the overlay.
static Ptr create(const core::pplmn::OwnedPeoplemon &ppl)
Creates a new peoplemon button from the peoplemon.
virtual void doSceneRemove() override
Called when the item should be removed from the overlay.
void setHighlightColor(const sf::Color &color)
Set the highlight color.
bool synced() const
Returns whether or not this button is synced.
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< PeoplemonButton > Ptr
virtual glm::vec2 getSize() const override
Returns the size of the button.
void sync(const core::pplmn::OwnedPeoplemon &ppl)
Syncs the HP bar and ailment texture with the peoplemon.
void update(float dt)
Updates the HP bar.
virtual bl::ecs::Entity getEntity() const override
Returns the entity (or top level entity) of the item.