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/vehicles/all.qh>
12 #include <common/mutators/mutator/waypoints/all.qh>
13 #include <common/stats.qh>
14 #include <lib/csqcmodel/cl_player.qh>
16 #include <server/mutators/mutator/gamemode_ctf.qc>
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)
72 float aspect = size_y / size_x;
73 return bound(1, floor((sqrt(4 * item_aspect * aspect * item_count + aspect * aspect) + aspect + 0.5) / 2), item_count);
76 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;
116 // return the string of the onscreen race timer
117 string MakeRaceString(int cp, float mytime, float theirtime, float lapdelta, string theirname)
125 if(theirtime == 0) // goal hit
129 timestr = strcat("+", ftos_decimals(+mytime, TIME_DECIMALS));
139 timestr = strcat("-", ftos_decimals(-mytime, TIME_DECIMALS));
145 lapstr = sprintf(_(" (-%dL)"), lapdelta);
148 else if(lapdelta < 0)
150 lapstr = sprintf(_(" (+%dL)"), -lapdelta);
154 else if(theirtime > 0) // anticipation
156 if(mytime >= theirtime)
157 timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
159 timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
169 cpname = _("Start line");
171 cpname = _("Finish line");
173 cpname = sprintf(_("Intermediate %d"), cp);
175 cpname = _("Finish line");
178 return strcat(col, cpname);
179 else if(theirname == "")
180 return strcat(col, sprintf("%s (%s)", cpname, timestr));
182 return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(theirname, col, lapstr)));
185 // Check if the given name already exist in race rankings? In that case, where? (otherwise return 0)
186 int race_CheckName(string net_name)
189 for (i=RANKINGS_CNT-1;i>=0;--i)
190 if(grecordholder[i] == net_name)
201 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
202 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
204 if(!length_ratio || !theAlpha)
210 if(length_ratio < -1)
213 else if(length_ratio < 0)
217 vector width, height;
219 pic = strcat(hud_skin_path, "/", pic, "_vertical");
220 if(precache_pic(pic) == "") {
221 pic = "gfx/hud/default/progressbar_vertical";
224 if (baralign == 1) // bottom align
225 theOrigin.y += (1 - length_ratio) * theSize.y;
226 else if (baralign == 2) // center align
227 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
228 else if (baralign == 3) // center align, positive values down, negative up
231 if (length_ratio > 0)
232 theOrigin.y += theSize.y;
235 theOrigin.y += (1 + length_ratio) * theSize.y;
236 length_ratio = -length_ratio;
239 theSize.y *= length_ratio;
242 width = eX * theSize.x;
243 height = eY * theSize.y;
244 if(theSize.y <= theSize.x * 2)
246 // button not high enough
247 // draw just upper and lower part then
248 square = eY * theSize.y * 0.5;
249 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
250 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
251 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
255 square = eY * theSize.x;
256 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
257 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
258 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
261 pic = strcat(hud_skin_path, "/", pic);
262 if(precache_pic(pic) == "") {
263 pic = "gfx/hud/default/progressbar";
266 if (baralign == 1) // right align
267 theOrigin.x += (1 - length_ratio) * theSize.x;
268 else if (baralign == 2) // center align
269 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
270 else if (baralign == 3) // center align, positive values on the right, negative on the left
273 if (length_ratio > 0)
274 theOrigin.x += theSize.x;
277 theOrigin.x += (1 + length_ratio) * theSize.x;
278 length_ratio = -length_ratio;
281 theSize.x *= length_ratio;
284 width = eX * theSize.x;
285 height = eY * theSize.y;
286 if(theSize.x <= theSize.y * 2)
288 // button not wide enough
289 // draw just left and right part then
290 square = eX * theSize.x * 0.5;
291 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
292 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
293 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
297 square = eX * theSize.y;
298 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
299 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
300 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
305 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
311 pic = strcat(hud_skin_path, "/num_leading");
312 if(precache_pic(pic) == "") {
313 pic = "gfx/hud/default/num_leading";
316 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
317 if(mySize.x/mySize.y > 2)
318 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);
319 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);
322 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha, float fadelerp)
324 vector newPos = '0 0 0', newSize = '0 0 0';
325 vector picpos, numpos;
329 if(mySize.y/mySize.x > 2)
331 newSize.y = 2 * mySize.x;
332 newSize.x = mySize.x;
334 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
339 newSize.x = 1/2 * mySize.y;
340 newSize.y = mySize.y;
342 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
349 picpos = newPos + eY * newSize.x;
354 numpos = newPos + eY * newSize.x;
358 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
359 // make number smaller than icon, it looks better
360 // reduce only y to draw numbers with different number of digits with the same y size
361 numpos.y += newSize.y * ((1 - 0.7) / 2);
363 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
367 if(mySize.x/mySize.y > 3)
369 newSize.x = 3 * mySize.y;
370 newSize.y = mySize.y;
372 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
377 newSize.y = 1/3 * mySize.x;
378 newSize.x = mySize.x;
380 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
384 if(icon_right_align) // right align
387 picpos = newPos + eX * 2 * newSize.y;
391 numpos = newPos + eX * newSize.y;
395 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
396 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
397 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
398 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
401 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, bool icon_right_align, vector color, float theAlpha)
403 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
414 void CSQC_BUMBLE_GUN_HUD();
418 if(autocvar__hud_configure) return;
419 if(intermission == 2) return;
421 if(hud == HUD_BUMBLEBEE_GUN)
422 CSQC_BUMBLE_GUN_HUD();
424 Vehicle info = Vehicles_from(hud);
429 bool HUD_Panel_CheckFlags(int showflags)
431 if ( HUD_Minigame_Showpanels() )
432 return showflags & PANEL_SHOW_MINIGAME;
433 if(intermission == 2)
434 return showflags & PANEL_SHOW_MAPVOTE;
435 return showflags & PANEL_SHOW_MAINGAME;
438 void HUD_Panel_Draw(entity panent)
441 if(autocvar__hud_configure)
443 if(panel.panel_configflags & PANEL_CONFIG_MAIN)
446 else if(HUD_Panel_CheckFlags(panel.panel_showflags))
452 // reset gametype specific icons
453 if(gametype == MAPINFO_TYPE_CTF)
460 // global hud theAlpha fade
461 if(menu_enabled == 1)
464 hud_fade_alpha = (1 - autocvar__menu_alpha);
466 if(scoreboard_fade_alpha)
467 hud_fade_alpha = (1 - scoreboard_fade_alpha);
469 HUD_Configure_Frame();
471 // panels that we want to be active together with the scoreboard
472 // they must fade only when the menu does
473 if(scoreboard_fade_alpha == 1)
475 HUD_Panel_Draw(HUD_PANEL(CENTERPRINT));
479 if(!autocvar__hud_configure && !hud_fade_alpha)
482 HUD_Panel_Draw(HUD_PANEL(VOTE));
488 if (hud_skin_prev != autocvar_hud_skin)
491 strunzone(hud_skin_path);
492 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
494 strunzone(hud_skin_prev);
495 hud_skin_prev = strzone(autocvar_hud_skin);
499 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
503 float hud_dock_color_team = autocvar_hud_dock_color_team;
504 if((teamplay) && hud_dock_color_team) {
505 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
506 color = '1 0 0' * hud_dock_color_team;
508 color = myteamcolors * hud_dock_color_team;
510 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
511 color = '1 0 0' * hud_dock_color_team;
515 string hud_dock_color = autocvar_hud_dock_color;
516 if(hud_dock_color == "shirt") {
517 f = stof(getplayerkeyvalue(current_player, "colors"));
518 color = colormapPaletteColor(floor(f / 16), 0);
520 else if(hud_dock_color == "pants") {
521 f = stof(getplayerkeyvalue(current_player, "colors"));
522 color = colormapPaletteColor(f % 16, 1);
525 color = stov(hud_dock_color);
529 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
530 if(precache_pic(pic) == "") {
531 pic = strcat(hud_skin_path, "/dock_medium");
532 if(precache_pic(pic) == "") {
533 pic = "gfx/hud/default/dock_medium";
536 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...
539 // cache the panel order into the panel_order array
540 if(autocvar__hud_panelorder != hud_panelorder_prev) {
541 for(i = 0; i < hud_panels_COUNT; ++i)
545 bool warning = false;
546 int argc = tokenize_console(autocvar__hud_panelorder);
547 if (argc > hud_panels_COUNT)
549 //first detect wrong/missing panel numbers
550 for(i = 0; i < hud_panels_COUNT; ++i) {
551 p_num = stoi(argv(i));
552 if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
553 if (panel_order[p_num] == -1) //found for the first time?
554 s = strcat(s, ftos(p_num), " ");
555 panel_order[p_num] = 1; //mark as found
560 for(i = 0; i < hud_panels_COUNT; ++i) {
561 if (panel_order[i] == -1) {
563 s = strcat(s, ftos(i), " "); //add missing panel number
567 LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
569 cvar_set("_hud_panelorder", s);
570 if(hud_panelorder_prev)
571 strunzone(hud_panelorder_prev);
572 hud_panelorder_prev = strzone(s);
574 //now properly set panel_order
576 for(i = 0; i < hud_panels_COUNT; ++i) {
577 panel_order[i] = stof(argv(i));
581 hud_draw_maximized = 0;
582 // draw panels in the order specified by panel_order array
583 for(i = hud_panels_COUNT - 1; i >= 0; --i)
584 HUD_Panel_Draw(hud_panels_from(panel_order[i]));
588 hud_draw_maximized = 1; // panels that may be maximized must check this var
589 // draw maximized panels on top
590 if(hud_panel_radar_maximized)
591 HUD_Panel_Draw(HUD_PANEL(RADAR));
592 if(autocvar__con_chat_maximized)
593 HUD_Panel_Draw(HUD_PANEL(CHAT));
594 if(hud_panel_quickmenu)
595 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
597 if (scoreboard_active || intermission == 2)
600 HUD_Configure_PostDraw();
602 hud_configure_prev = autocvar__hud_configure;