diff --git a/gui.cpp b/gui.cpp index 334900b..c9d8e1b 100644 --- a/gui.cpp +++ b/gui.cpp @@ -67,11 +67,6 @@ GUI::GUI() : $game_map(GAME_MAP_X, GAME_MAP_Y), $ui_text.setCharacterSize(UI_FONT_SIZE); $ui_text.setFillColor(color(Value::LIGHT_LIGHT)); - $map_text.setFont($font); - $map_text.setPosition(GAME_MAP_POS,0); - $map_text.setCharacterSize(MAP_FONT_SIZE); - $map_text.setFillColor(color(Value::MID)); - $game_map.generate(); } @@ -135,18 +130,6 @@ void GUI::run_systems() { System::combat($world, player); } -void GUI::burn() { - for(int i = 0; i < 20; ++i) { - $map_text.setFillColor(color(i % VALUES.size())); - int x = Random::uniform(-10,10); - int y = Random::uniform(-10,10); - draw_screen(false, x, y); - std::this_thread::sleep_for(2ms); - } - - $map_text.setFillColor(color(Value::MID)); -} - void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) { if(clear) $window.clear(); std::string screenout = $screen.ToString(); @@ -156,17 +139,19 @@ void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) { $window.draw($ui_text); std::wstring map_screen_utf8 = $converter.from_bytes(map_screenout); - $map_text.setString(map_screen_utf8); - sf::Texture ftext = $font.getTexture(MAP_FONT_SIZE); + float y = 0.0f; + float x = GAME_MAP_POS; + const float line_spacing = $font.getLineSpacing(MAP_FONT_SIZE); + for(size_t i = 0; i < map_screen_utf8.size(); i++) { wchar_t tile = map_screen_utf8[i]; sf::Glyph glyph = $font.getGlyph(tile, MAP_FONT_SIZE, false); sf::Sprite sprite(ftext); sprite.setTextureRect(glyph.textureRect); - auto pos = $map_text.findCharacterPos(i); - sprite.setPosition(pos); + sprite.setPosition({x, y}); + if(tile == L'█') { sprite.setColor(sf::Color(100,100,100)); } else if(tile == L'☺') { @@ -175,14 +160,19 @@ void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) { sprite.setColor(sf::Color::Red); } else if(tile == L'·') { sprite.setColor(color(Value::DARK_MID)); - } else if(tile == L'\n' || tile == L'\r') { - // skip newlines + } else if(tile == L'\r') { + continue; // skip these, just windows junk + } else if(tile == L'\n') { + // newline + y += line_spacing; + x = GAME_MAP_POS; continue; } else { sprite.setColor(color(Value::MID)); } $window.draw(sprite); + x += glyph.advance; } $window.display(); diff --git a/gui.hpp b/gui.hpp index d7926c3..b5d5143 100644 --- a/gui.hpp +++ b/gui.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -44,12 +45,12 @@ class GUI { Canvas $canvas; sf::Font $font; sf::Text $ui_text; - sf::Text $map_text; std::wstring_convert> $converter; sf::RenderWindow $window; Screen $screen; Screen $map_screen; DinkyECS::World $world; + std::unordered_map $sprites; public: GUI(); @@ -63,9 +64,9 @@ public: bool handle_events(); void draw_screen(bool clear=true, float map_off_x=0.0f, float map_off_y=0.0f); void shake(); - void burn(); void configure_world(); void run_systems(); + sf::Sprite get_text_sprite(wchar_t tile); int main(); };