diff --git a/gui.cpp b/gui.cpp index 992d014..f9c1926 100644 --- a/gui.cpp +++ b/gui.cpp @@ -34,7 +34,6 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) : $log({{"Welcome to the game!"}}), $status_ui(SCREEN_X, SCREEN_Y, 0, 0), $map_view(0, 0, GAME_MAP_POS, 0, false), - $modal_test(SCREEN_X/2, SCREEN_Y/4, 800, 200, false), $view_port{0,0}, $world(world), $sounds("./assets"), @@ -72,25 +71,26 @@ void GUI::create_renderer() { })); auto modal_buttons = Container::Horizontal({ - Button("OK", [&]{ println("OK pressed"); }), - Button("CANCEL", [&]{ println("CANCEL pressed"); }), + Button("OK", [&]{ $show_modal = false; }), + Button("CANCEL", [&]{ $show_modal = false; }), }); - $modal_test.set_renderer(Renderer([&, modal_buttons] { + auto modal_test = Renderer([&, modal_buttons] { return hbox({ hflow( vbox( text("Hello!"), modal_buttons->Render() ))}) | border; - })); + }); + modal_test->Add(modal_buttons); auto test_button = Container::Horizontal({ Button("Open Test Modal", [&]{ $show_modal = true; }), Button("Close It", [&]{ $show_modal = false; }), }); - auto status_rend = Renderer(test_button, [&, test_button, player]{ + auto status_rend = Renderer(test_button, [&, modal_test, test_button, player]{ const auto& player_combat = $world.get(player.entity); const auto& inventory = $world.get(player.entity); $status_text = player_combat.hp > 0 ? "NOT DEAD" : "DEAD!!!!!!"; @@ -118,7 +118,10 @@ void GUI::create_renderer() { }); }); + status_rend |= Modal(modal_test, &$show_modal); + $status_ui.set_renderer(status_rend); + $status_ui.add(modal_test); } void GUI::handle_world_events() { @@ -240,10 +243,6 @@ void GUI::render_scene() { $renderer.draw_text($status_ui); $renderer.draw_grid($map_view); - if($show_modal) { - $renderer.draw_text($modal_test); - } - $renderer.display(); } diff --git a/gui.hpp b/gui.hpp index d99af67..38af59d 100644 --- a/gui.hpp +++ b/gui.hpp @@ -43,7 +43,6 @@ class GUI { ActionLog $log; Panel $status_ui; Panel $map_view; - Panel $modal_test; bool $show_modal = false; Point $view_port; Component $test_button; diff --git a/render.cpp b/render.cpp index f0b4c28..9eaed74 100644 --- a/render.cpp +++ b/render.cpp @@ -217,15 +217,17 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star } void SFMLRender::draw_text(Panel &panel, bool with_border) { + int border_px = with_border ? UI_PANEL_BORDER_PX : 0; + sf::RectangleShape backing( - sf::Vector2f($ui_bounds.width * panel.width, - $ui_bounds.height * panel.height)); + sf::Vector2f($ui_bounds.width * panel.width + border_px, + $ui_bounds.height * panel.height + border_px)); backing.setFillColor(sf::Color(0, 0, 0)); if(with_border) { - backing.setOutlineColor(color(Value::MID)); - backing.setOutlineThickness(5); + backing.setOutlineColor($default_fg); + backing.setOutlineThickness(border_px); } backing.setPosition(panel.x, panel.y); diff --git a/render.hpp b/render.hpp index e0bbcab..ee76288 100644 --- a/render.hpp +++ b/render.hpp @@ -23,6 +23,7 @@ const int BASE_MAP_FONT_SIZE=90; const wchar_t BG_TILE = L'█'; const wchar_t UI_BASE_CHAR = L'█'; const int BG_BOX_OFFSET=5; +const int UI_PANEL_BORDER_PX=5; enum class Value { BLACK=0, DARK_DARK, DARK_MID,