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