]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/spect.qc
Improve spect HUD CVAR names
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / spect.qc
1 #include "spect.qh"
2
3 #include <client/hud/hud.qh>
4 #include <client/view.qh>
5
6 vector teamscore_size;
7 vector teamscore_fontsize;
8 vector teamname_fontsize;
9
10 void HUD_SpectHUD_Export(int fh)
11 {
12         // allow saving cvars that aesthetically change the panel into hud skin files
13 }
14
15 void HUD_SpectHUD_drawCurrentName(vector pos)
16 {
17         vector tmp;
18         
19         tmp = pos;
20         string s = entcs_GetName(current_player);
21         tmp.x -= stringwidth_colors(s, hud_fontsize * 2) / 2;
22         drawcolorcodedstring(tmp, s, hud_fontsize * 2, panel_fg_alpha, DRAWFLAG_NORMAL);
23         
24         tmp = pos;
25         s = "Spectating";
26         tmp.x -= stringwidth_colors(s, hud_fontsize) / 2;
27         tmp.y -= hud_fontsize.y;
28         drawcolorcodedstring(tmp, s, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
29 }
30         
31 void HUD_SpectHUD_drawTeamPlayers(vector pos, entity tm, vector rgb, bool invert)
32 {
33         vector tmp_over;
34         vector line_sz = vec2((vid_conwidth - 1) / 7, hud_fontsize.y * 1.5);
35         vector line_sz_sub = vec2((vid_conwidth - 1) / 7, hud_fontsize.y);
36         
37         string playername;
38         float a = panel_fg_alpha * 0.8;
39         entity pl;
40         
41         if(invert)
42                 pos.x -= line_sz.x + hud_fontsize.x;
43         else
44                 pos.x += hud_fontsize.x;        
45         
46         for(pl = players.sort_next; pl; pl = pl.sort_next)
47         {
48                 if(pl.team != tm.team)
49                         continue;
50                 
51                 float health = 0;
52                 float armor = 0;
53                 string icon = "";
54                 vector icon_size = '0 0 0';
55                 vector icon_rgb = '1 1 1';
56                 
57                 // Position and size calculation vectors
58                 tmp_over = pos;
59                 vector total_sz = vec2(line_sz.x, line_sz.y + line_sz_sub.y);
60                 
61                 if(pl.eliminated) {
62                         // z411 TODO : Unhardcode luma
63                         icon = "gfx/hud/luma/notify_death.tga";
64                         icon_rgb = rgb;
65                 } else {
66                         entity entcs = entcs_receiver(pl.sv_entnum);
67                         if(entcs.m_entcs_private) {
68                                 health = (entcs.healthvalue / autocvar_hud_panel_healtharmor_maxhealth) * line_sz.x;
69                                 armor = (GetResource(entcs, RES_ARMOR) / autocvar_hud_panel_healtharmor_maxarmor) * line_sz_sub.x;
70                                         
71                                 Weapon wep = REGISTRY_GET(Weapons, entcs.activewepid);
72                                 icon = strcat("gfx/hud/luma/", wep.model2);
73                         } else {
74                                 if(tm.team == NUM_TEAM_1)
75                                         icon = "gfx/hud/luma/player_red";
76                                 else if(tm.team == NUM_TEAM_2)
77                                         icon = "gfx/hud/luma/player_blue";
78                                 else if(tm.team == NUM_TEAM_3)
79                                         icon = "gfx/hud/luma/player_yellow";
80                                 else if(tm.team == NUM_TEAM_4)
81                                         icon = "gfx/hud/luma/player_pink";
82                                 else
83                                         icon = "gfx/hud/luma/player_neutral";
84                         }
85                 }
86                 
87                 // Draw weapon
88                 if(icon != "")  {
89                         vector tmp_sz = draw_getimagesize(icon);
90                         icon_size = vec2(total_sz.y*(tmp_sz.x/tmp_sz.y), total_sz.y);
91                         total_sz.x += icon_size.x;
92                                 
93                         if(invert) {
94                                 pos.x -= icon_size.x;
95                                 tmp_over.x -= icon_size.x;
96                         }
97                         drawpic(pos, icon, icon_size, icon_rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
98                         pos.x += icon_size.x;
99                 }
100                 
101                 // Get player's name
102                 playername = textShortenToWidth(entcs_GetName(pl.sv_entnum), line_sz.x * 0.8, hud_fontsize, stringwidth_colors);
103                 
104                 // Draw health and name
105                 drawfill(pos, line_sz, rgb * 0.7, a * 0.3, DRAWFLAG_NORMAL);
106                 if(health)
107                         drawfill(pos, vec2(health, line_sz.y), rgb * 0.7, a, DRAWFLAG_NORMAL);
108                 drawcolorcodedstring(pos + eY * ((line_sz.y - hud_fontsize.y) / 2) + eX * (hud_fontsize.x * 0.5), playername, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
109                 pos.y += line_sz.y;
110                 
111                 // Draw armor
112                 if(armor)
113                         drawfill(pos, vec2(armor, line_sz_sub.y), rgb, a, DRAWFLAG_NORMAL);
114                 
115                 // Highlight current player
116                 if(pl.sv_entnum == current_player && spectatee_status != -1)
117                         drawfill(tmp_over, total_sz, '1 1 1', 0.3, DRAWFLAG_NORMAL);
118                 if(pl.eliminated)
119                         drawfill(tmp_over, total_sz, '0 0 0', 0.4, DRAWFLAG_NORMAL);
120                 
121                 if(!invert)
122                         pos.x -= icon_size.x;
123                 pos.y += line_sz_sub.y * 2;
124         }
125 }
126
127
128 void HUD_SpectHUD_drawTeamScore(vector pos, entity tm, vector rgb, bool invert)
129 {
130         if(!tm) return;
131         
132         vector tmp;
133         string tmp_str;
134         
135         // Team score
136         tmp_str = ftos(tm.(teamscores(ts_primary)));
137         
138         if(invert)
139                 pos.x -= teamscore_size.x;
140         
141         drawfill(pos, teamscore_size, rgb * 0.8, 0.3, DRAWFLAG_NORMAL);
142         
143         tmp = pos;
144         tmp.x += (teamscore_size.x - stringwidth(tmp_str, true, teamscore_fontsize)) / 2;
145         tmp.y += (teamscore_size.y - teamscore_fontsize.y) / 2;
146                 
147         draw_beginBoldFont();
148         drawstring(tmp, tmp_str, teamscore_fontsize, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
149         draw_endBoldFont();
150         
151         // Team name
152         tmp_str = Team_CustomName(tm.team);
153         
154         tmp = pos;
155         if(invert)
156                 tmp.x -= stringwidth_colors(tmp_str, teamname_fontsize) + teamname_fontsize.x * 0.5;
157         else
158                 tmp.x += teamscore_size.x + teamname_fontsize.x * 0.5;
159         tmp.y += (teamscore_size.y - teamname_fontsize.y) / 2;
160         
161         drawcolorcodedstring(tmp, tmp_str, teamname_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
162 }
163
164 void HUD_SpectHUD_drawDuelScore(vector pos, entity pl, bool invert)
165 {
166         if(!pl) return;
167         
168         vector tmp, tmp_in;
169         string tmp_str;
170         vector health_sz = vec2((vid_conwidth - 1) / 6, teamscore_size.y * 0.4);
171         vector armor_sz = vec2(health_sz.x, health_sz.y / 4);
172         
173         float health = 0;
174         float armor = 0;
175         
176         entity entcs = entcs_receiver(pl.sv_entnum);
177         if(entcs.m_entcs_private) {
178                 health = (entcs.healthvalue / autocvar_hud_panel_healtharmor_maxhealth) * health_sz.x;
179                 armor = (GetResource(entcs, RES_ARMOR) / autocvar_hud_panel_healtharmor_maxarmor) * armor_sz.x;
180         }
181         
182         // Player score
183         tmp_str = ftos(pl.(scores(ps_primary)));
184         
185         if(invert)
186                 pos.x -= teamscore_size.x;
187         
188         drawfill(pos, teamscore_size, '0 0 0', 0.3, DRAWFLAG_NORMAL);
189         
190         tmp = pos;
191         tmp.x += (teamscore_size.x - stringwidth(tmp_str, true, teamscore_fontsize)) / 2;
192         tmp.y += (teamscore_size.y - teamscore_fontsize.y) / 2;
193                 
194         draw_beginBoldFont();
195         drawstring(tmp, tmp_str, teamscore_fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
196         draw_endBoldFont();
197         
198         // Player health/armor
199         tmp_in = pos;
200         tmp_in.y += ((teamscore_size.y / 2) - health_sz.y) / 2;
201         
202         // Background
203         tmp = tmp_in;
204         if(invert)
205                 tmp.x -= health_sz.x;
206         else
207                 tmp.x += teamscore_size.x;
208         
209         drawfill(tmp, health_sz, '0 0 0', 0.3, DRAWFLAG_NORMAL);
210         
211         // Bars
212         if(health) {
213                 tmp = tmp_in;
214                 if(invert)
215                         tmp.x -= health;
216                 else
217                         tmp.x += teamscore_size.x;
218         
219                 drawfill(tmp, vec2(health, health_sz.y), autocvar_hud_progressbar_health_color, 0.7, DRAWFLAG_NORMAL);
220         }
221         
222         if(armor) {
223                 tmp = tmp_in;
224                 tmp.y += health_sz.y - armor_sz.y;
225                 
226                 if(invert)
227                         tmp.x -= armor;
228                 else
229                         tmp.x += teamscore_size.x;
230                 
231                 drawfill(tmp, vec2(armor, armor_sz.y), autocvar_hud_progressbar_armor_color, 0.7, DRAWFLAG_NORMAL);
232         }
233         
234         // Player name
235         tmp_str = entcs_GetName(pl.sv_entnum);
236         
237         tmp = pos;
238         if(invert)
239                 tmp.x -= stringwidth_colors(tmp_str, teamname_fontsize) + teamname_fontsize.x * 0.5;
240         else
241                 tmp.x += teamscore_size.x + teamname_fontsize.x * 0.5;
242         tmp.y += ((teamscore_size.y / 2) - teamname_fontsize.y) / 2;
243         tmp.y += teamscore_size.y / 2;
244         
245         drawcolorcodedstring(tmp, tmp_str, teamname_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
246 }
247
248 void HUD_SpectHUD()
249 {
250         if(!spectatee_status) return;
251         
252         vector pos, rgb;
253         float ammo_y, timer_width;
254         entity tm;
255         
256         // Set main vars
257         HUD_Panel_LoadCvars();
258         HUD_Scale_Enable();
259         hud_fontsize = HUD_GetFontsize("hud_fontsize");
260         
261         // Spectator name
262         if (autocvar_hud_panel_spect_playername)
263         {
264                 if(spectatee_status != -1) {
265                         ammo_y = stov(cvar_string("hud_panel_ammo_pos")).y * vid_conheight;
266                         pos = panel_pos + vec2((vid_conwidth - 1) / 2, (ammo_y - (hud_fontsize.y * 2)));
267                         HUD_SpectHUD_drawCurrentName(pos);
268                 }
269         }
270         
271         // Scores
272         if (!autocvar_hud_panel_spect_scores) return;
273         if (teamplay)
274         {
275                 // Set vars
276                 teamscore_fontsize = hud_fontsize * 3;
277                 teamname_fontsize = hud_fontsize * 2;
278                 teamscore_size = vec2(teamscore_fontsize.x * 1.5, teamscore_fontsize.y * 1.25);
279                 timer_width = stov(cvar_string("hud_panel_timer_size")).x * vid_conwidth;
280                 
281                 // Team 1
282                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
283                 tm = GetTeam(NUM_TEAM_1, false);
284                 rgb = Team_ColorRGB(tm.team);
285                 pos.x -= (timer_width * 1.3) / 2;
286                 HUD_SpectHUD_drawTeamScore(pos, tm, rgb, true);
287                 
288                 pos = panel_pos + vec2(0, (vid_conheight - 1) / 4 + hud_fontsize.y);
289                 HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, false);
290                 
291                 // Team 2
292                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
293                 tm = GetTeam(NUM_TEAM_2, false);
294                 rgb = Team_ColorRGB(tm.team);
295                 pos.x += (timer_width * 1.3) / 2;
296                 HUD_SpectHUD_drawTeamScore(pos, tm, rgb, false);
297                 
298                 pos = panel_pos + vec2(vid_conwidth - 1, (vid_conheight - 1) / 4 + hud_fontsize.y);
299                 HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, true);
300
301                 // Team 3
302                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 41);
303                 tm = GetTeam(NUM_TEAM_3, false);
304                 rgb = Team_ColorRGB(tm.team);
305                 pos.x -= (timer_width * 1.3) / 2;
306                 HUD_SpectHUD_drawTeamScore(pos, tm, rgb, true);
307                 
308                 pos = panel_pos + vec2(0, (vid_conheight + 450) / 4 + hud_fontsize.y);
309                 HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, false);
310
311                 // Team 4
312                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 41);
313                 tm = GetTeam(NUM_TEAM_4, false);
314                 rgb = Team_ColorRGB(tm.team);
315                 pos.x += (timer_width * 1.3) / 2;
316                 HUD_SpectHUD_drawTeamScore(pos, tm, rgb, false);
317                 
318                 pos = panel_pos + vec2(vid_conwidth - 1, (vid_conheight + 450) / 4 + hud_fontsize.y);
319                 HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, true);
320         } else if(gametype == MAPINFO_TYPE_DUEL) {
321                 // Set vars
322                 teamscore_fontsize = hud_fontsize * 3;
323                 teamname_fontsize = hud_fontsize * 1.5;
324                 teamscore_size = vec2(teamscore_fontsize.x * 1.5, teamscore_fontsize.y * 1.25);
325                 timer_width = stov(cvar_string("hud_panel_timer_size")).x * vid_conwidth;
326                 
327                 entity pl_left = players.sort_next;
328                 entity pl_right = pl_left.sort_next;
329         
330                 // Left player
331                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
332                 pos.x -= (timer_width * 1.3) / 2;
333                 HUD_SpectHUD_drawDuelScore(pos, pl_left, true);
334                 
335                 // Right player
336                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
337                 pos.x += (timer_width * 1.3) / 2;
338                 HUD_SpectHUD_drawDuelScore(pos, pl_right, false);
339         }
340 }