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("_fadetime");
170 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
172 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
176 print(sprintf(_("^1Couldn't write to %s\n"), filename));
179 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
180 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
183 float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
187 for (i = 0; i < HUD_PANEL_NUM; ++i) {
188 if(i == highlightedPanel || !panel_enabled)
191 HUD_Panel_UpdatePosSizeForId(i);
193 panel_pos -= '1 1 0' * panel_bg_border;
194 panel_size += '2 2 0' * panel_bg_border;
196 if(myPos_y + mySize_y < panel_pos_y)
198 if(myPos_y > panel_pos_y + panel_size_y)
201 if(myPos_x + mySize_x < panel_pos_x)
203 if(myPos_x > panel_pos_x + panel_size_x)
206 // OK, there IS a collision.
208 myCenter_x = myPos_x + 0.5 * mySize_x;
209 myCenter_y = myPos_y + 0.5 * mySize_y;
211 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
212 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
214 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
216 if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
217 myTarget_x = panel_pos_x - mySize_x;
218 else // push it upwards
219 myTarget_y = panel_pos_y - mySize_y;
221 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
223 if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
224 myTarget_x = panel_pos_x + panel_size_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) // bottom left
230 if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
231 myTarget_x = panel_pos_x - mySize_x;
232 else // push it downwards
233 myTarget_y = panel_pos_y + panel_size_y;
235 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
237 if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
238 myTarget_x = panel_pos_x + panel_size_x;
239 else // push it downwards
240 myTarget_y = panel_pos_y + panel_size_y;
242 //if(cvar("hud_configure_checkcollisions_debug"))
243 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
249 void HUD_Panel_SetPos(vector pos)
251 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
255 //if(cvar("hud_configure_checkcollisions_debug"))
256 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
258 if(autocvar_hud_configure_grid)
260 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
261 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
264 if(hud_configure_checkcollisions)
265 pos = HUD_Panel_CheckMove(pos, mySize);
267 pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
268 pos_y = bound(0, pos_y, vid_conheight - mySize_y);
271 s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
273 HUD_Panel_GetName(highlightedPanel);
274 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
277 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
278 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
283 float dist_x, dist_y;
285 ratio = mySize_x/mySize_y;
287 for (i = 0; i < HUD_PANEL_NUM; ++i) {
288 if(i == highlightedPanel || !panel_enabled)
291 HUD_Panel_UpdatePosSizeForId(i);
293 panel_pos -= '1 1 0' * panel_bg_border;
294 panel_size += '2 2 0' * panel_bg_border;
296 targEndPos = panel_pos + panel_size;
298 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
299 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
302 if (resizeCorner == 1)
304 // check if this panel is on our way
305 if (resizeorigin_x <= panel_pos_x)
307 if (resizeorigin_y <= panel_pos_y)
309 if (targEndPos_x <= resizeorigin_x - mySize_x)
311 if (targEndPos_y <= resizeorigin_y - mySize_y)
314 // there is a collision:
315 // detect which side of the panel we are facing is actually limiting the resizing
316 // (which side the resize direction finds for first) and reduce the size up to there
318 // dist is the distance between resizeorigin and the "analogous" point of the panel
319 // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
320 dist_x = resizeorigin_x - targEndPos_x;
321 dist_y = resizeorigin_y - targEndPos_y;
322 if (dist_y <= 0 || dist_x / dist_y > ratio)
323 mySize_x = min(mySize_x, dist_x);
325 mySize_y = min(mySize_y, dist_y);
327 else if (resizeCorner == 2)
329 if (resizeorigin_x >= targEndPos_x)
331 if (resizeorigin_y <= panel_pos_y)
333 if (panel_pos_x >= resizeorigin_x + mySize_x)
335 if (targEndPos_y <= resizeorigin_y - mySize_y)
338 dist_x = panel_pos_x - resizeorigin_x;
339 dist_y = resizeorigin_y - targEndPos_y;
340 if (dist_y <= 0 || dist_x / dist_y > ratio)
341 mySize_x = min(mySize_x, dist_x);
343 mySize_y = min(mySize_y, dist_y);
345 else if (resizeCorner == 3)
347 if (resizeorigin_x <= panel_pos_x)
349 if (resizeorigin_y >= targEndPos_y)
351 if (targEndPos_x <= resizeorigin_x - mySize_x)
353 if (panel_pos_y >= resizeorigin_y + mySize_y)
356 dist_x = resizeorigin_x - targEndPos_x;
357 dist_y = panel_pos_y - resizeorigin_y;
358 if (dist_y <= 0 || dist_x / dist_y > ratio)
359 mySize_x = min(mySize_x, dist_x);
361 mySize_y = min(mySize_y, dist_y);
363 else if (resizeCorner == 4)
365 if (resizeorigin_x >= targEndPos_x)
367 if (resizeorigin_y >= targEndPos_y)
369 if (panel_pos_x >= resizeorigin_x + mySize_x)
371 if (panel_pos_y >= resizeorigin_y + mySize_y)
374 dist_x = panel_pos_x - resizeorigin_x;
375 dist_y = panel_pos_y - resizeorigin_y;
376 if (dist_y <= 0 || dist_x / dist_y > ratio)
377 mySize_x = min(mySize_x, dist_x);
379 mySize_y = min(mySize_y, dist_y);
381 //if(cvar("hud_configure_checkcollisions_debug"))
382 //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
388 void HUD_Panel_SetPosSize(vector mySize)
390 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
392 resizeorigin = panel_click_resizeorigin;
395 // minimum panel size cap
396 mySize_x = max(0.025 * vid_conwidth, mySize_x);
397 mySize_y = max(0.025 * vid_conheight, mySize_y);
399 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.
401 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
402 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
405 // collision testing|
406 // -----------------+
408 // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
409 if(resizeCorner == 1) {
410 myPos_x = resizeorigin_x - mySize_x;
411 myPos_y = resizeorigin_y - mySize_y;
412 } else if(resizeCorner == 2) {
413 myPos_x = resizeorigin_x;
414 myPos_y = resizeorigin_y - mySize_y;
415 } else if(resizeCorner == 3) {
416 myPos_x = resizeorigin_x - mySize_x;
417 myPos_y = resizeorigin_y;
418 } else { // resizeCorner == 4
419 myPos_x = resizeorigin_x;
420 myPos_y = resizeorigin_y;
423 // left/top screen edges
425 mySize_x = mySize_x + myPos_x;
427 mySize_y = mySize_y + myPos_y;
429 // bottom/right screen edges
430 if(myPos_x + mySize_x > vid_conwidth)
431 mySize_x = vid_conwidth - myPos_x;
432 if(myPos_y + mySize_y > vid_conheight)
433 mySize_y = vid_conheight - myPos_y;
435 //if(cvar("hud_configure_checkcollisions_debug"))
436 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
438 // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
439 if(autocvar_hud_configure_grid)
441 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
442 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
445 if(hud_configure_checkcollisions)
446 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
448 // 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)
449 mySize_x = max(0.025 * vid_conwidth, mySize_x);
450 mySize_y = max(0.025 * vid_conheight, mySize_y);
452 // do another pos check, as size might have changed by now
453 if(resizeCorner == 1) {
454 myPos_x = resizeorigin_x - mySize_x;
455 myPos_y = resizeorigin_y - mySize_y;
456 } else if(resizeCorner == 2) {
457 myPos_x = resizeorigin_x;
458 myPos_y = resizeorigin_y - mySize_y;
459 } else if(resizeCorner == 3) {
460 myPos_x = resizeorigin_x - mySize_x;
461 myPos_y = resizeorigin_y;
462 } else { // resizeCorner == 4
463 myPos_x = resizeorigin_x;
464 myPos_y = resizeorigin_y;
467 //if(cvar("hud_configure_checkcollisions_debug"))
468 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
470 HUD_Panel_GetName(highlightedPanel);
472 s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
473 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
475 s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
476 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
479 float pressed_key_time;
480 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
481 void HUD_Panel_Arrow_Action(float nPrimary)
483 if (highlightedPanel == -1)
486 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
489 if(autocvar_hud_configure_grid)
491 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
493 if (hudShiftState & S_SHIFT)
494 step = hud_configure_realGridSize_y;
496 step = 2 * hud_configure_realGridSize_y;
500 if (hudShiftState & S_SHIFT)
501 step = hud_configure_realGridSize_x;
503 step = 2 * hud_configure_realGridSize_x;
508 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
509 step = vid_conheight;
512 if (hudShiftState & S_SHIFT)
513 step = (step / 256); // more precision
515 step = (step / 64) * (1 + 2 * (time - pressed_key_time));
518 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
520 highlightedPanel_initial_pos = panel_pos;
521 highlightedPanel_initial_size = panel_size;
523 if (hudShiftState & S_ALT) // resize
525 highlightedAction = 1;
526 if(nPrimary == K_UPARROW)
528 else if(nPrimary == K_RIGHTARROW)
530 else if(nPrimary == K_LEFTARROW)
532 else // if(nPrimary == K_DOWNARROW)
535 // ctrl+arrow reduces the size, instead of increasing it
536 // Note that ctrl disables collisions check too, but it's fine
537 // since we don't collide with anything reducing the size
538 if (hudShiftState & S_CTRL) {
540 resizeCorner = 5 - resizeCorner;
545 panel_click_resizeorigin = panel_pos;
546 if(resizeCorner == 1) {
547 panel_click_resizeorigin += mySize;
549 } else if(resizeCorner == 2) {
550 panel_click_resizeorigin_y += mySize_y;
552 } else if(resizeCorner == 3) {
553 panel_click_resizeorigin_x += mySize_x;
555 } else { // resizeCorner == 4
558 HUD_Panel_SetPosSize(mySize);
562 highlightedAction = 2;
565 if(nPrimary == K_UPARROW)
567 else if(nPrimary == K_DOWNARROW)
569 else if(nPrimary == K_LEFTARROW)
571 else // if(nPrimary == K_RIGHTARROW)
574 HUD_Panel_SetPos(pos);
577 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
579 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
582 panel_pos_backup = highlightedPanel_initial_pos;
583 panel_size_backup = highlightedPanel_initial_size;
584 highlightedPanel_backup = highlightedPanel;
588 const float S_MOUSE1 = 1;
589 const float S_MOUSE2 = 2;
590 const float S_MOUSE3 = 4;
592 float prevMouseClicked; // previous state
593 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
594 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
596 void HUD_Panel_EnableMenu();
597 float tab_panels[HUD_PANEL_NUM];
598 float tab_panel, tab_backward;
599 vector tab_panel_pos;
600 void HUD_Panel_FirstInDrawQ(float id);
601 void reset_tab_panels()
604 for(i = 0; i < HUD_PANEL_NUM; ++i)
607 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
611 // we only care for keyboard events
612 if(bInputType != 0 && bInputType != 1)
615 if(!autocvar__hud_configure)
618 // allow console bind to work
621 con_keys = findkeysforcommand("toggleconsole");
622 keys = tokenize(con_keys);
624 float hit_con_bind, i;
625 for (i = 0; i < keys; ++i)
627 if(nPrimary == stof(argv(i)))
631 if(bInputType == 0) {
632 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
633 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
634 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
636 else if(bInputType == 1) {
637 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
638 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
639 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
642 if(nPrimary == K_CTRL)
644 if (bInputType == 1) //ctrl has been released
648 //switch to selected panel
649 highlightedPanel = tab_panel;
650 highlightedAction = 0;
651 HUD_Panel_FirstInDrawQ(highlightedPanel);
658 if(nPrimary == K_MOUSE1)
660 if(bInputType == 0) // key pressed
661 mouseClicked |= S_MOUSE1;
662 else if(bInputType == 1) // key released
663 mouseClicked -= (mouseClicked & S_MOUSE1);
665 else if(nPrimary == K_MOUSE2)
667 if(bInputType == 0) // key pressed
668 mouseClicked |= S_MOUSE2;
669 else if(bInputType == 1) // key released
670 mouseClicked -= (mouseClicked & S_MOUSE2);
672 else if(nPrimary == K_ESCAPE)
677 menu_enabled_time = time;
678 localcmd("menu_showhudexit\n");
680 else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
685 cvar_set("_hud_configure", "0");
687 else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
689 if (bInputType == 1 || mouseClicked)
692 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
693 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
694 //(it should only after every other panel of the hud)
695 //It's a minor bug anyway, we can live with it
697 float starting_panel;
698 float old_tab_panel = tab_panel;
699 if (tab_panel == -1) //first press of TAB
701 if (highlightedPanel != -1)
702 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
705 starting_panel = highlightedPanel; //can be -1, it means no starting panel
706 tab_panel_pos = panel_pos; //to compute level
710 if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
712 starting_panel = tab_panel;
714 tab_backward = (hudShiftState & S_SHIFT);
716 float k, level, start_pos_x;
717 vector candidate_pos;
718 const float LEVELS_NUM = 4;
719 float level_height = vid_conheight / LEVELS_NUM;
721 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
722 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
723 start_pos_x = tab_panel_pos_x;
728 for(i = 0; i < HUD_PANEL_NUM; ++i)
730 if (i == tab_panels[i] || i == starting_panel)
732 HUD_Panel_UpdatePosSizeForId(i)
733 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
734 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)) )
735 || ( 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)) ) )
738 tab_panel_pos = candidate_pos = panel_pos;
743 if (k == LEVELS_NUM) //tab_panel not found
746 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
751 starting_panel = old_tab_panel;
753 goto find_tab_panel; //u must find tab_panel!
757 level = mod(level + level_height, vid_conheight);
759 candidate_pos_x = vid_conwidth;
763 level = mod(level - level_height, vid_conheight);
764 start_pos_x = vid_conwidth;
769 tab_panels[tab_panel] = tab_panel;
771 else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
773 if (bInputType == 1 || mouseClicked)
776 if (highlightedPanel != -1)
778 HUD_Panel_GetName(highlightedPanel);
779 cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
782 cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
784 else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
786 if (bInputType == 1 || mouseClicked)
789 if (highlightedPanel != -1)
791 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
792 panel_size_copied = panel_size;
793 highlightedPanel_copied = highlightedPanel;
796 else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
798 if (bInputType == 1 || mouseClicked)
801 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
804 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
806 // reduce size if it'd go beyond screen boundaries
807 vector tmp_size = panel_size_copied;
808 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
809 tmp_size_x = vid_conwidth - panel_pos_x;
810 if (panel_pos_y + panel_size_copied_y > vid_conheight)
811 tmp_size_y = vid_conheight - panel_pos_y;
813 if (panel_size == tmp_size)
817 panel_pos_backup = panel_pos;
818 panel_size_backup = panel_size;
819 highlightedPanel_backup = highlightedPanel;
821 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
822 HUD_Panel_GetName(highlightedPanel);
823 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
825 else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
827 if (bInputType == 1 || mouseClicked)
829 //restore previous values
830 if (highlightedPanel_backup != -1)
832 HUD_Panel_GetName(highlightedPanel_backup);
833 s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
834 cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
835 s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
836 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
837 highlightedPanel_backup = -1;
840 else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
844 pressed_key_time = 0;
847 else if (pressed_key_time == 0)
848 pressed_key_time = time;
851 HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
853 else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
857 if (highlightedPanel != -1)
858 HUD_Panel_EnableMenu();
860 else if(hit_con_bind)
866 float HUD_Panel_Check_Mouse_Pos(float allow_move)
870 while(j < HUD_PANEL_NUM)
875 HUD_Panel_UpdatePosSizeForId(i);
877 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
880 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)
884 // resize from topleft border
885 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)
889 // resize from topright border
890 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)
894 // resize from bottomleft border
895 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)
899 // resize from bottomright border
900 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)
908 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
909 void HUD_Panel_FirstInDrawQ(float id)
912 var float place = -1;
913 // find out where in the array our current id is, save into place
914 for(i = 0; i < HUD_PANEL_NUM; ++i)
916 if(panel_order[i] == id)
922 // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
924 place = HUD_PANEL_NUM - 1;
926 // move all ids up by one step in the array until "place"
927 for(i = place; i > 0; --i)
929 panel_order[i] = panel_order[i-1];
931 // now save the new top id
934 // let's save them into the cvar by some strcat trickery
936 for(i = 0; i < HUD_PANEL_NUM; ++i)
938 s = strcat(s, ftos(panel_order[i]), " ");
940 cvar_set("_hud_panelorder", s);
941 if(hud_panelorder_prev)
942 strunzone(hud_panelorder_prev);
943 hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
946 void HUD_Panel_Highlight(float allow_move)
950 while(j < HUD_PANEL_NUM)
955 HUD_Panel_UpdatePosSizeForId(i);
957 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
960 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)
962 highlightedPanel = i;
963 HUD_Panel_FirstInDrawQ(i);
964 highlightedAction = 1;
965 panel_click_distance = mousepos - panel_pos;
968 // resize from topleft border
969 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)
971 highlightedPanel = i;
972 HUD_Panel_FirstInDrawQ(i);
973 highlightedAction = 2;
975 panel_click_distance = mousepos - panel_pos;
976 panel_click_resizeorigin = panel_pos + panel_size;
979 // resize from topright border
980 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)
982 highlightedPanel = i;
983 HUD_Panel_FirstInDrawQ(i);
984 highlightedAction = 2;
986 panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
987 panel_click_distance_y = mousepos_y - panel_pos_y;
988 panel_click_resizeorigin = panel_pos + eY * panel_size_y;
991 // resize from bottomleft border
992 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)
994 highlightedPanel = i;
995 HUD_Panel_FirstInDrawQ(i);
996 highlightedAction = 2;
998 panel_click_distance_x = mousepos_x - panel_pos_x;
999 panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
1000 panel_click_resizeorigin = panel_pos + eX * panel_size_x;
1003 // resize from bottomright border
1004 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)
1006 highlightedPanel = i;
1007 HUD_Panel_FirstInDrawQ(i);
1008 highlightedAction = 2;
1010 panel_click_distance = panel_size - mousepos + panel_pos;
1011 panel_click_resizeorigin = panel_pos;
1015 highlightedPanel = -1;
1016 highlightedAction = 0;
1019 void HUD_Panel_EnableMenu()
1022 menu_enabled_time = time;
1023 HUD_Panel_GetName(highlightedPanel);
1024 localcmd("menu_showhudoptions ", panel_name, "\n");
1026 float mouse_over_panel;
1027 void HUD_Panel_Mouse()
1029 // 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
1030 if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1034 print("menu_enabled: ", ftos(menu_enabled), "\n");
1035 print("Highlighted: ", ftos(highlightedPanel), "\n");
1036 print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1039 // instantly hide the editor cursor if we open the HUDExit dialog
1040 // as hud_fade_alpha doesn't decrease to 0 in this case
1041 // TODO: find a way to fade the cursor out even in this case
1042 if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1045 mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1047 mousepos_x = bound(0, mousepos_x, vid_conwidth);
1048 mousepos_y = bound(0, mousepos_y, vid_conheight);
1052 if(prevMouseClicked == 0)
1054 if (tab_panel != -1)
1056 //stop ctrl-tab selection
1060 HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1061 // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1062 if (highlightedPanel != -1)
1064 highlightedPanel_initial_pos = panel_pos;
1065 highlightedPanel_initial_size = panel_size;
1067 // doubleclick check
1068 if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1070 mouseClicked = 0; // to prevent spam, I guess.
1071 HUD_Panel_EnableMenu();
1075 if (mouseClicked & S_MOUSE1)
1077 prevMouseClickedTime = time;
1078 prevMouseClickedPos = mousepos;
1080 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1084 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1086 if (highlightedPanel != -1)
1088 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1089 if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1091 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1093 panel_pos_backup = highlightedPanel_initial_pos;
1094 panel_size_backup = highlightedPanel_initial_size;
1095 highlightedPanel_backup = highlightedPanel;
1098 // in case the clicked panel is inside another panel and we aren't
1099 // moving it, avoid the immediate "fix" of its position/size
1100 // (often unwanted and hateful) by disabling collisions check
1101 hud_configure_checkcollisions = false;
1104 if(highlightedAction == 1)
1105 HUD_Panel_SetPos(mousepos - panel_click_distance);
1106 else if(highlightedAction == 2)
1109 if(resizeCorner == 1) {
1110 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1111 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1112 } else if(resizeCorner == 2) {
1113 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1114 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1115 } else if(resizeCorner == 3) {
1116 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1117 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1118 } else { // resizeCorner == 4
1119 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1120 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1122 HUD_Panel_SetPosSize(mySize);
1127 if(menu_enabled == 2)
1128 mouse_over_panel = 0;
1130 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1131 if (mouse_over_panel && tab_panel == -1)
1132 drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1134 // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1135 const vector cursorsize = '32 32 0';
1137 if(!mouse_over_panel)
1138 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1139 else if(mouse_over_panel == 1)
1140 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1141 else if(mouse_over_panel == 2)
1142 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1144 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1146 prevMouseClicked = mouseClicked;
1149 const float hlBorderSize = 4;
1150 const string hlBorder = "gfx/hud/default/border_highlighted";
1151 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1152 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1154 drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1155 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);
1156 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);
1157 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);
1158 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);