From 380e18b91aea2418ccaf8528894c8efb6e621780 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 31 Dec 2024 05:53:27 -0500 Subject: [PATCH] All of the GUI panels are now their own classes and pulled out of the main GUI so I can devise how they're managed. --- gui.cpp | 32 +++++++++++++++++++++----------- gui.hpp | 16 ++++++++++++---- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/gui.cpp b/gui.cpp index de8c10a..3565357 100644 --- a/gui.cpp +++ b/gui.cpp @@ -79,15 +79,31 @@ void StatusUI::create_render() { set_renderer(status_rend); } +MapViewUI::MapViewUI(DinkyECS::World& world, LightRender& lights, Map& game_map) : + Panel(GAME_MAP_PIXEL_POS, 0, 0, 0, true), + $world(world), $lights(lights), $game_map(game_map) +{} +void MapViewUI::create_render() { + set_renderer(Renderer([&] { + System::draw_map($world, $game_map, $lights.lighting(), $canvas, width, height); + return canvas($canvas); + })); +} + +void MapViewUI::resize_canvas() { + // set canvas to best size + $canvas = Canvas(width * 2, height * 4); +} + GUI::GUI(DinkyECS::World &world, Map& game_map) : + $world(world), $game_map(game_map), $status_ui(world), $lights(game_map.width(), game_map.height()), - $world(world), - $sounds("./assets"), - $renderer() + $map_view($world, $lights, $game_map), + $sounds("./assets") { // this needs a config file soon // $sounds.load("ambient", "ambient_sound.mp3"); @@ -101,8 +117,7 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) : void GUI::resize_map(int new_size) { $renderer.resize_grid(new_size, $map_view); - // set canvas to best size - $canvas = Canvas($map_view.width * 2, $map_view.height * 4); + $map_view.resize_canvas(); } void GUI::save_world() { @@ -113,11 +128,7 @@ void GUI::save_world() { void GUI::create_renderer() { $renderer.init_terminal(); - $map_view.set_renderer(Renderer([&] { - System::draw_map($world, $game_map, $lights.lighting(), $canvas, $map_view.width, $map_view.height); - return canvas($canvas); - })); - + $map_view.create_render(); $status_ui.create_render(); $inventory_ui.create_render(); // don't activate this one @@ -186,7 +197,6 @@ bool GUI::handle_ui_events() { if(event.type == sf::Event::Closed) { shutdown(); } else if(event.type == sf::Event::KeyPressed) { - if(KB::isKeyPressed(KB::Left)) { player_motion.dx = -1; event_happened = true; diff --git a/gui.hpp b/gui.hpp index 56230c3..41a4113 100644 --- a/gui.hpp +++ b/gui.hpp @@ -65,6 +65,7 @@ class StatusUI : public Panel { Panel(0, 0, STATUS_UI_WIDTH, STATUS_UI_HEIGHT), $log({{"Welcome to the game!"}}), $world(world) {} + void create_render(); void log(string msg) { $log.log(msg); @@ -73,19 +74,26 @@ class StatusUI : public Panel { class MapViewUI : public Panel { public: - MapViewUI() : Panel(GAME_MAP_PIXEL_POS, 0, 0, 0, true) {} + Canvas $canvas; + DinkyECS::World& $world; + LightRender& $lights; + Map& $game_map; + + MapViewUI(DinkyECS::World& world, LightRender& lights, Map& game_map); + void create_render(); + void resize_canvas(); }; class GUI { - Canvas $canvas; + DinkyECS::World& $world; Map& $game_map; StatusUI $status_ui; + LightRender $lights; MapViewUI $map_view; InventoryUI $inventory_ui; - LightRender $lights; + Canvas $canvas; bool $show_modal = false; Component $test_button; - DinkyECS::World& $world; SoundManager $sounds; SFMLRender $renderer; UnDumbTSS $paused;