1 #define HUD_Write(s) fputs(fh, s)
2 // q: quoted, n: not quoted
3 #define HUD_Write_Cvar_n(cvar) HUD_Write(strcat("seta ", cvar, " ", cvar_string(cvar), "\n"))
4 #define HUD_Write_Cvar_q(cvar) HUD_Write(strcat("seta ", cvar, " \"", cvar_string(cvar), "\"\n"))
5 #define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel_name, cvar_suf))
6 #define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel_name, cvar_suf))
8 void HUD_Panel_ExportCfg(string cfgname)
11 string filename = strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg");
12 fh = fopen(filename, FILE_WRITE);
15 HUD_Write_Cvar_q("hud_skin");
16 HUD_Write_Cvar_q("hud_panel_bg");
17 HUD_Write_Cvar_q("hud_panel_bg_color");
18 HUD_Write_Cvar_q("hud_panel_bg_color_team");
19 HUD_Write_Cvar_q("hud_panel_bg_alpha");
20 HUD_Write_Cvar_q("hud_panel_bg_border");
21 HUD_Write_Cvar_q("hud_panel_bg_padding");
22 HUD_Write_Cvar_q("hud_panel_fg_alpha");
25 HUD_Write_Cvar_q("hud_dock");
26 HUD_Write_Cvar_q("hud_dock_color");
27 HUD_Write_Cvar_q("hud_dock_color_team");
28 HUD_Write_Cvar_q("hud_dock_alpha");
31 HUD_Write_Cvar_q("hud_progressbar_alpha");
32 HUD_Write_Cvar_q("hud_progressbar_strength_color");
33 HUD_Write_Cvar_q("hud_progressbar_shield_color");
34 HUD_Write_Cvar_q("hud_progressbar_health_color");
35 HUD_Write_Cvar_q("hud_progressbar_armor_color");
36 HUD_Write_Cvar_q("hud_progressbar_fuel_color");
37 HUD_Write_Cvar_q("hud_progressbar_nexball_color");
40 HUD_Write_Cvar_q("_hud_panelorder");
43 HUD_Write_Cvar_q("hud_configure_grid");
44 HUD_Write_Cvar_q("hud_configure_grid_xsize");
45 HUD_Write_Cvar_q("hud_configure_grid_ysize");
48 // common cvars for all panels
50 for (i = 0; i < HUD_PANEL_NUM; ++i)
54 HUD_Write_PanelCvar_n("");
55 HUD_Write_PanelCvar_q("_pos");
56 HUD_Write_PanelCvar_q("_size");
57 HUD_Write_PanelCvar_q("_bg");
58 HUD_Write_PanelCvar_q("_bg_color");
59 HUD_Write_PanelCvar_q("_bg_color_team");
60 HUD_Write_PanelCvar_q("_bg_alpha");
61 HUD_Write_PanelCvar_q("_bg_border");
62 HUD_Write_PanelCvar_q("_bg_padding");
64 case HUD_PANEL_WEAPONS:
65 HUD_Write_PanelCvar_q("_accuracy");
66 HUD_Write_PanelCvar_q("_label");
67 HUD_Write_PanelCvar_q("_complainbubble");
68 HUD_Write_PanelCvar_q("_complainbubble_padding");
69 HUD_Write_PanelCvar_q("_complainbubble_time");
70 HUD_Write_PanelCvar_q("_complainbubble_fadetime");
71 HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
72 HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
73 HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
74 HUD_Write_PanelCvar_q("_ammo");
75 HUD_Write_PanelCvar_q("_ammo_color");
76 HUD_Write_PanelCvar_q("_ammo_alpha");
77 HUD_Write_PanelCvar_q("_aspect");
78 HUD_Write_PanelCvar_q("_timeout");
79 HUD_Write_PanelCvar_q("_timeout_effect");
80 HUD_Write_PanelCvar_q("_onlyowned");
83 HUD_Write_PanelCvar_q("_onlycurrent");
84 HUD_Write_PanelCvar_q("_iconalign");
85 HUD_Write_PanelCvar_q("_progressbar");
86 HUD_Write_PanelCvar_q("_progressbar_name");
87 HUD_Write_PanelCvar_q("_progressbar_xoffset");
88 HUD_Write_PanelCvar_q("_text");
90 case HUD_PANEL_POWERUPS:
91 HUD_Write_PanelCvar_q("_flip");
92 HUD_Write_PanelCvar_q("_iconalign");
93 HUD_Write_PanelCvar_q("_baralign");
94 HUD_Write_PanelCvar_q("_progressbar");
95 HUD_Write_PanelCvar_q("_progressbar_strength");
96 HUD_Write_PanelCvar_q("_progressbar_shield");
98 case HUD_PANEL_HEALTHARMOR:
99 HUD_Write_PanelCvar_q("_flip");
100 HUD_Write_PanelCvar_q("_iconalign");
101 HUD_Write_PanelCvar_q("_baralign");
102 HUD_Write_PanelCvar_q("_progressbar");
103 HUD_Write_PanelCvar_q("_progressbar_health");
104 HUD_Write_PanelCvar_q("_progressbar_armor");
105 HUD_Write_PanelCvar_q("_progressbar_gfx");
106 HUD_Write_PanelCvar_q("_progressbar_gfx_smooth");
107 HUD_Write_PanelCvar_q("_text");
109 case HUD_PANEL_NOTIFY:
110 HUD_Write_PanelCvar_q("_flip");
111 HUD_Write_PanelCvar_q("_fontsize");
112 HUD_Write_PanelCvar_q("_print");
113 HUD_Write_PanelCvar_q("_time");
114 HUD_Write_PanelCvar_q("_fadetime");
116 case HUD_PANEL_TIMER:
117 HUD_Write_PanelCvar_q("_increment");
119 case HUD_PANEL_RADAR:
120 HUD_Write_PanelCvar_q("_foreground_alpha");
121 HUD_Write_PanelCvar_q("_rotation");
122 HUD_Write_PanelCvar_q("_zoommode");
123 HUD_Write_PanelCvar_q("_scale");
124 HUD_Write_PanelCvar_q("_maximized_scale");
125 HUD_Write_PanelCvar_q("_maximized_size");
127 case HUD_PANEL_SCORE:
128 HUD_Write_PanelCvar_q("_rankings");
131 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
133 case HUD_PANEL_MODICONS:
134 HUD_Write_PanelCvar_q("_dom_layout");
136 case HUD_PANEL_PRESSEDKEYS:
137 HUD_Write_PanelCvar_q("_aspect");
139 case HUD_PANEL_ENGINEINFO:
140 HUD_Write_PanelCvar_q("_framecounter_time");
141 HUD_Write_PanelCvar_q("_framecounter_decimals");
143 case HUD_PANEL_INFOMESSAGES:
144 HUD_Write_PanelCvar_q("_flip");
146 case HUD_PANEL_PHYSICS:
147 HUD_Write_PanelCvar_q("_speed_unit");
148 HUD_Write_PanelCvar_q("_speed_unit_show");
149 HUD_Write_PanelCvar_q("_speed_max");
150 HUD_Write_PanelCvar_q("_speed_vertical");
151 HUD_Write_PanelCvar_q("_topspeed");
152 HUD_Write_PanelCvar_q("_topspeed_time");
153 HUD_Write_PanelCvar_q("_acceleration_max");
154 HUD_Write_PanelCvar_q("_acceleration_vertical");
155 HUD_Write_PanelCvar_q("_flip");
156 HUD_Write_PanelCvar_q("_baralign");
157 HUD_Write_PanelCvar_q("_progressbar");
158 HUD_Write_PanelCvar_q("_acceleration_mode");
160 case HUD_PANEL_CENTERPRINT:
161 HUD_Write_PanelCvar_q("_align");
162 HUD_Write_PanelCvar_q("_flip");
163 HUD_Write_PanelCvar_q("_fontscale");
164 HUD_Write_PanelCvar_q("_time");
165 HUD_Write_PanelCvar_q("_fade_in");
166 HUD_Write_PanelCvar_q("_fade_out");
167 HUD_Write_PanelCvar_q("_fade_subsequent");
168 HUD_Write_PanelCvar_q("_fade_subsequent_passone");
169 HUD_Write_PanelCvar_q("_fade_subsequent_passone_minalpha");
170 HUD_Write_PanelCvar_q("_fade_subsequent_passtwo");
171 HUD_Write_PanelCvar_q("_fade_subsequent_passtwo_minalpha");
172 HUD_Write_PanelCvar_q("_fade_minfontsize");
177 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
179 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
183 print(sprintf(_("^1Couldn't write to %s\n"), filename));
186 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
187 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
190 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
194 for (i = 0; i < HUD_PANEL_NUM; ++i) {
195 if(i == highlightedPanel || !panel_enabled)
198 HUD_Panel_UpdatePosSizeForId(i);
200 panel_pos -= '1 1 0' * panel_bg_border;
201 panel_size += '2 2 0' * panel_bg_border;
203 if(myPos_y + mySize_y < panel_pos_y)
205 if(myPos_y > panel_pos_y + panel_size_y)
208 if(myPos_x + mySize_x < panel_pos_x)
210 if(myPos_x > panel_pos_x + panel_size_x)
213 // OK, there IS a collision.
215 myCenter_x = myPos_x + 0.5 * mySize_x;
216 myCenter_y = myPos_y + 0.5 * mySize_y;
218 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
219 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
221 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
223 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
224 myTarget_x = panel_pos_x - mySize_x;
225 else // push it upwards
226 myTarget_y = panel_pos_y - mySize_y;
228 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
230 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
231 myTarget_x = panel_pos_x + panel_size_x;
232 else // push it upwards
233 myTarget_y = panel_pos_y - mySize_y;
235 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
237 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
238 myTarget_x = panel_pos_x - mySize_x;
239 else // push it downwards
240 myTarget_y = panel_pos_y + panel_size_y;
242 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
244 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
245 myTarget_x = panel_pos_x + panel_size_x;
246 else // push it downwards
247 myTarget_y = panel_pos_y + panel_size_y;
249 //if(cvar("hud_configure_checkcollisions_debug"))
250 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
256 void HUD_Panel_SetPos(vector pos)
258 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
262 //if(cvar("hud_configure_checkcollisions_debug"))
263 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
265 if(autocvar_hud_configure_grid)
267 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
268 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
271 if(hud_configure_checkcollisions)
272 pos = HUD_Panel_CheckMove(pos, mySize);
274 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
275 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
278 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
280 HUD_Panel_GetName(highlightedPanel);
281 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
284 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
285 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
290 float dist_x, dist_y;
292 ratio = mySize_x/mySize_y;
294 for (i = 0; i < HUD_PANEL_NUM; ++i) {
295 if(i == highlightedPanel || !panel_enabled)
298 HUD_Panel_UpdatePosSizeForId(i);
300 panel_pos -= '1 1 0' * panel_bg_border;
301 panel_size += '2 2 0' * panel_bg_border;
303 targEndPos = panel_pos + panel_size;
305 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
306 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
309 if (resizeCorner == 1)
311 // check if this panel is on our way
312 if (resizeorigin_x <= panel_pos_x)
314 if (resizeorigin_y <= panel_pos_y)
316 if (targEndPos_x <= resizeorigin_x - mySize_x)
318 if (targEndPos_y <= resizeorigin_y - mySize_y)
321 // there is a collision:
322 // detect which side of the panel we are facing is actually limiting the resizing
323 // (which side the resize direction finds for first) and reduce the size up to there
325 // dist is the distance between resizeorigin and the "analogous" point of the panel
326 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
327 dist_x = resizeorigin_x - targEndPos_x;
328 dist_y = resizeorigin_y - targEndPos_y;
329 if (dist_y <= 0 || dist_x / dist_y > ratio)
330 mySize_x = min(mySize_x, dist_x);
332 mySize_y = min(mySize_y, dist_y);
334 else if (resizeCorner == 2)
336 if (resizeorigin_x >= targEndPos_x)
338 if (resizeorigin_y <= panel_pos_y)
340 if (panel_pos_x >= resizeorigin_x + mySize_x)
342 if (targEndPos_y <= resizeorigin_y - mySize_y)
345 dist_x = panel_pos_x - resizeorigin_x;
346 dist_y = resizeorigin_y - targEndPos_y;
347 if (dist_y <= 0 || dist_x / dist_y > ratio)
348 mySize_x = min(mySize_x, dist_x);
350 mySize_y = min(mySize_y, dist_y);
352 else if (resizeCorner == 3)
354 if (resizeorigin_x <= panel_pos_x)
356 if (resizeorigin_y >= targEndPos_y)
358 if (targEndPos_x <= resizeorigin_x - mySize_x)
360 if (panel_pos_y >= resizeorigin_y + mySize_y)
363 dist_x = resizeorigin_x - targEndPos_x;
364 dist_y = panel_pos_y - resizeorigin_y;
365 if (dist_y <= 0 || dist_x / dist_y > ratio)
366 mySize_x = min(mySize_x, dist_x);
368 mySize_y = min(mySize_y, dist_y);
370 else if (resizeCorner == 4)
372 if (resizeorigin_x >= targEndPos_x)
374 if (resizeorigin_y >= targEndPos_y)
376 if (panel_pos_x >= resizeorigin_x + mySize_x)
378 if (panel_pos_y >= resizeorigin_y + mySize_y)
381 dist_x = panel_pos_x - resizeorigin_x;
382 dist_y = panel_pos_y - resizeorigin_y;
383 if (dist_y <= 0 || dist_x / dist_y > ratio)
384 mySize_x = min(mySize_x, dist_x);
386 mySize_y = min(mySize_y, dist_y);
388 //if(cvar("hud_configure_checkcollisions_debug"))
389 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
395 void HUD_Panel_SetPosSize(vector mySize)
397 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
399 resizeorigin = panel_click_resizeorigin;
402 // minimum panel size cap
403 mySize_x = max(0.025 * vid_conwidth, mySize_x);
404 mySize_y = max(0.025 * vid_conheight, mySize_y);
406 if(highlightedPanel == HUD_PANEL_CHAT) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small.
408 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
409 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
412 // collision testing|
413 // -----------------+
415 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
416 if(resizeCorner == 1) {
417 myPos_x = resizeorigin_x - mySize_x;
418 myPos_y = resizeorigin_y - mySize_y;
419 } else if(resizeCorner == 2) {
420 myPos_x = resizeorigin_x;
421 myPos_y = resizeorigin_y - mySize_y;
422 } else if(resizeCorner == 3) {
423 myPos_x = resizeorigin_x - mySize_x;
424 myPos_y = resizeorigin_y;
425 } else { // resizeCorner == 4
426 myPos_x = resizeorigin_x;
427 myPos_y = resizeorigin_y;
430 // left/top screen edges
432 mySize_x = mySize_x + myPos_x;
434 mySize_y = mySize_y + myPos_y;
436 // bottom/right screen edges
437 if(myPos_x + mySize_x > vid_conwidth)
438 mySize_x = vid_conwidth - myPos_x;
439 if(myPos_y + mySize_y > vid_conheight)
440 mySize_y = vid_conheight - myPos_y;
442 //if(cvar("hud_configure_checkcollisions_debug"))
443 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
445 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
446 if(autocvar_hud_configure_grid)
448 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
449 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
452 if(hud_configure_checkcollisions)
453 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
455 // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then)
456 mySize_x = max(0.025 * vid_conwidth, mySize_x);
457 mySize_y = max(0.025 * vid_conheight, mySize_y);
459 // do another pos check, as size might have changed by now
460 if(resizeCorner == 1) {
461 myPos_x = resizeorigin_x - mySize_x;
462 myPos_y = resizeorigin_y - mySize_y;
463 } else if(resizeCorner == 2) {
464 myPos_x = resizeorigin_x;
465 myPos_y = resizeorigin_y - mySize_y;
466 } else if(resizeCorner == 3) {
467 myPos_x = resizeorigin_x - mySize_x;
468 myPos_y = resizeorigin_y;
469 } else { // resizeCorner == 4
470 myPos_x = resizeorigin_x;
471 myPos_y = resizeorigin_y;
474 //if(cvar("hud_configure_checkcollisions_debug"))
475 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
477 HUD_Panel_GetName(highlightedPanel);
479 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
480 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
482 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
483 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
486 float pressed_key_time;
487 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
488 void HUD_Panel_Arrow_Action(float nPrimary)
490 if (highlightedPanel == -1)
493 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
496 if(autocvar_hud_configure_grid)
498 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
500 if (hudShiftState & S_SHIFT)
501 step = hud_configure_realGridSize_y;
503 step = 2 * hud_configure_realGridSize_y;
507 if (hudShiftState & S_SHIFT)
508 step = hud_configure_realGridSize_x;
510 step = 2 * hud_configure_realGridSize_x;
515 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
516 step = vid_conheight;
519 if (hudShiftState & S_SHIFT)
520 step = (step / 256); // more precision
522 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
525 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
527 highlightedPanel_initial_pos = panel_pos;
528 highlightedPanel_initial_size = panel_size;
530 if (hudShiftState & S_ALT) // resize
532 highlightedAction = 1;
533 if(nPrimary == K_UPARROW)
535 else if(nPrimary == K_RIGHTARROW)
537 else if(nPrimary == K_LEFTARROW)
539 else // if(nPrimary == K_DOWNARROW)
542 // ctrl+arrow reduces the size, instead of increasing it
543 // Note that ctrl disables collisions check too, but it's fine
544 // since we don't collide with anything reducing the size
545 if (hudShiftState & S_CTRL) {
547 resizeCorner = 5 - resizeCorner;
552 panel_click_resizeorigin = panel_pos;
553 if(resizeCorner == 1) {
554 panel_click_resizeorigin += mySize;
556 } else if(resizeCorner == 2) {
557 panel_click_resizeorigin_y += mySize_y;
559 } else if(resizeCorner == 3) {
560 panel_click_resizeorigin_x += mySize_x;
562 } else { // resizeCorner == 4
565 HUD_Panel_SetPosSize(mySize);
569 highlightedAction = 2;
572 if(nPrimary == K_UPARROW)
574 else if(nPrimary == K_DOWNARROW)
576 else if(nPrimary == K_LEFTARROW)
578 else // if(nPrimary == K_RIGHTARROW)
581 HUD_Panel_SetPos(pos);
584 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
586 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
589 panel_pos_backup = highlightedPanel_initial_pos;
590 panel_size_backup = highlightedPanel_initial_size;
591 highlightedPanel_backup = highlightedPanel;
595 const float S_MOUSE1 = 1;
596 const float S_MOUSE2 = 2;
597 const float S_MOUSE3 = 4;
599 float prevMouseClicked; // previous state
600 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
601 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
603 void HUD_Panel_EnableMenu();
604 float tab_panels[HUD_PANEL_NUM];
605 float tab_panel, tab_backward;
606 vector tab_panel_pos;
607 void HUD_Panel_FirstInDrawQ(float id);
608 void reset_tab_panels()
611 for(i = 0; i < HUD_PANEL_NUM; ++i)
614 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
618 // we only care for keyboard events
619 if(bInputType != 0 && bInputType != 1)
622 if(!autocvar__hud_configure)
625 // allow console bind to work
628 con_keys = findkeysforcommand("toggleconsole");
629 keys = tokenize(con_keys);
631 float hit_con_bind, i;
632 for (i = 0; i < keys; ++i)
634 if(nPrimary == stof(argv(i)))
638 if(bInputType == 0) {
639 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
640 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
641 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
643 else if(bInputType == 1) {
644 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
645 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
646 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
649 if(nPrimary == K_CTRL)
651 if (bInputType == 1) //ctrl has been released
655 //switch to selected panel
656 highlightedPanel = tab_panel;
657 highlightedAction = 0;
658 HUD_Panel_FirstInDrawQ(highlightedPanel);
665 if(nPrimary == K_MOUSE1)
667 if(bInputType == 0) // key pressed
668 mouseClicked |= S_MOUSE1;
669 else if(bInputType == 1) // key released
670 mouseClicked -= (mouseClicked & S_MOUSE1);
672 else if(nPrimary == K_MOUSE2)
674 if(bInputType == 0) // key pressed
675 mouseClicked |= S_MOUSE2;
676 else if(bInputType == 1) // key released
677 mouseClicked -= (mouseClicked & S_MOUSE2);
679 else if(nPrimary == K_ESCAPE)
684 menu_enabled_time = time;
685 localcmd("menu_showhudexit\n");
687 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
692 cvar_set("_hud_configure", "0");
694 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
696 if (bInputType == 1 || mouseClicked)
699 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
700 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
701 //(it should only after every other panel of the hud)
702 //It's a minor bug anyway, we can live with it
704 float starting_panel;
705 float old_tab_panel = tab_panel;
706 if (tab_panel == -1) //first press of TAB
708 if (highlightedPanel != -1)
709 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
712 starting_panel = highlightedPanel; //can be -1, it means no starting panel
713 tab_panel_pos = panel_pos; //to compute level
717 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
719 starting_panel = tab_panel;
721 tab_backward = (hudShiftState & S_SHIFT);
723 float k, level, start_pos_x;
724 vector candidate_pos;
725 const float LEVELS_NUM = 4;
726 float level_height = vid_conheight / LEVELS_NUM;
728 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
729 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
730 start_pos_x = tab_panel_pos_x;
735 for(i = 0; i < HUD_PANEL_NUM; ++i)
737 if (i == tab_panels[i] || i == starting_panel)
739 HUD_Panel_UpdatePosSizeForId(i)
740 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
741 if ( ( !tab_backward && panel_pos_x >= start_pos_x && (panel_pos_x < candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y <= candidate_pos_y)) )
742 || ( tab_backward && panel_pos_x <= start_pos_x && (panel_pos_x > candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y >= candidate_pos_y)) ) )
745 tab_panel_pos = candidate_pos = panel_pos;
750 if (k == LEVELS_NUM) //tab_panel not found
753 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
758 starting_panel = old_tab_panel;
760 goto find_tab_panel; //u must find tab_panel!
764 level = mod(level + level_height, vid_conheight);
766 candidate_pos_x = vid_conwidth;
770 level = mod(level - level_height, vid_conheight);
771 start_pos_x = vid_conwidth;
776 tab_panels[tab_panel] = tab_panel;
778 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
780 if (bInputType == 1 || mouseClicked)
783 if (highlightedPanel != -1)
785 HUD_Panel_GetName(highlightedPanel);
786 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
789 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
791 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
793 if (bInputType == 1 || mouseClicked)
796 if (highlightedPanel != -1)
798 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
799 panel_size_copied = panel_size;
800 highlightedPanel_copied = highlightedPanel;
803 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
805 if (bInputType == 1 || mouseClicked)
808 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
811 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
813 // reduce size if it'd go beyond screen boundaries
814 vector tmp_size = panel_size_copied;
815 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
816 tmp_size_x = vid_conwidth - panel_pos_x;
817 if (panel_pos_y + panel_size_copied_y > vid_conheight)
818 tmp_size_y = vid_conheight - panel_pos_y;
820 if (panel_size == tmp_size)
824 panel_pos_backup = panel_pos;
825 panel_size_backup = panel_size;
826 highlightedPanel_backup = highlightedPanel;
828 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
829 HUD_Panel_GetName(highlightedPanel);
830 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
832 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
834 if (bInputType == 1 || mouseClicked)
836 //restore previous values
837 if (highlightedPanel_backup != -1)
839 HUD_Panel_GetName(highlightedPanel_backup);
840 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
841 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
842 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
843 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
844 highlightedPanel_backup = -1;
847 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
851 pressed_key_time = 0;
854 else if (pressed_key_time == 0)
855 pressed_key_time = time;
858 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
860 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
864 if (highlightedPanel != -1)
865 HUD_Panel_EnableMenu();
867 else if(hit_con_bind)
873 float HUD_Panel_Check_Mouse_Pos(float allow_move)
877 while(j < HUD_PANEL_NUM)
882 HUD_Panel_UpdatePosSizeForId(i);
884 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
887 if(allow_move && mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
891 // resize from topleft border
892 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
896 // resize from topright border
897 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
901 // resize from bottomleft border
902 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
906 // resize from bottomright border
907 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
915 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
916 void HUD_Panel_FirstInDrawQ(float id)
919 var float place = -1;
920 // find out where in the array our current id is, save into place
921 for(i = 0; i < HUD_PANEL_NUM; ++i)
923 if(panel_order[i] == id)
929 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
931 place = HUD_PANEL_NUM - 1;
933 // move all ids up by one step in the array until "place"
934 for(i = place; i > 0; --i)
936 panel_order[i] = panel_order[i-1];
938 // now save the new top id
941 // let's save them into the cvar by some strcat trickery
943 for(i = 0; i < HUD_PANEL_NUM; ++i)
945 s = strcat(s, ftos(panel_order[i]), " ");
947 cvar_set("_hud_panelorder", s);
948 if(hud_panelorder_prev)
949 strunzone(hud_panelorder_prev);
950 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
953 void HUD_Panel_Highlight(float allow_move)
957 while(j < HUD_PANEL_NUM)
962 HUD_Panel_UpdatePosSizeForId(i);
964 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
967 if(allow_move && mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
969 highlightedPanel = i;
970 HUD_Panel_FirstInDrawQ(i);
971 highlightedAction = 1;
972 panel_click_distance = mousepos - panel_pos;
975 // resize from topleft border
976 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
978 highlightedPanel = i;
979 HUD_Panel_FirstInDrawQ(i);
980 highlightedAction = 2;
982 panel_click_distance = mousepos - panel_pos;
983 panel_click_resizeorigin = panel_pos + panel_size;
986 // resize from topright border
987 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
989 highlightedPanel = i;
990 HUD_Panel_FirstInDrawQ(i);
991 highlightedAction = 2;
993 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
994 panel_click_distance_y = mousepos_y - panel_pos_y;
995 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
998 // resize from bottomleft border
999 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
1001 highlightedPanel = i;
1002 HUD_Panel_FirstInDrawQ(i);
1003 highlightedAction = 2;
1005 panel_click_distance_x = mousepos_x - panel_pos_x;
1006 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
1007 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
1010 // resize from bottomright border
1011 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
1013 highlightedPanel = i;
1014 HUD_Panel_FirstInDrawQ(i);
1015 highlightedAction = 2;
1017 panel_click_distance = panel_size - mousepos + panel_pos;
1018 panel_click_resizeorigin = panel_pos;
1022 highlightedPanel = -1;
1023 highlightedAction = 0;
1026 void HUD_Panel_EnableMenu()
1029 menu_enabled_time = time;
1030 HUD_Panel_GetName(highlightedPanel);
1031 localcmd("menu_showhudoptions ", panel_name, "\n");
1033 float mouse_over_panel;
1034 void HUD_Panel_Mouse()
1036 // TODO: needs better check... is there any float that contains the current state of the menu? _menu_alpha isn't apparently updated the frame the menu gets enabled
1037 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1041 print("menu_enabled: ", ftos(menu_enabled), "\n");
1042 print("Highlighted: ", ftos(highlightedPanel), "\n");
1043 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1046 // instantly hide the editor cursor if we open the HUDExit dialog
1047 // as hud_fade_alpha doesn't decrease to 0 in this case
1048 // TODO: find a way to fade the cursor out even in this case
1049 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1052 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1054 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1055 mousepos_y = bound(0, mousepos_y, vid_conheight);
1059 if(prevMouseClicked == 0)
1061 if (tab_panel != -1)
1063 //stop ctrl-tab selection
1067 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1068 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1069 if (highlightedPanel != -1)
1071 highlightedPanel_initial_pos = panel_pos;
1072 highlightedPanel_initial_size = panel_size;
1074 // doubleclick check
1075 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1077 mouseClicked = 0; // to prevent spam, I guess.
1078 HUD_Panel_EnableMenu();
1082 if (mouseClicked & S_MOUSE1)
1084 prevMouseClickedTime = time;
1085 prevMouseClickedPos = mousepos;
1087 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1091 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1093 if (highlightedPanel != -1)
1095 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1096 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1098 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1100 panel_pos_backup = highlightedPanel_initial_pos;
1101 panel_size_backup = highlightedPanel_initial_size;
1102 highlightedPanel_backup = highlightedPanel;
1105 // in case the clicked panel is inside another panel and we aren't
1106 // moving it, avoid the immediate "fix" of its position/size
1107 // (often unwanted and hateful) by disabling collisions check
1108 hud_configure_checkcollisions = false;
1111 if(highlightedAction == 1)
1112 HUD_Panel_SetPos(mousepos - panel_click_distance);
1113 else if(highlightedAction == 2)
1116 if(resizeCorner == 1) {
1117 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1118 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1119 } else if(resizeCorner == 2) {
1120 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1121 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1122 } else if(resizeCorner == 3) {
1123 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1124 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1125 } else { // resizeCorner == 4
1126 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1127 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1129 HUD_Panel_SetPosSize(mySize);
1134 if(menu_enabled == 2)
1135 mouse_over_panel = 0;
1137 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1138 if (mouse_over_panel && tab_panel == -1)
1139 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1141 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1142 const vector cursorsize = '32 32 0';
1144 if(!mouse_over_panel)
1145 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1146 else if(mouse_over_panel == 1)
1147 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1148 else if(mouse_over_panel == 2)
1149 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1151 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1153 prevMouseClicked = mouseClicked;
1156 const float hlBorderSize = 4;
1157 const string hlBorder = "gfx/hud/default/border_highlighted";
1158 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1159 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1161 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1162 drawpic_tiled(panel_pos - '1 1 0' * myBorder, hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1163 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * (panel_size_y + 2 * myBorder - hlBorderSize), hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1164 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize, hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1165 drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize + eX * (panel_size_x + 2 * myBorder - hlBorderSize), hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);