From ab3e70a8d7c9e024fda6945f5fd50bcb2293e1fa Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 10 Feb 2018 17:52:03 +0100 Subject: [PATCH] Waypoint drawing: fix icon color when g_waypointsprite_iconcolor is active, don't check icon existence if g_waypointsprite_text is active --- .../mutator/waypoints/waypointsprites.qc | 63 +++++++++++-------- .../mutator/waypoints/waypointsprites.qh | 2 +- qcsrc/common/turrets/cl_turrets.qc | 2 +- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc index 325bc05c9..9a5ac2bf6 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc @@ -384,7 +384,7 @@ vector drawspritearrow(vector o, float ang, vector rgb, float a, float t) } // returns location of sprite healthbar -vector drawsprite_TextOrIcon(bool is_text, vector o, float ang, float minwidth, vector rgb, float a, vector sz, string str, string pic) +vector drawsprite_TextOrIcon(bool is_text, vector o, float ang, float minwidth, vector rgb, float a, vector sz, string str) { float algnx, algny; float sw, w, h; @@ -437,7 +437,7 @@ vector drawsprite_TextOrIcon(bool is_text, vector o, float ang, float minwidth, if (is_text) drawstring(o, str, sz, rgb, a, DRAWFLAG_NORMAL); else - drawpic(o, pic, sz, rgb, a, DRAWFLAG_NORMAL); + drawpic(o, str, sz, rgb, a, DRAWFLAG_NORMAL); o.x += 0.5 * sw; o.y += 0.5 * h; @@ -673,23 +673,31 @@ void Draw_WaypointSprite(entity this) o = drawspritearrow(o, ang, rgb, a, SPRITE_ARROW_SCALE * t); - vector iconcolor = ((autocvar_g_waypointsprite_iconcolor) ? '1 1 1' : rgb); - string spr_icon = spritelookupicon(this, spriteimage); - string pic = spr_icon; - bool icon_found = !(!spr_icon || spr_icon == ""); - if (icon_found) // it's valid, but let's make sure it exists! - { - pic = strcat(hud_skin_path, "/", spr_icon); - if(precache_pic(pic) == "") - { - pic = strcat("gfx/hud/default/", spr_icon); - if(!precache_pic(pic)) - icon_found = false; - } - } - + string pic = ""; + bool is_text = true; + if (!autocvar_g_waypointsprite_text) + { + string spr_icon = spritelookupicon(this, spriteimage); + pic = spr_icon; + bool icon_found = !(!spr_icon || spr_icon == ""); + if (icon_found) // it's valid, but let's make sure it exists! + { + pic = strcat(hud_skin_path, "/", spr_icon); + if(precache_pic(pic) == "") + { + pic = strcat("gfx/hud/default/", spr_icon); + if(!precache_pic(pic)) + icon_found = false; + } + } + if (icon_found) + is_text = false; + } + + vector sz; + vector txt_color; string txt = string_null; - if (autocvar_g_waypointsprite_text || !icon_found) + if (is_text) { if (autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam) txt = _("Spam"); @@ -699,15 +707,18 @@ void Draw_WaypointSprite(entity this) txt = sprintf(_("%s needing help!"), txt); if (autocvar_g_waypointsprite_uppercase) txt = strtoupper(txt); + txt_color = rgb; + sz = waypointsprite_fontsize * '1 1 0'; + } + else + { + // for convenience icon path and color are saved to txt and txt_color + txt = pic; + txt_color = ((autocvar_g_waypointsprite_iconcolor) ? '1 1 1' : rgb); + sz = autocvar_g_waypointsprite_iconsize * '1 1 0'; } draw_beginBoldFont(); - bool is_text = (autocvar_g_waypointsprite_text || !icon_found); - vector sz; - if (is_text) - sz = waypointsprite_fontsize * '1 1 0'; - else - sz = autocvar_g_waypointsprite_iconsize * '1 1 0'; if (this.health >= 0) { float align = 0, marg; @@ -721,7 +732,7 @@ void Draw_WaypointSprite(entity this) marg = SPRITE_HEALTHBAR_MARGIN * t + 0.5 * sz.y; float minwidth = (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t; - o = drawsprite_TextOrIcon(is_text, o, ang, minwidth, iconcolor, a, sz, txt, pic); + o = drawsprite_TextOrIcon(is_text, o, ang, minwidth, txt_color, a, sz, txt); drawhealthbar( o, 0, @@ -742,7 +753,7 @@ void Draw_WaypointSprite(entity this) } else { - drawsprite_TextOrIcon(is_text, o, ang, 0, iconcolor, a, sz, txt, pic); + drawsprite_TextOrIcon(is_text, o, ang, 0, txt_color, a, sz, txt); } draw_endBoldFont(); diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh index c9e19ccad..95b8890cc 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh @@ -101,7 +101,7 @@ void drawhealthbar(vector org, float rot, float h, vector sz, vector hotspot, fl vector drawspritearrow(vector o, float ang, vector rgb, float a, float t); // returns location of sprite healthbar -vector drawsprite_TextOrIcon(bool is_text, vector o, float ang, float minwidth, vector rgb, float a, vector sz, string str, string pic); +vector drawsprite_TextOrIcon(bool is_text, vector o, float ang, float minwidth, vector rgb, float a, vector sz, string str); float spritelookupblinkvalue(entity this, string s); vector spritelookupcolor(entity this, string s, vector def); diff --git a/qcsrc/common/turrets/cl_turrets.qc b/qcsrc/common/turrets/cl_turrets.qc index d3ee5cb65..850dd0ceb 100644 --- a/qcsrc/common/turrets/cl_turrets.qc +++ b/qcsrc/common/turrets/cl_turrets.qc @@ -180,7 +180,7 @@ void turret_draw2d(entity this) } o = drawspritearrow(o, M_PI, rgb, a, SPRITE_ARROW_SCALE * t); - o = drawsprite_TextOrIcon(true, o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt, ""); + o = drawsprite_TextOrIcon(true, o, M_PI, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt); drawhealthbar( o, 0, -- 2.39.2