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>
15 #include <server/mutators/mutator/gamemode_ctf.qh> // TODO: remove
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)
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)
80 float ratio, best_ratio = 0;
81 float best_columns = 1, best_rows = 1;
82 bool vertical = (psize.x / psize.y >= item_aspect);
85 psize = eX * psize.y + eY * psize.x;
86 item_aspect = 1 / item_aspect;
89 rows = ceil(sqrt(item_count));
90 columns = ceil(item_count/rows);
93 ratio = (psize.x/columns) / (psize.y/rows);
94 if(ratio > item_aspect)
95 ratio = item_aspect * item_aspect / ratio;
97 if(ratio <= best_ratio)
98 break; // ratio starts decreasing by now, skip next configurations
100 best_columns = columns;
108 rows = ceil(item_count/columns);
112 return eX * best_rows + eY * best_columns;
114 return eX * best_columns + eY * best_rows;
123 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
124 void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
126 TC(bool, vertical); TC(int, drawflag);
127 if(!length_ratio || !theAlpha)
133 if(length_ratio < -1)
136 else if(length_ratio < 0)
140 vector width, height;
142 pic = strcat(hud_skin_path, "/", pic, "_vertical");
143 if(precache_pic(pic) == "") {
144 pic = "gfx/hud/default/progressbar_vertical";
147 if (baralign == 1) // bottom align
148 theOrigin.y += (1 - length_ratio) * theSize.y;
149 else if (baralign == 2) // center align
150 theOrigin.y += 0.5 * (1 - length_ratio) * theSize.y;
151 else if (baralign == 3) // center align, positive values down, negative up
154 if (length_ratio > 0)
155 theOrigin.y += theSize.y;
158 theOrigin.y += (1 + length_ratio) * theSize.y;
159 length_ratio = -length_ratio;
162 theSize.y *= length_ratio;
165 width = eX * theSize.x;
166 height = eY * theSize.y;
167 if(theSize.y <= theSize.x * 2)
169 // button not high enough
170 // draw just upper and lower part then
171 square = eY * theSize.y * 0.5;
172 bH = eY * (0.25 * theSize.y / (theSize.x * 2));
173 drawsubpic(theOrigin, square + width, pic, '0 0 0', eX + bH, theColor, theAlpha, drawflag);
174 drawsubpic(theOrigin + square, square + width, pic, eY - bH, eX + bH, theColor, theAlpha, drawflag);
178 square = eY * theSize.x;
179 drawsubpic(theOrigin, width + square, pic, '0 0 0', '1 0.25 0', theColor, theAlpha, drawflag);
180 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0 0.25 0', '1 0.5 0', theColor, theAlpha, drawflag);
181 drawsubpic(theOrigin + height - square, width + square, pic, '0 0.75 0', '1 0.25 0', theColor, theAlpha, drawflag);
184 pic = strcat(hud_skin_path, "/", pic);
185 if(precache_pic(pic) == "") {
186 pic = "gfx/hud/default/progressbar";
189 if (baralign == 1) // right align
190 theOrigin.x += (1 - length_ratio) * theSize.x;
191 else if (baralign == 2) // center align
192 theOrigin.x += 0.5 * (1 - length_ratio) * theSize.x;
193 else if (baralign == 3) // center align, positive values on the right, negative on the left
196 if (length_ratio > 0)
197 theOrigin.x += theSize.x;
200 theOrigin.x += (1 + length_ratio) * theSize.x;
201 length_ratio = -length_ratio;
204 theSize.x *= length_ratio;
207 width = eX * theSize.x;
208 height = eY * theSize.y;
209 if(theSize.x <= theSize.y * 2)
211 // button not wide enough
212 // draw just left and right part then
213 square = eX * theSize.x * 0.5;
214 bW = eX * (0.25 * theSize.x / (theSize.y * 2));
215 drawsubpic(theOrigin, square + height, pic, '0 0 0', eY + bW, theColor, theAlpha, drawflag);
216 drawsubpic(theOrigin + square, square + height, pic, eX - bW, eY + bW, theColor, theAlpha, drawflag);
220 square = eX * theSize.y;
221 drawsubpic(theOrigin, height + square, pic, '0 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
222 drawsubpic(theOrigin + square, theSize - 2 * square, pic, '0.25 0 0', '0.5 1 0', theColor, theAlpha, drawflag);
223 drawsubpic(theOrigin + width - square, height + square, pic, '0.75 0 0', '0.25 1 0', theColor, theAlpha, drawflag);
228 void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theAlpha, int drawflag)
235 pic = strcat(hud_skin_path, "/num_leading");
236 if(precache_pic(pic) == "") {
237 pic = "gfx/hud/default/num_leading";
240 drawsubpic(pos, eX * min(mySize.x * 0.5, mySize.y) + eY * mySize.y, pic, '0 0 0', '0.25 1 0', color, theAlpha, drawflag);
241 if(mySize.x/mySize.y > 2)
242 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);
243 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);
246 void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha, float fadelerp)
248 TC(bool, vertical); TC(int, icon_right_align);
249 vector newPos = '0 0 0', newSize = '0 0 0';
250 vector picpos, numpos;
254 if(mySize.y/mySize.x > 2)
256 newSize.y = 2 * mySize.x;
257 newSize.x = mySize.x;
259 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
264 newSize.x = 1/2 * mySize.y;
265 newSize.y = mySize.y;
267 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
274 picpos = newPos + eY * newSize.x;
279 numpos = newPos + eY * newSize.x;
283 drawpic_aspect_skin(picpos, icon, newSize, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
284 // make number smaller than icon, it looks better
285 // reduce only y to draw numbers with different number of digits with the same y size
286 numpos.y += newSize.y * ((1 - 0.7) / 2);
288 drawstring_aspect(numpos, ftos(x), newSize, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL);
292 if(mySize.x/mySize.y > 3)
294 newSize.x = 3 * mySize.y;
295 newSize.y = mySize.y;
297 newPos.x = myPos.x + (mySize.x - newSize.x) / 2;
302 newSize.y = 1/3 * mySize.x;
303 newSize.x = mySize.x;
305 newPos.y = myPos.y + (mySize.y - newSize.y) / 2;
309 if(icon_right_align) // right align
312 picpos = newPos + eX * 2 * newSize.y;
316 numpos = newPos + eX * newSize.y;
320 // NOTE: newSize_x is always equal to 3 * mySize_y so we can use
321 // '2 1 0' * newSize_y instead of eX * (2/3) * newSize_x + eY * newSize_y
322 drawstring_aspect_expanding(numpos, ftos(x), '2 1 0' * newSize.y, color, panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
323 drawpic_aspect_skin_expanding(picpos, icon, '1 1 0' * newSize.y, '1 1 1', panel_fg_alpha * theAlpha, DRAWFLAG_NORMAL, fadelerp);
326 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, bool vertical, int icon_right_align, vector color, float theAlpha)
328 TC(bool, vertical); TC(int, icon_right_align);
329 DrawNumIcon_expanding(myPos, mySize, x, icon, vertical, icon_right_align, color, theAlpha, 0);
340 void CSQC_BUMBLE_GUN_HUD();
344 if(autocvar__hud_configure) return;
345 if(intermission == 2) return;
347 if(hud == HUD_BUMBLEBEE_GUN)
348 CSQC_BUMBLE_GUN_HUD();
350 Vehicle info = Vehicles_from(hud);
355 bool HUD_Panel_CheckFlags(int showflags)
358 if ( HUD_Minigame_Showpanels() )
359 return showflags & PANEL_SHOW_MINIGAME;
360 if(intermission == 2)
361 return showflags & PANEL_SHOW_MAPVOTE;
362 return showflags & PANEL_SHOW_MAINGAME;
365 void HUD_Panel_Draw(entity panent)
368 if(autocvar__hud_configure)
370 if(panel.panel_configflags & PANEL_CONFIG_MAIN)
373 else if(HUD_Panel_CheckFlags(panel.panel_showflags))
379 // reset gametype specific icons
380 if(gametype == MAPINFO_TYPE_CTF)
387 // global hud theAlpha fade
388 if(menu_enabled == 1)
391 hud_fade_alpha = (1 - autocvar__menu_alpha);
393 if(scoreboard_fade_alpha)
394 hud_fade_alpha = (1 - scoreboard_fade_alpha);
396 HUD_Configure_Frame();
398 // panels that we want to be active together with the scoreboard
399 // they must fade only when the menu does
400 if(scoreboard_fade_alpha == 1)
402 HUD_Panel_Draw(HUD_PANEL(CENTERPRINT));
406 if(!autocvar__hud_configure && !hud_fade_alpha)
409 HUD_Panel_Draw(HUD_PANEL(VOTE));
415 if (hud_skin_prev != autocvar_hud_skin)
418 strunzone(hud_skin_path);
419 hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin));
421 strunzone(hud_skin_prev);
422 hud_skin_prev = strzone(autocvar_hud_skin);
426 if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
430 float hud_dock_color_team = autocvar_hud_dock_color_team;
431 if((teamplay) && hud_dock_color_team) {
432 if(autocvar__hud_configure && myteam == NUM_SPECTATOR)
433 color = '1 0 0' * hud_dock_color_team;
435 color = myteamcolors * hud_dock_color_team;
437 else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
438 color = '1 0 0' * hud_dock_color_team;
442 string hud_dock_color = autocvar_hud_dock_color;
443 if(hud_dock_color == "shirt") {
444 f = stof(getplayerkeyvalue(current_player, "colors"));
445 color = colormapPaletteColor(floor(f / 16), 0);
447 else if(hud_dock_color == "pants") {
448 f = stof(getplayerkeyvalue(current_player, "colors"));
449 color = colormapPaletteColor(f % 16, 1);
452 color = stov(hud_dock_color);
456 pic = strcat(hud_skin_path, "/", autocvar_hud_dock);
457 if(precache_pic(pic) == "") {
458 pic = strcat(hud_skin_path, "/dock_medium");
459 if(precache_pic(pic) == "") {
460 pic = "gfx/hud/default/dock_medium";
463 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...
466 // cache the panel order into the panel_order array
467 if(autocvar__hud_panelorder != hud_panelorder_prev) {
468 for(i = 0; i < hud_panels_COUNT; ++i)
472 bool warning = false;
473 int argc = tokenize_console(autocvar__hud_panelorder);
474 if (argc > hud_panels_COUNT)
476 //first detect wrong/missing panel numbers
477 for(i = 0; i < hud_panels_COUNT; ++i) {
478 p_num = stoi(argv(i));
479 if (p_num >= 0 && p_num < hud_panels_COUNT) { //correct panel number?
480 if (panel_order[p_num] == -1) //found for the first time?
481 s = strcat(s, ftos(p_num), " ");
482 panel_order[p_num] = 1; //mark as found
487 for(i = 0; i < hud_panels_COUNT; ++i) {
488 if (panel_order[i] == -1) {
490 s = strcat(s, ftos(i), " "); //add missing panel number
494 LOG_TRACE("Automatically fixed wrong/missing panel numbers in _hud_panelorder\n");
496 cvar_set("_hud_panelorder", s);
497 if(hud_panelorder_prev)
498 strunzone(hud_panelorder_prev);
499 hud_panelorder_prev = strzone(s);
501 //now properly set panel_order
503 for(i = 0; i < hud_panels_COUNT; ++i) {
504 panel_order[i] = stof(argv(i));
508 hud_draw_maximized = 0;
509 // draw panels in the order specified by panel_order array
510 for(i = hud_panels_COUNT - 1; i >= 0; --i)
511 HUD_Panel_Draw(hud_panels_from(panel_order[i]));
515 hud_draw_maximized = 1; // panels that may be maximized must check this var
516 // draw maximized panels on top
517 if(hud_panel_radar_maximized)
518 HUD_Panel_Draw(HUD_PANEL(RADAR));
519 if(autocvar__con_chat_maximized)
520 HUD_Panel_Draw(HUD_PANEL(CHAT));
521 if(hud_panel_quickmenu)
522 HUD_Panel_Draw(HUD_PANEL(QUICKMENU));
524 if (scoreboard_active || intermission == 2)
527 HUD_Configure_PostDraw();
529 hud_configure_prev = autocvar__hud_configure;