From d6e64dd06b21e959a0a635bb5eb008bbf2ed3a59 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 16 May 2025 00:43:45 -0400 Subject: [PATCH] The log is now moved to the map, but changing StatusUI caused a weird compiler error so need to remove logs from that separate. --- autowalker.cpp | 2 +- gui/fsm.cpp | 19 ++++++++----------- gui/fsm.hpp | 1 - gui/map_view.cpp | 42 ++++++++++++++++++++++++++---------------- gui/map_view.hpp | 5 +++++ 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/autowalker.cpp b/autowalker.cpp index f5de524..ba2bc95 100644 --- a/autowalker.cpp +++ b/autowalker.cpp @@ -42,7 +42,7 @@ Pathing compute_paths(gui::FSM& fsm) { } void Autowalker::log(std::wstring msg) { - fsm.$status_ui.log(msg); + fsm.$map_ui.log(msg); } void Autowalker::status(std::wstring msg) { diff --git a/gui/fsm.cpp b/gui/fsm.cpp index 5000a2a..2ab8e7a 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -58,12 +58,12 @@ namespace gui { $combat_ui.init(); $status_ui.init(); - $status_ui.log(L"Welcome to the game!"); $boss_fight_ui = $levels.create_bossfight($level.world); $boss_fight_ui->init(); $map_ui.init(); + $map_ui.log(L"Welcome to the game!"); $mini_map.init($main_ui.$overlay_ui.$gui); run_systems(); @@ -397,15 +397,15 @@ namespace gui { auto &damage = std::any_cast(data); if(damage.enemy_did > 0) { - $status_ui.log(fmt::format(L"Enemy HIT YOU for {} damage!", damage.enemy_did)); + $map_ui.log(fmt::format(L"Enemy HIT YOU for {} damage!", damage.enemy_did)); } else { - $status_ui.log(L"Enemy MISSED YOU."); + $map_ui.log(L"Enemy MISSED YOU."); } if(damage.player_did > 0) { - $status_ui.log(fmt::format(L"You HIT enemy for {} damage!", damage.player_did)); + $map_ui.log(fmt::format(L"You HIT enemy for {} damage!", damage.player_did)); } else { - $status_ui.log(L"You MISSED the enemy."); + $map_ui.log(L"You MISSED the enemy."); } } break; @@ -425,10 +425,7 @@ namespace gui { event(Event::LOOT_OPEN); break; case eGUI::LOOT: { - // auto &item = std::any_cast(data); - // $status_ui.log(fmt::format("You picked up a {}.", - // std::string(item.data["name"]))); - $status_ui.log(L"You picked up an item."); + $map_ui.log(L"You picked up an item."); } break; case eGUI::HP_STATUS: System::player_status($level); @@ -456,11 +453,11 @@ namespace gui { case eGUI::NOOP: { if(data.type() == typeid(std::string)) { auto name = std::any_cast(data); - $status_ui.log(fmt::format(L"NOOP EVENT! {},{}", evt, entity)); + $map_ui.log(fmt::format(L"NOOP EVENT! {},{}", evt, entity)); } } break; default: - $status_ui.log(fmt::format(L"INVALID EVENT! {},{}", evt, entity)); + $map_ui.log(fmt::format(L"INVALID EVENT! {},{}", evt, entity)); } } } diff --git a/gui/fsm.hpp b/gui/fsm.hpp index a70c64f..5c6dc15 100644 --- a/gui/fsm.hpp +++ b/gui/fsm.hpp @@ -1,6 +1,5 @@ #pragma once #include "constants.hpp" -#include "stats.hpp" #include "levelmanager.hpp" #include "../fsm.hpp" #include "gui/debug_ui.hpp" diff --git a/gui/map_view.cpp b/gui/map_view.cpp index 9d63209..6377cff 100644 --- a/gui/map_view.cpp +++ b/gui/map_view.cpp @@ -13,6 +13,7 @@ namespace gui { using namespace components; + using namespace guecs; MapViewUI::MapViewUI(GameLevel &level) : $level(level), @@ -29,16 +30,15 @@ namespace gui { //auto cell = overlay.cell_for(top_right); $gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); $gui.layout( - "[status| *%(200)map_grid | _ ]" + "[log_view| *%(200)map_grid | _ ]" ); auto grid = $gui.entity("map_grid"); - $gui.set(grid, + $gui.set(grid, {L"Loading...", 65, {27, 26, 23, 150}, 10}); - auto status = $gui.entity("status"); - $gui.set(status, - {L"Loading...", 25, {37, 36, 33}, 25}); + $log_to = $gui.entity("log_view"); + $gui.set($log_to, {L"Welcome to the Game!", 25, {37, 36, 33}, 25}); $paper.sprite->setPosition({0, 0}); $gui.init(); @@ -48,23 +48,33 @@ namespace gui { window.draw(*$paper.sprite); auto grid = $gui.entity("map_grid"); - auto status = $gui.entity("status"); std::wstring map_out = System::draw_map($level, 23, 9, compass_dir); - auto& map_text = $gui.get(grid); + auto& map_text = $gui.get(grid); map_text.update(map_out); - auto& status_text = $gui.get(status); - - std::wstring status_out = fmt::format( - L"Level: {}\n" - L"Enemies Killed: A Lot\n", - $level.index + 1); - - status_text.update(status_out); - $gui.render(window); // $gui.debug_layout(window); } + + void MapViewUI::update() { + if($gui.has($log_to)) { + auto& text = $gui.get($log_to); + //BUG: I'm calling this what it is, fix it + wstring log_garbage; + for(auto msg : $messages) { + log_garbage += msg + L"\n"; + } + text.update(log_garbage); + } + } + + void MapViewUI::log(wstring msg) { + $messages.push_front(msg); + if($messages.size() > MAX_LOG_MESSAGES) { + $messages.pop_back(); + } + update(); + } } diff --git a/gui/map_view.hpp b/gui/map_view.hpp index 0c10417..05978f8 100644 --- a/gui/map_view.hpp +++ b/gui/map_view.hpp @@ -3,17 +3,22 @@ #include "textures.hpp" #include #include "tilemap.hpp" +#include namespace gui { class MapViewUI { public: guecs::UI $gui; GameLevel $level; + DinkyECS::Entity $log_to; textures::SpriteTexture $paper; + std::deque $messages; MapViewUI(GameLevel &level); void init(); void render(sf::RenderWindow &window, int compass_dir); void update_level(GameLevel &level); + void log(std::wstring msg); + void update(); }; }