]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/shownames.qc
make them fade out/in :o
[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         InterpolateOrigin_Do();
15
16         if(!self.sameteam)
17         {
18             traceline(self.origin, view_origin, 1, self);
19             if(trace_endpos != view_origin) // fade out
20             {
21                 self.alpha = max(0, self.alpha - 4 * frametime);
22                 if(!self.alpha)
23                     return;
24             }
25             else // fade in
26                 self.alpha = min(1, self.alpha + 4 * frametime);
27
28
29             /* WIP, why does trace_ent != self not work as intended here?
30             if(autocvar_hud_shownames_enemies != 2) // player has to point at enemy if so
31             {
32                 traceline(view_origin, view_origin + view_forward * MAX_SHOT_DISTANCE, MOVETYPE_FLY, world);
33                 print("trace_endpos: ", vtos(trace_endpos), " view_origin: ", vtos(view_origin), "\n");
34                 if(trace_ent != self)
35                     return;
36             }*/
37         }
38
39         // otherwise, increase alpha until 1
40
41         float a;
42         a = autocvar_hud_panel_fg_alpha * self.alpha;
43
44         // draw the sprite image
45         vector o;
46         o = project_3d_to_2d(self.origin);
47
48         if not(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
49         {
50             o_z = 0;
51
52             vector myPos, mySize;
53             mySize = (eX * autocvar_hud_shownames_aspect + eY) * autocvar_hud_shownames_height;
54             myPos = o - '0.5 0 0' * mySize_x - '0 1 0' * mySize_y;
55
56             vector iconpos, iconsize;
57             vector namepos;
58             float namesize;
59
60             iconpos = myPos;
61
62             if(autocvar_hud_shownames_status)
63             {
64                 if(self.sameteam)
65                 {
66                     iconsize = eX * 2 * mySize_y + eY * mySize_y;
67                     // "ghost" backgrounds
68                     drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '0 0 0', a * 0.5, DRAWFLAG_NORMAL);
69                     drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '0 0 0', a * 0.5, DRAWFLAG_NORMAL);
70
71                     drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, self.healthvalue/autocvar_hud_panel_healtharmor_maxhealth), vid_conwidth, myPos_y + iconsize_y);
72                     drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '1 1 1', a, DRAWFLAG_NORMAL);
73
74                     drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, self.armorvalue/autocvar_hud_panel_healtharmor_maxarmor), vid_conwidth, myPos_y + iconsize_y);
75                     drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '1 1 1', a, DRAWFLAG_NORMAL);
76                     drawresetcliparea();
77                 }
78                 else if(autocvar_hud_shownames_status == 2 && teamplay)
79                 {
80                     iconsize = eX * 2 * mySize_y + eY * mySize_y;
81                     drawpic_aspect_skin(iconpos, "health_unknown", '1 1 0' * iconsize_y, '0 0 0', a, DRAWFLAG_NORMAL);
82                     drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor_unknown", '1 1 0' * iconsize_y, '0 0 0', a, DRAWFLAG_NORMAL);
83                 }
84             }
85
86             namepos = myPos + eX * 2 * iconsize_y + eY * 0.5 * (autocvar_hud_shownames_height - autocvar_hud_shownames_fontsize);
87             namesize = mySize_x - 2 * iconsize_y;
88
89             string s;
90             s = GetPlayerName(self.the_entnum-1);
91             s = textShortenToWidth(s, namesize, '1 1 0' * autocvar_hud_shownames_fontsize, stringwidth_colors);
92
93             float width;
94             width = stringwidth(s, TRUE, '1 1 0' * autocvar_hud_shownames_fontsize);
95
96             if (width != namesize)
97                 namepos_x += (namesize - width) / 2;
98             drawcolorcodedstring(namepos, s, '1 1 0' * autocvar_hud_shownames_fontsize, a, DRAWFLAG_NORMAL);
99         }
100     }
101 }