Added a Background guecs component.
This commit is contained in:
parent
69a810b5a1
commit
3a6ba8445a
7 changed files with 78 additions and 56 deletions
|
@ -1,46 +1,41 @@
|
|||
#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"
|
||||
#include "guecs.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace components;
|
||||
using namespace ftxui;
|
||||
using namespace guecs;
|
||||
|
||||
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;
|
||||
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
|
||||
$gui.layout("[log_view]");
|
||||
}
|
||||
|
||||
void StatusUI::create_render() {
|
||||
auto player = $level.world->get_the<Player>();
|
||||
void StatusUI::render(TexturePack &textures) {
|
||||
auto& world = $gui.world();
|
||||
auto& cell = $gui.cells().at("log_view");
|
||||
$log_to = $gui.entity("log_view");
|
||||
world.set<lel::Cell>($log_to, cell);
|
||||
world.set<Rectangle>($log_to, {});
|
||||
world.set<Textual>($log_to, {"TEST"});
|
||||
|
||||
auto status_rend = Renderer([&, player]{
|
||||
const auto& player_combat = $level.world->get<Combat>(player.entity);
|
||||
const auto& combat = $level.world->get<Combat>(player.entity);
|
||||
$gui.init(textures);
|
||||
}
|
||||
|
||||
auto log_box = vbox($log_list) | yflex_grow | border;
|
||||
void StatusUI::draw(sf::RenderWindow &window) {
|
||||
auto &world = $gui.world();
|
||||
auto &text = world.get<Textual>($log_to);
|
||||
std::string log;
|
||||
|
||||
return hbox({
|
||||
hflow(
|
||||
vbox(
|
||||
text(fmt::format("HP: {: >3} DMG: {: >3}",
|
||||
player_combat.hp,
|
||||
combat.damage)),
|
||||
separator(),
|
||||
log_box
|
||||
) | flex_grow
|
||||
)
|
||||
});
|
||||
});
|
||||
for(auto msg : $messages) {
|
||||
log += msg + "\n";
|
||||
}
|
||||
|
||||
set_renderer(status_rend);
|
||||
text.label = log;
|
||||
|
||||
$gui.render(window);
|
||||
}
|
||||
|
||||
void StatusUI::log(std::string msg) {
|
||||
|
@ -48,10 +43,5 @@ namespace gui {
|
|||
if($messages.size() > MAX_LOG_MESSAGES) {
|
||||
$messages.pop_back();
|
||||
}
|
||||
|
||||
$log_list.clear();
|
||||
for(auto msg : $messages) {
|
||||
$log_list.push_back(text(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue