From 4e7f837240e2dd4d3bc3b4024529b1bf517a96b6 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 3 May 2025 23:38:03 -0400 Subject: [PATCH] Cleanup of GUECS and the textures manager. --- guecs.cpp | 45 ++++++++++++++++++++++++--------------------- guecs.hpp | 3 ++- textures.cpp | 6 +++--- textures.hpp | 5 ++--- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/guecs.cpp b/guecs.cpp index e348cbe..4737691 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -68,6 +68,12 @@ namespace guecs { bar.init(cell); } + void Meter::render(lel::Cell& cell) { + float level = std::clamp(percent, 0.0f, 1.0f) * float(cell.w); + // ZED: this 6 is a border width, make it a thing + bar.shape->setSize({std::max(level, 0.0f), float(cell.h - 6)}); + } + void Sound::play(bool hover) { if(!hover) { sound::play(on_click); @@ -187,15 +193,15 @@ namespace guecs { }); $world.query([](auto, auto& cell, auto& shader) { - shader.init(cell); + shader.init(cell); }); - $world.query([](auto, auto& bg, auto &) { - bg.shape->setFillColor(ColorValue::BLACK); + $world.query([](auto, auto& bg, auto &meter) { + bg.shape->setFillColor(meter.color); }); $world.query([](auto, auto &cell, auto& meter) { - meter.init(cell); + meter.init(cell); }); $world.query([this](auto, auto& cell, auto& text) { @@ -207,18 +213,18 @@ namespace guecs { }); $world.query([&](auto, auto &cell, auto &sprite) { - sprite.init(cell); + sprite.init(cell); }); } void UI::debug_layout(sf::RenderWindow& window) { $world.query([&](const auto, auto &cell) { - sf::RectangleShape rect{{float(cell.w), float(cell.h)}}; - rect.setPosition({float(cell.x), float(cell.y)}); - rect.setFillColor(sf::Color::Transparent); - rect.setOutlineColor(sf::Color::Red); - rect.setOutlineThickness(2.0f); - window.draw(rect); + sf::RectangleShape rect{{float(cell.w), float(cell.h)}}; + rect.setPosition({float(cell.x), float(cell.y)}); + rect.setFillColor(sf::Color::Transparent); + rect.setOutlineColor(sf::Color::Red); + rect.setOutlineThickness(2.0f); + window.draw(rect); }); } @@ -236,11 +242,9 @@ namespace guecs { render_helper(window, ent, true, rect.shape); }); - $world.query([&](auto ent, auto& cell, const auto &meter) { - float level = std::clamp(meter.percent, 0.0f, 1.0f) * float(cell.w); - // ZED: this 6 is a border width, make it a thing - meter.bar.shape->setSize({std::max(level, 0.0f), float(cell.h - 6)}); - render_helper(window, ent, true, meter.bar.shape); + $world.query([&](auto ent, auto& cell, auto &meter) { + meter.render(cell); + render_helper(window, ent, true, meter.bar.shape); }); $world.query([&](auto ent, auto& sprite) { @@ -306,9 +310,8 @@ namespace guecs { void UI::show_text(const string& region, const wstring& content) { auto ent = entity(region); - if(has(ent)) { - auto& text = get(ent); - text.text->setString(content); + if(auto tc = get_if(ent)) { + tc->text->setString(content); } else { auto &cell = cell_for(ent); Textual to_set{content, 20}; @@ -341,8 +344,8 @@ namespace guecs { void UI::show_label(const string& region, const wstring& content) { auto ent = entity(region); - if(auto text = get_if