From dd71c71495653bce110fc9e058b5c3172f25d0a6 Mon Sep 17 00:00:00 2001 From: xtreme8000 Date: Thu, 15 Oct 2020 14:56:56 +0200 Subject: [PATCH] Brings back country flags to the server list * linear filter news images * linear filter fog gradient --- src/hud.c | 28 ++++++++++++++++++++++------ src/hud.h | 2 ++ src/main.c | 16 ++++++++++++---- src/texture.c | 19 ++++++++++++------- src/texture.h | 3 ++- 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/hud.c b/src/hud.c index c6c3965..5a6291c 100644 --- a/src/hud.c +++ b/src/hud.c @@ -2142,6 +2142,7 @@ static void hud_serverlist_render(mu_Context* ctx, float scalex, float scaley) { mu_begin_panel(ctx, "Servers"); int width = mu_get_current_container(ctx)->body.w; + int flag_width = ctx->style->size.y + ctx->style->padding * 2; mu_layout_row(ctx, 5, (int[]) {0.12F * width, 0.418F * width, 0.22F * width, 0.117F * width, -1}, 0); if(mu_button(ctx, "Players")) { @@ -2170,6 +2171,11 @@ static void hud_serverlist_render(mu_Context* ctx, float scalex, float scaley) { pthread_mutex_unlock(&serverlist_lock); } + mu_layout_row(ctx, 6, + (int[]) {0.12F * width, flag_width, 0.418F * width - flag_width - ctx->style->spacing * 2, + 0.22F * width, 0.117F * width, -1}, + 0); + pthread_mutex_lock(&serverlist_lock); if(server_count > 0) { for(int k = 0; k < server_count; k++) { @@ -2185,10 +2191,15 @@ static void hud_serverlist_render(mu_Context* ctx, float scalex, float scaley) { 1 : 2; + mu_push_id(ctx, &serverlist[k].identifier, strlen(serverlist[k].identifier)); + mu_text_color(ctx, 230 / f, 230 / f, 230 / f); bool join = false; if(mu_button_ex(ctx, total_str, 0, MU_OPT_NOFRAME | MU_OPT_ALIGNCENTER)) join = true; + if(mu_button_ex(ctx, "", texture_flag_index(serverlist[k].country) + HUD_FLAG_INDEX_START, + MU_OPT_NOFRAME)) + join = true; if(mu_button_ex(ctx, serverlist[k].name, 0, MU_OPT_NOFRAME)) join = true; if(mu_button_ex(ctx, serverlist[k].map, 0, MU_OPT_NOFRAME)) @@ -2196,18 +2207,22 @@ static void hud_serverlist_render(mu_Context* ctx, float scalex, float scaley) { if(mu_button_ex(ctx, serverlist[k].gamemode, 0, MU_OPT_NOFRAME | MU_OPT_ALIGNCENTER)) join = true; - if(serverlist[k].ping < 110) - mu_text_color(ctx, 0, 255 / f, 0); - else if(serverlist[k].ping < 200) - mu_text_color(ctx, 255 / f, 255 / f, 0); - else - mu_text_color(ctx, 255 / f, 0, 0); + if(serverlist[k].ping >= 0) { + if(serverlist[k].ping < 110) + mu_text_color(ctx, 0, 255 / f, 0); + else if(serverlist[k].ping < 200) + mu_text_color(ctx, 255 / f, 255 / f, 0); + else + mu_text_color(ctx, 255 / f, 0, 0); + } sprintf(total_str, "%ims", serverlist[k].ping); if(mu_button_ex(ctx, (serverlist[k].ping >= 0) ? total_str : "?", 0, MU_OPT_NOFRAME | MU_OPT_ALIGNCENTER)) join = true; + mu_pop_id(ctx); + if(join) { server_c(serverlist[k].identifier, serverlist[k].name); break; @@ -2281,6 +2296,7 @@ static void hud_serverlist_render(mu_Context* ctx, float scalex, float scaley) { int width, height; lodepng_decode32(&buffer, &width, &height, img, size); texture_create_buffer(¤t->image, width, height, buffer, 1); + texture_filter(¤t->image, TEXTURE_FILTER_LINEAR); } current->next = (k < news_entries - 1) ? malloc(sizeof(struct serverlist_news_entry)) : NULL; current = current->next; diff --git a/src/hud.h b/src/hud.h index 977d61a..152e728 100644 --- a/src/hud.h +++ b/src/hud.h @@ -62,6 +62,8 @@ extern struct hud hud_controls; extern struct hud* hud_active; extern struct window_instance* hud_window; +#define HUD_FLAG_INDEX_START 64 + void hud_change(struct hud* new); void hud_init(); void hud_mousemode(int mode); diff --git a/src/main.c b/src/main.c index 1ce4c06..79335bf 100644 --- a/src/main.c +++ b/src/main.c @@ -451,14 +451,22 @@ void display() { cmd->rect.rect.w, cmd->rect.rect.h); break; case MU_COMMAND_ICON: - if(hud_active->ui_images) { + glColor4ub(cmd->icon.color.r, cmd->icon.color.g, cmd->icon.color.b, cmd->icon.color.a); + int size = min(cmd->icon.rect.w, cmd->icon.rect.h); + + if(cmd->icon.id >= HUD_FLAG_INDEX_START - 1) { + float u, v; + texture_flag_offset(cmd->icon.id - HUD_FLAG_INDEX_START, &u, &v); + + texture_draw_sector(&texture_ui_flags, cmd->icon.rect.x, + settings.window_height - cmd->icon.rect.y - size * 0.167F, size, + size * 0.667F, u, v, 18.0F / 256.0F, 12.0F / 256.0F); + glEnable(GL_BLEND); + } else if(hud_active->ui_images) { bool resize = false; struct texture* img = hud_active->ui_images(cmd->icon.id, &resize); if(img) { - glColor4ub(cmd->icon.color.r, cmd->icon.color.g, cmd->icon.color.b, cmd->icon.color.a); - int size = min(cmd->icon.rect.w, cmd->icon.rect.h); - texture_draw(img, cmd->icon.rect.x, settings.window_height - cmd->icon.rect.y, resize ? size : cmd->icon.rect.w, resize ? size : cmd->icon.rect.h); glEnable(GL_BLEND); diff --git a/src/texture.c b/src/texture.c index 84ba6ba..705eceb 100644 --- a/src/texture.c +++ b/src/texture.c @@ -89,12 +89,16 @@ 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) { - char** res = bsearch(country, texture_flags, 251, sizeof(char*), texture_flag_cmp); - if(res) { - int i = res - texture_flags; - *u = (i % 14) * (18.0F / 256.0F); - *v = (i / 14) * (12.0F / 256.0F); +int texture_flag_index(const char* country) { + char** res = bsearch(country, texture_flags, sizeof(texture_flags) / sizeof(texture_flags[0]), sizeof(char*), + texture_flag_cmp); + return res ? (res - texture_flags) : -1; +} + +void texture_flag_offset(int index, float* u, float* v) { + if(index >= 0) { + *u = (index % 14) * (18.0F / 256.0F); + *v = (index / 14) * (12.0F / 256.0F); } else { *u = 0.0F; *v = 0.9375F; @@ -217,7 +221,7 @@ void texture_draw_empty(float x, float y, float w, float h) { glDisableClientState(GL_VERTEX_ARRAY); } -#define texture_emit_rotated(tx, ty, x, y, a) cos(a) * x - sin(a) * y + tx, sin(a) * x + cos(a) * y + ty +#define texture_emit_rotated(tx, ty, x, y, a) cos(a) * (x)-sin(a) * (y) + (tx), sin(a) * (x) + cos(a) * (y) + (ty) void texture_draw_empty_rotated(float x, float y, float w, float h, float angle) { float vertices[12] @@ -392,6 +396,7 @@ void texture_init() { CHECK_ALLOCATION_ERROR(gradient) texture_gradient_fog(gradient); texture_create_buffer(&texture_gradient, 512, 512, (unsigned char*)gradient, 1); + texture_filter(&texture_gradient, TEXTURE_FILTER_LINEAR); texture_create_buffer(&texture_dummy, 1, 1, (unsigned char[]) {0, 0, 0, 0}, 1); } diff --git a/src/texture.h b/src/texture.h index 44ef7a8..6d9380e 100644 --- a/src/texture.h +++ b/src/texture.h @@ -71,7 +71,8 @@ extern struct texture texture_ui_knob; #define TEXTURE_FILTER_NEAREST 0 #define TEXTURE_FILTER_LINEAR 1 -void texture_flag_offset(const char* country, float* u, float* v); +int texture_flag_index(const char* country); +void texture_flag_offset(int index, float* u, float* v); void texture_filter(struct texture* t, int filter); void texture_init(void); int texture_create(struct texture* t, char* filename);