#include "map_view.hpp" #include #include #include "dbc.hpp" #include "components.hpp" #include "rand.hpp" #include "animation.hpp" #include "systems.hpp" #include "rand.hpp" #include #include #include #include namespace gui { using namespace components; using namespace guecs; MapViewUI::MapViewUI(GameLevel &level) : $level(level), $map_render(std::make_shared()), $map_sprite($map_render->getTexture()), $map_tiles(matrix::make(12,11)), $paper(textures::get("full_screen_paper")) { } void MapViewUI::update_level(GameLevel &level) { $level = level; } void MapViewUI::init() { $gui.position(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); $gui.layout( "[log_view| *%(200)map_grid | _ ]" ); $log_to = $gui.entity("log_view"); $gui.set($log_to, {L"Welcome to the Game!", 25, {37, 36, 33}, 25}); $paper.sprite->setPosition({0, 0}); auto map_cell = $gui.cell_for("map_grid"); $map_sprite.setPosition({(float)map_cell.x, (float)map_cell.y + 30}); $gui.init(); } void MapViewUI::save_map(int compass_dir) { (void)compass_dir; // confirm we get two different maps auto out_img = $map_render->getTexture().copyToImage(); bool worked = out_img.saveToFile("tmp/map_render.png"); dbc::check(worked, "failed to render map"); } void MapViewUI::render(sf::RenderWindow &window, int compass_dir) { window.draw(*$paper.sprite); System::draw_map($level, $map_tiles, $entity_map, compass_dir); System::render_map($map_tiles, $entity_map, *$map_render); $map_sprite.setTexture($map_render->getTexture(), true); window.draw($map_sprite); $gui.render(window); // $gui.debug_layout(window); } void MapViewUI::update() { if(auto text = $gui.get_if($log_to)) { //BUG: I'm calling this what it is, fix it wstring log_garbage; for(auto msg : $messages) { log_garbage += msg + L"\n"; } text->update(log_garbage); } } void MapViewUI::log(wstring msg) { $messages.push_front(msg); if($messages.size() > MAX_LOG_MESSAGES) { $messages.pop_back(); } update(); } }