--- /home/yonatyt/simu-git/simutrans-master/simmesg.cc 2021-08-19 20:50:23.000000000 -0400 +++ /home/yonatyt/simu-git/files/simmesg.cc 2021-08-20 15:58:26.605359000 -0400 @@ -20,6 +20,9 @@ #include "gui/messagebox.h" #include +// for get img from the vehicle +#include "bauer/vehikelbauer.h" +#include "descriptor/vehicle_desc.h" #define MAX_SAVED_MESSAGES (2000) @@ -229,6 +232,83 @@ return pos; } +image_id message_t::get_image_from_text(const char* text) +{ + cbuffer_t buf_a; + cbuffer_t buf_b; + const char *str = text; + const char *new_text = ""; + const char *wt_text = ""; + + if( *( str += strcspn( str, "<" ) ) ) { + str += 1; + size_t end = strlen( str ); + size_t start = 0; + while( start < end ) { + if( str[start] == '>' ) { + break; + } + if( str[start] == ',' ) { + new_text = strdup(buf_a); + str += 1; + while( start < end ) { + if( str[start] == '>' ) { + wt_text = strdup(buf_b); + break; + } + buf_b.printf( "%c", str[start] ); + start++; + } + break; + } + buf_a.printf( "%c", str[start] ); + start++; + } + } + + waytype_t wt = invalid_wt; + if ( strcmp( wt_text , "wt_road") == 0 ) { + wt = road_wt; + } + else if ( strcmp( wt_text , "wt_rail") == 0 ) { + wt = track_wt; + } + else if ( strcmp( wt_text , "wt_water") == 0 ) { + wt = water_wt; + } + else if ( strcmp( wt_text , "wt_monorail") == 0 ) { + wt = monorail_wt; + } + else if ( strcmp( wt_text , "wt_maglev") == 0 ) { + wt = maglev_wt; + } + else if ( strcmp( wt_text , "wt_tram") == 0 ) { + wt = tram_wt; + } + else if ( strcmp( wt_text , "wt_narrowgauge") == 0 ) { + wt = narrowgauge_wt; + } + else if ( strcmp( wt_text , "wt_air") == 0 ) { + wt = air_wt; + } + else if ( strcmp( wt_text , "wt_power") == 0 ) { + wt = powerline_wt; + } + else { + wt = invalid_wt; + } + + if( new_text && wt != invalid_wt ) { + slist_tpl const& list = vehicle_builder_t::get_info(wt); + FOR(slist_tpl const, i, list) { + if ( strcmp(i->get_name(), new_text) == 0 ) { + return i->get_base_image(); + } + } + } + return IMG_EMPTY; +} + void message_t::rotate90( sint16 size_w ) { --- /home/yonatyt/simu-git/simutrans-master/simmesg.h 2021-08-19 20:50:23.000000000 -0400 +++ /home/yonatyt/simu-git/files/simmesg.h 2021-08-20 15:51:48.403685000 -0400 @@ -93,6 +93,12 @@ * syntax: either @x,y or (x,y) */ static koord get_coord_from_text(const char* text); + + /** + * Returns first image from text (or IMG_EMPTY if none is found). + * syntax: either + */ + static image_id get_image_from_text(const char* text); }; #endif --- /home/yonatyt/simu-git/simutrans-master/simtool.cc 2021-08-19 20:50:23.000000000 -0400 +++ /home/yonatyt/simu-git/files/simtool.cc 2021-08-20 15:52:42.982170000 -0400 @@ -236,9 +236,14 @@ void open_error_msg_win(const char* error) { koord pos = message_t::get_coord_from_text(error); + image_id image = message_t::get_image_from_text(error); + if (pos != koord::invalid) { create_win( new news_loc(error, pos), w_time_delete, magic_none); } + else if (image != IMG_EMPTY) { + create_win( new news_img(error, image), w_time_delete, magic_none ); + } else { create_win( new news_img(error), w_time_delete, magic_none); }