After some prototyping I have what I think I want for the map. Just a simple piece of paper you take out that has the ASCII map on it.

This commit is contained in:
Zed A. Shaw 2025-03-21 02:51:02 -04:00
parent acbf384e2a
commit 6c9016eb0f
21 changed files with 1184 additions and 92 deletions

View file

@ -6,64 +6,63 @@
#include "rand.hpp"
#include "animation.hpp"
#include "rand.hpp"
#include <codecvt>
#include <iostream>
namespace gui {
using namespace components;
MapViewUI::MapViewUI(GameLevel &level) :
$level(level)
$level(level), $tiles(level.map->width(), level.map->height())
{
$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::init() {
$gui.world().set_the<guecs::Background>({$gui.$parser});
void MapViewUI::init(int x, int y, int w, int h) {
$gui.position(x, y, w, h);
$gui.layout(
"[*%(100,900)map_grid]"
"[_ ]"
"[_ ]"
"[_ ]"
"[_ ]"
"[_ ]"
"[_ ]"
"[_ ]"
"[_ ]");
for(auto& [name, cell] : $gui.cells()) {
auto box = $gui.entity(name);
if(name != "map_grid") {
if(name == "status") {
$gui.set<guecs::Sprite>(box, {"paper_ui_background"});
} else if(name != "map_grid") {
$gui.set<guecs::Rectangle>(box, {});
$gui.set<guecs::Label>(box, {name});
}
}
auto grid = $gui.entity("map_grid");
$gui.set<guecs::WideText>(grid, {L"Loading...", 25, ColorValue::DARK_LIGHT, 20});
$gui.set<guecs::Sprite>(grid, {"paper_ui_background"});
$gui.init();
for(auto& [name, cell] : $grid.cells()) {
auto box = $grid.entity(name);
$grid.set<guecs::Rectangle>(box, {});
$grid.set<guecs::Label>(box, {name});
}
$grid.init();
}
void MapViewUI::render(sf::RenderWindow &window) {
$tiles = $level.map->tiles();
auto grid = $gui.entity("map_grid");
auto player_pos = $level.world->get<Position>($level.player);
std::string map_out = $tiles.to_string(player_pos.location.x, player_pos.location.y);
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring map_wstr = converter.from_bytes(map_out);
auto& map_text = $gui.get<guecs::WideText>(grid);
map_text.update(map_wstr);
$gui.render(window);
$grid.render(window);
}
}