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 // needs to be done so early because of the constants they create
89 static_init_precache();
91 RegisterSLCategories();
93 float ddsload = cvar("r_texture_dds_load");
94 float texcomp = cvar("gl_texturecompression");
96 if (ddsload != cvar("r_texture_dds_load") || texcomp != cvar("gl_texturecompression")) localcmd("\nr_restart\n");
100 if (cvar("_menu_initialized")) // always show menu after menu_restart
103 cvar_set("_menu_initialized", "1");
107 const float MENU_ASPECT = 1280 / 1024;
109 void draw_reset_cropped()
111 draw_reset(conwidth, conheight, 0.5 * (realconwidth - conwidth), 0.5 * (realconheight - conheight));
113 void draw_reset_full()
115 draw_reset(realconwidth, realconheight, 0, 0);
118 void UpdateConWidthHeight(float w, float h, float p)
120 if (w != vidwidth_s || h != vidheight_s || p != vidpixelheight_s)
122 if (updateConwidths(w, h, p)) localcmd(sprintf("\nexec %s\n", cvar_string("menu_font_cfg")));
125 vidpixelheight_s = p;
127 conwidth_s = conwidth;
128 conheight_s = conheight;
129 realconwidth = cvar("vid_conwidth");
130 realconheight = cvar("vid_conheight");
131 if (realconwidth / realconheight > MENU_ASPECT)
134 conwidth = realconheight * MENU_ASPECT;
135 conheight = realconheight;
140 conwidth = realconwidth;
141 conheight = realconwidth / MENU_ASPECT;
145 if (conwidth_s != conwidth || conheight_s != conheight)
147 draw_reset_cropped();
148 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
153 vidwidth_s = vidheight_s = vidpixelheight_s = 0; // retry next frame
157 string m_goto_buffer;
158 void m_init_delayed()
160 draw_reset_cropped();
162 menuInitialized = false;
163 if (!preMenuInit()) return;
164 menuInitialized = true;
167 if (cvar_string("menu_skin") != "")
169 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
170 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
172 if (fh < 0 && cvar_defstring("menu_skin") != "")
174 cvar_set("menu_skin", cvar_defstring("menu_skin"));
175 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
176 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
180 draw_currentSkin = "gfx/menu/default";
181 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
183 if (fh < 0) error("cannot load any menu skin\n");
184 draw_currentSkin = strzone(draw_currentSkin);
185 for (string s; (s = fgets(fh)); )
187 // these two are handled by skinlist.qc
188 if (substring(s, 0, 6) == "title ") continue;
189 if (substring(s, 0, 7) == "author ") continue;
190 int n = tokenize_console(s);
192 Skin_ApplySetting(argv(0), substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
196 int glob = search_begin(strcat(draw_currentSkin, "/*.tga"), true, true);
199 for (int i = 0, n = search_getsize(glob); i < n; ++i)
200 precache_pic(search_getfilename(glob, i));
204 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
206 anim = NEW(AnimHost);
207 main = NEW(MainWindow);
208 main.configureMainWindow(main);
210 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
213 menuMousePos = '0.5 0.5 0';
219 m_goto(m_goto_buffer);
220 strfree(m_goto_buffer);
223 if (Menu_Active) m_display(); // delayed menu display
225 cvar_set("_menu_initialized", "2");
228 void m_keyup(float key, float ascii)
230 if (!menuInitialized) return;
231 if (!Menu_Active) return;
232 draw_reset_cropped();
233 main.keyUp(main, key, ascii, menuShiftState);
234 if (key >= K_MOUSE1 && key <= K_MOUSE3)
236 --mouseButtonsPressed;
237 if (!mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
238 if (mouseButtonsPressed < 0)
240 mouseButtonsPressed = 0;
241 LOG_TRACE("Warning: released an already released button");
244 if (key == K_ALT) menuShiftState &= ~S_ALT;
245 if (key == K_CTRL) menuShiftState &= ~S_CTRL;
246 if (key == K_SHIFT) menuShiftState &= ~S_SHIFT;
249 void m_keydown(float key, float ascii)
251 if (!menuInitialized) return;
252 if (!Menu_Active) return;
254 if (menuMouseMode && key >= K_MOUSE1 && key <= K_MOUSE3)
256 // detect a click outside of the game window
257 vector p = getmousepos();
258 if (p.x < 0 || p.x > realconwidth || p.y < 0 || p.y > realconheight)
260 ++mouseButtonsPressed;
267 entity e = keyGrabber;
269 e.keyGrabbed(e, key, ascii);
273 draw_reset_cropped();
274 if (!mouseButtonsPressed && key >= K_MOUSE1 && key <= K_MOUSE3)
275 main.mousePress(main, menuMousePos);
276 if (!main.keyDown(main, key, ascii, menuShiftState))
278 // disable menu on unhandled ESC
280 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
284 if (key >= K_MOUSE1 && key <= K_MOUSE3)
286 ++mouseButtonsPressed;
287 if (mouseButtonsPressed > 10)
289 mouseButtonsPressed = 10;
290 LOG_TRACE("Warning: pressed an already pressed button");
293 if (key == K_ALT) menuShiftState |= S_ALT;
294 if (key == K_CTRL) menuShiftState |= S_CTRL;
295 if (key == K_SHIFT) menuShiftState |= S_SHIFT;
305 void draw_Picture_Aligned(vector algn, float scalemode, string img, float a)
307 vector sz = draw_PictureSize(img);
308 bool width_is_larger = (sz.x * draw_scale.y >= sz.y * draw_scale.x);
309 vector isz_w = '1 0 0' + '0 1 0' * ((sz.y / sz.x) * (draw_scale.x / draw_scale.y));
310 vector isz_h = '0 1 0' + '1 0 0' * ((sz.x / sz.y) * (draw_scale.y / draw_scale.x));
316 isz = (width_is_larger ? isz_h : isz_w);
318 case SCALEMODE_LETTERBOX:
319 isz = (width_is_larger ? isz_w : isz_h);
321 case SCALEMODE_WIDTH:
324 case SCALEMODE_HEIGHT:
327 case SCALEMODE_STRETCH:
331 vector org = eX * (algn.x * (1 - isz.x)) + eY * (algn.y * (1 - isz.y));
332 draw_Picture(org, img, isz, '1 1 1', a);
335 void drawBackground(string img, float a, string algn, float force1)
337 if (main.mainNexposee.ModalController_state == 0) return;
339 int scalemode = SCALEMODE_CROP;
340 int len = strlen(algn);
341 for (int i = 0, l = 0; i < len; ++i)
343 string c = substring(algn, i, 1);
347 scalemode = SCALEMODE_CROP;
350 scalemode = SCALEMODE_LETTERBOX;
353 scalemode = SCALEMODE_HEIGHT;
356 scalemode = SCALEMODE_WIDTH;
359 scalemode = SCALEMODE_STRETCH;
361 case "1": case "4": case "7":
364 case "2": case "5": case "8":
367 case "3": case "6": case "9":
376 case "7": case "8": case "9":
379 case "4": case "5": case "6":
382 case "1": case "2": case "3":
391 draw_Picture_Aligned(v, scalemode, img, a);
395 // force all secondary layers to use alpha 1. Prevents ugly issues
396 // with overlap. It's a flag because it cannot be used for the
398 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), 1);
402 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), a);
410 int menu_tooltips_old;
411 vector menuTooltipAveragedMousePos;
412 entity menuTooltipItem;
413 vector menuTooltipOrigin;
414 vector menuTooltipSize;
415 float menuTooltipAlpha;
416 string menuTooltipText;
417 int menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
418 bool m_testmousetooltipbox(vector pos)
421 (pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x)
422 && (pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y)
425 bool m_testtooltipbox(vector tooltippos)
427 if (tooltippos.x < 0) return false;
428 if (tooltippos.y < 0) return false;
429 if (tooltippos.x + menuTooltipSize.x > 1) return false;
430 if (tooltippos.y + menuTooltipSize.y > 1) return false;
431 menuTooltipOrigin = tooltippos;
434 bool m_allocatetooltipbox(vector pos)
437 avoidplus.x = (SKINAVOID_TOOLTIP_x + SKINSIZE_CURSOR_x - SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth;
438 avoidplus.y = (SKINAVOID_TOOLTIP_y + SKINSIZE_CURSOR_y - SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight;
442 avoidminus.x = (SKINAVOID_TOOLTIP_x + SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth + menuTooltipSize.x;
443 avoidminus.y = (SKINAVOID_TOOLTIP_y + SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight + menuTooltipSize.y;
447 vector v = pos + avoidplus;
448 if (m_testtooltipbox(v)) return true;
451 v.x = pos.x - menuTooltipSize.x * 0.5;
452 if (m_testtooltipbox(v)) return true;
455 v.x = pos.x - avoidminus.x;
456 if (m_testtooltipbox(v)) return true;
459 v.y = pos.y - avoidminus.y;
460 if (m_testtooltipbox(v)) return true;
463 v.x = pos.x - menuTooltipSize.x * 0.5;
464 if (m_testtooltipbox(v)) return true;
467 v.x = pos.x + avoidplus.x;
468 if (m_testtooltipbox(v)) return true;
472 entity m_findtooltipitem(entity root, vector pos)
475 for (entity it = root; it.instanceOfContainer; )
477 while (it.instanceOfNexposee && it.focusedChild)
479 it = it.focusedChild;
480 pos = globalToBox(pos, it.Container_origin, it.Container_size);
482 if (it.instanceOfNexposee)
484 it = it.itemFromPoint(it, pos);
485 if (it.tooltip) best = it;
486 else if (menu_tooltips == 2 && (it.controlledCvar || it.onClickCommand)) best = it;
489 else if (it.instanceOfModalController)
491 it = it.focusedChild;
495 it = it.itemFromPoint(it, pos);
498 if (it.tooltip) best = it;
499 else if (menu_tooltips == 2 && (it.controlledCvar || it.onClickCommand)) best = it;
500 pos = globalToBox(pos, it.Container_origin, it.Container_size);
507 if (menu_tooltips == 2)
510 if (menuTooltipItem.controlledCvar)
512 string cvar_list = getCvarsMulti(menuTooltipItem);
514 cvar_list = strcat(menuTooltipItem.controlledCvar, " ", cvar_list);
516 cvar_list = menuTooltipItem.controlledCvar;
517 s = strcat("[", cvar_list, " \"", cvar_string(menuTooltipItem.controlledCvar), "\"]");
519 else if (menuTooltipItem.onClickCommand)
521 s = strcat("<", menuTooltipItem.onClickCommand, ">");
525 return menuTooltipItem.tooltip;
527 if (menuTooltipItem.tooltip) return strcat(menuTooltipItem.tooltip, " ", s);
530 return menuTooltipItem.tooltip;
532 void m_tooltip(vector pos)
534 static string prev_tooltip;
536 menu_tooltips = cvar("menu_tooltips");
539 // don't return immediately, fade out the active tooltip first
540 if (menuTooltipItem == NULL) return;
542 menu_tooltips_old = menu_tooltips;
546 float f = bound(0, frametime * 2, 1);
547 menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + pos * f;
548 if (vdist(pos - menuTooltipAveragedMousePos, <, 0.01))
550 it = m_findtooltipitem(main, pos);
552 if (it.instanceOfListBox && it.isScrolling(it)) it = NULL;
554 if (it && prev_tooltip != it.tooltip)
556 // fade out if tooltip of a certain item has changed
557 menuTooltipState = 3;
558 strcpy(prev_tooltip, it.tooltip);
560 else if (menuTooltipItem && !m_testmousetooltipbox(pos))
562 menuTooltipState = 3; // fade out if mouse touches it
570 vector fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
572 // float menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
573 if (it != menuTooltipItem)
575 switch (menuTooltipState)
580 // another item: fade out first
581 menuTooltipState = 2;
586 menuTooltipState = 1;
587 menuTooltipItem = it;
589 menuTooltipOrigin.x = -1; // unallocated
591 strcpy(menuTooltipText, gettooltip());
595 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i)
597 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
600 float f = draw_TextWidth(s, false, fontsize);
603 menuTooltipSize.x = w + 2 * (SKINMARGIN_TOOLTIP_x / conwidth);
604 menuTooltipSize.y = i * fontsize.y + 2 * (SKINMARGIN_TOOLTIP_y / conheight);
605 menuTooltipSize.z = 0;
609 // changing item while fading in: fade out first
610 menuTooltipState = 2;
613 // changing item while fading out: can't
617 else if (menuTooltipState == 2) // re-fade in?
619 menuTooltipState = 1;
622 switch (menuTooltipState)
625 menuTooltipAlpha = bound(0, menuTooltipAlpha + 5 * frametime, 1);
626 if (menuTooltipAlpha == 1) menuTooltipState = 0;
629 case 3: // forced fade out
630 menuTooltipAlpha = bound(0, menuTooltipAlpha - 2 * frametime, 1);
631 if (menuTooltipAlpha == 0)
633 menuTooltipState = 0;
634 menuTooltipItem = NULL;
639 if (menuTooltipItem == NULL)
641 strfree(menuTooltipText);
646 if (menu_tooltips != menu_tooltips_old)
648 if (menu_tooltips != 0 && menu_tooltips_old != 0) menuTooltipItem = NULL; // reload tooltip next frame
649 menu_tooltips_old = menu_tooltips;
651 else if (menuTooltipOrigin.x < 0) // unallocated?
653 m_allocatetooltipbox(pos);
655 if (menuTooltipOrigin.x >= 0)
658 vector p = SKINBORDER_TOOLTIP;
660 p.y *= 1 / conheight;
661 draw_BorderPicture(menuTooltipOrigin, SKINGFX_TOOLTIP, menuTooltipSize, '1 1 1', menuTooltipAlpha, p);
662 p = menuTooltipOrigin;
663 p.x += SKINMARGIN_TOOLTIP_x / conwidth;
664 p.y += SKINMARGIN_TOOLTIP_y / conheight;
666 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i, p.y += fontsize.y)
668 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
671 draw_Text(p, s, fontsize, SKINCOLOR_TOOLTIP, SKINALPHA_TOOLTIP * menuTooltipAlpha, false);
677 const int MIN_DISCONNECTION_TIME = 1;
678 float autocvar_menu_force_on_disconnection;
679 bool autocvar_g_campaign;
680 void m_draw(float width, float height)
682 static float connected_time;
683 if (clientstate() == CS_DISCONNECTED)
685 if (connected_time && time - connected_time > MIN_DISCONNECTION_TIME)
687 if (autocvar_g_campaign)
689 // in the case player uses the disconnect command (in the console or with a key)
690 // reset g_campaign and update menu items to reflect cvar values that may have been restored after quiting the campaign
691 // see also LEAVEMATCH_CMD
692 cvar_set("g_campaign", "0");
695 if (autocvar_menu_force_on_disconnection > 0)
697 localcmd("\nmenu_cmd directmenu Welcome RESET\n");
702 connected_time = time;
706 execute_next_frame();
708 menuMouseMode = cvar("menu_mouse_absolute");
710 if (anim) anim.tickAll(anim);
712 UpdateConWidthHeight(width, height, cvar("vid_pixelheight"));
714 if (!menuInitialized)
716 // TODO draw an info image about this situation
720 if (!menuNotTheFirstFrame)
722 menuNotTheFirstFrame = true;
723 if (Menu_Active && !cvar("menu_video_played"))
725 localcmd("cd loop $menu_cdtrack\n");
726 // TODO: use this when we have a welcome sound
727 //localcmd("cd loop $menu_cdtrack; play sound/announcer/default/welcome.wav\n");
728 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME
730 // ALWAYS set this cvar; if we start but menu is not active, this means we want no background music!
731 localcmd("set menu_video_played 1\n");
735 float realFrametime = frametime = min(0.2, t - menuPrevTime);
739 t = cvar("menu_slowmo");
752 if (getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU)
753 && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
754 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
758 if (cvar("cl_capturevideo")) frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
760 prevMenuAlpha = menuAlpha;
763 if (menuAlpha == 0 && menuLogoAlpha < 2)
765 menuLogoAlpha += 2 * frametime;
769 menuAlpha = min(1, menuAlpha + 5 * frametime);
775 menuAlpha = max(0, menuAlpha - 5 * frametime);
779 draw_reset_cropped();
781 if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
783 if (menuLogoAlpha > 0)
786 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_BACKGROUND, 1);
787 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1), SKINALIGN_BACKGROUND, true);
788 draw_reset_cropped();
789 if (menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
791 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
792 draw_drawMousePointer(menuMousePos);
797 else if (SKINALPHA_BACKGROUND_INGAME)
802 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME,
803 SKINALIGN_BACKGROUND_INGAME, false);
804 draw_reset_cropped();
808 if (menuAlpha != prevMenuAlpha) cvar_set("_menu_alpha", ftos(menuAlpha));
810 draw_reset_cropped();
812 draw_reset_cropped();
816 if (prevMenuAlpha > 0) main.initializeDialog(main, main.firstChild);
817 draw_reset_cropped();
822 draw_alpha *= menuAlpha;
826 vector rawMousePos = getmousepos();
827 vector newMouse = globalToBox(rawMousePos, draw_shift, draw_scale);
828 if (rawMousePos != '0 0 0' && newMouse != menuMousePos)
830 menuMousePos = newMouse;
831 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
832 else main.mouseMove(main, menuMousePos);
835 else if (frametime > 0)
837 vector dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
838 if (dMouse != '0 0 0')
840 vector minpos = globalToBox('0 0 0', draw_shift, draw_scale);
841 vector maxpos = globalToBox(eX * (realconwidth - 1) + eY * (realconheight - 1), draw_shift, draw_scale);
842 dMouse = globalToBoxSize(dMouse, draw_scale);
843 menuMousePos += dMouse * cvar("menu_mouse_speed");
844 menuMousePos.x = bound(minpos.x, menuMousePos.x, maxpos.x);
845 menuMousePos.y = bound(minpos.y, menuMousePos.y, maxpos.y);
846 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
847 else main.mouseMove(main, menuMousePos);
852 m_tooltip(menuMousePos);
854 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
856 draw_drawMousePointer(menuMousePos);
858 draw_reset_cropped();
868 setkeydest(KEY_MENU);
869 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
871 if (!menuInitialized) return;
873 if (mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
874 mouseButtonsPressed = 0;
876 main.focusEnter(main);
877 main.showNotify(main);
883 setkeydest(KEY_GAME);
884 setmousetarget(MT_CLIENT);
886 if (!menuInitialized) return;
888 main.focusLeave(main);
889 main.hideNotify(main);
892 void m_toggle(int mode)
896 if (mode == 1) return;
901 if (mode == 0) return;
909 FOREACH_ENTITY_ORDERED(it.destroy, {
910 if (it.classname == "vtbl") continue;
915 void m_focus_item_chain(entity outermost, entity innermost)
917 if (innermost.parent != outermost) m_focus_item_chain(outermost, innermost.parent);
918 innermost.parent.setFocus(innermost.parent, innermost);
921 void m_activate_window(entity wnd)
923 entity par = wnd.parent;
924 if (par) m_activate_window(par);
926 if (par.instanceOfModalController)
928 if (wnd.tabSelectingButton)
930 TabButton_Click(wnd.tabSelectingButton, wnd);
933 par.initializeDialog(par, wnd);
935 else if (par.instanceOfNexposee)
937 // nexposee (sorry for violating abstraction here)
938 par.selectedChild = wnd;
939 par.animationState = 1;
940 Container_setFocus(par, NULL);
942 else if (par.instanceOfContainer)
945 if (par.focused) par.setFocus(par, wnd);
949 void m_setpointerfocus(entity wnd)
951 if (!wnd.instanceOfContainer) return;
952 entity focus = wnd.preferredFocusedGrandChild(wnd);
954 menuMousePos = focus.origin + 0.5 * focus.size;
955 menuMousePos.x *= 1 / conwidth;
956 menuMousePos.y *= 1 / conheight;
957 entity par = wnd.parent;
958 if (par.focused) par.setFocus(par, wnd);
959 if (wnd.focused) m_focus_item_chain(wnd, focus);
962 void m_goto(string itemname)
964 if (!menuInitialized)
966 strcpy(m_goto_buffer, itemname);
969 if (itemname == "") // this can be called by GameCommand
971 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
976 itemname = "nexposee";
979 if (itemname == "nexposee")
981 // unlike 'togglemenu 1', this closes modal and root dialogs if opened
982 m_activate_window(main.mainNexposee);
988 for (e = NULL; (e = find(e, name, itemname)); )
989 if (e.classname != "vtbl") break;
991 if ((e) && (!e.requiresConnection || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))))
994 e.hideMenuOnClose = true;
996 m_activate_window(e);
997 m_setpointerfocus(e);
1003 void m_play_focus_sound()
1005 static float menuLastFocusSoundTime;
1006 if (cvar("menu_sounds") < 2) return;
1007 if (time - menuLastFocusSoundTime <= 0.25) return;
1008 localsound(MENU_SOUND_FOCUS);
1009 menuLastFocusSoundTime = time;
1012 void m_play_click_sound(string soundfile)
1014 if (!cvar("menu_sounds")) return;
1015 localsound(soundfile);