#include "status_ui.hpp" #include // for Render #include // for ftxui #include #include #include #include "components.hpp" #include "color.hpp" namespace gui { using namespace components; using namespace ftxui; StatusUI::StatusUI(GameLevel level) : Panel(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT, false), $level(level) { default_bg = ColorValue::DARK_MID; } void StatusUI::create_render() { auto player = $level.world->get_the(); auto status_rend = Renderer([&, player]{ const auto& player_combat = $level.world->get(player.entity); const auto& combat = $level.world->get(player.entity); auto log_box = vbox($log_list) | yflex_grow | border; return hbox({ hflow( vbox( text(fmt::format("HP: {: >3} DMG: {: >3}", player_combat.hp, combat.damage)), separator(), log_box ) | flex_grow ) }); }); set_renderer(status_rend); } void StatusUI::log(std::string msg) { $messages.push_front(msg); if($messages.size() > MAX_LOG_MESSAGES) { $messages.pop_back(); } $log_list.clear(); for(auto msg : $messages) { $log_list.push_back(text(msg)); } } }