Move the map_view and mini_map into gui as well.

This commit is contained in:
Zed A. Shaw 2025-05-16 00:07:24 -04:00
parent bed5ce22d2
commit a2246d2b71
6 changed files with 5 additions and 6 deletions

View file

@ -9,8 +9,8 @@
#include "gui/status_ui.hpp"
#include "gui/loot_ui.hpp"
#include "gui/boss_fight_ui.hpp"
#include "map_view.hpp"
#include "mini_map.hpp"
#include "gui/map_view.hpp"
#include "gui/mini_map.hpp"
namespace gui {
enum class State {

70
gui/map_view.cpp Normal file
View file

@ -0,0 +1,70 @@
#include "map_view.hpp"
#include <functional>
#include <string>
#include "dbc.hpp"
#include "components.hpp"
#include "rand.hpp"
#include "animation.hpp"
#include "systems.hpp"
#include "rand.hpp"
#include <codecvt>
#include <iostream>
#include <fmt/xchar.h>
namespace gui {
using namespace components;
MapViewUI::MapViewUI(GameLevel &level) :
$level(level),
$paper(textures::get("full_screen_paper"))
{
}
void MapViewUI::update_level(GameLevel &level) {
$level = level;
}
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<guecs::Textual>(grid,
{L"Loading...", 65, {27, 26, 23, 150}, 10});
auto status = $gui.entity("status");
$gui.set<guecs::Textual>(status,
{L"Loading...", 25, {37, 36, 33}, 25});
$paper.sprite->setPosition({0, 0});
$gui.init();
}
void MapViewUI::render(sf::RenderWindow &window, int compass_dir) {
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<guecs::Textual>(grid);
map_text.update(map_out);
auto& status_text = $gui.get<guecs::Textual>(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);
}
}

19
gui/map_view.hpp Normal file
View file

@ -0,0 +1,19 @@
#pragma once
#include "levelmanager.hpp"
#include "textures.hpp"
#include <guecs/ui.hpp>
#include "tilemap.hpp"
namespace gui {
class MapViewUI {
public:
guecs::UI $gui;
GameLevel $level;
textures::SpriteTexture $paper;
MapViewUI(GameLevel &level);
void init();
void render(sf::RenderWindow &window, int compass_dir);
void update_level(GameLevel &level);
};
}

39
gui/mini_map.cpp Normal file
View file

@ -0,0 +1,39 @@
#include "mini_map.hpp"
#include <functional>
#include <string>
#include "dbc.hpp"
#include "components.hpp"
#include "rand.hpp"
#include "animation.hpp"
#include "systems.hpp"
#include "rand.hpp"
#include <codecvt>
#include <iostream>
#include <memory>
namespace gui {
using namespace components;
MiniMapUI::MiniMapUI(GameLevel &level) :
$map_grid{L"...", 45, {200, 200, 200, 100}, 10},
$level(level)
{
$font = std::make_shared<sf::Font>(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, int compass_dir) {
std::wstring map_out = System::draw_map($level, 5, 3, compass_dir);
$map_grid.update(map_out);
window.draw(*$map_grid.text);
}
}

20
gui/mini_map.hpp Normal file
View file

@ -0,0 +1,20 @@
#pragma once
#include "levelmanager.hpp"
#include "textures.hpp"
#include <guecs/ui.hpp>
#include "tilemap.hpp"
namespace gui {
class MiniMapUI {
public:
guecs::Textual $map_grid;
guecs::UI $gui;
GameLevel $level;
shared_ptr<sf::Font> $font = nullptr;
MiniMapUI(GameLevel &level);
void init(guecs::UI& overlay);
void render(sf::RenderWindow &window, int compass_dir);
void update_level(GameLevel &level);
};
}