3 #include "panel/scoreboard.qh"
5 #include "hud_config.qh"
6 #include "../mapvoting.qh"
7 #include "../teamradar.qh"
8 #include <common/t_items.qh>
9 #include <common/deathtypes/all.qh>
10 #include <common/items/_mod.qh>
11 #include <common/mapinfo.qh>
12 #include <common/vehicles/all.qh>
13 #include <common/mutators/mutator/waypoints/all.qh>
14 #include <common/stats.qh>
15 #include <lib/csqcmodel/cl_player.qh>
16 #include <server/mutators/mutator/gamemode_ctf.qh> // TODO: remove
25 vector HUD_Get_Num_Color (float x, float maxvalue)
30 color.x = sin(2*M_PI*time);
32 color.z = sin(2*M_PI*time);
34 else if(x > maxvalue * 0.75) {
35 color.x = 0.4 - (x-150)*0.02 * 0.4; //red value between 0.4 -> 0
36 color.y = 0.9 + (x-150)*0.02 * 0.1; // green value between 0.9 -> 1
39 else if(x > maxvalue * 0.5) {
40 color.x = 1 - (x-100)*0.02 * 0.6; //red value between 1 -> 0.4
41 color.y = 1 - (x-100)*0.02 * 0.1; // green value between 1 -> 0.9
42 color.z = 1 - (x-100)*0.02; // blue value between 1 -> 0
44 else if(x > maxvalue * 0.25) {
47 color.z = 0.2 + (x-50)*0.02 * 0.8; // blue value between 0.2 -> 1
49 else if(x > maxvalue * 0.1) {
51 color.y = (x-20)*90/27/100; // green value between 0 -> 1
52 color.z = (x-20)*90/27/100 * 0.2; // blue value between 0 -> 0.2
60 blinkingamt = (1 - x/maxvalue/0.25);
63 color.x = color.x - color.x * blinkingamt * sin(2*M_PI*time);
64 color.y = color.y - color.y * blinkingamt * sin(2*M_PI*time);
65 color.z = color.z - color.z * blinkingamt * sin(2*M_PI*time);
70 float HUD_GetRowCount(int item_count, vector size, float item_aspect)
73 float aspect = size_y / size_x;
74 return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count);
77 vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
81 float ratio, best_ratio = 0;
82 float best_columns = 1, best_rows = 1;
83 bool vertical = (psize.x / psize.y >= item_aspect);
86 psize = eX * psize.y + eY * psize.x;
87 item_aspect = 1 / item_aspect;
90 rows = ceil(sqrt(item_count));
91 columns = ceil(item_count/rows);
94 ratio = (psize.x/columns) / (psize.y/rows);
95 if(ratio > item_aspect)
96 ratio = item_aspect * item_aspect / ratio;
98 if(ratio <= best_ratio)
99 break; // ratio starts decreasing by now, skip next configurations
101 best_columns = columns;
109 rows = ceil(item_count/columns);
113 return eX * best_rows + eY * best_columns;
115 return eX * best_columns + eY * best_rows;
124 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
125 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
127 TC(bool, vertical); TC(int, drawflag);
128 if(!length_ratio || !theAlpha)
134 if(length_ratio < -1)
137 else if(length_ratio < 0)
140 theOrigin = HUD_Shift(theOrigin);
141 theSize = HUD_Scale(theSize);
144 vector width, height;
146 pic = strcat(hud_skin_path, "/", pic, "_vertical");
147 if(precache_pic(pic) == "") {
148 pic = "gfx/hud/default/progressbar_vertical";
151 if (baralign == 1) // bottom align
152 theOrigin.y += (1 - length_ratio) * theSize.y;
153 else if (baralign == 2) // center align
154 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
155 else if (baralign == 3) // center align, positive values down, negative up
158 if (length_ratio > 0)
159 theOrigin.y += theSize.y;
162 theOrigin.y += (1 + length_ratio) * theSize.y;
163 length_ratio = -length_ratio;
166 theSize.y *= length_ratio;
169 width = eX * theSize.x;
170 height = eY * theSize.y;
171 if(theSize.y <= theSize.x * 2)
173 // button not high enough
174 // draw just upper and lower part then
175 square = eY * theSize.y * 0.5;
176 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
177 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
178 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
182 square = eY * theSize.x;
183 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
184 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
185 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
188 pic = strcat(hud_skin_path, "/", pic);
189 if(precache_pic(pic) == "") {
190 pic = "gfx/hud/default/progressbar";
193 if (baralign == 1) // right align
194 theOrigin.x += (1 - length_ratio) * theSize.x;
195 else if (baralign == 2) // center align
196 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
197 else if (baralign == 3) // center align, positive values on the right, negative on the left
200 if (length_ratio > 0)
201 theOrigin.x += theSize.x;
204 theOrigin.x += (1 + length_ratio) * theSize.x;
205 length_ratio = -length_ratio;
208 theSize.x *= length_ratio;
211 width = eX * theSize.x;
212 height = eY * theSize.y;
213 if(theSize.x <= theSize.y * 2)
215 // button not wide enough
216 // draw just left and right part then
217 square = eX * theSize.x * 0.5;
218 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
219 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
220 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
224 square = eX * theSize.y;
225 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
226 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
227 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
232 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
238 pos = HUD_Shift(pos);
239 mySize = HUD_Scale(mySize);
242 pic = strcat(hud_skin_path, "/num_leading");
243 if(precache_pic(pic) == "") {
244 pic = "gfx/hud/default/num_leading";
247 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
248 if(mySize.x/mySize.y > 2)
249 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);
250 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);
253 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha, float fadelerp)
255 TC(bool, vertical); TC(int, icon_right_align);
256 vector newPos = '0 0 0', newSize = '0 0 0';
257 vector picpos, numpos;
261 if(mySize.y/mySize.x > 2)
263 newSize.y = 2 * mySize.x;
264 newSize.x = mySize.x;
266 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
271 newSize.x = 1/2 * mySize.y;
272 newSize.y = mySize.y;
274 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
281 picpos = newPos + eY * newSize.x;
286 numpos = newPos + eY * newSize.x;
290 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
291 // make number smaller than icon, it looks better
292 // reduce only y to draw numbers with different number of digits with the same y size
293 numpos.y += newSize.y * ((1 - 0.7) / 2);
295 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
299 if(mySize.x/mySize.y > 3)
301 newSize.x = 3 * mySize.y;
302 newSize.y = mySize.y;
304 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
309 newSize.y = 1/3 * mySize.x;
310 newSize.x = mySize.x;
312 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
316 if(icon_right_align) // right align
319 picpos = newPos + eX * 2 * newSize.y;
323 numpos = newPos + eX * newSize.y;
327 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
328 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
329 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
330 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
333 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha)
335 TC(bool, vertical); TC(int, icon_right_align);
336 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_Minigame_Showpanels();
362 bool HUD_Panel_CheckFlags(int showflags)
365 if ( HUD_Minigame_Showpanels() )
366 return showflags & PANEL_SHOW_MINIGAME;
367 if(intermission == 2)
368 return showflags & PANEL_SHOW_MAPVOTE;
369 return showflags & PANEL_SHOW_MAINGAME;
372 void HUD_Panel_Draw(entity panent)
375 if(autocvar__hud_configure)
377 if(panel.panel_configflags & PANEL_CONFIG_MAIN)
380 else if(HUD_Panel_CheckFlags(panel.panel_showflags))
386 // reset gametype specific icons
387 if(gametype.m_modicons_reset)
388 gametype.m_modicons_reset();
391 float autocvar_hud_dynamic_shake = 1;
392 float autocvar_hud_dynamic_shake_damage_max = 130;
393 float autocvar_hud_dynamic_shake_damage_min = 10;
394 float autocvar_hud_dynamic_shake_scale = 0.2;
395 float hud_dynamic_shake_x[10] = {0, 1, -0.7, 0.5, -0.3, 0.2, -0.1, 0.1, 0.0, 0};
396 float hud_dynamic_shake_y[10] = {0, 0.4, 0.8, -0.2, -0.6, 0.0, 0.3, 0.1, -0.1, 0};
397 bool Hud_Shake_Update()
399 if(time - hud_dynamic_shake_time < 0)
402 float anim_speed = 17 + 9 * hud_dynamic_shake_factor;
403 float elapsed_time = (time - hud_dynamic_shake_time) * anim_speed;
404 int i = floor(elapsed_time);
408 float f = elapsed_time - i;
409 hud_dynamic_shake_realofs.x = (1 - f) * hud_dynamic_shake_x[i] + f * hud_dynamic_shake_x[i+1];
410 hud_dynamic_shake_realofs.y = (1 - f) * hud_dynamic_shake_y[i] + f * hud_dynamic_shake_y[i+1];
411 hud_dynamic_shake_realofs.z = 0;
412 hud_dynamic_shake_realofs *= hud_dynamic_shake_factor * autocvar_hud_dynamic_shake_scale;
413 hud_dynamic_shake_realofs.x = bound(-0.1, hud_dynamic_shake_realofs.x, 0.1) * vid_conwidth;
414 hud_dynamic_shake_realofs.y = bound(-0.1, hud_dynamic_shake_realofs.y, 0.1) * vid_conheight;
418 entity CSQCModel_server2csqc(int i);
419 void calc_followmodel_ofs(entity view);
420 void Hud_Dynamic_Frame()
422 vector ofs = '0 0 0';
425 if (autocvar_hud_dynamic_follow)
427 entity view = CSQCModel_server2csqc(player_localentnum - 1);
428 calc_followmodel_ofs(view);
429 ofs = -cl_followmodel_ofs * autocvar_hud_dynamic_follow_scale;
430 ofs.x *= autocvar_hud_dynamic_follow_scale_xyz.z;
431 ofs.y *= autocvar_hud_dynamic_follow_scale_xyz.x;
432 ofs.z *= autocvar_hud_dynamic_follow_scale_xyz.y;
434 if (fabs(ofs.x) < 0.001) ofs.x = 0;
435 if (fabs(ofs.y) < 0.001) ofs.y = 0;
436 if (fabs(ofs.z) < 0.001) ofs.z = 0;
437 ofs.x = bound(-0.1, ofs.x, 0.1);
438 ofs.y = bound(-0.1, ofs.y, 0.1);
439 ofs.z = bound(-0.1, ofs.z, 0.1);
441 hud_shift.x = ofs.y * vid_conwidth;
442 hud_shift.y = ofs.z * vid_conheight;
445 hud_scale.x = (1 + hud_shift.z);
446 hud_scale.y = hud_scale.x;
449 if(autocvar_hud_dynamic_shake > 0)
451 static float old_health = 0;
452 float health = max(-1, STAT(HEALTH));
453 if(hud_dynamic_shake_factor == -1) // don't allow the effect for this frame
455 hud_dynamic_shake_factor = 0;
460 float new_hud_dynamic_shake_factor = 0;
461 if (old_health - health >= autocvar_hud_dynamic_shake_damage_min
462 && autocvar_hud_dynamic_shake_damage_max > autocvar_hud_dynamic_shake_damage_min
463 && old_health > 0 && !intermission)
465 float m = max(autocvar_hud_dynamic_shake_damage_min, 1);
466 new_hud_dynamic_shake_factor = (old_health - health - m) / (autocvar_hud_dynamic_shake_damage_max - m);
467 if(new_hud_dynamic_shake_factor >= 1)
468 new_hud_dynamic_shake_factor = 1;
469 if(new_hud_dynamic_shake_factor >= hud_dynamic_shake_factor)
471 hud_dynamic_shake_factor = new_hud_dynamic_shake_factor;
472 hud_dynamic_shake_time = time;
476 if(hud_dynamic_shake_factor)
477 if(!Hud_Shake_Update())
478 hud_dynamic_shake_factor = 0;
481 if(hud_dynamic_shake_factor > 0)
483 hud_shift.x += hud_dynamic_shake_realofs.x;
484 hud_shift.y += hud_dynamic_shake_realofs.y;
488 hud_scale_center.x = 0.5 * vid_conwidth;
489 hud_scale_center.y = 0.5 * vid_conheight;
491 hud_scale_current = hud_scale;
492 hud_shift_current = hud_shift;
498 // global hud alpha fade (scoreboard-related panels behave differently and override it temporarly)
499 if(hud_configure_menu_open == 1)
501 else if(!autocvar__hud_configure)
502 hud_fade_alpha = (1 - scoreboard_fade_alpha) * (1 - autocvar__menu_alpha);
504 hud_fade_alpha = 1 - autocvar__menu_alpha;
506 HUD_Configure_Frame();
510 // panels that we want to be active together with the scoreboard
511 // they must fade only when the menu does
512 if(scoreboard_fade_alpha == 1)
514 if(autocvar__menu_alpha == 1)
516 if(scoreboard_fade_alpha == 1)
518 HUD_Panel_Draw(HUD_PANEL(SCOREBOARD));
519 HUD_Panel_Draw(HUD_PANEL(CENTERPRINT));
524 if(!autocvar__hud_configure && !hud_fade_alpha)
527 HUD_Panel_Draw(HUD_PANEL(VOTE));
533 if (hud_skin_prev != autocvar_hud_skin)
536 strunzone(hud_skin_path);
537 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
539 strunzone(hud_skin_prev);
540 hud_skin_prev = strzone(autocvar_hud_skin);
544 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
548 float hud_dock_color_team = autocvar_hud_dock_color_team;
549 if((teamplay) && hud_dock_color_team) {
550 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
551 color = '1 0 0' * hud_dock_color_team;
553 color = myteamcolors * hud_dock_color_team;
555 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
556 color = '1 0 0' * hud_dock_color_team;
560 string hud_dock_color = autocvar_hud_dock_color;
561 if(hud_dock_color == "shirt") {
562 f = entcs_GetClientColors(current_player);
563 color = colormapPaletteColor(floor(f / 16), 0);
565 else if(hud_dock_color == "pants") {
566 f = entcs_GetClientColors(current_player);
567 color = colormapPaletteColor(f % 16, 1);
570 color = stov(hud_dock_color);
574 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
575 if(precache_pic(pic) == "") {
576 pic = strcat(hud_skin_path, "/dock_medium");
577 if(precache_pic(pic) == "") {
578 pic = "gfx/hud/default/dock_medium";
581 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...
584 // cache the panel order into the panel_order array
585 if(autocvar__hud_panelorder != hud_panelorder_prev) {
586 for(i = 0; i < hud_panels_COUNT; ++i)
590 bool warning = false;
591 int argc = tokenize_console(autocvar__hud_panelorder);
592 if (argc > hud_panels_COUNT)
594 //first detect wrong/missing panel numbers
595 for(i = 0; i < hud_panels_COUNT; ++i) {
596 p_num = stoi(argv(i));
597 if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
598 if (panel_order[p_num] == -1) //found for the first time?
599 s = strcat(s, ftos(p_num), " ");
600 panel_order[p_num] = 1; //mark as found
605 for(i = 0; i < hud_panels_COUNT; ++i) {
606 if (panel_order[i] == -1) {
608 s = strcat(s, ftos(i), " "); //add missing panel number
612 LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder");
614 cvar_set("_hud_panelorder", s);
615 if(hud_panelorder_prev)
616 strunzone(hud_panelorder_prev);
617 hud_panelorder_prev = strzone(s);
619 //now properly set panel_order
621 for(i = 0; i < hud_panels_COUNT; ++i) {
622 panel_order[i] = stof(argv(i));
626 hud_draw_maximized = 0;
627 // draw panels in the order specified by panel_order array
628 for(i = hud_panels_COUNT - 1; i >= 0; --i)
629 HUD_Panel_Draw(hud_panels_from(panel_order[i]));
633 hud_draw_maximized = 1; // panels that may be maximized must check this var
634 // draw maximized panels on top
635 if(hud_panel_radar_maximized)
636 HUD_Panel_Draw(HUD_PANEL(RADAR));
637 if(autocvar__con_chat_maximized)
638 HUD_Panel_Draw(HUD_PANEL(CHAT));
639 if(hud_panel_quickmenu)
640 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
642 if (scoreboard_active || intermission == 2)
645 HUD_Configure_PostDraw();
647 hud_configure_prev = autocvar__hud_configure;