3 #include "hud_config.qh"
4 #include "../mapvoting.qh"
5 #include "../teamradar.qh"
6 #include <common/t_items.qh>
7 #include <common/deathtypes/all.qh>
8 #include <common/items/all.qc>
9 #include <common/mapinfo.qh>
10 #include <common/vehicles/all.qh>
11 #include <common/mutators/mutator/waypoints/all.qh>
12 #include <common/stats.qh>
13 #include <lib/csqcmodel/cl_player.qh>
14 #include <server/mutators/mutator/gamemode_ctf.qh> // TODO: remove
23 vector HUD_Get_Num_Color (float x, float maxvalue)
28 color.x = sin(2*M_PI*time);
30 color.z = sin(2*M_PI*time);
32 else if(x > maxvalue * 0.75) {
33 color.x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
34 color.y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
37 else if(x > maxvalue * 0.5) {
38 color.x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
39 color.y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
40 color.z = 1 - (x-100)*0.02; // blue value between 1 -> 0
42 else if(x > maxvalue * 0.25) {
45 color.z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
47 else if(x > maxvalue * 0.1) {
49 color.y = (x-20)*90/27/100; // green value between 0 -> 1
50 color.z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
58 blinkingamt = (1 - x/maxvalue/0.25);
61 color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time);
62 color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time);
63 color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time);
68 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)
79 float ratio, best_ratio = 0;
80 float best_columns = 1, best_rows = 1;
81 bool vertical = (psize.x / psize.y >= item_aspect);
84 psize = eX * psize.y + eY * psize.x;
85 item_aspect = 1 / item_aspect;
88 rows = ceil(sqrt(item_count));
89 columns = ceil(item_count/rows);
92 ratio = (psize.x/columns) / (psize.y/rows);
93 if(ratio > item_aspect)
94 ratio = item_aspect * item_aspect / ratio;
96 if(ratio <= best_ratio)
97 break; // ratio starts decreasing by now, skip next configurations
99 best_columns = columns;
107 rows = ceil(item_count/columns);
111 return eX * best_rows + eY * best_columns;
113 return eX * best_columns + eY * best_rows;
122 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
123 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
125 TC(bool, vertical); TC(int, drawflag);
126 if(!length_ratio || !theAlpha)
132 if(length_ratio < -1)
135 else if(length_ratio < 0)
138 theOrigin = HUD_Shift(theOrigin);
139 theSize = HUD_Scale(theSize);
142 vector width, height;
144 pic = strcat(hud_skin_path, "/", pic, "_vertical");
145 if(precache_pic(pic) == "") {
146 pic = "gfx/hud/default/progressbar_vertical";
149 if (baralign == 1) // bottom align
150 theOrigin.y += (1 - length_ratio) * theSize.y;
151 else if (baralign == 2) // center align
152 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
153 else if (baralign == 3) // center align, positive values down, negative up
156 if (length_ratio > 0)
157 theOrigin.y += theSize.y;
160 theOrigin.y += (1 + length_ratio) * theSize.y;
161 length_ratio = -length_ratio;
164 theSize.y *= length_ratio;
167 width = eX * theSize.x;
168 height = eY * theSize.y;
169 if(theSize.y <= theSize.x * 2)
171 // button not high enough
172 // draw just upper and lower part then
173 square = eY * theSize.y * 0.5;
174 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
175 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
176 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
180 square = eY * theSize.x;
181 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
182 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
183 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
186 pic = strcat(hud_skin_path, "/", pic);
187 if(precache_pic(pic) == "") {
188 pic = "gfx/hud/default/progressbar";
191 if (baralign == 1) // right align
192 theOrigin.x += (1 - length_ratio) * theSize.x;
193 else if (baralign == 2) // center align
194 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
195 else if (baralign == 3) // center align, positive values on the right, negative on the left
198 if (length_ratio > 0)
199 theOrigin.x += theSize.x;
202 theOrigin.x += (1 + length_ratio) * theSize.x;
203 length_ratio = -length_ratio;
206 theSize.x *= length_ratio;
209 width = eX * theSize.x;
210 height = eY * theSize.y;
211 if(theSize.x <= theSize.y * 2)
213 // button not wide enough
214 // draw just left and right part then
215 square = eX * theSize.x * 0.5;
216 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
217 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
218 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
222 square = eX * theSize.y;
223 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
224 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
225 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
230 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
236 pos = HUD_Shift(pos);
237 mySize = HUD_Scale(mySize);
240 pic = strcat(hud_skin_path, "/num_leading");
241 if(precache_pic(pic) == "") {
242 pic = "gfx/hud/default/num_leading";
245 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
246 if(mySize.x/mySize.y > 2)
247 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);
248 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);
251 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha, float fadelerp)
253 TC(bool, vertical); TC(int, icon_right_align);
254 vector newPos = '0 0 0', newSize = '0 0 0';
255 vector picpos, numpos;
259 if(mySize.y/mySize.x > 2)
261 newSize.y = 2 * mySize.x;
262 newSize.x = mySize.x;
264 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
269 newSize.x = 1/2 * mySize.y;
270 newSize.y = mySize.y;
272 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
279 picpos = newPos + eY * newSize.x;
284 numpos = newPos + eY * newSize.x;
288 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
289 // make number smaller than icon, it looks better
290 // reduce only y to draw numbers with different number of digits with the same y size
291 numpos.y += newSize.y * ((1 - 0.7) / 2);
293 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
297 if(mySize.x/mySize.y > 3)
299 newSize.x = 3 * mySize.y;
300 newSize.y = mySize.y;
302 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
307 newSize.y = 1/3 * mySize.x;
308 newSize.x = mySize.x;
310 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
314 if(icon_right_align) // right align
317 picpos = newPos + eX * 2 * newSize.y;
321 numpos = newPos + eX * newSize.y;
325 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
326 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
327 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
328 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
331 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha)
333 TC(bool, vertical); TC(int, icon_right_align);
334 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
345 void CSQC_BUMBLE_GUN_HUD();
349 if(autocvar__hud_configure) return;
350 if(intermission == 2) return;
352 if(hud == HUD_BUMBLEBEE_GUN)
353 CSQC_BUMBLE_GUN_HUD();
355 Vehicle info = Vehicles_from(hud);
360 bool HUD_Panel_CheckFlags(int showflags)
363 if ( HUD_Minigame_Showpanels() )
364 return showflags & PANEL_SHOW_MINIGAME;
365 if(intermission == 2)
366 return showflags & PANEL_SHOW_MAPVOTE;
367 return showflags & PANEL_SHOW_MAINGAME;
370 void HUD_Panel_Draw(entity panent)
373 if(autocvar__hud_configure)
375 if(panel.panel_configflags & PANEL_CONFIG_MAIN)
378 else if(HUD_Panel_CheckFlags(panel.panel_showflags))
384 // reset gametype specific icons
385 if(gametype == MAPINFO_TYPE_CTF)
389 float autocvar_hud_dynamic_shake = 1;
390 float autocvar_hud_dynamic_shake_damage_max = 130;
391 float autocvar_hud_dynamic_shake_damage_min = 10;
392 float autocvar_hud_dynamic_shake_scale = 0.2;
393 float hud_dynamic_shake_x[10] = {0, 1, -0.7, 0.5, -0.3, 0.2, -0.1, 0.1, 0.0, 0};
394 float hud_dynamic_shake_y[10] = {0, 0.4, 0.8, -0.2, -0.6, 0.0, 0.3, 0.1, -0.1, 0};
395 bool Hud_Shake_Update()
397 if(time - hud_dynamic_shake_time < 0)
400 float anim_speed = 17 + 9 * hud_dynamic_shake_factor;
401 float elapsed_time = (time - hud_dynamic_shake_time) * anim_speed;
402 int i = floor(elapsed_time);
406 float f = elapsed_time - i;
407 hud_dynamic_shake_realofs.x = (1 - f) * hud_dynamic_shake_x[i] + f * hud_dynamic_shake_x[i+1];
408 hud_dynamic_shake_realofs.y = (1 - f) * hud_dynamic_shake_y[i] + f * hud_dynamic_shake_y[i+1];
409 hud_dynamic_shake_realofs.z = 0;
410 hud_dynamic_shake_realofs *= hud_dynamic_shake_factor * autocvar_hud_dynamic_shake_scale;
411 hud_dynamic_shake_realofs.x = bound(-0.1, hud_dynamic_shake_realofs.x, 0.1) * vid_conwidth;
412 hud_dynamic_shake_realofs.y = bound(-0.1, hud_dynamic_shake_realofs.y, 0.1) * vid_conheight;
416 void calc_followmodel_ofs(entity view);
417 void Hud_Dynamic_Frame()
419 vector ofs = '0 0 0';
422 if (autocvar_hud_dynamic_follow)
424 entity view = CSQCModel_server2csqc(player_localentnum - 1);
425 calc_followmodel_ofs(view);
426 ofs = -cl_followmodel_ofs * autocvar_hud_dynamic_follow_scale;
427 ofs.x *= autocvar_hud_dynamic_follow_scale_xyz.z;
428 ofs.y *= autocvar_hud_dynamic_follow_scale_xyz.x;
429 ofs.z *= autocvar_hud_dynamic_follow_scale_xyz.y;
431 if (fabs(ofs.x) < 0.001) ofs.x = 0;
432 if (fabs(ofs.y) < 0.001) ofs.y = 0;
433 if (fabs(ofs.z) < 0.001) ofs.z = 0;
434 ofs.x = bound(-0.1, ofs.x, 0.1);
435 ofs.y = bound(-0.1, ofs.y, 0.1);
436 ofs.z = bound(-0.1, ofs.z, 0.1);
438 hud_shift.x = ofs.y * vid_conwidth;
439 hud_shift.y = ofs.z * vid_conheight;
442 hud_scale.x = (1 + hud_shift.z);
443 hud_scale.y = hud_scale.x;
446 if(autocvar_hud_dynamic_shake > 0)
448 static float old_health = 0;
449 float health = max(-1, STAT(HEALTH));
450 if(hud_dynamic_shake_factor == -1) // don't allow the effect for this frame
452 hud_dynamic_shake_factor = 0;
457 float new_hud_dynamic_shake_factor = 0;
458 if (old_health - health >= autocvar_hud_dynamic_shake_damage_min
459 && autocvar_hud_dynamic_shake_damage_max > autocvar_hud_dynamic_shake_damage_min
460 && old_health > 0 && !intermission)
462 float m = max(autocvar_hud_dynamic_shake_damage_min, 1);
463 new_hud_dynamic_shake_factor = (old_health - health - m) / (autocvar_hud_dynamic_shake_damage_max - m);
464 if(new_hud_dynamic_shake_factor >= 1)
465 new_hud_dynamic_shake_factor = 1;
466 if(new_hud_dynamic_shake_factor >= hud_dynamic_shake_factor)
468 hud_dynamic_shake_factor = new_hud_dynamic_shake_factor;
469 hud_dynamic_shake_time = time;
473 if(hud_dynamic_shake_factor)
474 if(!Hud_Shake_Update())
475 hud_dynamic_shake_factor = 0;
478 if(hud_dynamic_shake_factor > 0)
480 hud_shift.x += hud_dynamic_shake_realofs.x;
481 hud_shift.y += hud_dynamic_shake_realofs.y;
485 hud_scale_center.x = 0.5 * vid_conwidth;
486 hud_scale_center.y = 0.5 * vid_conheight;
488 hud_scale_current = hud_scale;
489 hud_shift_current = hud_shift;
494 void HUD_DrawScoreboard();
495 void HUD_Scoreboard(void)
497 HUD_DrawScoreboard();
503 // global hud alpha fade (scoreboard-related panels behave differently and override it temporarly)
504 if(menu_enabled == 1)
506 else if(!autocvar__hud_configure)
507 hud_fade_alpha = (1 - scoreboard_fade_alpha) * (1 - autocvar__menu_alpha);
509 hud_fade_alpha = 1 - autocvar__menu_alpha;
511 HUD_Configure_Frame();
515 // panels that we want to be active together with the scoreboard
516 // they must fade only when the menu does
517 if(scoreboard_fade_alpha == 1)
519 if(autocvar__menu_alpha == 1)
521 if(scoreboard_fade_alpha == 1)
523 HUD_Panel_Draw(HUD_PANEL(SCOREBOARD));
524 HUD_Panel_Draw(HUD_PANEL(CENTERPRINT));
529 if(!autocvar__hud_configure && !hud_fade_alpha)
532 HUD_Panel_Draw(HUD_PANEL(VOTE));
538 if (hud_skin_prev != autocvar_hud_skin)
541 strunzone(hud_skin_path);
542 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
544 strunzone(hud_skin_prev);
545 hud_skin_prev = strzone(autocvar_hud_skin);
549 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
553 float hud_dock_color_team = autocvar_hud_dock_color_team;
554 if((teamplay) && hud_dock_color_team) {
555 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
556 color = '1 0 0' * hud_dock_color_team;
558 color = myteamcolors * hud_dock_color_team;
560 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
561 color = '1 0 0' * hud_dock_color_team;
565 string hud_dock_color = autocvar_hud_dock_color;
566 if(hud_dock_color == "shirt") {
567 f = stof(getplayerkeyvalue(current_player, "colors"));
568 color = colormapPaletteColor(floor(f / 16), 0);
570 else if(hud_dock_color == "pants") {
571 f = stof(getplayerkeyvalue(current_player, "colors"));
572 color = colormapPaletteColor(f % 16, 1);
575 color = stov(hud_dock_color);
579 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
580 if(precache_pic(pic) == "") {
581 pic = strcat(hud_skin_path, "/dock_medium");
582 if(precache_pic(pic) == "") {
583 pic = "gfx/hud/default/dock_medium";
586 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...
589 // cache the panel order into the panel_order array
590 if(autocvar__hud_panelorder != hud_panelorder_prev) {
591 for(i = 0; i < hud_panels_COUNT; ++i)
595 bool warning = false;
596 int argc = tokenize_console(autocvar__hud_panelorder);
597 if (argc > hud_panels_COUNT)
599 //first detect wrong/missing panel numbers
600 for(i = 0; i < hud_panels_COUNT; ++i) {
601 p_num = stoi(argv(i));
602 if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
603 if (panel_order[p_num] == -1) //found for the first time?
604 s = strcat(s, ftos(p_num), " ");
605 panel_order[p_num] = 1; //mark as found
610 for(i = 0; i < hud_panels_COUNT; ++i) {
611 if (panel_order[i] == -1) {
613 s = strcat(s, ftos(i), " "); //add missing panel number
617 LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
619 cvar_set("_hud_panelorder", s);
620 if(hud_panelorder_prev)
621 strunzone(hud_panelorder_prev);
622 hud_panelorder_prev = strzone(s);
624 //now properly set panel_order
626 for(i = 0; i < hud_panels_COUNT; ++i) {
627 panel_order[i] = stof(argv(i));
631 hud_draw_maximized = 0;
632 // draw panels in the order specified by panel_order array
633 for(i = hud_panels_COUNT - 1; i >= 0; --i)
634 HUD_Panel_Draw(hud_panels_from(panel_order[i]));
638 hud_draw_maximized = 1; // panels that may be maximized must check this var
639 // draw maximized panels on top
640 if(hud_panel_radar_maximized)
641 HUD_Panel_Draw(HUD_PANEL(RADAR));
642 if(autocvar__con_chat_maximized)
643 HUD_Panel_Draw(HUD_PANEL(CHAT));
644 if(hud_panel_quickmenu)
645 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
647 if (scoreboard_active || intermission == 2)
650 HUD_Configure_PostDraw();
652 hud_configure_prev = autocvar__hud_configure;