From bc21aebd490345e99d926bab71f542720be98d36 Mon Sep 17 00:00:00 2001 From: Samual Date: Tue, 30 Aug 2011 04:05:25 -0400 Subject: [PATCH] Implement fade delay feature which waits X seconds before beginning to show name of player - helps to prevent showing names of players when they aren't in view for very long --- qcsrc/client/shownames.qc | 20 +++++++++++++++----- qcsrc/client/shownames.qh | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/qcsrc/client/shownames.qc b/qcsrc/client/shownames.qc index 8e13b722d..3e9a22cfd 100644 --- a/qcsrc/client/shownames.qc +++ b/qcsrc/client/shownames.qc @@ -3,8 +3,10 @@ // self.healthvalue // self.armorvalue // self.sameteam = player is on same team as local client +// self.fadedelay = time to wait before name tag starts fading in for enemies // const float SHOWNAMES_FADESPEED = 4; +const float SHOWNAMES_FADEDELAY = 0.5; void Draw_ShowNames(entity ent) { if(!autocvar_hud_shownames) @@ -59,19 +61,27 @@ void Draw_ShowNames(entity ent) } onscreen = (o_z >= 0 && o_x >= 0 && o_y >= 0 && o_x <= vid_conwidth && o_y <= vid_conheight); + + if(!ent.fadedelay) + ent.fadedelay = time + SHOWNAMES_FADEDELAY; if(!ent.sameteam && (!onscreen || !hit)) // out of view, fade out - ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * frametime); + { + ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * frametime); + ent.fadedelay = 0; // reset fade in delay, enemy has left the view + } else if(ent.healthvalue < 1) // dead player, fade out slowly - ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * 0.25 * frametime); + ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * 0.25 * frametime); else if(overlap) // tag overlap detected, fade out - ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * frametime); - else // fade in + ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * frametime); + else if(ent.sameteam) // fade in for team mates + ent.alpha = min(1, ent.alpha + SHOWNAMES_FADESPEED * frametime); + else if(time > ent.fadedelay) // fade in for enemies ent.alpha = min(1, ent.alpha + SHOWNAMES_FADESPEED * frametime); if(!ent.alpha) return; - + float dist; dist = vlen(ent.origin - view_origin); diff --git a/qcsrc/client/shownames.qh b/qcsrc/client/shownames.qh index 50380e820..d30f1acce 100644 --- a/qcsrc/client/shownames.qh +++ b/qcsrc/client/shownames.qh @@ -1,4 +1,5 @@ .float healthvalue; .float armorvalue; .float sameteam; +.float fadedelay; -- 2.39.2