Not the greatest but this is kind of what I want for the map.
This commit is contained in:
parent
6c9016eb0f
commit
2b57552152
1 changed files with 19 additions and 24 deletions
43
map_view.cpp
43
map_view.cpp
|
@ -23,42 +23,37 @@ namespace gui {
|
|||
|
||||
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 == "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});
|
||||
}
|
||||
}
|
||||
$gui.layout("[map_grid]");
|
||||
|
||||
auto grid = $gui.entity("map_grid");
|
||||
$gui.set<guecs::WideText>(grid, {L"Loading...", 25, ColorValue::DARK_LIGHT, 20});
|
||||
$gui.set<guecs::WideText>(grid, {L"Loading...", 45, ColorValue::DARK_LIGHT, 10});
|
||||
$gui.set<guecs::Sprite>(grid, {"paper_ui_background"});
|
||||
|
||||
$gui.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);
|
||||
auto player_pos = $level.world->get<Position>($level.player).location;
|
||||
|
||||
std::string map;
|
||||
|
||||
matrix::box it{$level.map->walls(), player_pos.x, player_pos.y, 7, 3};
|
||||
|
||||
while(it.next())
|
||||
{
|
||||
if(it.x == player_pos.x && it.y == player_pos.y) {
|
||||
map += "@";
|
||||
} else {
|
||||
map += $tiles.at(it.x, it.y).display;
|
||||
}
|
||||
|
||||
if(it.x == it.right - 1) map += "\n";
|
||||
}
|
||||
|
||||
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);
|
||||
std::wstring map_wstr = converter.from_bytes(map);
|
||||
|
||||
auto& map_text = $gui.get<guecs::WideText>(grid);
|
||||
map_text.update(map_wstr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue