]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/shownames.qc
remove the shownames HUD panel, start implementing the actual drawing/positioning...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / shownames.qc
1 void Draw_WaypointSprite()
2 {
3     if(!autocvar_hud_shownames)
4         return;
5
6     string spriteimage;
7     float t;
8
9     if(self.lifetime)
10         self.alpha = pow(bound(0, (self.fadetime - time) / self.lifetime, 1), waypointsprite_timealphaexponent);
11     else
12         self.alpha = 1;
13
14     if(self.hideflags & 2)
15         return; // radar only
16
17     if(autocvar_cl_hidewaypoints >= 2)
18         return;
19
20     if(self.hideflags & 1)
21         if(autocvar_cl_hidewaypoints)
22             return; // fixed waypoint
23
24     InterpolateOrigin_Do();
25
26     t = GetPlayerColor(player_localentnum - 1) + 1;
27
28     spriteimage = "";
29
30     // choose the sprite
31     switch(self.rule)
32     {
33         case SPRITERULE_DEFAULT:
34             if(self.team)
35             {
36                 if(self.team == t)
37                     spriteimage = self.netname;
38                 else
39                     spriteimage = "";
40             }
41             else
42                 spriteimage = self.netname;
43             break;
44         case SPRITERULE_TEAMPLAY:
45             if(t == COLOR_SPECTATOR + 1)
46                 spriteimage = self.netname3;
47             else if(self.team == t)
48                 spriteimage = self.netname2;
49             else
50                 spriteimage = self.netname;
51             break;
52         default:
53             error("Invalid waypointsprite rule!");
54             break;
55     }
56
57     if(spriteimage == "")
58         return;
59     
60     float dist;
61     dist = vlen(self.origin - view_origin);
62     
63     float a;
64     a = self.alpha * autocvar_hud_panel_fg_alpha;
65
66     if(self.maxdistance > waypointsprite_normdistance)
67         a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
68     else if(self.maxdistance > 0)
69         a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
70
71     if(a <= 0)
72         return;
73     
74     // draw the sprite image
75     vector o;
76     float rot;
77     o = project_3d_to_2d(self.origin);
78     rot = 0;
79
80     if(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
81     {
82         // scale it to be just in view
83         vector d;
84         float f1, f2;
85
86         // get the waypoint angle vector
87         /*
88         d_x = view_right * (self.origin - view_origin) * vid_conwidth / vid_width;
89         d_y = -view_up * (self.origin - view_origin) * vid_conheight / (vid_height * vid_pixelheight);
90         d_z = 0;
91         */
92         
93         d = o - '0.5 0 0' * vid_conwidth - '0 0.5 0' * vid_conheight;
94
95         /*
96         if(autocvar_v_flipped)
97             d_x = -d_x;
98         */
99
100         f1 = d_x / vid_conwidth;
101         f2 = d_y / vid_conheight;
102
103         if(max(f1, -f1) > max(f2, -f2))
104         {
105             if(d_z * f1 > 0)
106             {
107                 // RIGHT edge
108                 d = d * (0.5 / f1);
109                 rot = 3;
110             }
111             else
112             {
113                 // LEFT edge
114                 d = d * (-0.5 / f1);
115                 rot = 1;
116             }
117         }
118         else
119         {
120             if(d_z * f2 > 0)
121             {
122                 // BOTTOM edge
123                 d = d * (0.5 / f2);
124                 rot = 0;
125             }
126             else
127             {
128                 // TOP edge
129                 d = d * (-0.5 / f2);
130                 rot = 2;
131             }
132         }
133
134         o = d + '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
135     }
136     o_z = 0;
137
138     float vidscale;
139     vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
140
141     t = stof(db_get(tempdb, strcat("/spriteframes/", spriteimage)));
142     if(t == 0)
143         spriteimage = strcat("models/sprites/", spriteimage);
144     else
145         spriteimage = strcat("models/sprites/", spriteimage, "_frame", ftos(mod(floor((max(0, time - self.spawntime)) * 2), t)));
146
147     float edgedistance_min, crosshairdistance;
148     edgedistance_min = min4(o_y, o_x,vid_conwidth - o_x, vid_conheight - o_y);
149
150     crosshairdistance = sqrt( pow(o_x - vid_conwidth/2, 2) + pow(o_y - vid_conheight/2, 2) );
151
152     t = waypointsprite_scale * vidscale;
153     a *= waypointsprite_alpha;
154
155     {
156         a = a * (1 - (1 - waypointsprite_distancefadealpha) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
157         t = t * (1 - (1 - waypointsprite_distancefadescale) * (bound(0, dist/waypointsprite_distancefadedistance, 1)));
158     }
159     if (edgedistance_min < waypointsprite_edgefadedistance) {
160         a = a * (1 - (1 - waypointsprite_edgefadealpha) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
161         t = t * (1 - (1 - waypointsprite_edgefadescale) * (1 - bound(0, edgedistance_min/waypointsprite_edgefadedistance, 1)));
162     }
163     if(crosshairdistance < waypointsprite_crosshairfadedistance) {
164         a = a * (1 - (1 - waypointsprite_crosshairfadealpha) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
165         t = t * (1 - (1 - waypointsprite_crosshairfadescale) * (1 - bound(0, crosshairdistance/waypointsprite_crosshairfadedistance, 1)));
166     }
167     drawrotpic(o, rot * 90 * DEG2RAD, spriteimage, SPRITE_SIZE * t, SPRITE_HOTSPOT * t, '1 1 1', a, DRAWFLAG_MIPMAP);
168
169     if(self.build_finished)
170     {
171         if(time < self.build_finished + 0.25)
172         {
173             if(time < self.build_started)
174                 self.health = self.build_starthealth;
175             else if(time < self.build_finished)
176                 self.health = (time - self.build_started) / (self.build_finished - self.build_started) * (1 - self.build_starthealth) + self.build_starthealth;
177             else
178                 self.health = 1;
179         }
180         else
181             self.health = -1;
182     }
183
184     if(self.health >= 0)
185     {
186         float align;
187         if(self.build_finished)
188             align = 0.5;
189         else
190             align = 0;
191         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);
192     }
193 }
194
195 float shownames_alpha;
196 void HUD_ShowNames(void)
197 {
198     // for each playerslot etc
199
200     vector iconpos, iconsize;
201     vector namepos, namesize;
202     if(mySize_x/mySize_y > 6)
203     {
204         iconpos = myPos;
205         iconsize = eX * 2 * mySize_y + eY * mySize_y;
206
207         namepos = myPos + eX * 2 * mySize_y;
208         namesize = eX * mySize_x - eX * 2 * mySize_y + eY * mySize_y;
209     }
210     else
211     {
212         iconpos = myPos + eX * 0.5 * mySize_x - eX * 0.5 * mySize_y;
213         iconsize = eX * mySize_y + eY * 0.5 * mySize_y;
214
215         namepos = myPos + eY * 0.5 * mySize_y;
216         namesize = eX * mySize_x + eY * 0.5 * mySize_y;
217     }
218
219     if(shownames_health > 0) // otherwise player is an enemy
220     {
221         // "ghost" backgrounds
222         drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
223         drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '0 0 0', panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
224
225         drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, shownames_health/autocvar_hud_panel_healtharmor_maxhealth), vid_conwidth, myPos_y + iconsize_y);
226         drawpic_aspect_skin(iconpos, "health", '1 1 0' * iconsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
227
228         drawsetcliparea(0, myPos_y + iconsize_y - iconsize_y * min(1, shownames_armor/autocvar_hud_panel_healtharmor_maxarmor), vid_conwidth, myPos_y + iconsize_y);
229         drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor", '1 1 0' * iconsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
230         drawresetcliparea();
231     }
232     else
233     {
234         drawpic_aspect_skin(iconpos, "health_unknown", '1 1 0' * iconsize_y, '0 0 0', panel_fg_alpha, DRAWFLAG_NORMAL);
235         drawpic_aspect_skin(iconpos + '0.5 0 0' * iconsize_x, "armor_unknown", '1 1 0' * iconsize_y, '0 0 0', panel_fg_alpha, DRAWFLAG_NORMAL);
236     }
237
238     if(autocvar__hud_configure)
239         drawcolorcodedstring_aspect(namepos, "Player1234", namesize, panel_fg_alpha, DRAWFLAG_NORMAL);
240     else
241         drawcolorcodedstring_aspect(namepos, shownames_netname, namesize, panel_fg_alpha, DRAWFLAG_NORMAL);
242 }
243