Cleanup of GUECS and the textures manager.

This commit is contained in:
Zed A. Shaw 2025-05-03 23:38:03 -04:00
parent 438bd8ab8a
commit 4e7f837240
4 changed files with 31 additions and 28 deletions

View file

@ -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<lel::Cell, Effect>([](auto, auto& cell, auto& shader) {
shader.init(cell);
shader.init(cell);
});
$world.query<Rectangle, Meter>([](auto, auto& bg, auto &) {
bg.shape->setFillColor(ColorValue::BLACK);
$world.query<Rectangle, Meter>([](auto, auto& bg, auto &meter) {
bg.shape->setFillColor(meter.color);
});
$world.query<lel::Cell, Meter>([](auto, auto &cell, auto& meter) {
meter.init(cell);
meter.init(cell);
});
$world.query<lel::Cell, Textual>([this](auto, auto& cell, auto& text) {
@ -207,18 +213,18 @@ namespace guecs {
});
$world.query<lel::Cell, Sprite>([&](auto, auto &cell, auto &sprite) {
sprite.init(cell);
sprite.init(cell);
});
}
void UI::debug_layout(sf::RenderWindow& window) {
$world.query<lel::Cell>([&](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<lel::Cell, Meter>([&](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<lel::Cell, Meter>([&](auto ent, auto& cell, auto &meter) {
meter.render(cell);
render_helper(window, ent, true, meter.bar.shape);
});
$world.query<Sprite>([&](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<Textual>(ent)) {
auto& text = get<Textual>(ent);
text.text->setString(content);
if(auto tc = get_if<Textual>(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<Label>(ent)) {
text->text->setString(content);
if(auto tc = get_if<Label>(ent)) {
tc->text->setString(content);
} else {
auto &cell = cell_for(ent);
Label to_set{content, 20};