You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.5 KiB
57 lines
1.5 KiB
#include "status_ui.hpp"
|
|
#include <ftxui/dom/node.hpp> // for Render
|
|
#include <ftxui/screen/box.hpp> // for ftxui
|
|
#include <ftxui/component/loop.hpp>
|
|
#include <ftxui/screen/color.hpp>
|
|
#include <ftxui/dom/table.hpp>
|
|
#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<Player>();
|
|
|
|
auto status_rend = Renderer([&, player]{
|
|
const auto& player_combat = $level.world->get<Combat>(player.entity);
|
|
const auto& combat = $level.world->get<Combat>(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));
|
|
}
|
|
}
|
|
}
|
|
|