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");
124 case HUD_PANEL_SCORE:
125 HUD_Write_PanelCvar_q("_rankings");
128 HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
130 case HUD_PANEL_MODICONS:
131 HUD_Write_PanelCvar_q("_dom_layout");
133 case HUD_PANEL_PRESSEDKEYS:
134 HUD_Write_PanelCvar_q("_aspect");
136 case HUD_PANEL_ENGINEINFO:
137 HUD_Write_PanelCvar_q("_framecounter_time");
138 HUD_Write_PanelCvar_q("_framecounter_decimals");
140 case HUD_PANEL_INFOMESSAGES:
141 HUD_Write_PanelCvar_q("_flip");
143 case HUD_PANEL_PHYSICS:
144 HUD_Write_PanelCvar_q("_speed_unit");
145 HUD_Write_PanelCvar_q("_speed_unit_show");
146 HUD_Write_PanelCvar_q("_speed_max");
147 HUD_Write_PanelCvar_q("_speed_vertical");
148 HUD_Write_PanelCvar_q("_topspeed");
149 HUD_Write_PanelCvar_q("_topspeed_time");
150 HUD_Write_PanelCvar_q("_acceleration_max");
151 HUD_Write_PanelCvar_q("_acceleration_vertical");
152 HUD_Write_PanelCvar_q("_flip");
153 HUD_Write_PanelCvar_q("_baralign");
154 HUD_Write_PanelCvar_q("_progressbar");
155 HUD_Write_PanelCvar_q("_acceleration_mode");
157 case HUD_PANEL_CENTERPRINT:
158 HUD_Write_PanelCvar_q("_align");
159 HUD_Write_PanelCvar_q("_flip");
160 HUD_Write_PanelCvar_q("_fontscale");
161 HUD_Write_PanelCvar_q("_time");
162 HUD_Write_PanelCvar_q("_fadetime");
167 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
169 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
173 print(sprintf(_("^1Couldn't write to %s\n"), filename));
176 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
177 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
180 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
184 for (i = 0; i < HUD_PANEL_NUM; ++i) {
185 if(i == highlightedPanel || !panel_enabled)
188 HUD_Panel_UpdatePosSizeForId(i);
190 panel_pos -= '1 1 0' * panel_bg_border;
191 panel_size += '2 2 0' * panel_bg_border;
193 if(myPos_y + mySize_y < panel_pos_y)
195 if(myPos_y > panel_pos_y + panel_size_y)
198 if(myPos_x + mySize_x < panel_pos_x)
200 if(myPos_x > panel_pos_x + panel_size_x)
203 // OK, there IS a collision.
205 myCenter_x = myPos_x + 0.5 * mySize_x;
206 myCenter_y = myPos_y + 0.5 * mySize_y;
208 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
209 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
211 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
213 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
214 myTarget_x = panel_pos_x - mySize_x;
215 else // push it upwards
216 myTarget_y = panel_pos_y - mySize_y;
218 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
220 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
221 myTarget_x = panel_pos_x + panel_size_x;
222 else // push it upwards
223 myTarget_y = panel_pos_y - mySize_y;
225 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
227 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
228 myTarget_x = panel_pos_x - mySize_x;
229 else // push it downwards
230 myTarget_y = panel_pos_y + panel_size_y;
232 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
234 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
235 myTarget_x = panel_pos_x + panel_size_x;
236 else // push it downwards
237 myTarget_y = panel_pos_y + panel_size_y;
239 //if(cvar("hud_configure_checkcollisions_debug"))
240 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
246 void HUD_Panel_SetPos(vector pos)
248 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
252 //if(cvar("hud_configure_checkcollisions_debug"))
253 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
255 if(autocvar_hud_configure_grid)
257 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
258 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
261 if(hud_configure_checkcollisions)
262 pos = HUD_Panel_CheckMove(pos, mySize);
264 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
265 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
268 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
270 HUD_Panel_GetName(highlightedPanel);
271 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
274 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
275 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
280 float dist_x, dist_y;
282 ratio = mySize_x/mySize_y;
284 for (i = 0; i < HUD_PANEL_NUM; ++i) {
285 if(i == highlightedPanel || !panel_enabled)
288 HUD_Panel_UpdatePosSizeForId(i);
290 panel_pos -= '1 1 0' * panel_bg_border;
291 panel_size += '2 2 0' * panel_bg_border;
293 targEndPos = panel_pos + panel_size;
295 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
296 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
299 if (resizeCorner == 1)
301 // check if this panel is on our way
302 if (resizeorigin_x <= panel_pos_x)
304 if (resizeorigin_y <= panel_pos_y)
306 if (targEndPos_x <= resizeorigin_x - mySize_x)
308 if (targEndPos_y <= resizeorigin_y - mySize_y)
311 // there is a collision:
312 // detect which side of the panel we are facing is actually limiting the resizing
313 // (which side the resize direction finds for first) and reduce the size up to there
315 // dist is the distance between resizeorigin and the "analogous" point of the panel
316 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
317 dist_x = resizeorigin_x - targEndPos_x;
318 dist_y = resizeorigin_y - targEndPos_y;
319 if (dist_y <= 0 || dist_x / dist_y > ratio)
320 mySize_x = min(mySize_x, dist_x);
322 mySize_y = min(mySize_y, dist_y);
324 else if (resizeCorner == 2)
326 if (resizeorigin_x >= targEndPos_x)
328 if (resizeorigin_y <= panel_pos_y)
330 if (panel_pos_x >= resizeorigin_x + mySize_x)
332 if (targEndPos_y <= resizeorigin_y - mySize_y)
335 dist_x = panel_pos_x - resizeorigin_x;
336 dist_y = resizeorigin_y - targEndPos_y;
337 if (dist_y <= 0 || dist_x / dist_y > ratio)
338 mySize_x = min(mySize_x, dist_x);
340 mySize_y = min(mySize_y, dist_y);
342 else if (resizeCorner == 3)
344 if (resizeorigin_x <= panel_pos_x)
346 if (resizeorigin_y >= targEndPos_y)
348 if (targEndPos_x <= resizeorigin_x - mySize_x)
350 if (panel_pos_y >= resizeorigin_y + mySize_y)
353 dist_x = resizeorigin_x - targEndPos_x;
354 dist_y = panel_pos_y - resizeorigin_y;
355 if (dist_y <= 0 || dist_x / dist_y > ratio)
356 mySize_x = min(mySize_x, dist_x);
358 mySize_y = min(mySize_y, dist_y);
360 else if (resizeCorner == 4)
362 if (resizeorigin_x >= targEndPos_x)
364 if (resizeorigin_y >= targEndPos_y)
366 if (panel_pos_x >= resizeorigin_x + mySize_x)
368 if (panel_pos_y >= resizeorigin_y + mySize_y)
371 dist_x = panel_pos_x - resizeorigin_x;
372 dist_y = panel_pos_y - resizeorigin_y;
373 if (dist_y <= 0 || dist_x / dist_y > ratio)
374 mySize_x = min(mySize_x, dist_x);
376 mySize_y = min(mySize_y, dist_y);
378 //if(cvar("hud_configure_checkcollisions_debug"))
379 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
385 void HUD_Panel_SetPosSize(vector mySize)
387 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
389 resizeorigin = panel_click_resizeorigin;
392 // minimum panel size cap
393 mySize_x = max(0.025 * vid_conwidth, mySize_x);
394 mySize_y = max(0.025 * vid_conheight, mySize_y);
396 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.
398 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
399 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
402 // collision testing|
403 // -----------------+
405 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
406 if(resizeCorner == 1) {
407 myPos_x = resizeorigin_x - mySize_x;
408 myPos_y = resizeorigin_y - mySize_y;
409 } else if(resizeCorner == 2) {
410 myPos_x = resizeorigin_x;
411 myPos_y = resizeorigin_y - mySize_y;
412 } else if(resizeCorner == 3) {
413 myPos_x = resizeorigin_x - mySize_x;
414 myPos_y = resizeorigin_y;
415 } else { // resizeCorner == 4
416 myPos_x = resizeorigin_x;
417 myPos_y = resizeorigin_y;
420 // left/top screen edges
422 mySize_x = mySize_x + myPos_x;
424 mySize_y = mySize_y + myPos_y;
426 // bottom/right screen edges
427 if(myPos_x + mySize_x > vid_conwidth)
428 mySize_x = vid_conwidth - myPos_x;
429 if(myPos_y + mySize_y > vid_conheight)
430 mySize_y = vid_conheight - myPos_y;
432 //if(cvar("hud_configure_checkcollisions_debug"))
433 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
435 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
436 if(autocvar_hud_configure_grid)
438 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
439 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
442 if(hud_configure_checkcollisions)
443 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
445 // 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)
446 mySize_x = max(0.025 * vid_conwidth, mySize_x);
447 mySize_y = max(0.025 * vid_conheight, mySize_y);
449 // do another pos check, as size might have changed by now
450 if(resizeCorner == 1) {
451 myPos_x = resizeorigin_x - mySize_x;
452 myPos_y = resizeorigin_y - mySize_y;
453 } else if(resizeCorner == 2) {
454 myPos_x = resizeorigin_x;
455 myPos_y = resizeorigin_y - mySize_y;
456 } else if(resizeCorner == 3) {
457 myPos_x = resizeorigin_x - mySize_x;
458 myPos_y = resizeorigin_y;
459 } else { // resizeCorner == 4
460 myPos_x = resizeorigin_x;
461 myPos_y = resizeorigin_y;
464 //if(cvar("hud_configure_checkcollisions_debug"))
465 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
467 HUD_Panel_GetName(highlightedPanel);
469 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
470 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
472 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
473 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
476 float pressed_key_time;
477 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
478 void HUD_Panel_Arrow_Action(float nPrimary)
480 if (highlightedPanel == -1)
483 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
486 if(autocvar_hud_configure_grid)
488 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
490 if (hudShiftState & S_SHIFT)
491 step = hud_configure_realGridSize_y;
493 step = 2 * hud_configure_realGridSize_y;
497 if (hudShiftState & S_SHIFT)
498 step = hud_configure_realGridSize_x;
500 step = 2 * hud_configure_realGridSize_x;
505 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
506 step = vid_conheight;
509 if (hudShiftState & S_SHIFT)
510 step = (step / 256); // more precision
512 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
515 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
517 highlightedPanel_initial_pos = panel_pos;
518 highlightedPanel_initial_size = panel_size;
520 if (hudShiftState & S_ALT) // resize
522 highlightedAction = 1;
523 if(nPrimary == K_UPARROW)
525 else if(nPrimary == K_RIGHTARROW)
527 else if(nPrimary == K_LEFTARROW)
529 else // if(nPrimary == K_DOWNARROW)
532 // ctrl+arrow reduces the size, instead of increasing it
533 // Note that ctrl disables collisions check too, but it's fine
534 // since we don't collide with anything reducing the size
535 if (hudShiftState & S_CTRL) {
537 resizeCorner = 5 - resizeCorner;
542 panel_click_resizeorigin = panel_pos;
543 if(resizeCorner == 1) {
544 panel_click_resizeorigin += mySize;
546 } else if(resizeCorner == 2) {
547 panel_click_resizeorigin_y += mySize_y;
549 } else if(resizeCorner == 3) {
550 panel_click_resizeorigin_x += mySize_x;
552 } else { // resizeCorner == 4
555 HUD_Panel_SetPosSize(mySize);
559 highlightedAction = 2;
562 if(nPrimary == K_UPARROW)
564 else if(nPrimary == K_DOWNARROW)
566 else if(nPrimary == K_LEFTARROW)
568 else // if(nPrimary == K_RIGHTARROW)
571 HUD_Panel_SetPos(pos);
574 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
576 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
579 panel_pos_backup = highlightedPanel_initial_pos;
580 panel_size_backup = highlightedPanel_initial_size;
581 highlightedPanel_backup = highlightedPanel;
585 const float S_MOUSE1 = 1;
586 const float S_MOUSE2 = 2;
587 const float S_MOUSE3 = 4;
589 float prevMouseClicked; // previous state
590 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
591 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
593 void HUD_Panel_EnableMenu();
594 float tab_panels[HUD_PANEL_NUM];
595 float tab_panel, tab_backward;
596 vector tab_panel_pos;
597 void HUD_Panel_FirstInDrawQ(float id);
598 void reset_tab_panels()
601 for(i = 0; i < HUD_PANEL_NUM; ++i)
604 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
608 // we only care for keyboard events
609 if(bInputType != 0 && bInputType != 1)
612 if(!autocvar__hud_configure)
615 // allow console bind to work
618 con_keys = findkeysforcommand("toggleconsole");
619 keys = tokenize(con_keys);
621 float hit_con_bind, i;
622 for (i = 0; i < keys; ++i)
624 if(nPrimary == stof(argv(i)))
628 if(bInputType == 0) {
629 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
630 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
631 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
633 else if(bInputType == 1) {
634 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
635 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
636 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
639 if(nPrimary == K_CTRL)
641 if (bInputType == 1) //ctrl has been released
645 //switch to selected panel
646 highlightedPanel = tab_panel;
647 highlightedAction = 0;
648 HUD_Panel_FirstInDrawQ(highlightedPanel);
655 if(nPrimary == K_MOUSE1)
657 if(bInputType == 0) // key pressed
658 mouseClicked |= S_MOUSE1;
659 else if(bInputType == 1) // key released
660 mouseClicked -= (mouseClicked & S_MOUSE1);
662 else if(nPrimary == K_MOUSE2)
664 if(bInputType == 0) // key pressed
665 mouseClicked |= S_MOUSE2;
666 else if(bInputType == 1) // key released
667 mouseClicked -= (mouseClicked & S_MOUSE2);
669 else if(nPrimary == K_ESCAPE)
674 menu_enabled_time = time;
675 localcmd("menu_showhudexit\n");
677 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
682 cvar_set("_hud_configure", "0");
684 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
686 if (bInputType == 1 || mouseClicked)
689 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
690 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
691 //(it should only after every other panel of the hud)
692 //It's a minor bug anyway, we can live with it
694 float starting_panel;
695 float old_tab_panel = tab_panel;
696 if (tab_panel == -1) //first press of TAB
698 if (highlightedPanel != -1)
699 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
702 starting_panel = highlightedPanel; //can be -1, it means no starting panel
703 tab_panel_pos = panel_pos; //to compute level
707 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
709 starting_panel = tab_panel;
711 tab_backward = (hudShiftState & S_SHIFT);
713 float k, level, start_pos_x;
714 vector candidate_pos;
715 const float LEVELS_NUM = 4;
716 float level_height = vid_conheight / LEVELS_NUM;
718 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
719 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
720 start_pos_x = tab_panel_pos_x;
725 for(i = 0; i < HUD_PANEL_NUM; ++i)
727 if (i == tab_panels[i] || i == starting_panel)
729 HUD_Panel_UpdatePosSizeForId(i)
730 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
731 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)) )
732 || ( 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)) ) )
735 tab_panel_pos = candidate_pos = panel_pos;
740 if (k == LEVELS_NUM) //tab_panel not found
743 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
748 starting_panel = old_tab_panel;
750 goto find_tab_panel; //u must find tab_panel!
754 level = mod(level + level_height, vid_conheight);
756 candidate_pos_x = vid_conwidth;
760 level = mod(level - level_height, vid_conheight);
761 start_pos_x = vid_conwidth;
766 tab_panels[tab_panel] = tab_panel;
768 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
770 if (bInputType == 1 || mouseClicked)
773 if (highlightedPanel != -1)
775 HUD_Panel_GetName(highlightedPanel);
776 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
779 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
781 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
783 if (bInputType == 1 || mouseClicked)
786 if (highlightedPanel != -1)
788 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
789 panel_size_copied = panel_size;
790 highlightedPanel_copied = highlightedPanel;
793 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
795 if (bInputType == 1 || mouseClicked)
798 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
801 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
803 // reduce size if it'd go beyond screen boundaries
804 vector tmp_size = panel_size_copied;
805 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
806 tmp_size_x = vid_conwidth - panel_pos_x;
807 if (panel_pos_y + panel_size_copied_y > vid_conheight)
808 tmp_size_y = vid_conheight - panel_pos_y;
810 if (panel_size == tmp_size)
814 panel_pos_backup = panel_pos;
815 panel_size_backup = panel_size;
816 highlightedPanel_backup = highlightedPanel;
818 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
819 HUD_Panel_GetName(highlightedPanel);
820 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
822 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
824 if (bInputType == 1 || mouseClicked)
826 //restore previous values
827 if (highlightedPanel_backup != -1)
829 HUD_Panel_GetName(highlightedPanel_backup);
830 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
831 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
832 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
833 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
834 highlightedPanel_backup = -1;
837 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
841 pressed_key_time = 0;
844 else if (pressed_key_time == 0)
845 pressed_key_time = time;
848 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
850 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
854 if (highlightedPanel != -1)
855 HUD_Panel_EnableMenu();
857 else if(hit_con_bind)
863 float HUD_Panel_Check_Mouse_Pos(float allow_move)
867 while(j < HUD_PANEL_NUM)
872 HUD_Panel_UpdatePosSizeForId(i);
874 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
877 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)
881 // resize from topleft border
882 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)
886 // resize from topright border
887 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)
891 // resize from bottomleft border
892 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)
896 // resize from bottomright border
897 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)
905 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
906 void HUD_Panel_FirstInDrawQ(float id)
909 var float place = -1;
910 // find out where in the array our current id is, save into place
911 for(i = 0; i < HUD_PANEL_NUM; ++i)
913 if(panel_order[i] == id)
919 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
921 place = HUD_PANEL_NUM - 1;
923 // move all ids up by one step in the array until "place"
924 for(i = place; i > 0; --i)
926 panel_order[i] = panel_order[i-1];
928 // now save the new top id
931 // let's save them into the cvar by some strcat trickery
933 for(i = 0; i < HUD_PANEL_NUM; ++i)
935 s = strcat(s, ftos(panel_order[i]), " ");
937 cvar_set("_hud_panelorder", s);
938 if(hud_panelorder_prev)
939 strunzone(hud_panelorder_prev);
940 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
943 void HUD_Panel_Highlight(float allow_move)
947 while(j < HUD_PANEL_NUM)
952 HUD_Panel_UpdatePosSizeForId(i);
954 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
957 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)
959 highlightedPanel = i;
960 HUD_Panel_FirstInDrawQ(i);
961 highlightedAction = 1;
962 panel_click_distance = mousepos - panel_pos;
965 // resize from topleft border
966 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)
968 highlightedPanel = i;
969 HUD_Panel_FirstInDrawQ(i);
970 highlightedAction = 2;
972 panel_click_distance = mousepos - panel_pos;
973 panel_click_resizeorigin = panel_pos + panel_size;
976 // resize from topright border
977 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)
979 highlightedPanel = i;
980 HUD_Panel_FirstInDrawQ(i);
981 highlightedAction = 2;
983 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
984 panel_click_distance_y = mousepos_y - panel_pos_y;
985 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
988 // resize from bottomleft border
989 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)
991 highlightedPanel = i;
992 HUD_Panel_FirstInDrawQ(i);
993 highlightedAction = 2;
995 panel_click_distance_x = mousepos_x - panel_pos_x;
996 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
997 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
1000 // resize from bottomright border
1001 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)
1003 highlightedPanel = i;
1004 HUD_Panel_FirstInDrawQ(i);
1005 highlightedAction = 2;
1007 panel_click_distance = panel_size - mousepos + panel_pos;
1008 panel_click_resizeorigin = panel_pos;
1012 highlightedPanel = -1;
1013 highlightedAction = 0;
1016 void HUD_Panel_EnableMenu()
1019 menu_enabled_time = time;
1020 HUD_Panel_GetName(highlightedPanel);
1021 localcmd("menu_showhudoptions ", panel_name, "\n");
1023 float mouse_over_panel;
1024 void HUD_Panel_Mouse()
1026 // 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
1027 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1031 print("menu_enabled: ", ftos(menu_enabled), "\n");
1032 print("Highlighted: ", ftos(highlightedPanel), "\n");
1033 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1036 // instantly hide the editor cursor if we open the HUDExit dialog
1037 // as hud_fade_alpha doesn't decrease to 0 in this case
1038 // TODO: find a way to fade the cursor out even in this case
1039 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1042 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1044 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1045 mousepos_y = bound(0, mousepos_y, vid_conheight);
1049 if(prevMouseClicked == 0)
1051 if (tab_panel != -1)
1053 //stop ctrl-tab selection
1057 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1058 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1059 if (highlightedPanel != -1)
1061 highlightedPanel_initial_pos = panel_pos;
1062 highlightedPanel_initial_size = panel_size;
1064 // doubleclick check
1065 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1067 mouseClicked = 0; // to prevent spam, I guess.
1068 HUD_Panel_EnableMenu();
1072 if (mouseClicked & S_MOUSE1)
1074 prevMouseClickedTime = time;
1075 prevMouseClickedPos = mousepos;
1077 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1081 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1083 if (highlightedPanel != -1)
1085 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1086 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1088 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1090 panel_pos_backup = highlightedPanel_initial_pos;
1091 panel_size_backup = highlightedPanel_initial_size;
1092 highlightedPanel_backup = highlightedPanel;
1095 // in case the clicked panel is inside another panel and we aren't
1096 // moving it, avoid the immediate "fix" of its position/size
1097 // (often unwanted and hateful) by disabling collisions check
1098 hud_configure_checkcollisions = false;
1101 if(highlightedAction == 1)
1102 HUD_Panel_SetPos(mousepos - panel_click_distance);
1103 else if(highlightedAction == 2)
1106 if(resizeCorner == 1) {
1107 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1108 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1109 } else if(resizeCorner == 2) {
1110 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1111 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1112 } else if(resizeCorner == 3) {
1113 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1114 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1115 } else { // resizeCorner == 4
1116 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1117 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1119 HUD_Panel_SetPosSize(mySize);
1124 if(menu_enabled == 2)
1125 mouse_over_panel = 0;
1127 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1128 if (mouse_over_panel && tab_panel == -1)
1129 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1131 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1132 const vector cursorsize = '32 32 0';
1134 if(!mouse_over_panel)
1135 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1136 else if(mouse_over_panel == 1)
1137 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1138 else if(mouse_over_panel == 2)
1139 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1141 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1143 prevMouseClicked = mouseClicked;
1146 const float hlBorderSize = 4;
1147 const string hlBorder = "gfx/hud/default/border_highlighted";
1148 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1149 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1151 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1152 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);
1153 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);
1154 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);
1155 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);