diff --git a/resources/png/ui/flags.png b/resources/png/ui/flags.png new file mode 100644 index 0000000..84e6be8 Binary files /dev/null and b/resources/png/ui/flags.png differ diff --git a/src/hud.c b/src/hud.c index 6c49bb8..a82e50f 100644 --- a/src/hud.c +++ b/src/hud.c @@ -1349,6 +1349,7 @@ struct serverlist_entry { char gamemode[8]; int ping; char identifier[32]; + char country[4]; }; static http_t* request_serverlist = NULL; @@ -1478,6 +1479,12 @@ static void hud_serverlist_render(float scalex, float scaley) { font_render((settings.window_width-600*scaley)/2.0F+480*scaley,450*scaley-20*scaley*(k+1)-serverlist_scroll,16*scaley,serverlist[k].gamemode); sprintf(total_str,"%ims",serverlist[k].ping); + if(serverlist[k].current>=0) { + float u,v; + texture_flag_offset(serverlist[k].country,&u,&v); + texture_draw_sector(&texture_ui_flags,(settings.window_width-600*scaley)/2.0F+55*scaley,448*scaley-20*scaley*(k+1)-serverlist_scroll,18*scaley,12*scaley,u,v,18.0F/256.0F,12.0F/256.0F); + } + if(serverlist[k].ping<110) glColor3f(0.0F,1.0F*f,0.0F); else if(serverlist[k].ping<200) @@ -1561,6 +1568,7 @@ static void hud_serverlist_render(float scalex, float scaley) { strncpy(serverlist[k].map,json_object_get_string(s,"map"),20); strncpy(serverlist[k].gamemode,json_object_get_string(s,"game_mode"),7); strncpy(serverlist[k].identifier,json_object_get_string(s,"identifier"),31); + strncpy(serverlist[k].country,json_object_get_string(s,"country"),3); player_count += serverlist[k].current; } serverlist[0].current = serverlist[0].max = -1; @@ -1569,6 +1577,7 @@ static void hud_serverlist_render(float scalex, float scaley) { strcpy(serverlist[0].map,"-"); strcpy(serverlist[0].gamemode,"-"); strcpy(serverlist[0].identifier,"aos://16777343:32887"); + strcpy(serverlist[0].country,"US"); qsort(serverlist,server_count,sizeof(struct serverlist_entry),hud_serverlist_sort); http_release(request_serverlist); diff --git a/src/texture.c b/src/texture.c index ba84554..dce889a 100644 --- a/src/texture.c +++ b/src/texture.c @@ -56,6 +56,38 @@ struct texture texture_ui_input; struct texture texture_ui_box_empty; struct texture texture_ui_box_check; struct texture texture_ui_arrow; +struct texture texture_ui_flags; + +static char* texture_flags[250] = { + "AD","AE","AF","AG","AI","AL","AM","AN","AO","AQ","AR","AS","AT","AU", + "AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM", + "BN","BO","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG", + "CH","CI","CK","CL","CM","CN","CO","CR","CS","CU","CV","CX","CY","CZ", + "DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI", + "FJ","FK","FM","FO","FR","FX","GA","GB","GD","GE","GF","GG","GH","GI", + "GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN", + "HR","HT","HU","ID","IE","IL","IN","IO","IQ","IR","IS","IT","JE","JM", + "JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA", + "LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME", + "MF","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU", + "MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP", + "NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR", + "PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD", + "SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","ST","SV","SY", + "SZ","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TP","TR", + "TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG", + "VI","VN","VU","WF","WS","XT","YE","YT","YU","ZA","ZM","ZW" + }; + +static int texture_flag_cmp(const void* a, const void* b) { + return strcmp(a,*(const void* const*)b); +} + +void texture_flag_offset(const char* country, float* u, float* v) { + int i = (char**)bsearch(country,texture_flags,250,sizeof(char*),texture_flag_cmp)-texture_flags; + *u = (i%14)*(18.0F/256.0F); + *v = (i/14)*(12.0F/256.0F); +} void texture_filter(struct texture* t, int filter) { glBindTexture(GL_TEXTURE_2D,t->texture_id); @@ -328,10 +360,11 @@ void texture_init() { texture_create(&texture_ui_reload,"png/ui/reload.png"); texture_create(&texture_ui_bg,"png/ui/bg.png"); texture_create(&texture_ui_input,"png/ui/input.png"); - texture_create(&texture_ui_box_empty,"png/ui/box_empty.png"); texture_create(&texture_ui_box_check,"png/ui/box_check.png"); texture_create(&texture_ui_arrow,"png/ui/arrow.png"); + texture_create(&texture_ui_flags,"png/ui/flags.png"); + texture_filter(&texture_ui_flags,TEXTURE_FILTER_LINEAR); unsigned int* pixels = malloc(64*64*sizeof(unsigned int)); diff --git a/src/texture.h b/src/texture.h index 3d30948..6a0343e 100644 --- a/src/texture.h +++ b/src/texture.h @@ -58,10 +58,12 @@ extern struct texture texture_ui_input; extern struct texture texture_ui_box_empty; extern struct texture texture_ui_box_check; extern struct texture texture_ui_arrow; +extern struct texture texture_ui_flags; #define TEXTURE_FILTER_NEAREST 0 #define TEXTURE_FILTER_LINEAR 1 +void texture_flag_offset(const char* country, float* u, float* v); void texture_filter(struct texture* t, int filter); void texture_init(void); int texture_create(struct texture* t, char* filename);