#include "combat_ui.hpp" #include "constants.hpp" #include "color.hpp" #include "events.hpp" namespace gui { using namespace guecs; CombatUI::CombatUI(GameLevel level) : $level(level) { $gui.position(RAY_VIEW_X, RAY_VIEW_HEIGHT, RAY_VIEW_WIDTH, SCREEN_HEIGHT - RAY_VIEW_HEIGHT); $gui.layout( "[*%(100,150)button_attack1 | *%(100,150)button_attack2 | *%(100,150)button_attack3 | *%(100,150)button_heal]" "[ >.%(100,50)label_hp | *%.(198,50)bar_hp | _ ]"); } void CombatUI::render(TexturePack& textures) { auto& world = $gui.world(); world.set_the({$gui.$parser}); for(auto& [name, cell] : $gui.cells()) { if(name.starts_with("button_")) { auto button = $gui.entity(name); world.set(button, cell); world.set(button, {"trash_button"}); world.set(button, guecs::make_action(*$level.world, Events::GUI::ATTACK)); world.set(button, {"Attack"}); } else if(name.starts_with("bar_")) { $meter = $gui.entity(name); world.set($meter, cell); world.set($meter, {}); world.set($meter, {}); } else { // ignored, it's just space $gui.entity(name); } } $gui.init(textures); } void CombatUI::draw(sf::RenderWindow& window) { $gui.render(window); } void CombatUI::set_damage(float percent) { fmt::println("combat ui sets damage: {}", percent); auto& meter = $gui.world().get($meter); meter.percent = percent; } }