3 #include "hud_config.qh"
4 #include "../mapvoting.qh"
5 #include "../scoreboard.qh"
6 #include "../teamradar.qh"
7 #include <common/t_items.qh>
8 #include <common/deathtypes/all.qh>
9 #include <common/items/all.qc>
10 #include <common/mapinfo.qh>
11 #include <common/mutators/mutator/waypoints/all.qh>
12 #include <common/stats.qh>
13 #include <lib/csqcmodel/cl_player.qh>
15 #include <server/mutators/mutator/gamemode_ctf.qc>
24 vector HUD_Get_Num_Color (float x, float maxvalue)
29 color.x = sin(2*M_PI*time);
31 color.z = sin(2*M_PI*time);
33 else if(x > maxvalue * 0.75) {
34 color.x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
35 color.y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
38 else if(x > maxvalue * 0.5) {
39 color.x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
40 color.y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
41 color.z = 1 - (x-100)*0.02; // blue value between 1 -> 0
43 else if(x > maxvalue * 0.25) {
46 color.z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
48 else if(x > maxvalue * 0.1) {
50 color.y = (x-20)*90/27/100; // green value between 0 -> 1
51 color.z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
59 blinkingamt = (1 - x/maxvalue/0.25);
62 color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time);
63 color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time);
64 color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time);
69 float HUD_GetRowCount(int item_count, vector size, float item_aspect)
71 float aspect = size_y / size_x;
72 return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count);
75 vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
78 float ratio, best_ratio = 0;
79 float best_columns = 1, best_rows = 1;
80 bool vertical = (psize.x / psize.y >= item_aspect);
83 psize = eX * psize.y + eY * psize.x;
84 item_aspect = 1 / item_aspect;
87 rows = ceil(sqrt(item_count));
88 columns = ceil(item_count/rows);
91 ratio = (psize.x/columns) / (psize.y/rows);
92 if(ratio > item_aspect)
93 ratio = item_aspect * item_aspect / ratio;
95 if(ratio <= best_ratio)
96 break; // ratio starts decreasing by now, skip next configurations
98 best_columns = columns;
106 rows = ceil(item_count/columns);
110 return eX * best_rows + eY * best_columns;
112 return eX * best_columns + eY * best_rows;
121 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
122 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
124 if(!length_ratio || !theAlpha)
130 if(length_ratio < -1)
133 else if(length_ratio < 0)
137 vector width, height;
139 pic = strcat(hud_skin_path, "/", pic, "_vertical");
140 if(precache_pic(pic) == "") {
141 pic = "gfx/hud/default/progressbar_vertical";
144 if (baralign == 1) // bottom align
145 theOrigin.y += (1 - length_ratio) * theSize.y;
146 else if (baralign == 2) // center align
147 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
148 else if (baralign == 3) // center align, positive values down, negative up
151 if (length_ratio > 0)
152 theOrigin.y += theSize.y;
155 theOrigin.y += (1 + length_ratio) * theSize.y;
156 length_ratio = -length_ratio;
159 theSize.y *= length_ratio;
162 width = eX * theSize.x;
163 height = eY * theSize.y;
164 if(theSize.y <= theSize.x * 2)
166 // button not high enough
167 // draw just upper and lower part then
168 square = eY * theSize.y * 0.5;
169 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
170 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
171 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
175 square = eY * theSize.x;
176 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
177 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
178 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
181 pic = strcat(hud_skin_path, "/", pic);
182 if(precache_pic(pic) == "") {
183 pic = "gfx/hud/default/progressbar";
186 if (baralign == 1) // right align
187 theOrigin.x += (1 - length_ratio) * theSize.x;
188 else if (baralign == 2) // center align
189 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
190 else if (baralign == 3) // center align, positive values on the right, negative on the left
193 if (length_ratio > 0)
194 theOrigin.x += theSize.x;
197 theOrigin.x += (1 + length_ratio) * theSize.x;
198 length_ratio = -length_ratio;
201 theSize.x *= length_ratio;
204 width = eX * theSize.x;
205 height = eY * theSize.y;
206 if(theSize.x <= theSize.y * 2)
208 // button not wide enough
209 // draw just left and right part then
210 square = eX * theSize.x * 0.5;
211 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
212 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
213 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
217 square = eX * theSize.y;
218 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
219 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
220 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
225 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
231 pic = strcat(hud_skin_path, "/num_leading");
232 if(precache_pic(pic) == "") {
233 pic = "gfx/hud/default/num_leading";
236 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
237 if(mySize.x/mySize.y > 2)
238 drawsubpic(pos + eX * mySize.y, eX * (mySize.x - 2 * mySize.y) + eY * mySize.y, pic, '0.25 0 0', '0.5 1 0', color, theAlpha, drawflag);
239 drawsubpic(pos + eX * mySize.x - eX * min(mySize.x * 0.5, mySize.y), eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0.75 0 0', '0.25 1 0', color, theAlpha, drawflag);
242 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha, float fadelerp)
244 vector newPos = '0 0 0', newSize = '0 0 0';
245 vector picpos, numpos;
249 if(mySize.y/mySize.x > 2)
251 newSize.y = 2 * mySize.x;
252 newSize.x = mySize.x;
254 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
259 newSize.x = 1/2 * mySize.y;
260 newSize.y = mySize.y;
262 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
269 picpos = newPos + eY * newSize.x;
274 numpos = newPos + eY * newSize.x;
278 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
279 // make number smaller than icon, it looks better
280 // reduce only y to draw numbers with different number of digits with the same y size
281 numpos.y += newSize.y * ((1 - 0.7) / 2);
283 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
287 if(mySize.x/mySize.y > 3)
289 newSize.x = 3 * mySize.y;
290 newSize.y = mySize.y;
292 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
297 newSize.y = 1/3 * mySize.x;
298 newSize.x = mySize.x;
300 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
304 if(icon_right_align) // right align
307 picpos = newPos + eX * 2 * newSize.y;
311 numpos = newPos + eX * newSize.y;
315 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
316 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
317 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
318 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
321 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha)
323 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
336 if(autocvar__hud_configure) return;
337 if(intermission == 2) return;
339 if(hud == HUD_BUMBLEBEE_GUN)
340 CSQC_BUMBLE_GUN_HUD();
342 Vehicle info = Vehicles_from(hud);
347 bool HUD_Panel_CheckFlags(int showflags)
349 if ( HUD_Minigame_Showpanels() )
350 return showflags & PANEL_SHOW_MINIGAME;
351 if(intermission == 2)
352 return showflags & PANEL_SHOW_MAPVOTE;
353 return showflags & PANEL_SHOW_MAINGAME;
356 void HUD_Panel_Draw(entity panent)
359 if(autocvar__hud_configure)
361 if(panel.panel_configflags & PANEL_CONFIG_MAIN)
364 else if(HUD_Panel_CheckFlags(panel.panel_showflags))
370 // reset gametype specific icons
371 if(gametype == MAPINFO_TYPE_CTF)
378 // global hud theAlpha fade
379 if(menu_enabled == 1)
382 hud_fade_alpha = (1 - autocvar__menu_alpha);
384 if(scoreboard_fade_alpha)
385 hud_fade_alpha = (1 - scoreboard_fade_alpha);
387 HUD_Configure_Frame();
389 // panels that we want to be active together with the scoreboard
390 // they must fade only when the menu does
391 if(scoreboard_fade_alpha == 1)
393 HUD_Panel_Draw(HUD_PANEL(CENTERPRINT));
397 if(!autocvar__hud_configure && !hud_fade_alpha)
400 HUD_Panel_Draw(HUD_PANEL(VOTE));
406 if (hud_skin_prev != autocvar_hud_skin)
409 strunzone(hud_skin_path);
410 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
412 strunzone(hud_skin_prev);
413 hud_skin_prev = strzone(autocvar_hud_skin);
417 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
421 float hud_dock_color_team = autocvar_hud_dock_color_team;
422 if((teamplay) && hud_dock_color_team) {
423 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
424 color = '1 0 0' * hud_dock_color_team;
426 color = myteamcolors * hud_dock_color_team;
428 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
429 color = '1 0 0' * hud_dock_color_team;
433 string hud_dock_color = autocvar_hud_dock_color;
434 if(hud_dock_color == "shirt") {
435 f = stof(getplayerkeyvalue(current_player, "colors"));
436 color = colormapPaletteColor(floor(f / 16), 0);
438 else if(hud_dock_color == "pants") {
439 f = stof(getplayerkeyvalue(current_player, "colors"));
440 color = colormapPaletteColor(f % 16, 1);
443 color = stov(hud_dock_color);
447 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
448 if(precache_pic(pic) == "") {
449 pic = strcat(hud_skin_path, "/dock_medium");
450 if(precache_pic(pic) == "") {
451 pic = "gfx/hud/default/dock_medium";
454 drawpic('0 0 0', pic, eX * vid_conwidth + eY * vid_conheight, color, autocvar_hud_dock_alpha * hud_fade_alpha, DRAWFLAG_NORMAL); // no aspect ratio forcing on dock...
457 // cache the panel order into the panel_order array
458 if(autocvar__hud_panelorder != hud_panelorder_prev) {
459 for(i = 0; i < hud_panels_COUNT; ++i)
463 bool warning = false;
464 int argc = tokenize_console(autocvar__hud_panelorder);
465 if (argc > hud_panels_COUNT)
467 //first detect wrong/missing panel numbers
468 for(i = 0; i < hud_panels_COUNT; ++i) {
469 p_num = stoi(argv(i));
470 if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
471 if (panel_order[p_num] == -1) //found for the first time?
472 s = strcat(s, ftos(p_num), " ");
473 panel_order[p_num] = 1; //mark as found
478 for(i = 0; i < hud_panels_COUNT; ++i) {
479 if (panel_order[i] == -1) {
481 s = strcat(s, ftos(i), " "); //add missing panel number
485 LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
487 cvar_set("_hud_panelorder", s);
488 if(hud_panelorder_prev)
489 strunzone(hud_panelorder_prev);
490 hud_panelorder_prev = strzone(s);
492 //now properly set panel_order
494 for(i = 0; i < hud_panels_COUNT; ++i) {
495 panel_order[i] = stof(argv(i));
499 hud_draw_maximized = 0;
500 // draw panels in the order specified by panel_order array
501 for(i = hud_panels_COUNT - 1; i >= 0; --i)
502 HUD_Panel_Draw(hud_panels_from(panel_order[i]));
506 hud_draw_maximized = 1; // panels that may be maximized must check this var
507 // draw maximized panels on top
508 if(hud_panel_radar_maximized)
509 HUD_Panel_Draw(HUD_PANEL(RADAR));
510 if(autocvar__con_chat_maximized)
511 HUD_Panel_Draw(HUD_PANEL(CHAT));
512 if(hud_panel_quickmenu)
513 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
515 if (scoreboard_active || intermission == 2)
518 HUD_Configure_PostDraw();
520 hud_configure_prev = autocvar__hud_configure;