You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.8 KiB
68 lines
1.8 KiB
#include "map_view.hpp"
|
|
#include <functional>
|
|
#include <string>
|
|
#include "dbc.hpp"
|
|
#include "components.hpp"
|
|
#include "rand.hpp"
|
|
#include "animation.hpp"
|
|
#include "rand.hpp"
|
|
#include <codecvt>
|
|
#include <iostream>
|
|
|
|
namespace gui {
|
|
using namespace components;
|
|
|
|
MapViewUI::MapViewUI(GameLevel &level) :
|
|
$level(level), $tiles(level.map->width(), level.map->height())
|
|
{
|
|
}
|
|
|
|
void MapViewUI::update_level(GameLevel &level) {
|
|
$level = level;
|
|
}
|
|
|
|
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});
|
|
}
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|