]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/spect.qc
Merge branch 'LegendaryGuard/bai_mod' into z411/bai-server
[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 bool autocvar_hud_spectatorteamdisplay = true; //LegendGuard adds a bool to enable/disable team display HUD 06-04-2021
10 bool autocvar_hud_spectatorplayernamedisplay = true; //LegendGuard adds a bool to enable/disable player name display HUD 06-04-2021
11
12 void HUD_SpectHUD_Export(int fh)
13 {
14         // allow saving cvars that aesthetically change the panel into hud skin files
15 }
16
17 void HUD_SpectHUD_drawCurrentName(vector pos)
18 {
19         string s = entcs_GetName(current_player);
20         pos.x -= stringwidth_colors(s, hud_fontsize * 2) / 2;
21         drawcolorcodedstring(pos, s, hud_fontsize * 2, panel_fg_alpha, DRAWFLAG_NORMAL);
22 }
23         
24 void HUD_SpectHUD_drawTeamPlayers(vector pos, entity tm, vector rgb, bool invert)
25 {
26         vector tmp_over;
27         vector line_sz = vec2((vid_conwidth - 1) / 7, hud_fontsize.y * 1.5);
28         vector line_sz_sub = vec2((vid_conwidth - 1) / 7, hud_fontsize.y);
29         
30         string playername;
31         float a = panel_fg_alpha * 0.8;
32         entity pl;
33         
34         if(invert)
35                 pos.x -= line_sz.x + hud_fontsize.x;
36         else
37                 pos.x += hud_fontsize.x;        
38         
39         for(pl = players.sort_next; pl; pl = pl.sort_next)
40         {
41                 if(pl.team != tm.team)
42                         continue;
43                 
44                 float health = 0;
45                 float armor = 0;
46                 string icon = "";
47                 vector icon_size = '0 0 0';
48                 vector icon_rgb = '1 1 1';
49                 
50                 // Position and size calculation vectors
51                 tmp_over = pos;
52                 vector total_sz = vec2(line_sz.x, line_sz.y + line_sz_sub.y);
53                 
54                 if(pl.eliminated) {
55                         // z411 TODO : Unhardcode luma
56                         icon = "gfx/hud/luma/notify_death.tga";
57                         icon_rgb = rgb;
58                 } else {
59                         entity entcs = entcs_receiver(pl.sv_entnum);
60                         if(entcs.m_entcs_private) {
61                                 health = (entcs.healthvalue / autocvar_hud_panel_healtharmor_maxhealth) * line_sz.x;
62                                 armor = (GetResource(entcs, RES_ARMOR) / autocvar_hud_panel_healtharmor_maxarmor) * line_sz_sub.x;
63                                         
64                                 Weapon wep = REGISTRY_GET(Weapons, entcs.activewepid);
65                                 icon = strcat("gfx/hud/luma/", wep.model2);
66                         } else {
67                                 if(tm.team == NUM_TEAM_1)
68                                         icon = "gfx/hud/luma/player_red";
69                                 else if(tm.team == NUM_TEAM_2)
70                                         icon = "gfx/hud/luma/player_blue";
71                                 else if(tm.team == NUM_TEAM_3)
72                                         icon = "gfx/hud/luma/player_yellow";
73                                 else if(tm.team == NUM_TEAM_4)
74                                         icon = "gfx/hud/luma/player_pink";
75                                 else
76                                         icon = "gfx/hud/luma/player_neutral";
77                         }
78                 }
79                 
80                 // Draw weapon
81                 if(icon != "")  {
82                         vector tmp_sz = draw_getimagesize(icon);
83                         icon_size = vec2(total_sz.y*(tmp_sz.x/tmp_sz.y), total_sz.y);
84                         total_sz.x += icon_size.x;
85                                 
86                         if(invert) {
87                                 pos.x -= icon_size.x;
88                                 tmp_over.x -= icon_size.x;
89                         }
90                         drawpic(pos, icon, icon_size, icon_rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
91                         pos.x += icon_size.x;
92                 }
93                 
94                 // Get player's name
95                 playername = textShortenToWidth(entcs_GetName(pl.sv_entnum), line_sz.x * 0.8, hud_fontsize, stringwidth_colors);
96                 
97                 // Draw health and name
98                 drawfill(pos, line_sz, rgb * 0.7, a * 0.3, DRAWFLAG_NORMAL);
99                 if(health)
100                         drawfill(pos, vec2(health, line_sz.y), rgb * 0.7, a, DRAWFLAG_NORMAL);
101                 drawcolorcodedstring(pos + eY * ((line_sz.y - hud_fontsize.y) / 2) + eX * (hud_fontsize.x * 0.5), playername, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
102                 pos.y += line_sz.y;
103                 
104                 // Draw armor
105                 if(armor)
106                         drawfill(pos, vec2(armor, line_sz_sub.y), rgb, a, DRAWFLAG_NORMAL);
107                 
108                 // Highlight current player
109                 if(pl.sv_entnum == current_player && spectatee_status != -1)
110                         drawfill(tmp_over, total_sz, '1 1 1', 0.3, DRAWFLAG_NORMAL);
111                 if(pl.eliminated)
112                         drawfill(tmp_over, total_sz, '0 0 0', 0.4, DRAWFLAG_NORMAL);
113                 
114                 if(!invert)
115                         pos.x -= icon_size.x;
116                 pos.y += line_sz_sub.y * 2;
117         }
118 }
119
120
121 void HUD_SpectHUD_drawTeamScore(vector pos, entity tm, vector rgb, bool invert)
122 {
123         if(!tm) return;
124         
125         vector tmp;
126         string tmp_str;
127         
128         // Team score
129         tmp_str = ftos(tm.(teamscores(ts_primary)));
130         
131         if(invert)
132                 pos.x -= teamscore_size.x;
133         
134         drawfill(pos, teamscore_size, rgb * 0.8, 0.3, DRAWFLAG_NORMAL);
135         
136         tmp = pos;
137         tmp.x += (teamscore_size.x - stringwidth(tmp_str, true, teamscore_fontsize)) / 2;
138         tmp.y += (teamscore_size.y - teamscore_fontsize.y) / 2;
139                 
140         draw_beginBoldFont();
141         drawstring(tmp, tmp_str, teamscore_fontsize, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
142         draw_endBoldFont();
143         
144         // Team name
145         tmp_str = Team_CustomName(tm.team);
146         
147         tmp = pos;
148         if(invert)
149                 tmp.x -= stringwidth_colors(tmp_str, teamname_fontsize) + teamname_fontsize.x * 0.5;
150         else
151                 tmp.x += teamscore_size.x + teamname_fontsize.x * 0.5;
152         tmp.y += (teamscore_size.y - teamname_fontsize.y) / 2;
153         
154         drawcolorcodedstring(tmp, tmp_str, teamname_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
155 }
156
157 void HUD_SpectHUD()
158 {
159         if(!spectatee_status) return;
160         
161         vector pos, rgb;
162         float ammo_y, timer_width;
163         entity tm;
164         
165         // Set main vars
166         HUD_Panel_LoadCvars();
167         HUD_Scale_Enable();
168         hud_fontsize = HUD_GetFontsize("hud_fontsize");
169         
170         // Spectator name
171         if (autocvar_hud_spectatorplayernamedisplay)
172         {
173                 if(spectatee_status != -1) {
174                         ammo_y = stov(cvar_string("hud_panel_ammo_pos")).y * vid_conheight;
175                         pos = panel_pos + vec2((vid_conwidth - 1) / 2, (ammo_y - (hud_fontsize.y * 2)));
176                         HUD_SpectHUD_drawCurrentName(pos);
177                 }
178         }
179         
180         if(!teamplay) return;
181         
182         if (autocvar_hud_spectatorteamdisplay)
183         {
184                 // Set vars
185                 teamscore_fontsize = hud_fontsize * 3;
186                 teamname_fontsize = hud_fontsize * 2;
187                 teamscore_size = vec2(teamscore_fontsize.x * 1.5, teamscore_fontsize.y * 1.25);
188                 timer_width = stov(cvar_string("hud_panel_timer_size")).x * vid_conwidth;
189                 
190                 // Team 1
191                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
192                 tm = GetTeam(NUM_TEAM_1, false);
193                 rgb = Team_ColorRGB(tm.team);
194                 pos.x -= (timer_width * 1.3) / 2;
195                 HUD_SpectHUD_drawTeamScore(pos, tm, rgb, true);
196                 
197                 pos = panel_pos + vec2(0, (vid_conheight - 1) / 4 + hud_fontsize.y);
198                 HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, false);
199                 
200                 // Team 2
201                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
202                 tm = GetTeam(NUM_TEAM_2, false);
203                 rgb = Team_ColorRGB(tm.team);
204                 pos.x += (timer_width * 1.3) / 2;
205                 HUD_SpectHUD_drawTeamScore(pos, tm, rgb, false);
206                 
207                 pos = panel_pos + vec2(vid_conwidth - 1, (vid_conheight - 1) / 4 + hud_fontsize.y);
208                 HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, true);
209
210                 // Team 3
211                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 41);
212                 tm = GetTeam(NUM_TEAM_3, false);
213                 rgb = Team_ColorRGB(tm.team);
214                 pos.x -= (timer_width * 1.3) / 2;
215                 HUD_SpectHUD_drawTeamScore(pos, tm, rgb, true);
216                 
217                 pos = panel_pos + vec2(0, (vid_conheight + 450) / 4 + hud_fontsize.y);
218                 HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, false);
219
220                 // Team 4
221                 pos = panel_pos + vec2((vid_conwidth - 1) / 2, 41);
222                 tm = GetTeam(NUM_TEAM_4, false);
223                 rgb = Team_ColorRGB(tm.team);
224                 pos.x += (timer_width * 1.3) / 2;
225                 HUD_SpectHUD_drawTeamScore(pos, tm, rgb, false);
226                 
227                 pos = panel_pos + vec2(vid_conwidth - 1, (vid_conheight + 450) / 4 + hud_fontsize.y);
228                 HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, true);
229         }
230 }