From a53f81715d28b30f07e5110d4420056932bdc1c7 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 20 Mar 2025 04:13:22 -0400 Subject: [PATCH] Have a basic map prototype gui working. --- guecs.cpp | 3 ++- gui_fsm.cpp | 2 ++ map_view.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- map_view.hpp | 7 ++++++- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/guecs.cpp b/guecs.cpp index 47ec57b..a1360d0 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -11,7 +11,8 @@ namespace guecs { void UI::layout(std::string grid) { $grid = grid; - $parser.parse($grid); + bool good = $parser.parse($grid); + dbc::check(good, "LEL parsing failed."); for(auto& [name, cell] : $parser.cells) { auto ent = entity(name); diff --git a/gui_fsm.cpp b/gui_fsm.cpp index deebc5c..b3a70f4 100644 --- a/gui_fsm.cpp +++ b/gui_fsm.cpp @@ -43,6 +43,7 @@ namespace gui { $level.world->set_the({}); $main_ui.init(); + $map_ui.init(); $combat_ui.init(); $status_ui.init(); @@ -320,6 +321,7 @@ namespace gui { void FSM::render() { if(in_state(State::MAPPING)) { $window.clear(); + $map_ui.render($window); } else if(in_state(State::NEXT_LEVEL)) { $window.clear(); $boss_fight_ui->render($window); diff --git a/map_view.cpp b/map_view.cpp index befb89b..2a2766a 100644 --- a/map_view.cpp +++ b/map_view.cpp @@ -1,6 +1,11 @@ #include "map_view.hpp" #include #include +#include "dbc.hpp" +#include "components.hpp" +#include "rand.hpp" +#include "animation.hpp" +#include "rand.hpp" namespace gui { using namespace components; @@ -8,13 +13,57 @@ namespace gui { MapViewUI::MapViewUI(GameLevel &level) : $level(level) { + $gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + $gui.layout( + "[*%(100,900)left|*%(200,900)map_grid| _]" + "[_ | _ | _]" + "[_ | _ | _]" + "[_ | _ | _]" + "[_ | _ | _]" + "[_ | _ | _]" + "[_ | _ | _]" + "[_ | _ | _]" + "[_ | _ | _]" + "[bottom_status_left | bottom_status_right ]"); + + auto cell = $gui.cell_for($gui.entity("map_grid")); + $grid.position(cell.x, cell.y, cell.w, cell.h); + $grid.layout( + "[cell_11|cell_12|cell_13|cell_14|cell_15|cell_16|cell_17]" + "[cell_21|cell_22|cell_23|cell_24|cell_25|cell_26|cell_27]" + "[cell_31|cell_32|cell_33|cell_34|cell_35|cell_36|cell_37]" + "[cell_41|cell_42|cell_43|cell_44|cell_45|cell_46|cell_47]" + "[cell_51|cell_52|cell_53|cell_54|cell_55|cell_56|cell_57]"); } void MapViewUI::update_level(GameLevel &level) { $level = level; } - void MapViewUI::draw_map() { + void MapViewUI::init() { + $gui.world().set_the({$gui.$parser}); + + for(auto& [name, cell] : $gui.cells()) { + auto box = $gui.entity(name); + if(name != "map_grid") { + $gui.set(box, {}); + $gui.set(box, {name}); + } + } + + $gui.init(); + + for(auto& [name, cell] : $grid.cells()) { + auto box = $grid.entity(name); + $grid.set(box, {}); + $grid.set(box, {name}); + } + + $grid.init(); + } + void MapViewUI::render(sf::RenderWindow &window) { + $gui.render(window); + $grid.render(window); } } diff --git a/map_view.hpp b/map_view.hpp index 959e39c..cc6791d 100644 --- a/map_view.hpp +++ b/map_view.hpp @@ -1,13 +1,18 @@ #pragma once #include "levelmanager.hpp" +#include "textures.hpp" +#include "guecs.hpp" namespace gui { class MapViewUI { public: + guecs::UI $gui; + guecs::UI $grid; GameLevel $level; MapViewUI(GameLevel &level); - void draw_map(); + void init(); + void render(sf::RenderWindow &window); void update_level(GameLevel &level); }; }