5 #include "anim/animhost.qh"
7 #include "item/dialog.qh"
8 #include "item/listbox.qh"
9 #include "item/nexposee.qh"
11 #include "xonotic/commandbutton.qh"
12 #include "xonotic/mainwindow.qh"
13 #include "xonotic/serverlist.qh"
14 #include "xonotic/slider_resolution.qh"
16 .string controlledCvar;
18 #include "xonotic/util.qh"
20 #include <common/items/_mod.qh>
21 #include <common/weapons/_all.qh>
22 #include <common/mapinfo.qh>
23 #include <common/mutators/base.qh>
25 int mouseButtonsPressed;
33 bool menuNotTheFirstFrame;
36 float conwidth_s, conheight_s;
37 float vidwidth_s, vidheight_s, vidpixelheight_s;
38 float realconwidth, realconheight;
43 vidwidth_s = vidheight_s = vidpixelheight_s = 0; // Force updateConwidths on next draw
51 if (isserver()) gamestatus |= GAME_ISSERVER;
52 if (clientstate() == CS_CONNECTED || isdemo()) gamestatus |= GAME_CONNECTED;
53 if (cvar("developer") > 0) gamestatus |= GAME_DEVELOPER;
58 bool restarting = false;
59 cvar_set("_menu_alpha", "0");
60 prvm_language = cvar_string("prvm_language");
61 if (prvm_language == "")
64 cvar_set("prvm_language", prvm_language);
65 localcmd("\nmenu_restart\n");
68 prvm_language = strzone(prvm_language);
69 cvar_set("_menu_prvm_language", prvm_language);
72 LOG_TRACEF("^4MQC Build information: ^1%s", WATERMARK);
75 // list all game dirs (TEST)
76 if (cvar("developer") > 0)
78 for (int i = 0; ; ++i)
80 string s = getgamedirinfo(i, GETGAMEDIRINFO_NAME);
82 LOG_TRACE(s, ": ", getgamedirinfo(i, GETGAMEDIRINFO_DESCRIPTION));
86 registercvar("_menu_cmd_closemenu_available", "0", 0);
87 cvar_set("_menu_cmd_closemenu_available", "1");
89 // needs to be done so early because of the constants they create
92 static_init_precache();
94 RegisterSLCategories();
96 float ddsload = cvar("r_texture_dds_load");
97 float texcomp = cvar("gl_texturecompression");
99 if (ddsload != cvar("r_texture_dds_load") || texcomp != cvar("gl_texturecompression")) localcmd("\nr_restart\n");
103 if (cvar("_menu_initialized")) // always show menu after menu_restart
106 cvar_set("_menu_initialized", "1");
110 const float MENU_ASPECT = 1280 / 1024;
112 void draw_reset_cropped()
114 draw_reset(conwidth, conheight, 0.5 * (realconwidth - conwidth), 0.5 * (realconheight - conheight));
116 void draw_reset_full()
118 draw_reset(realconwidth, realconheight, 0, 0);
121 void UpdateConWidthHeight(float w, float h, float p)
123 if (w != vidwidth_s || h != vidheight_s || p != vidpixelheight_s)
125 if (updateConwidths(w, h, p)) localcmd(sprintf("\nexec %s\n", cvar_string("menu_font_cfg")));
128 vidpixelheight_s = p;
130 conwidth_s = conwidth;
131 conheight_s = conheight;
132 realconwidth = cvar("vid_conwidth");
133 realconheight = cvar("vid_conheight");
134 if (realconwidth / realconheight > MENU_ASPECT)
137 conwidth = realconheight * MENU_ASPECT;
138 conheight = realconheight;
143 conwidth = realconwidth;
144 conheight = realconwidth / MENU_ASPECT;
148 if (conwidth_s != conwidth || conheight_s != conheight)
150 draw_reset_cropped();
151 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
156 vidwidth_s = vidheight_s = vidpixelheight_s = 0; // retry next frame
160 string m_goto_buffer;
161 void m_init_delayed()
163 draw_reset_cropped();
165 menuInitialized = false;
166 if (!preMenuInit()) return;
167 menuInitialized = true;
170 if (cvar_string("menu_skin") != "")
172 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
173 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
175 if (fh < 0 && cvar_defstring("menu_skin") != "")
177 cvar_set("menu_skin", cvar_defstring("menu_skin"));
178 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
179 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
183 draw_currentSkin = "gfx/menu/default";
184 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
186 if (fh < 0) error("cannot load any menu skin\n");
187 draw_currentSkin = strzone(draw_currentSkin);
188 for (string s; (s = fgets(fh)); )
190 // these two are handled by skinlist.qc
191 if (substring(s, 0, 6) == "title ") continue;
192 if (substring(s, 0, 7) == "author ") continue;
193 int n = tokenize_console(s);
195 Skin_ApplySetting(argv(0), substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
199 int glob = search_begin(strcat(draw_currentSkin, "/*.tga"), true, true);
202 for (int i = 0, n = search_getsize(glob); i < n; ++i)
203 precache_pic(search_getfilename(glob, i));
207 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
209 anim = NEW(AnimHost);
210 main = NEW(MainWindow);
211 main.configureMainWindow(main);
213 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
216 menuMousePos = '0.5 0.5 0';
222 m_goto(m_goto_buffer);
223 strfree(m_goto_buffer);
226 if (Menu_Active) m_display(); // delayed menu display
228 cvar_set("_menu_initialized", "2");
231 void m_keyup(float key, float ascii)
233 if (!menuInitialized) return;
234 if (!Menu_Active) return;
235 draw_reset_cropped();
236 main.keyUp(main, key, ascii, menuShiftState);
237 if (key >= K_MOUSE1 && key <= K_MOUSE3)
239 --mouseButtonsPressed;
240 if (!mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
241 if (mouseButtonsPressed < 0)
243 mouseButtonsPressed = 0;
244 LOG_TRACE("Warning: released an already released button");
247 if (key == K_ALT) menuShiftState &= ~S_ALT;
248 if (key == K_CTRL) menuShiftState &= ~S_CTRL;
249 if (key == K_SHIFT) menuShiftState &= ~S_SHIFT;
252 void m_keydown(float key, float ascii)
254 if (!menuInitialized) return;
255 if (!Menu_Active) return;
257 if (menuMouseMode && key >= K_MOUSE1 && key <= K_MOUSE3)
259 // detect a click outside of the game window
260 vector p = getmousepos();
261 if (p.x < 0 || p.x > realconwidth || p.y < 0 || p.y > realconheight)
263 ++mouseButtonsPressed;
270 entity e = keyGrabber;
272 e.keyGrabbed(e, key, ascii);
276 draw_reset_cropped();
277 if (!mouseButtonsPressed && key >= K_MOUSE1 && key <= K_MOUSE3)
278 main.mousePress(main, menuMousePos);
279 if (!main.keyDown(main, key, ascii, menuShiftState))
281 // disable menu on unhandled ESC
283 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
287 if (key >= K_MOUSE1 && key <= K_MOUSE3)
289 ++mouseButtonsPressed;
290 if (mouseButtonsPressed > 10)
292 mouseButtonsPressed = 10;
293 LOG_TRACE("Warning: pressed an already pressed button");
296 if (key == K_ALT) menuShiftState |= S_ALT;
297 if (key == K_CTRL) menuShiftState |= S_CTRL;
298 if (key == K_SHIFT) menuShiftState |= S_SHIFT;
308 void draw_Picture_Aligned(vector algn, float scalemode, string img, float a)
310 vector sz = draw_PictureSize(img);
311 bool width_is_larger = (sz.x * draw_scale.y >= sz.y * draw_scale.x);
312 vector isz_w = '1 0 0' + '0 1 0' * ((sz.y / sz.x) * (draw_scale.x / draw_scale.y));
313 vector isz_h = '0 1 0' + '1 0 0' * ((sz.x / sz.y) * (draw_scale.y / draw_scale.x));
319 isz = (width_is_larger ? isz_h : isz_w);
321 case SCALEMODE_LETTERBOX:
322 isz = (width_is_larger ? isz_w : isz_h);
324 case SCALEMODE_WIDTH:
327 case SCALEMODE_HEIGHT:
330 case SCALEMODE_STRETCH:
334 vector org = eX * (algn.x * (1 - isz.x)) + eY * (algn.y * (1 - isz.y));
335 draw_Picture(org, img, isz, '1 1 1', a);
338 void drawBackground(string img, float a, string algn, float force1)
340 if (main.mainNexposee.ModalController_state == 0) return;
342 int scalemode = SCALEMODE_CROP;
343 int len = strlen(algn);
344 for (int i = 0, l = 0; i < len; ++i)
346 string c = substring(algn, i, 1);
350 scalemode = SCALEMODE_CROP;
353 scalemode = SCALEMODE_LETTERBOX;
356 scalemode = SCALEMODE_HEIGHT;
359 scalemode = SCALEMODE_WIDTH;
362 scalemode = SCALEMODE_STRETCH;
364 case "1": case "4": case "7":
367 case "2": case "5": case "8":
370 case "3": case "6": case "9":
379 case "7": case "8": case "9":
382 case "4": case "5": case "6":
385 case "1": case "2": case "3":
394 draw_Picture_Aligned(v, scalemode, img, a);
398 // force all secondary layers to use alpha 1. Prevents ugly issues
399 // with overlap. It's a flag because it cannot be used for the
401 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), 1);
405 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), a);
413 int menu_tooltips_old;
414 vector menuTooltipAveragedMousePos;
415 entity menuTooltipItem;
416 vector menuTooltipOrigin;
417 vector menuTooltipSize;
418 float menuTooltipAlpha;
419 string menuTooltipText;
420 int menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
421 bool m_testmousetooltipbox(vector pos)
424 (pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x)
425 && (pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y)
428 bool m_testtooltipbox(vector tooltippos)
430 if (tooltippos.x < 0) return false;
431 if (tooltippos.y < 0) return false;
432 if (tooltippos.x + menuTooltipSize.x > 1) return false;
433 if (tooltippos.y + menuTooltipSize.y > 1) return false;
434 menuTooltipOrigin = tooltippos;
437 bool m_allocatetooltipbox(vector pos)
440 avoidplus.x = (SKINAVOID_TOOLTIP_x + SKINSIZE_CURSOR_x - SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth;
441 avoidplus.y = (SKINAVOID_TOOLTIP_y + SKINSIZE_CURSOR_y - SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight;
445 avoidminus.x = (SKINAVOID_TOOLTIP_x + SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth + menuTooltipSize.x;
446 avoidminus.y = (SKINAVOID_TOOLTIP_y + SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight + menuTooltipSize.y;
450 vector v = pos + avoidplus;
451 if (m_testtooltipbox(v)) return true;
454 v.x = pos.x - menuTooltipSize.x * 0.5;
455 if (m_testtooltipbox(v)) return true;
458 v.x = pos.x - avoidminus.x;
459 if (m_testtooltipbox(v)) return true;
462 v.y = pos.y - avoidminus.y;
463 if (m_testtooltipbox(v)) return true;
466 v.x = pos.x - menuTooltipSize.x * 0.5;
467 if (m_testtooltipbox(v)) return true;
470 v.x = pos.x + avoidplus.x;
471 if (m_testtooltipbox(v)) return true;
475 entity m_findtooltipitem(entity root, vector pos)
478 for (entity it = root; it.instanceOfContainer; )
480 while (it.instanceOfNexposee && it.focusedChild)
482 it = it.focusedChild;
483 pos = globalToBox(pos, it.Container_origin, it.Container_size);
485 if (it.instanceOfNexposee)
487 it = it.itemFromPoint(it, pos);
488 if (it.tooltip) best = it;
489 else if (menu_tooltips == 2 && (it.controlledCvar || it.onClickCommand)) best = it;
492 else if (it.instanceOfModalController)
494 it = it.focusedChild;
498 it = it.itemFromPoint(it, pos);
501 if (it.tooltip) best = it;
502 else if (menu_tooltips == 2 && (it.controlledCvar || it.onClickCommand)) best = it;
503 pos = globalToBox(pos, it.Container_origin, it.Container_size);
510 if (menu_tooltips == 2)
513 if (menuTooltipItem.controlledCvar)
515 string cvar_list = getCvarsMulti(menuTooltipItem);
517 cvar_list = strcat(menuTooltipItem.controlledCvar, " ", cvar_list);
519 cvar_list = menuTooltipItem.controlledCvar;
520 s = strcat("[", cvar_list, " \"", cvar_string(menuTooltipItem.controlledCvar), "\"]");
522 else if (menuTooltipItem.onClickCommand)
524 s = strcat("<", menuTooltipItem.onClickCommand, ">");
528 return menuTooltipItem.tooltip;
530 if (menuTooltipItem.tooltip) return strcat(menuTooltipItem.tooltip, " ", s);
533 return menuTooltipItem.tooltip;
535 void m_tooltip(vector pos)
537 static string prev_tooltip;
539 menu_tooltips = cvar("menu_tooltips");
542 // don't return immediately, fade out the active tooltip first
543 if (menuTooltipItem == NULL) return;
545 menu_tooltips_old = menu_tooltips;
549 float f = bound(0, frametime * 2, 1);
550 menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + pos * f;
551 if (vdist(pos - menuTooltipAveragedMousePos, <, 0.01))
553 it = m_findtooltipitem(main, pos);
555 if (it.instanceOfListBox && it.isScrolling(it)) it = NULL;
557 if (it && prev_tooltip != it.tooltip)
559 // fade out if tooltip of a certain item has changed
560 menuTooltipState = 3;
561 strcpy(prev_tooltip, it.tooltip);
563 else if (menuTooltipItem && !m_testmousetooltipbox(pos))
565 menuTooltipState = 3; // fade out if mouse touches it
573 vector fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
575 // float menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
576 if (it != menuTooltipItem)
578 switch (menuTooltipState)
583 // another item: fade out first
584 menuTooltipState = 2;
589 menuTooltipState = 1;
590 menuTooltipItem = it;
592 menuTooltipOrigin.x = -1; // unallocated
594 strcpy(menuTooltipText, gettooltip());
598 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i)
600 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
603 float f = draw_TextWidth(s, false, fontsize);
606 menuTooltipSize.x = w + 2 * (SKINMARGIN_TOOLTIP_x / conwidth);
607 menuTooltipSize.y = i * fontsize.y + 2 * (SKINMARGIN_TOOLTIP_y / conheight);
608 menuTooltipSize.z = 0;
612 // changing item while fading in: fade out first
613 menuTooltipState = 2;
616 // changing item while fading out: can't
620 else if (menuTooltipState == 2) // re-fade in?
622 menuTooltipState = 1;
625 switch (menuTooltipState)
628 menuTooltipAlpha = bound(0, menuTooltipAlpha + 5 * frametime, 1);
629 if (menuTooltipAlpha == 1) menuTooltipState = 0;
632 case 3: // forced fade out
633 menuTooltipAlpha = bound(0, menuTooltipAlpha - 2 * frametime, 1);
634 if (menuTooltipAlpha == 0)
636 menuTooltipState = 0;
637 menuTooltipItem = NULL;
642 if (menuTooltipItem == NULL)
644 strfree(menuTooltipText);
649 if (menu_tooltips != menu_tooltips_old)
651 if (menu_tooltips != 0 && menu_tooltips_old != 0) menuTooltipItem = NULL; // reload tooltip next frame
652 menu_tooltips_old = menu_tooltips;
654 else if (menuTooltipOrigin.x < 0) // unallocated?
656 m_allocatetooltipbox(pos);
658 if (menuTooltipOrigin.x >= 0)
661 vector p = SKINBORDER_TOOLTIP;
663 p.y *= 1 / conheight;
664 draw_BorderPicture(menuTooltipOrigin, SKINGFX_TOOLTIP, menuTooltipSize, '1 1 1', menuTooltipAlpha, p);
665 p = menuTooltipOrigin;
666 p.x += SKINMARGIN_TOOLTIP_x / conwidth;
667 p.y += SKINMARGIN_TOOLTIP_y / conheight;
669 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i, p.y += fontsize.y)
671 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
674 draw_Text(p, s, fontsize, SKINCOLOR_TOOLTIP, SKINALPHA_TOOLTIP * menuTooltipAlpha, false);
680 const int MIN_DISCONNECTION_TIME = 1;
681 float autocvar_menu_force_on_disconnection;
682 bool autocvar_g_campaign;
683 void m_draw(float width, float height)
685 static float connected_time;
686 if (clientstate() == CS_DISCONNECTED)
688 if (connected_time && time - connected_time > MIN_DISCONNECTION_TIME)
690 if (autocvar_g_campaign)
692 // in the case player uses the disconnect command (in the console or with a key)
693 // reset g_campaign and update menu items to reflect cvar values that may have been restored after quiting the campaign
694 // see also LEAVEMATCH_CMD
695 cvar_set("g_campaign", "0");
698 if (autocvar_menu_force_on_disconnection > 0)
700 localcmd("\nmenu_cmd directmenu Welcome RESET\n");
705 connected_time = time;
709 execute_next_frame();
711 menuMouseMode = cvar("menu_mouse_absolute");
713 if (anim) anim.tickAll(anim);
715 UpdateConWidthHeight(width, height, cvar("vid_pixelheight"));
717 if (!menuInitialized)
719 // TODO draw an info image about this situation
723 if (!menuNotTheFirstFrame)
725 menuNotTheFirstFrame = true;
726 if (Menu_Active && !cvar("menu_video_played"))
728 localcmd("cd loop $menu_cdtrack\n");
729 // TODO: use this when we have a welcome sound
730 //localcmd("cd loop $menu_cdtrack; play sound/announcer/default/welcome.wav\n");
731 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME
733 // ALWAYS set this cvar; if we start but menu is not active, this means we want no background music!
734 localcmd("set menu_video_played 1\n");
738 float realFrametime = frametime = min(0.2, t - menuPrevTime);
742 t = cvar("menu_slowmo");
755 if (getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU)
756 && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
757 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
761 if (cvar("cl_capturevideo")) frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
763 prevMenuAlpha = menuAlpha;
766 if (menuAlpha == 0 && menuLogoAlpha < 2)
768 menuLogoAlpha += 2 * frametime;
772 menuAlpha = min(1, menuAlpha + 5 * frametime);
778 menuAlpha = max(0, menuAlpha - 5 * frametime);
782 draw_reset_cropped();
784 if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
786 if (menuLogoAlpha > 0)
789 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_BACKGROUND, 1);
790 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1), SKINALIGN_BACKGROUND, true);
791 draw_reset_cropped();
792 if (menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
794 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
795 draw_drawMousePointer(menuMousePos);
800 else if (SKINALPHA_BACKGROUND_INGAME)
805 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME,
806 SKINALIGN_BACKGROUND_INGAME, false);
807 draw_reset_cropped();
811 if (menuAlpha != prevMenuAlpha) cvar_set("_menu_alpha", ftos(menuAlpha));
813 draw_reset_cropped();
815 draw_reset_cropped();
819 if (prevMenuAlpha > 0) main.initializeDialog(main, main.firstChild);
820 draw_reset_cropped();
825 draw_alpha *= menuAlpha;
829 vector rawMousePos = getmousepos();
830 vector newMouse = globalToBox(rawMousePos, draw_shift, draw_scale);
831 if (rawMousePos != '0 0 0' && newMouse != menuMousePos)
833 menuMousePos = newMouse;
834 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
835 else main.mouseMove(main, menuMousePos);
838 else if (frametime > 0)
840 vector dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
841 if (dMouse != '0 0 0')
843 vector minpos = globalToBox('0 0 0', draw_shift, draw_scale);
844 vector maxpos = globalToBox(eX * (realconwidth - 1) + eY * (realconheight - 1), draw_shift, draw_scale);
845 dMouse = globalToBoxSize(dMouse, draw_scale);
846 menuMousePos += dMouse * cvar("menu_mouse_speed");
847 menuMousePos.x = bound(minpos.x, menuMousePos.x, maxpos.x);
848 menuMousePos.y = bound(minpos.y, menuMousePos.y, maxpos.y);
849 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
850 else main.mouseMove(main, menuMousePos);
855 m_tooltip(menuMousePos);
857 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
859 draw_drawMousePointer(menuMousePos);
861 draw_reset_cropped();
871 setkeydest(KEY_MENU);
872 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
874 if (!menuInitialized) return;
876 if (mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
877 mouseButtonsPressed = 0;
879 main.focusEnter(main);
880 main.showNotify(main);
886 setkeydest(KEY_GAME);
887 setmousetarget(MT_CLIENT);
889 if (!menuInitialized) return;
891 main.focusLeave(main);
892 main.hideNotify(main);
895 void m_toggle(int mode)
899 if (mode == 1) return;
904 if (mode == 0) return;
912 FOREACH_ENTITY_ORDERED(it.destroy, {
913 if (it.classname == "vtbl") continue;
916 cvar_set("_menu_cmd_closemenu_available", "0");
919 void m_focus_item_chain(entity outermost, entity innermost)
921 if (innermost.parent != outermost) m_focus_item_chain(outermost, innermost.parent);
922 innermost.parent.setFocus(innermost.parent, innermost);
925 void m_activate_window(entity wnd)
927 entity par = wnd.parent;
928 if (par) m_activate_window(par);
930 if (par.instanceOfModalController)
932 if (wnd.tabSelectingButton)
934 TabButton_Click(wnd.tabSelectingButton, wnd);
937 par.initializeDialog(par, wnd);
939 else if (par.instanceOfNexposee)
941 // nexposee (sorry for violating abstraction here)
942 par.selectedChild = wnd;
943 par.animationState = 1;
944 Container_setFocus(par, NULL);
946 else if (par.instanceOfContainer)
949 if (par.focused) par.setFocus(par, wnd);
953 void m_setpointerfocus(entity wnd)
955 if (!wnd.instanceOfContainer) return;
956 entity focus = wnd.preferredFocusedGrandChild(wnd);
958 menuMousePos = focus.origin + 0.5 * focus.size;
959 menuMousePos.x *= 1 / conwidth;
960 menuMousePos.y *= 1 / conheight;
961 entity par = wnd.parent;
962 if (par.focused) par.setFocus(par, wnd);
963 if (wnd.focused) m_focus_item_chain(wnd, focus);
966 void m_goto(string itemname)
968 if (!menuInitialized)
970 strcpy(m_goto_buffer, itemname);
973 if (itemname == "") // this can be called by GameCommand
975 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
980 itemname = "nexposee";
983 if (itemname == "nexposee")
985 // unlike 'togglemenu 1', this closes modal and root dialogs if opened
986 m_activate_window(main.mainNexposee);
992 for (e = NULL; (e = find(e, name, itemname)); )
993 if (e.classname != "vtbl") break;
995 if ((e) && (!e.requiresConnection || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))))
998 e.hideMenuOnClose = true;
1000 m_activate_window(e);
1001 m_setpointerfocus(e);
1007 void m_play_focus_sound()
1009 static float menuLastFocusSoundTime;
1010 if (cvar("menu_sounds") < 2) return;
1011 if (time - menuLastFocusSoundTime <= 0.25) return;
1012 localsound(MENU_SOUND_FOCUS);
1013 menuLastFocusSoundTime = time;
1016 void m_play_click_sound(string soundfile)
1018 if (!cvar("menu_sounds")) return;
1019 localsound(soundfile);