diff --git a/combat_ui.cpp b/combat_ui.cpp index 8466856..524408a 100644 --- a/combat_ui.cpp +++ b/combat_ui.cpp @@ -18,6 +18,8 @@ namespace gui { 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); diff --git a/constants.hpp b/constants.hpp index 8d5b995..7d721b5 100644 --- a/constants.hpp +++ b/constants.hpp @@ -38,10 +38,10 @@ constexpr int BASE_MAP_FONT_SIZE=90; constexpr int GAME_MAP_PIXEL_POS = 600; constexpr int MAX_FONT_SIZE = 140; constexpr int MIN_FONT_SIZE = 20; -constexpr int STATUS_UI_WIDTH = 29; -constexpr int STATUS_UI_HEIGHT = 25; -constexpr int STATUS_UI_X = 43; -constexpr int STATUS_UI_Y = 200; +constexpr int STATUS_UI_WIDTH = SCREEN_WIDTH - RAY_VIEW_WIDTH; +constexpr int STATUS_UI_HEIGHT = SCREEN_HEIGHT; +constexpr int STATUS_UI_X = 0; +constexpr int STATUS_UI_Y = 0; constexpr float PERCENT = 0.01f; constexpr int COMBAT_UI_WIDTH = 89; constexpr int COMBAT_UI_HEIGHT = 6; diff --git a/guecs.cpp b/guecs.cpp index c13fdaf..a545c5d 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -22,6 +22,15 @@ namespace guecs { } void UI::init(TexturePack& textures) { + if($world.has_the()) { + auto& bg = $world.get_the(); + bg.init(); + } + + $world.query([](auto, auto& bg) { + bg.init(); + }); + $world.query([](auto, auto& cell, auto& rect) { rect.init(cell); }); @@ -49,6 +58,11 @@ namespace guecs { } void UI::render(sf::RenderWindow& window) { + if($world.has_the()) { + auto& bg = $world.get_the(); + window.draw(*bg.shape); + } + $world.query([&](auto, auto& rect) { window.draw(*rect.shape); }); diff --git a/guecs.hpp b/guecs.hpp index 337c8d1..91ad747 100644 --- a/guecs.hpp +++ b/guecs.hpp @@ -42,10 +42,9 @@ namespace guecs { shared_ptr shape = nullptr; void init(lel::Cell& cell) { - sf::Vector2f size{(float)cell.w, (float)cell.h}; + sf::Vector2f size{float(cell.w) - 6, float(cell.h) - 6}; if(shape == nullptr) shape = make_shared(size); shape->setPosition({float(cell.x + 3), float(cell.y + 3)}); - shape->setSize({float(cell.w - 6), float(cell.h - 6)}); shape->setFillColor(ColorValue::DARK_MID); shape->setOutlineColor(ColorValue::MID); shape->setOutlineThickness(1); @@ -65,6 +64,31 @@ namespace guecs { std::string name; }; + struct Background { + float x = 0.0f; + float y = 0.0f; + float w = 0.0f; + float h = 0.0f; + + shared_ptr shape = nullptr; + + Background(lel::Parser& parser) : + x(parser.grid_x), + y(parser.grid_y), + w(parser.grid_w), + h(parser.grid_h) + {} + + Background() {} + + void init() { + sf::Vector2f size{float(w), float(h)}; + if(shape == nullptr) shape = make_shared(size); + shape->setPosition({float(x), float(y)}); + shape->setFillColor(ColorValue::MID); + } + }; + class UI { public: DinkyECS::World $world; diff --git a/gui.cpp b/gui.cpp index 007f304..6711fe0 100644 --- a/gui.cpp +++ b/gui.cpp @@ -53,7 +53,7 @@ namespace gui { $combat_view.render($textures); - $status_view.create_render(); + $status_view.render($textures); $status_view.log("Welcome to the game!"); $renderer.init_terminal(); @@ -323,18 +323,7 @@ namespace gui { } void FSM::draw_gui() { - sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, SCREEN_HEIGHT}); - rect.setPosition({0,0}); - rect.setFillColor({30, 30, 30}); - $window.draw(rect); - - auto left_gui = $textures.sprite_textures.at("left_gui").sprite; - left_gui->setPosition({0,0}); - $window.draw(*left_gui); - - $status_view.render(); - $renderer.draw($status_view); - + $status_view.draw($window); $combat_view.draw($window); auto debug = $level.world->get_the(); diff --git a/status_ui.cpp b/status_ui.cpp index 5d4cd60..b56ea75 100644 --- a/status_ui.cpp +++ b/status_ui.cpp @@ -1,46 +1,41 @@ #include "status_ui.hpp" -#include // for Render -#include // for ftxui -#include -#include -#include #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(); - - 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::render(TexturePack &textures) { + auto& world = $gui.world(); + auto& cell = $gui.cells().at("log_view"); + $log_to = $gui.entity("log_view"); + world.set($log_to, cell); + world.set($log_to, {}); + world.set($log_to, {"TEST"}); + + $gui.init(textures); + } + + void StatusUI::draw(sf::RenderWindow &window) { + auto &world = $gui.world(); + auto &text = world.get($log_to); + std::string log; + + for(auto msg : $messages) { + log += msg + "\n"; + } + + 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)); - } } } diff --git a/status_ui.hpp b/status_ui.hpp index 698893b..e2c35f0 100644 --- a/status_ui.hpp +++ b/status_ui.hpp @@ -1,18 +1,21 @@ #pragma once -#include "panel.hpp" #include "levelmanager.hpp" #include "constants.hpp" #include +#include "texture.hpp" +#include "guecs.hpp" namespace gui { - class StatusUI : public Panel { + class StatusUI { public: - std::vector $log_list; + guecs::UI $gui; + DinkyECS::Entity $log_to; std::deque $messages; GameLevel $level; StatusUI(GameLevel level); - void create_render(); void update_level(GameLevel &level) { $level = level; } void log(std::string msg); + void render(TexturePack &textures); + void draw(sf::RenderWindow &window); }; }