From 269af02993c9e487e178cdd4ea4a1413e111d6ab Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 16 Jan 2025 15:33:24 -0500 Subject: [PATCH] There's now a GUI that shows up when you interact with stairs down. --- gui.cpp | 24 ++++++++++++++++++++++++ gui.hpp | 15 +++++++++++++++ status.txt | 2 ++ 3 files changed, 41 insertions(+) diff --git a/gui.cpp b/gui.cpp index a459029..b14a799 100644 --- a/gui.cpp +++ b/gui.cpp @@ -30,6 +30,24 @@ using namespace std::chrono_literals; using namespace ftxui; using namespace components; +void NextLevelUI::create_render() { + has_border = true; + $no_button = Button("NO, I'M NOT", []{ fmt::println("no don't go down"); }); + $yes_button = Button("YES, I'M READY", []{ fmt::println("Going down."); }); + + $render = Renderer([&] { + return vflow({ + paragraph($message) | border, + $no_button->Render(), + $yes_button->Render() + }) | flex; + }); + + set_renderer($render); + add($yes_button); + add($no_button); +} + void DeathUI::create_render() { has_border = true; $exit_button = Button("EXIT", []{ std::exit(0); }); @@ -211,6 +229,7 @@ void GUI::create_renderer() { $status_ui.create_render(); $inventory_ui.create_render(); $death_ui.create_render(); + $next_level_ui.create_render(); $active_panels = {&$map_view, &$status_ui}; } @@ -269,6 +288,7 @@ void GUI::handle_world_events() { auto& device = std::any_cast(data); $status_ui.log(format("Up stairs has test {}.", (bool)device.config["test"])); + toggle_modal(&$next_level_ui, $next_level); } break; default: $status_ui.log(format("INVALID EVENT! {},{}", evt, entity)); @@ -441,6 +461,10 @@ void GUI::render_scene() { draw_paused(); $death_ui.render(); $renderer.draw($death_ui); + } else if($next_level) { + draw_paused(); + $next_level_ui.render(); + $renderer.draw($next_level_ui); } else { $map_view.render(); $renderer.draw($map_view); diff --git a/gui.hpp b/gui.hpp index 109de45..e5efb1c 100644 --- a/gui.hpp +++ b/gui.hpp @@ -59,6 +59,19 @@ class DeathUI : public Panel { void create_render(); }; +class NextLevelUI : public Panel { + public: + Component $render = nullptr; + Component $yes_button = nullptr; + Component $no_button = nullptr; + std::string $message = "Are you ready to go further down?"; + + NextLevelUI() : + Panel(INVENTORY_PIXEL_X, INVENTORY_PIXEL_Y, INVENTORY_WIDTH, INVENTORY_HEIGHT) {} + + void create_render(); +}; + class InventoryUI : public Panel { public: @@ -117,10 +130,12 @@ class GUI { MapViewUI $map_view; InventoryUI $inventory_ui; DeathUI $death_ui; + NextLevelUI $next_level_ui; Canvas $canvas; bool $inventory_open = false; bool $player_died = false; bool $modal_shown = false; + bool $next_level = false; Component $test_button; SoundManager $sounds; SFMLRender $renderer; diff --git a/status.txt b/status.txt index 635230a..cb2b814 100644 --- a/status.txt +++ b/status.txt @@ -1,5 +1,7 @@ TODAY'S GOAL: +* GUI needs to become a statemachine now. Too many panels open at too many times. +* Panels should be able to take a width/height and center theirself for me * Linux on Arch catch2 fails with catch2-main missing and xwayland displays weird when small (gentoo plasma6 wayland). * Position needs three types of collision: full, false, and none. * Stairs \u2ac5 for stairs down, and \u2259 stairs up