@ -123,6 +123,22 @@ bool GUI::handle_events() {
return event_happened ;
return event_happened ;
}
}
sf : : Sprite & GUI : : get_text_sprite ( wchar_t tile ) {
if ( ! $ sprites . contains ( tile ) ) {
sf : : Glyph glyph = $ font . getGlyph ( tile , MAP_FONT_SIZE , false ) ;
// WARNING! we actually have to do this here because SFML caches
// the glyphs on the font texture, so this gets loaded each time
// we get a new glyph from the font.
$ font_texture = $ font . getTexture ( MAP_FONT_SIZE ) ;
sf : : Sprite sprite ( $ font_texture ) ;
sprite . setTextureRect ( glyph . textureRect ) ;
$ sprites [ tile ] = sprite ;
}
return $ sprites [ tile ] ;
}
void GUI : : run_systems ( ) {
void GUI : : run_systems ( ) {
auto player = $ world . get < Player > ( ) ;
auto player = $ world . get < Player > ( ) ;
System : : enemy_pathing ( $ world , $ game_map , player ) ;
System : : enemy_pathing ( $ world , $ game_map , player ) ;
@ -133,33 +149,39 @@ void GUI::run_systems() {
void GUI : : draw_screen ( bool clear , float map_off_x , float map_off_y ) {
void GUI : : draw_screen ( bool clear , float map_off_x , float map_off_y ) {
if ( clear ) $ window . clear ( ) ;
if ( clear ) $ window . clear ( ) ;
std : : string screenout = $ screen . ToString ( ) ;
std : : string screenout = $ screen . ToString ( ) ;
std : : string map_screenout = $ map_screen . ToString ( ) ;
std : : wstring main_screen_utf8 = $ converter . from_bytes ( screenout ) ;
std : : wstring main_screen_utf8 = $ converter . from_bytes ( screenout ) ;
$ ui_text . setString ( main_screen_utf8 ) ;
$ ui_text . setString ( main_screen_utf8 ) ;
$ window . draw ( $ ui_text ) ;
$ window . draw ( $ ui_text ) ;
std : : string map_screenout = $ map_screen . ToString ( ) ;
std : : wstring map_screen_utf8 = $ converter . from_bytes ( map_screenout ) ;
std : : wstring map_screen_utf8 = $ converter . from_bytes ( map_screenout ) ;
sf : : Texture ftext = $ font . getTexture ( MAP_FONT_SIZE ) ;
float y = 0.0f ;
float y = 0.0f ;
float x = GAME_MAP_POS ;
float x = GAME_MAP_POS ;
const float line_spacing = $ font . getLineSpacing ( MAP_FONT_SIZE ) ;
const float line_spacing = $ font . getLineSpacing ( MAP_FONT_SIZE ) ;
sf : : Glyph base_glyph = $ font . getGlyph ( L ' █ ' , MAP_FONT_SIZE , false ) ;
auto bg_sprite = get_text_sprite ( L ' █ ' ) ;
bg_sprite . setColor ( sf : : Color ( 20 , 20 , 20 ) ) ;
auto add_sprite = get_text_sprite ( L ' ! ' ) ;
bool has_add = false ;
for ( size_t i = 0 ; i < map_screen_utf8 . size ( ) ; i + + ) {
for ( size_t i = 0 ; i < map_screen_utf8 . size ( ) ; i + + ) {
wchar_t tile = map_screen_utf8 [ i ] ;
wchar_t tile = map_screen_utf8 [ i ] ;
sf : : Glyph glyph = $ font . getGlyph ( tile , MAP_FONT_SIZE , false ) ;
sf : : Sprite & sprite = get_text_sprite ( tile ) ;
sf : : Sprite sprite ( ftext ) ;
sprite . setTextureRect ( glyph . textureRect ) ;
sprite . setPosition ( { x , y } ) ;
sprite . setPosition ( { x , y } ) ;
bg_sprite . setPosition ( { x , y } ) ;
if ( tile = = L ' █ ' ) {
if ( tile = = L ' █ ' ) {
sprite . setColor ( sf : : Color ( 100 , 100 , 10 0) ) ;
sprite . setColor ( sf : : Color ( 80 , 80 , 8 0) ) ;
} else if ( tile = = L ' ☺ ' ) {
} else if ( tile = = L ' ☺ ' ) {
sprite . setColor ( sf : : Color : : Blue ) ;
sprite . setColor ( sf : : Color : : Blue ) ;
} else if ( tile = = L ' Ω ' ) {
} else if ( tile = = L ' Ω ' ) {
sprite . setColor ( sf : : Color : : Red ) ;
sprite . setColor ( sf : : Color : : Red ) ;
} else if ( tile = = L ' · ' ) {
add_sprite . setColor ( sf : : Color : : Red ) ;
sprite . setColor ( color ( Value : : DARK_MID ) ) ;
add_sprite . setPosition ( { x - 3 , y - 3 } ) ;
has_add = true ;
} else if ( tile = = L ' # ' ) {
sprite . setColor ( sf : : Color ( 5 , 5 , 5 ) ) ;
} else if ( tile = = L ' \r ' ) {
} else if ( tile = = L ' \r ' ) {
continue ; // skip these, just windows junk
continue ; // skip these, just windows junk
} else if ( tile = = L ' \n ' ) {
} else if ( tile = = L ' \n ' ) {
@ -171,8 +193,13 @@ void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
sprite . setColor ( color ( Value : : MID ) ) ;
sprite . setColor ( color ( Value : : MID ) ) ;
}
}
$ window . draw ( bg_sprite ) ;
$ window . draw ( sprite ) ;
$ window . draw ( sprite ) ;
x + = glyph . advance ;
if ( has_add ) {
$ window . draw ( add_sprite ) ;
has_add = false ;
}
x + = base_glyph . advance ;
}
}
$ window . display ( ) ;
$ window . display ( ) ;