diff --git a/assets/config.json b/assets/config.json index 79613ff..cc97800 100644 --- a/assets/config.json +++ b/assets/config.json @@ -54,7 +54,8 @@ "tunnel_with_rocks_stage": "assets/tunnel_with_rocks_stage.png", "ritual_crafting_area": "assets/ritual_crafting_area.png", "the_ritual_circle": "assets/the_ritual_circle.png", - "paper_ui_background": "assets/paper_ui_background.png" + "paper_ui_background": "assets/paper_ui_background.png", + "full_screen_paper": "assets/full_screen_paper.png" }, "worldgen": { "enemy_probability": 50, diff --git a/assets/full_screen_paper.png b/assets/full_screen_paper.png new file mode 100644 index 0000000..12b5cfd Binary files /dev/null and b/assets/full_screen_paper.png differ diff --git a/guecs.cpp b/guecs.cpp index 5d9b1b3..ac5fdfd 100644 --- a/guecs.cpp +++ b/guecs.cpp @@ -40,6 +40,7 @@ namespace guecs { bg.init(); } + $world.query([](auto, auto& bg) { bg.init(); }); @@ -75,7 +76,17 @@ namespace guecs { $world.query([&](auto, auto &cell, auto &sprite) { sprite.init(cell); }); + } + void UI::debug_layout(sf::RenderWindow& window) { + $world.query([&](const auto, auto &cell) { + sf::RectangleShape rect{{float(cell.w), float(cell.h)}}; + rect.setPosition({float(cell.x), float(cell.y)}); + rect.setFillColor(sf::Color::Transparent); + rect.setOutlineColor(sf::Color::Red); + rect.setOutlineThickness(2.0f); + window.draw(rect); + }); } void UI::render(sf::RenderWindow& window) { @@ -114,6 +125,8 @@ namespace guecs { $world.query([&](auto, auto& text) { window.draw(*text.text); }); + + } bool UI::mouse(float x, float y) { diff --git a/guecs.hpp b/guecs.hpp index a077b24..2144f0d 100644 --- a/guecs.hpp +++ b/guecs.hpp @@ -212,6 +212,7 @@ namespace guecs { void init(); void render(sf::RenderWindow& window); bool mouse(float x, float y); + void debug_layout(sf::RenderWindow& window); template void set(DinkyECS::Entity ent, Comp val) { diff --git a/gui_fsm.cpp b/gui_fsm.cpp index 599a2ae..c472ed4 100644 --- a/gui_fsm.cpp +++ b/gui_fsm.cpp @@ -18,6 +18,8 @@ namespace gui { $level($levels.current()), $combat_ui($level), $status_ui($level), + $map_ui($level), + $mini_map($level), $font{FONT_FILE_NAME} { } @@ -42,12 +44,15 @@ namespace gui { $main_ui.init(); $combat_ui.init(); $status_ui.init(); + $status_ui.log("Welcome to the game!"); - $status_ui.update(); $boss_fight_ui = $levels.create_bossfight($level.world); $boss_fight_ui->init(); + $map_ui.init(); + $mini_map.init($main_ui.$overlay_ui.$gui); + run_systems(); state(State::IDLE); } @@ -126,13 +131,13 @@ namespace gui { state(State::ROTATING); break; case MAP_OPEN: - $status_ui.map_open = !$status_ui.map_open; + $map_open = !$map_open; break; case ATTACK: state(State::ATTACKING); break; case START_COMBAT: - $main_ui.$overlay_ui.show_sprite("top_right", "cinqueda"); + $map_open = false; state(State::IN_COMBAT); break; case CLOSE: @@ -291,10 +296,13 @@ namespace gui { $boss_fight_ui->render($window); } else { $main_ui.render(); - $status_ui.render($window); - $combat_ui.render($window); + if($map_open) { + $map_ui.render($window); + } else { + $mini_map.render($window); + } } } @@ -359,7 +367,6 @@ namespace gui { // $status_ui.log(fmt::format("You picked up a {}.", // std::string(item.data["name"]))); $status_ui.log("You picked up an item."); - $status_ui.update(); } break; case eGUI::ATTACK: event(Event::ATTACK); @@ -378,11 +385,9 @@ namespace gui { auto name = std::any_cast(data); $status_ui.log(fmt::format("NOOP EVENT! {},{} name={}", evt, entity, name)); } - $status_ui.update(); } break; default: $status_ui.log(fmt::format("INVALID EVENT! {},{}", evt, entity)); - $status_ui.update(); } } } @@ -392,8 +397,10 @@ namespace gui { $level = $levels.next(); $status_ui.update_level($level); + $map_ui.update_level($level); $combat_ui.update_level($level); $main_ui.update_level($level); + $boss_fight_ui = $levels.create_bossfight($level.world); $boss_fight_ui->init(); diff --git a/gui_fsm.hpp b/gui_fsm.hpp index d916cec..ea1c8cb 100644 --- a/gui_fsm.hpp +++ b/gui_fsm.hpp @@ -7,6 +7,8 @@ #include "combat_ui.hpp" #include "status_ui.hpp" #include "boss_fight_ui.hpp" +#include "map_view.hpp" +#include "mini_map.hpp" namespace gui { enum class State { @@ -44,12 +46,15 @@ namespace gui { sf::RenderWindow $window; bool $draw_stats = false; bool autowalking = false; + bool $map_open = false; LevelManager $levels; MainUI $main_ui; GameLevel $level; shared_ptr $boss_fight_ui = nullptr; CombatUI $combat_ui; StatusUI $status_ui; + MapViewUI $map_ui; + MiniMapUI $mini_map; sf::Font $font; FSM(); diff --git a/main_ui.cpp b/main_ui.cpp index dc64a42..2dc993c 100644 --- a/main_ui.cpp +++ b/main_ui.cpp @@ -61,6 +61,7 @@ namespace gui { void MainUI::draw_blood() { auto player = $level.world->get_the(); auto player_combat = $level.world->get(player.entity); + if(float(player_combat.hp) / float(player_combat.max_hp) < 0.5) { $overlay_ui.show_sprite("middle", "blood_splatter"); } else { diff --git a/map_view.cpp b/map_view.cpp index 1844083..3c719a1 100644 --- a/map_view.cpp +++ b/map_view.cpp @@ -15,8 +15,7 @@ namespace gui { MapViewUI::MapViewUI(GameLevel &level) : $level(level), - $tiles(level.map->width(), - level.map->height()) + $paper(textures::get("full_screen_paper")) { } @@ -24,28 +23,37 @@ namespace gui { $level = level; } - void MapViewUI::init(int x, int y, int w, int h) { - $gui.position(x, y, w, h); - $gui.layout("[map_grid]"); + void MapViewUI::init() { + //auto top_right = overlay.entity("top_right"); + //auto cell = overlay.cell_for(top_right); + $gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + $gui.layout( + "[status| *%(200)map_grid | _ ]" + ); auto grid = $gui.entity("map_grid"); $gui.set(grid, - {L"Loading...", 45, ColorValue::DARK_LIGHT, 10}); + {L"Loading...", 65, {27, 26, 23, 150}, 10}); - $gui.set(grid, {"paper_ui_background"}); + auto status = $gui.entity("status"); + $gui.set(status, + {"Loading...", 25, {37, 36, 33}, 25}); + $paper.sprite->setPosition({0, 0}); $gui.init(); } void MapViewUI::render(sf::RenderWindow &window) { - $tiles = $level.map->tiles(); + window.draw(*$paper.sprite); + auto grid = $gui.entity("map_grid"); - std::wstring map_out = System::draw_map($level, 13, 6); + std::wstring map_out = System::draw_map($level, 23, 9); auto& map_text = $gui.get(grid); map_text.update(map_out); $gui.render(window); + // $gui.debug_layout(window); } } diff --git a/map_view.hpp b/map_view.hpp index c5c8e4a..8a5d85a 100644 --- a/map_view.hpp +++ b/map_view.hpp @@ -9,10 +9,10 @@ namespace gui { public: guecs::UI $gui; GameLevel $level; - TileMap $tiles; + textures::SpriteTexture $paper; MapViewUI(GameLevel &level); - void init(int x, int y, int w, int h); + void init(); void render(sf::RenderWindow &window); void update_level(GameLevel &level); }; diff --git a/meson.build b/meson.build index 36255be..945449b 100644 --- a/meson.build +++ b/meson.build @@ -102,6 +102,7 @@ sources = [ 'main_ui.cpp', 'map.cpp', 'map_view.cpp', + 'mini_map.cpp', 'matrix.cpp', 'matrix.cpp', 'overlay_ui.cpp', diff --git a/mini_map.cpp b/mini_map.cpp new file mode 100644 index 0000000..d0968b0 --- /dev/null +++ b/mini_map.cpp @@ -0,0 +1,39 @@ +#include "mini_map.hpp" +#include +#include +#include "dbc.hpp" +#include "components.hpp" +#include "rand.hpp" +#include "animation.hpp" +#include "systems.hpp" +#include "rand.hpp" +#include +#include +#include + +namespace gui { + using namespace components; + + MiniMapUI::MiniMapUI(GameLevel &level) : + $map_grid{L"...", 45, {200, 200, 200, 100}, 10}, + $level(level) + { + $font = std::make_shared(FONT_FILE_NAME); + } + + void MiniMapUI::update_level(GameLevel &level) { + $level = level; + } + + void MiniMapUI::init(guecs::UI& overlay) { + auto top_right = overlay.entity("top_right"); + auto cell = overlay.cell_for(top_right); + $map_grid.init(cell, $font); + } + + void MiniMapUI::render(sf::RenderWindow &window) { + std::wstring map_out = System::draw_map($level, 5, 3); + $map_grid.update(map_out); + window.draw(*$map_grid.text); + } +} diff --git a/mini_map.hpp b/mini_map.hpp new file mode 100644 index 0000000..56e0abc --- /dev/null +++ b/mini_map.hpp @@ -0,0 +1,20 @@ +#pragma once +#include "levelmanager.hpp" +#include "textures.hpp" +#include "guecs.hpp" +#include "tilemap.hpp" + +namespace gui { + class MiniMapUI { + public: + guecs::WideText $map_grid; + guecs::UI $gui; + GameLevel $level; + shared_ptr $font = nullptr; + + MiniMapUI(GameLevel &level); + void init(guecs::UI& overlay); + void render(sf::RenderWindow &window); + void update_level(GameLevel &level); + }; +} diff --git a/overlay_ui.cpp b/overlay_ui.cpp index 0235d6c..8ed7221 100644 --- a/overlay_ui.cpp +++ b/overlay_ui.cpp @@ -11,7 +11,7 @@ namespace gui { OverlayUI::OverlayUI() { $gui.position(RAY_VIEW_X, RAY_VIEW_Y, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT); $gui.layout( - "[top_left|top|top_right]" + "[top_left|top|>(170)top_right]" "[*%(300,300)middle|_|_]" "[_|_|_]" "[_|_|_]" @@ -25,6 +25,7 @@ namespace gui { void OverlayUI::render(sf::RenderWindow& window) { $gui.render(window); + // $gui.debug_layout(window); } void OverlayUI::show_sprite(string region, string sprite_name) { diff --git a/status_ui.cpp b/status_ui.cpp index 2ed44b7..7ae23d8 100644 --- a/status_ui.cpp +++ b/status_ui.cpp @@ -10,8 +10,7 @@ namespace gui { using std::any, std::any_cast, std::string, std::make_any; StatusUI::StatusUI(GameLevel level) : - $level(level), $ritual_ui(level), - $map_ui($level) + $level(level), $ritual_ui(level) { $gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT); $gui.layout( @@ -38,8 +37,6 @@ namespace gui { $log_to = $gui.entity("log_view"); $gui.set($log_to, {}); $gui.set($log_to, {"Welcome to the Game!", 20}); - - $map_ui.init(cell.x, cell.y, cell.w, cell.h); } else { auto button = $gui.entity(name); $gui.set(button, {}); @@ -92,8 +89,6 @@ namespace gui { } else { log(fmt::format("You are out of {}.", name)); } - - update(); } } } @@ -137,11 +132,6 @@ namespace gui { void StatusUI::render(sf::RenderWindow &window) { $gui.render(window); - - if(map_open) { - $map_ui.render(window); - } - $ritual_ui.render(window); } @@ -150,11 +140,11 @@ namespace gui { if($messages.size() > MAX_LOG_MESSAGES) { $messages.pop_back(); } + update(); } void StatusUI::update_level(GameLevel &level) { $level = level; - $map_ui.update_level($level); init(); } } diff --git a/status_ui.hpp b/status_ui.hpp index 8f4ecb8..0fccb6f 100644 --- a/status_ui.hpp +++ b/status_ui.hpp @@ -5,19 +5,16 @@ #include "textures.hpp" #include "guecs.hpp" #include "ritual_ui.hpp" -#include "map_view.hpp" namespace gui { class StatusUI { public: - bool map_open = false; guecs::UI $gui; DinkyECS::Entity $log_to; std::map $slots; std::deque $messages; GameLevel $level; RitualUI $ritual_ui; - MapViewUI $map_ui; StatusUI(GameLevel level); void select_slot(DinkyECS::Entity ent, std::any data);