From d59fe32ad976493b2e17fa3cb2f6334ff44f8f79 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 5 Feb 2018 03:41:55 +1000 Subject: [PATCH] Experimental support for waypoint icons (drawing of icon currently broken) --- defaultClient.cfg | 1 + qcsrc/common/mutators/events.qh | 1 + .../mutator/waypoints/waypointsprites.qc | 64 +++++++++++++++---- .../mutator/waypoints/waypointsprites.qh | 1 + 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/defaultClient.cfg b/defaultClient.cfg index e4904ff58..6b8c0f7d6 100644 --- a/defaultClient.cfg +++ b/defaultClient.cfg @@ -385,6 +385,7 @@ set g_waypointsprite_timealphaexponent 1 seta g_waypointsprite_turrets 1 "disable turret waypoints" seta g_waypointsprite_turrets_maxdist 5000 "max distance for turret waypoints" seta g_waypointsprite_uppercase 1 +seta g_waypointsprite_text 0 "Always show text instead of icons, setting this to 0 will still use text if the icon is unavailable" alias "g_waypointsprite_personal" "impulse 30" alias "g_waypointsprite_personal_p" "impulse 31" diff --git a/qcsrc/common/mutators/events.qh b/qcsrc/common/mutators/events.qh index 107a82030..cf8584870 100644 --- a/qcsrc/common/mutators/events.qh +++ b/qcsrc/common/mutators/events.qh @@ -65,6 +65,7 @@ MUTATOR_HOOKABLE(IsFlying, EV_IsFlying); /**/ i(string, MUTATOR_ARGV_1_string) \ /**/ o(vector, MUTATOR_ARGV_2_vector) \ /**/ o(string, MUTATOR_ARGV_3_string) \ + /**/ o(string, MUTATOR_ARGV_4_string) \ /**/ MUTATOR_HOOKABLE(WP_Format, EV_WP_Format); diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc index 6dec163fa..6ad7bf5c6 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc @@ -265,6 +265,25 @@ string spritelookuptext(entity this, string s) return s; } + +string spritelookupicon(entity this, string s) +{ + // TODO: needs icons! //if (s == WP_RaceStartFinish.netname) return (race_checkpointtime || race_mycheckpointtime) ? _("Finish") : _("Start"); + if (s == WP_Weapon.netname) return Weapons_from(this.wp_extra).model2; + if (s == WP_Item.netname) return Items_from(this.wp_extra).m_icon; + //if (s == WP_Monster.netname) return get_monsterinfo(this.wp_extra).m_icon; + if (MUTATOR_CALLHOOK(WP_Format, this, s)) + { + return M_ARGV(4, string); + } + + // need to loop, as our netname could be one of three + FOREACH(Waypoints, it.netname == s, { + return it.m_icon; + }); + + return s; +} #endif #ifdef CSQC @@ -646,20 +665,40 @@ void Draw_WaypointSprite(entity this) o = drawspritearrow(o, ang, rgb, a, SPRITE_ARROW_SCALE * t); - string txt; - if (autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam) - txt = _("Spam"); - else - txt = spritelookuptext(this, spriteimage); - if (this.helpme && time < this.helpme) - txt = sprintf(_("%s needing help!"), txt); - if (autocvar_g_waypointsprite_uppercase) - txt = strtoupper(txt); + 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 txt = string_null; + if (autocvar_g_waypointsprite_text || !icon_found) + { + if (autocvar_g_waypointsprite_spam && waypointsprite_count >= autocvar_g_waypointsprite_spam) + txt = _("Spam"); + else + txt = spritelookuptext(this, spriteimage); + if (this.helpme && time < this.helpme) + txt = sprintf(_("%s needing help!"), txt); + if (autocvar_g_waypointsprite_uppercase) + txt = strtoupper(txt); + } draw_beginBoldFont(); if (this.health >= 0) { - o = drawspritetext(o, ang, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt); + if(autocvar_g_waypointsprite_text || !icon_found) + o = drawspritetext(o, ang, (SPRITE_HEALTHBAR_WIDTH + 2 * SPRITE_HEALTHBAR_BORDER) * t, rgb, a, waypointsprite_fontsize * '1 1 0', txt); + else + drawpic_aspect(o, pic, vec2(SPRITE_HEALTHBAR_WIDTH * t, SPRITE_HEALTHBAR_HEIGHT * t), rgb, a, DRAWFLAG_NORMAL); float align, marg; if (this.build_finished) @@ -690,7 +729,10 @@ void Draw_WaypointSprite(entity this) } else { - o = drawspritetext(o, ang, 0, rgb, a, waypointsprite_fontsize * '1 1 0', txt); + if (autocvar_g_waypointsprite_text || !icon_found) + o = drawspritetext(o, ang, 0, rgb, a, waypointsprite_fontsize * '1 1 0', txt); + else + drawpic_aspect(o, pic, vec2(SPRITE_HEALTHBAR_WIDTH * t, SPRITE_HEALTHBAR_HEIGHT * t), rgb, a, DRAWFLAG_NORMAL); } draw_endBoldFont(); } diff --git a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh index 6a8d57157..d032a26ee 100644 --- a/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh +++ b/qcsrc/common/mutators/mutator/waypoints/waypointsprites.qh @@ -53,6 +53,7 @@ float autocvar_g_waypointsprite_timealphaexponent; bool autocvar_g_waypointsprite_turrets = true; float autocvar_g_waypointsprite_turrets_maxdist = 5000; bool autocvar_g_waypointsprite_uppercase; +bool autocvar_g_waypointsprite_text; float waypointsprite_fadedistance; float waypointsprite_normdistance; -- 2.39.2