]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/shownames.qc
@ CSQC: You've been trolled, you've been trolled... Also enemy nametags are no longer...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / shownames.qc
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?
3 // self.healthvalue
4 // self.armorvalue
5 // self.sameteam = player is on same team as local client
6 //
7 void Draw_ShowNames()
8 {
9     if(!autocvar_hud_shownames)
10         return;
11
12     if(self.sameteam || (!self.sameteam && autocvar_hud_shownames_enemies))
13     {
14         float a;
15         a = autocvar_hud_panel_fg_alpha;
16
17         InterpolateOrigin_Do();
18
19         if(!self.sameteam)
20         {
21             traceline(self.origin, view_origin, 1, self);
22             if(trace_endpos != view_origin)
23                 return;
24         }
25
26         // draw the sprite image
27         vector o;
28         o = project_3d_to_2d(self.origin);
29
30         if not(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
31         {
32             o_z = 0;
33
34             vector myPos, mySize;
35             mySize = (eX * autocvar_hud_shownames_aspect + eY) * autocvar_hud_shownames_height;
36             myPos = o - '0.5 0 0' * mySize_x - '0 1 0' * mySize_y;
37
38             vector iconpos, iconsize;
39             vector namepos;
40             float namesize;
41
42             iconpos = myPos;
43
44             if(autocvar_hud_shownames_status)
45             {
46                 if(self.sameteam)
47                 {
48                     iconsize = eX * 2 * mySize_y + eY * mySize_y;
49                     // "ghost" backgrounds
50                     drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '0 0 0', a * 0.5, DRAWFLAG_NORMAL);
51                     drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '0 0 0', a * 0.5, DRAWFLAG_NORMAL);
52
53                     drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, self.healthvalue/autocvar_hud_panel_healtharmor_maxhealth), vid_conwidth, myPos_y + iconsize_y);
54                     drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '1 1 1', a, DRAWFLAG_NORMAL);
55
56                     drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, self.armorvalue/autocvar_hud_panel_healtharmor_maxarmor), vid_conwidth, myPos_y + iconsize_y);
57                     drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '1 1 1', a, DRAWFLAG_NORMAL);
58                     drawresetcliparea();
59                 }
60                 else if(autocvar_hud_shownames_status == 2)
61                 {
62                     iconsize = eX * 2 * mySize_y + eY * mySize_y;
63                     drawpic_aspect_skin(iconpos, "health_unknown", '1 1 0' * iconsize_y, '0 0 0', a, DRAWFLAG_NORMAL);
64                     drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor_unknown", '1 1 0' * iconsize_y, '0 0 0', a, DRAWFLAG_NORMAL);
65                 }
66             }
67
68             namepos = myPos + eX * 2 * iconsize_y + eY * 0.5 * (autocvar_hud_shownames_height - autocvar_hud_shownames_fontsize);
69             namesize = mySize_x - 2 * iconsize_y;
70
71             string s;
72             s = GetPlayerName(self.the_entnum-1);
73             s = textShortenToWidth(s, namesize, '1 1 0' * autocvar_hud_shownames_fontsize, stringwidth_colors);
74             drawcolorcodedstring(namepos, s, '1 1 0' * autocvar_hud_shownames_fontsize, a, DRAWFLAG_NORMAL);
75
76             /* Or maybe a health bar instead?
77              *
78             if(self.health >= 0)
79             {
80                 float align;
81                 if(self.build_finished)
82                     align = 0.5;
83                 else
84                     align = 0;
85                 drawhealthbar(o, rot * 90 * DEG2RAD, self.health, SPRITE_SIZE * t, SPRITE_HOTSPOT * t, SPRITE_HEALTHBAR_WIDTH * t, SPRITE_HEALTHBAR_HEIGHT * t, SPRITE_HEALTHBAR_MARGIN * t, SPRITE_HEALTHBAR_BORDER * t, align, self.teamradar_color, a * SPRITE_HEALTHBAR_BORDERALPHA, self.teamradar_color, a * SPRITE_HEALTHBAR_HEALTHALPHA, DRAWFLAG_NORMAL);
86             }
87             */
88         }
89     }
90 }