2 #include "../dpdefs/csprogsdefs.qh"
4 #include "../common/constants.qh"
5 #include "../common/teams.qh"
6 #include "../common/util.qh"
7 #include "../common/mapinfo.qh"
8 #include "autocvars.qh"
10 #include "../csqcmodellib/cl_model.qh"
11 #include "shownames.qh"
17 // self.isactive = player is in range and coordinates/status (health and armor) are up to date
18 // self.origin = player origin TODO: should maybe move this so it's the origin of the shownames tag already in SSQC for culling?
21 // self.sameteam = player is on same team as local client
22 // self.fadedelay = time to wait before name tag starts fading in for enemies
23 // self.pointtime = last time you pointed at this player
24 // self.csqcmodel_isdead = value of csqcmodel_isdead to know when the player is dead or not
26 const float SHOWNAMES_FADESPEED = 4;
27 const float SHOWNAMES_FADEDELAY = 0.4;
28 void Draw_ShowNames(entity ent)
30 if(!autocvar_hud_shownames)
33 if(ent.sv_entnum == player_localentnum) // ent is me or person i'm spectating
34 if(!(autocvar_hud_shownames_self && autocvar_chase_active))
37 if(ent.sameteam || (!ent.sameteam && autocvar_hud_shownames_enemies))
39 ent.origin_z += autocvar_hud_shownames_offset;
42 if(ent.sameteam && !autocvar_hud_shownames_crosshairdistance)
48 traceline(view_origin, ent.origin, MOVE_NORMAL, ent);
49 if(trace_fraction < 1 && (trace_networkentity != ent.sv_entnum && trace_ent.entnum != ent.sv_entnum))
56 float overlap = false, onscreen, crosshairdistance;
59 o = project_3d_to_2d(ent.origin);
61 if(autocvar_hud_shownames_antioverlap)
63 // fade tag out if another tag that is closer to you overlaps
65 for(e = world; (e = find(e, classname, "shownames_tag")); )
69 eo = project_3d_to_2d(e.origin);
70 if (!(eo.z < 0 || eo.x < 0 || eo.y < 0 || eo.x > vid_conwidth || eo.y > vid_conheight))
73 if(vlen((eX * o.x + eY * o.y) - eo) < autocvar_hud_shownames_antioverlap_distance && vlen(ent.origin - view_origin) > vlen(e.origin - view_origin))
82 onscreen = (o.z >= 0 && o.x >= 0 && o.y >= 0 && o.x <= vid_conwidth && o.y <= vid_conheight);
83 crosshairdistance = sqrt( pow(o.x - vid_conwidth/2, 2) + pow(o.y - vid_conheight/2, 2) );
85 if(autocvar_hud_shownames_crosshairdistance)
87 if(autocvar_hud_shownames_crosshairdistance > crosshairdistance)
90 if (ent.pointtime + autocvar_hud_shownames_crosshairdistance_time <= time)
93 overlap = (autocvar_hud_shownames_crosshairdistance_antioverlap ? overlap : false); // override what antioverlap says unless allowed by cvar.
97 ent.fadedelay = time + SHOWNAMES_FADEDELAY;
99 if(!ent.sameteam && (!onscreen || !hit)) // out of view, fade out
101 ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * frametime);
102 ent.fadedelay = 0; // reset fade in delay, enemy has left the view
104 else if(ent.csqcmodel_isdead) // dead player, fade out slowly
105 ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * 0.25 * frametime);
106 else if(overlap) // tag overlap detected, fade out
107 ent.alpha = max(0, ent.alpha - SHOWNAMES_FADESPEED * frametime);
108 else if(ent.sameteam) // fade in for team mates
109 ent.alpha = min(1, ent.alpha + SHOWNAMES_FADESPEED * frametime);
110 else if(time > ent.fadedelay) // fade in for enemies
111 ent.alpha = min(1, ent.alpha + SHOWNAMES_FADESPEED * frametime);
113 // multiply by player alpha
114 if(!ent.sameteam || (ent.sv_entnum == player_localentnum))
115 ent.alpha *= getplayeralpha(ent.sv_entnum-1);
117 if(ent.alpha < ALPHA_MIN_VISIBLE && gametype != MAPINFO_TYPE_CTS)
121 dist = vlen(ent.origin - view_origin);
124 a = autocvar_hud_shownames_alpha;
126 if(autocvar_hud_shownames_maxdistance)
128 if(dist >= autocvar_hud_shownames_maxdistance)
130 a *= ((autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance) - max(0, dist - autocvar_hud_shownames_mindistance)) / (autocvar_hud_shownames_maxdistance - autocvar_hud_shownames_mindistance);
138 if(autocvar_hud_shownames_resize) // limit resize so its never smaller than 0.5... gets unreadable
139 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);
141 // draw the sprite image
146 vector myPos, mySize;
147 mySize = (eX * autocvar_hud_shownames_aspect + eY) * autocvar_hud_shownames_fontsize;
148 myPos = o - '0.5 0 0' * mySize.x - '0 1 0' * mySize.y;
154 myPos.x += 0.5 * (mySize.x / resize - mySize.x);
155 myPos.y += (mySize.y / resize - mySize.y);
157 vector namepos; // this is where the origin of the string
161 namewidth = mySize.x;
163 if(autocvar_hud_shownames_status && teamplay)
167 if(ent.healthvalue > 0)
169 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", ent.healthvalue/autocvar_hud_panel_healtharmor_maxhealth, 0, 1, '1 0 0', a, DRAWFLAG_NORMAL);
171 if(ent.armorvalue > 0)
172 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", ent.armorvalue/autocvar_hud_panel_healtharmor_maxarmor, 0, 0, '0 1 0', a, DRAWFLAG_NORMAL);
178 s = GetPlayerName(ent.sv_entnum-1);
179 if((autocvar_hud_shownames_decolorize == 1 && teamplay) || autocvar_hud_shownames_decolorize == 2)
180 s = playername(s, GetPlayerColor(ent.sv_entnum-1));
182 drawfontscale = '1 1 0' * resize;
183 s = textShortenToWidth(s, namewidth, '1 1 0' * autocvar_hud_shownames_fontsize, stringwidth_colors);
186 width = stringwidth(s, true, '1 1 0' * autocvar_hud_shownames_fontsize);
188 if (width != namewidth)
189 namepos.x += (namewidth - width) / 2;
190 drawcolorcodedstring(namepos, s, '1 1 0' * autocvar_hud_shownames_fontsize, a, DRAWFLAG_NORMAL);
191 drawfontscale = '1 1 0';
196 entity shownames_ent[255];
197 void Draw_ShowNames_All()
200 for(i = 0; i < maxclients; ++i)
203 t = GetPlayerColor(i);
204 if(t == NUM_SPECTATOR)
208 e = shownames_ent[i];
212 e.classname = "shownames_tag";
214 shownames_ent[i] = e;
218 entcs = entcs_receiver[i];
221 e.healthvalue = entcs.healthvalue;
222 e.armorvalue = entcs.armorvalue;
223 e.sameteam = 1; /* (teamplay && (t == myteam)); */
227 e.healthvalue = 2342;
232 setorigin(e, getplayerorigin(i));
233 if(e.origin == GETPLAYERORIGIN_ERROR)
236 e.csqcmodel_isdead = getplayerisdead(i);