]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/score.qc
Merge branch 'master' into terencehill/menu_hudskin_selector
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / score.qc
1 // Score (#7)
2
3 void HUD_UpdatePlayerTeams();
4 void HUD_Score_Rankings(vector pos, vector mySize, entity me)
5 {
6         float score;
7         entity tm = world, pl;
8         int SCOREPANEL_MAX_ENTRIES = 6;
9         float SCOREPANEL_ASPECTRATIO = 2;
10         int entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize.y/mySize.x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
11         vector fontsize = '1 1 0' * (mySize.y/entries);
12
13         vector rgb, score_color;
14         rgb = '1 1 1';
15         score_color = '1 1 1';
16
17         float name_size = mySize.x*0.75;
18         float spacing_size = mySize.x*0.04;
19         const float highlight_alpha = 0.2;
20         int i = 0, first_pl = 0;
21         bool me_printed = false;
22         string s;
23         if (autocvar__hud_configure)
24         {
25                 float players_per_team = 0;
26                 if (team_count)
27                 {
28                         // show team scores in the first line
29                         float score_size = mySize.x / team_count;
30                         players_per_team = max(2, ceil((entries - 1) / team_count));
31                         for(i=0; i<team_count; ++i) {
32                                 if (i == floor((entries - 2) / players_per_team) || (entries == 1 && i == 0))
33                                         HUD_Panel_DrawHighlight(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
34                                 drawstring_aspect(pos + eX * score_size * i, ftos(175 - 23*i), eX * score_size + eY * fontsize.y, Team_ColorRGB(ColorByTeam(i)) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
35                         }
36                         first_pl = 1;
37                         pos.y += fontsize.y;
38                 }
39                 score = 10 + SCOREPANEL_MAX_ENTRIES * 3;
40                 for (i=first_pl; i<entries; ++i)
41                 {
42                         //simulate my score is lower than all displayed players,
43                         //so that I don't appear at all showing pure rankings.
44                         //This is to better show the difference between the 2 ranking views
45                         if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
46                         {
47                                 rgb = '1 1 0';
48                                 drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
49                                 s = entcs_GetName(player_localnum);
50                                 score = 7;
51                         }
52                         else
53                         {
54                                 s = sprintf(_("Player %d"), i + 1 - first_pl);
55                                 score -= 3;
56                         }
57
58                         if (team_count)
59                                 score_color = Team_ColorRGB(ColorByTeam(floor((i - first_pl) / players_per_team))) * 0.8;
60                         s = textShortenToWidth(s, name_size, fontsize, stringwidth_colors);
61                         drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
62                         drawstring(pos + eX * (name_size + spacing_size), ftos(score), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
63                         pos.y += fontsize.y;
64                 }
65                 return;
66         }
67
68         if (!scoreboard_fade_alpha) // the scoreboard too calls HUD_UpdatePlayerTeams
69                 HUD_UpdatePlayerTeams();
70         if (team_count)
71         {
72                 // show team scores in the first line
73                 float score_size = mySize.x / team_count;
74                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
75                         if(tm.team == NUM_SPECTATOR)
76                                 continue;
77                         if (tm.team == myteam)
78                                 drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
79                         drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores[ts_primary])), eX * score_size + eY * fontsize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
80                         ++i;
81                 }
82                 first_pl = 1;
83                 pos.y += fontsize.y;
84                 tm = teams.sort_next;
85         }
86         i = first_pl;
87
88         do
89         for (pl = players.sort_next; pl && i<entries; pl = pl.sort_next)
90         {
91                 if ((team_count && pl.team != tm.team) || pl.team == NUM_SPECTATOR)
92                         continue;
93
94                 if (i == entries-1 && !me_printed && pl != me)
95                 if (autocvar_hud_panel_score_rankings == 1 && spectatee_status != -1)
96                 {
97                         for (pl = me.sort_next; pl; pl = pl.sort_next)
98                                 if (pl.team != NUM_SPECTATOR)
99                                         break;
100
101                         if (pl)
102                                 rgb = '1 1 0'; //not last but not among the leading players: yellow
103                         else
104                                 rgb = '1 0 0'; //last: red
105                         pl = me;
106                 }
107
108                 if (pl == me)
109                 {
110                         if (i == first_pl)
111                                 rgb = '0 1 0'; //first: green
112                         me_printed = true;
113                         drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
114                 }
115                 if (team_count)
116                         score_color = Team_ColorRGB(pl.team) * 0.8;
117                 s = textShortenToWidth(entcs_GetName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
118                 drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
119                 drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
120                 pos.y += fontsize.y;
121                 ++i;
122         }
123         while (i<entries && team_count && (tm = tm.sort_next) && (tm.team != NUM_SPECTATOR || (tm = tm.sort_next)));
124 }
125
126 void HUD_Score()
127 {
128         if(!autocvar__hud_configure)
129         {
130                 if(!autocvar_hud_panel_score) return;
131                 if(spectatee_status == -1 && (gametype == MAPINFO_TYPE_RACE || gametype == MAPINFO_TYPE_CTS)) return;
132         }
133
134         HUD_Panel_UpdateCvars();
135         vector pos, mySize;
136         pos = panel_pos;
137         mySize = panel_size;
138
139         HUD_Panel_DrawBg(1);
140         if(panel_bg_padding)
141         {
142                 pos += '1 1 0' * panel_bg_padding;
143                 mySize -= '2 2 0' * panel_bg_padding;
144         }
145
146         float score, distribution = 0;
147         string sign;
148         vector distribution_color;
149         entity tm, pl, me;
150
151         me = playerslots[current_player];
152
153         if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
154                 string timer, distrtimer;
155
156                 pl = players.sort_next;
157                 if(pl == me)
158                         pl = pl.sort_next;
159                 if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
160                         if(pl.scores[ps_primary] == 0)
161                                 pl = world;
162
163                 score = me.(scores[ps_primary]);
164                 timer = TIME_ENCODED_TOSTRING(score);
165
166                 draw_beginBoldFont();
167                 if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
168                         // distribution display
169                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
170
171                         distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
172
173                         if (distribution <= 0) {
174                                 distribution_color = '0 1 0';
175                                 sign = "-";
176                         }
177                         else {
178                                 distribution_color = '1 0 0';
179                                 sign = "+";
180                         }
181                         drawstring_aspect(pos + eX * 0.75 * mySize.x, strcat(sign, distrtimer), eX * 0.25 * mySize.x + eY * (1/3) * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
182                 }
183                 // race record display
184                 if (distribution <= 0)
185                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
186                 drawstring_aspect(pos, timer, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
187                 draw_endBoldFont();
188         } else if (!teamplay) { // non-teamgames
189                 if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
190                 {
191                         HUD_Score_Rankings(pos, mySize, me);
192                         return;
193                 }
194                 // me vector := [team/connected frags id]
195                 pl = players.sort_next;
196                 if(pl == me)
197                         pl = pl.sort_next;
198
199                 if(autocvar__hud_configure)
200                         distribution = 42;
201                 else if(pl)
202                         distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
203                 else
204                         distribution = 0;
205
206                 score = me.(scores[ps_primary]);
207                 if(autocvar__hud_configure)
208                         score = 123;
209
210                 if(distribution >= 5)
211                         distribution_color = eY;
212                 else if(distribution >= 0)
213                         distribution_color = '1 1 1';
214                 else if(distribution >= -5)
215                         distribution_color = '1 1 0';
216                 else
217                         distribution_color = eX;
218
219                 string distribution_str;
220                 distribution_str = ftos(distribution);
221                 draw_beginBoldFont();
222                 if (distribution >= 0)
223                 {
224                         if (distribution > 0)
225                                 distribution_str = strcat("+", distribution_str);
226                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
227                 }
228                 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
229                 drawstring_aspect(pos + eX * 0.75 * mySize.x, distribution_str, eX * 0.25 * mySize.x + eY * (1/3) * mySize.y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
230                 draw_endBoldFont();
231         } else { // teamgames
232                 float row, column, rows = 0, columns = 0;
233                 vector offset = '0 0 0';
234                 vector score_pos, score_size; //for scores other than myteam
235                 if(autocvar_hud_panel_score_rankings)
236                 {
237                         HUD_Score_Rankings(pos, mySize, me);
238                         return;
239                 }
240                 if(spectatee_status == -1)
241                 {
242                         rows = HUD_GetRowCount(team_count, mySize, 3);
243                         columns = ceil(team_count/rows);
244                         score_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
245
246                         float newSize;
247                         if(score_size.x/score_size.y > 3)
248                         {
249                                 newSize = 3 * score_size.y;
250                                 offset.x = score_size.x - newSize;
251                                 pos.x += offset.x/2;
252                                 score_size.x = newSize;
253                         }
254                         else
255                         {
256                                 newSize = 1/3 * score_size.x;
257                                 offset.y = score_size.y - newSize;
258                                 pos.y += offset.y/2;
259                                 score_size.y = newSize;
260                         }
261                 }
262                 else
263                         score_size = eX * mySize.x*(1/4) + eY * mySize.y*(1/3);
264
265                 float max_fragcount;
266                 max_fragcount = -99;
267                 draw_beginBoldFont();
268                 row = column = 0;
269                 for(tm = teams.sort_next; tm; tm = tm.sort_next) {
270                         if(tm.team == NUM_SPECTATOR)
271                                 continue;
272                         score = tm.(teamscores[ts_primary]);
273                         if(autocvar__hud_configure)
274                                 score = 123;
275
276                         if (score > max_fragcount)
277                                 max_fragcount = score;
278
279                         if (spectatee_status == -1)
280                         {
281                                 score_pos = pos + eX * column * (score_size.x + offset.x) + eY * row * (score_size.y + offset.y);
282                                 if (max_fragcount == score)
283                                         HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
284                                 drawstring_aspect(score_pos, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
285                                 ++row;
286                                 if(row >= rows)
287                                 {
288                                         row = 0;
289                                         ++column;
290                                 }
291                         }
292                         else if(tm.team == myteam) {
293                                 if (max_fragcount == score)
294                                         HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize.x + eY * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
295                                 drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize.x + eY * mySize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
296                         } else {
297                                 if (max_fragcount == score)
298                                         HUD_Panel_DrawHighlight(pos + eX * 0.75 * mySize.x + eY * (1/3) * rows * mySize.y, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
299                                 drawstring_aspect(pos + eX * 0.75 * mySize.x + eY * (1/3) * rows * mySize.y, ftos(score), score_size, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
300                                 ++rows;
301                         }
302                 }
303                 draw_endBoldFont();
304         }
305 }