1 // self.isactive = player is in range and coordinates/status (health and armor) are up to date
2 // self.origin = player origin TODO: should maybe move this so it's the origin of the shownames tag already in SSQC for culling?
5 // self.sameteam = player is on same team as local client
7 const float SHOWNAMES_FADESPEED = 4;
10 if(!autocvar_hud_shownames)
13 if(self.sameteam || (!self.sameteam && autocvar_hud_shownames_enemies))
15 self.origin = getplayerorigin(self.the_entnum-1);
16 self.origin_z += autocvar_hud_shownames_offset;
20 /* WIP, why does trace_ent != self not work as intended here?
21 if(autocvar_hud_shownames_enemies != 2) // player has to point at enemy if so
23 traceline(view_origin, view_origin + view_forward * MAX_SHOT_DISTANCE, MOVETYPE_FLY, world);
24 print("trace_endpos: ", vtos(trace_endpos), " view_origin: ", vtos(view_origin), "\n");
29 traceline(self.origin, view_origin, 1, self);
33 o = project_3d_to_2d(self.origin);
36 if(autocvar_hud_shownames_antioverlap)
38 // fade tag out if another tag that is closer to you overlaps
40 for(e = world; (e = find(e, classname, "shownames_tag")); )
44 eo = project_3d_to_2d(e.origin);
45 if not(eo_z < 0 || eo_x < 0 || eo_y < 0 || eo_x > vid_conwidth || eo_y > vid_conheight)
48 if(vlen((eX * o_x + eY * o_y) - eo) < autocvar_hud_shownames_antioverlap_distance && vlen(self.origin - view_origin) > vlen(e.origin - view_origin))
57 if(!self.sameteam && trace_endpos != view_origin) // out of view, fade out
58 self.alpha = max(0, self.alpha - SHOWNAMES_FADESPEED * frametime);
59 else if(!self.healthvalue) // dead player, fade out slowly
60 self.alpha = max(0, self.alpha - SHOWNAMES_FADESPEED * 0.25 * frametime);
61 else if(overlap) // tag overlap detected, fade out
62 self.alpha = max(0, self.alpha - SHOWNAMES_FADESPEED * frametime);
64 self.alpha = min(1, self.alpha + SHOWNAMES_FADESPEED * frametime);
70 dist = vlen(self.origin - view_origin);
73 a = autocvar_hud_shownames_alpha;
75 if(autocvar_hud_shownames_maxdistance)
77 if(dist >= autocvar_hud_shownames_maxdistance)
79 a *= ((autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance) - max(0, dist - autocvar_hud_shownames_mindistance)) / (autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance);
87 if(autocvar_hud_shownames_resize) // limit resize so its never smaller than 0.5... gets unreadable
88 resize = 0.5 + 0.5 * ((autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance) - max(0, dist - autocvar_hud_shownames_mindistance)) / (autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance);
90 // draw the sprite image
91 if not(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
96 mySize = (eX * autocvar_hud_shownames_aspect + eY) * autocvar_hud_shownames_fontsize;
97 myPos = o - '0.5 0 0' * mySize_x - '0 1 0' * mySize_y;
103 myPos_x += 0.5 * (mySize_x / resize - mySize_x);
104 myPos_y += (mySize_y / resize - mySize_y);
106 vector namepos; // this is where the origin of the string
110 namewidth = mySize_x;
112 if(autocvar_hud_shownames_status && teamplay)
116 if(self.healthvalue > 0)
118 HUD_Panel_DrawProgressBar(namepos + '0 1 0' * autocvar_hud_shownames_fontsize * resize, eX * 0.5 * mySize_x + eY * resize * autocvar_hud_shownames_statusbar_height, "nametag_statusbar", self.healthvalue/autocvar_hud_panel_healtharmor_maxhealth, 0, 1, '1 0 0', a, DRAWFLAG_NORMAL);
120 if(self.armorvalue > 0)
121 HUD_Panel_DrawProgressBar(namepos + '0 1 0' * autocvar_hud_shownames_fontsize * resize + eX * 0.5 * mySize_x, eX * 0.5 * mySize_x + eY * resize * autocvar_hud_shownames_statusbar_height, "nametag_statusbar", self.armorvalue/autocvar_hud_panel_healtharmor_maxarmor, 0, 0, '0 1 0', a, DRAWFLAG_NORMAL);
127 s = GetPlayerName(self.the_entnum-1);
128 if((autocvar_hud_shownames_decolorize == 1 && teamplay) || autocvar_hud_shownames_decolorize == 2)
129 s = playername(s, GetPlayerColor(self.the_entnum-1));
131 drawfontscale = '1 1 0' * resize;
132 s = textShortenToWidth(s, namewidth, '1 1 0' * autocvar_hud_shownames_fontsize, stringwidth_colors);
135 width = stringwidth(s, TRUE, '1 1 0' * autocvar_hud_shownames_fontsize);
137 if (width != namewidth)
138 namepos_x += (namewidth - width) / 2;
139 drawcolorcodedstring(namepos, s, '1 1 0' * autocvar_hud_shownames_fontsize, a, DRAWFLAG_NORMAL);
140 drawfontscale = '1 1 0';