13 constexpr
float ArrowHeight = 8.f;
18 , currentOverlay(nullptr)
23 void QtyEntry::ensureCreated() {
24 if (background.entity() == bl::ecs::InvalidEntity) {
25 background.create(engine, {10.f, 10.f});
26 background.setFillColor(sf::Color::White);
27 background.setOutlineColor(sf::Color::Black);
28 background.setOutlineThickness(2.f);
29 background.getTransform().setDepth(bl::cam::OverlayCamera::MinDepth);
32 text.setParent(background);
34 upArrow.create(engine, {6.f, 0.f}, {12.f, ArrowHeight}, {0.f, ArrowHeight});
35 upArrow.setFillColor(sf::Color::Black);
36 upArrow.setParent(background);
38 downArrow.create(engine, {0.f, 0.f}, {12.f, 0.f}, {6.f, ArrowHeight});
39 downArrow.setFillColor(sf::Color::Black);
40 downArrow.setParent(background);
43 if (!currentOverlay ||
44 engine.renderer().getObserver().getOrCreateSceneOverlay() != currentOverlay) {
45 currentOverlay = engine.renderer().getObserver().getOrCreateSceneOverlay();
46 background.addToScene(currentOverlay, bl::rc::UpdateSpeed::Static);
47 text.addToScene(currentOverlay, bl::rc::UpdateSpeed::Static);
48 upArrow.addToScene(currentOverlay, bl::rc::UpdateSpeed::Static);
49 downArrow.addToScene(currentOverlay, bl::rc::UpdateSpeed::Static);
54 if (background.entity() != bl::ecs::InvalidEntity) {
55 background.removeFromScene();
56 currentOverlay =
nullptr;
62 if (background.entity() != bl::ecs::InvalidEntity) {
63 background.getTransform().setPosition(position.x, position.y);
67 sf::Vector2f
QtyEntry::getSize()
const {
return {background.getSize().x, background.getSize().y}; }
73 text.getSection().setString(std::to_string(mn));
74 float w = text.getLocalBounds().width;
75 text.getSection().setString(std::to_string(mx));
76 w = std::max(w, text.getLocalBounds().width);
79 background.getTransform().setPosition(position.x, position.y);
82 ArrowHeight * 2.f + text.getLocalBounds().height + 6.f + text.getLocalBounds().top + 6.f});
83 upArrow.getTransform().setPosition(w * 0.5f, 4.f);
84 downArrow.getTransform().setPosition(w * 0.5f, background.getSize().y - ArrowHeight - 2.f);
85 text.getTransform().setPosition(0.f, ArrowHeight + 5.f);
94 void QtyEntry::updateText() {
95 text.getSection().setString(std::to_string(qty));
96 text.getTransform().setPosition(background.getSize().x * 0.5f -
97 text.getLocalBounds().width * 0.5f,
98 text.getTransform().getLocalPosition().y);
99 upArrow.setHidden(qty >= maxQty);
100 downArrow.setHidden(qty <= minQty);
106 if (rateLimit(ignore))
return;
107 qty = std::min(maxQty, qty + q);
113 if (rateLimit(ignore))
return;
114 qty = std::max(minQty, qty - q);
119 bool QtyEntry::rateLimit(
bool ignore) {
120 if (debounce.getElapsedTime().asSeconds() >= 0.4f || ignore) {
Core classes and functionality for both the editor and game.
static const sf::VulkanFont & MenuFont()
static bl::audio::AudioSystem::Handle MenuMoveSound()
void configure(int minQty, int maxQty, int qty)
Configures the entry with the given parameters and adds to the overlay.
void setPosition(const sf::Vector2f &position)
Sets the position of the selector.
void up(int q, bool ignoreDebounce)
Increments the qty up.
void down(int q, bool ignoreDebounce)
Decrements the qty down.
sf::Vector2f getSize() const
Returns the size of the entry in pixels.
void hide()
Removes the quantity entry from the overlay.
int curQty() const
Returns the currently selected qty.
QtyEntry(bl::engine::Engine &engine)
Construct a new quantity entry helper.