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"
18 #include "xonotic/util.qh"
20 #include "../common/items/all.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")) 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_INFOF("^4MQC Build information: ^1%s\n", WATERMARK);
75 // list all game dirs (TEST)
76 if (cvar("developer"))
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 strunzone(m_goto_buffer);
221 m_goto_buffer = string_null;
224 if (Menu_Active) m_display(); // delayed menu display
227 void m_keyup(float key, float ascii)
229 if (!menuInitialized) return;
230 if (!Menu_Active) return;
231 draw_reset_cropped();
232 main.keyUp(main, key, ascii, menuShiftState);
233 if (key >= K_MOUSE1 && key <= K_MOUSE3)
235 --mouseButtonsPressed;
236 if (!mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
237 if (mouseButtonsPressed < 0)
239 mouseButtonsPressed = 0;
240 LOG_TRACE("Warning: released an already released button\n");
243 if (key == K_ALT) menuShiftState &= ~S_ALT;
244 if (key == K_CTRL) menuShiftState &= ~S_CTRL;
245 if (key == K_SHIFT) menuShiftState &= ~S_SHIFT;
248 void m_keydown(float key, float ascii)
250 if (!menuInitialized) return;
251 if (!Menu_Active) return;
253 if (menuMouseMode && key >= K_MOUSE1 && key <= K_MOUSE3)
255 // detect a click outside of the game window
256 vector p = getmousepos();
257 if (p.x < 0 || p.x > realconwidth || p.y < 0 || p.y > realconheight)
259 ++mouseButtonsPressed;
266 entity e = keyGrabber;
268 e.keyGrabbed(e, key, ascii);
272 draw_reset_cropped();
273 if (!mouseButtonsPressed && key >= K_MOUSE1 && key <= K_MOUSE3)
274 main.mousePress(main, menuMousePos);
275 if (!main.keyDown(main, key, ascii, menuShiftState))
277 // disable menu on unhandled ESC
279 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
283 if (key >= K_MOUSE1 && key <= K_MOUSE3)
285 ++mouseButtonsPressed;
286 if (mouseButtonsPressed > 10)
288 mouseButtonsPressed = 10;
289 LOG_TRACE("Warning: pressed an already pressed button\n");
292 if (key == K_ALT) menuShiftState |= S_ALT;
293 if (key == K_CTRL) menuShiftState |= S_CTRL;
294 if (key == K_SHIFT) menuShiftState |= S_SHIFT;
304 void draw_Picture_Aligned(vector algn, float scalemode, string img, float a)
306 vector sz = draw_PictureSize(img);
307 bool width_is_larger = (sz.x * draw_scale.y >= sz.y * draw_scale.x);
308 vector isz_w = '1 0 0' + '0 1 0' * ((sz.y / sz.x) * (draw_scale.x / draw_scale.y));
309 vector isz_h = '0 1 0' + '1 0 0' * ((sz.x / sz.y) * (draw_scale.y / draw_scale.x));
315 isz = (width_is_larger ? isz_h : isz_w);
317 case SCALEMODE_LETTERBOX:
318 isz = (width_is_larger ? isz_w : isz_h);
320 case SCALEMODE_WIDTH:
323 case SCALEMODE_HEIGHT:
326 case SCALEMODE_STRETCH:
330 vector org = eX * (algn.x * (1 - isz.x)) + eY * (algn.y * (1 - isz.y));
331 draw_Picture(org, img, isz, '1 1 1', a);
334 void drawBackground(string img, float a, string algn, float force1)
336 if (main.mainNexposee.ModalController_state == 0) return;
338 int scalemode = SCALEMODE_CROP;
339 for (int i = 0, l = 0; i < strlen(algn); ++i)
341 string c = substring(algn, i, 1);
345 scalemode = SCALEMODE_CROP;
348 scalemode = SCALEMODE_LETTERBOX;
351 scalemode = SCALEMODE_HEIGHT;
354 scalemode = SCALEMODE_WIDTH;
357 scalemode = SCALEMODE_STRETCH;
359 case "1": case "4": case "7":
362 case "2": case "5": case "8":
365 case "3": case "6": case "9":
374 case "7": case "8": case "9":
377 case "4": case "5": case "6":
380 case "1": case "2": case "3":
389 draw_Picture_Aligned(v, scalemode, img, a);
393 // force all secondary layers to use alpha 1. Prevents ugly issues
394 // with overlap. It's a flag because it cannot be used for the
396 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), 1);
400 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), a);
408 int menu_tooltips_old;
409 vector menuTooltipAveragedMousePos;
410 entity menuTooltipItem;
411 vector menuTooltipOrigin;
412 vector menuTooltipSize;
413 float menuTooltipAlpha;
414 string menuTooltipText;
415 int menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
416 bool m_testmousetooltipbox(vector pos)
419 (pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x)
420 && (pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y)
423 bool m_testtooltipbox(vector tooltippos)
425 if (tooltippos.x < 0) return false;
426 if (tooltippos.y < 0) return false;
427 if (tooltippos.x + menuTooltipSize.x > 1) return false;
428 if (tooltippos.y + menuTooltipSize.y > 1) return false;
429 menuTooltipOrigin = tooltippos;
432 bool m_allocatetooltipbox(vector pos)
435 avoidplus.x = (SKINAVOID_TOOLTIP_x + SKINSIZE_CURSOR_x - SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth;
436 avoidplus.y = (SKINAVOID_TOOLTIP_y + SKINSIZE_CURSOR_y - SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight;
440 avoidminus.x = (SKINAVOID_TOOLTIP_x + SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth + menuTooltipSize.x;
441 avoidminus.y = (SKINAVOID_TOOLTIP_y + SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight + menuTooltipSize.y;
445 vector v = pos + avoidplus;
446 if (m_testtooltipbox(v)) return true;
449 v.x = pos.x - menuTooltipSize.x * 0.5;
450 if (m_testtooltipbox(v)) return true;
453 v.x = pos.x - avoidminus.x;
454 if (m_testtooltipbox(v)) return true;
457 v.y = pos.y - avoidminus.y;
458 if (m_testtooltipbox(v)) return true;
461 v.x = pos.x - menuTooltipSize.x * 0.5;
462 if (m_testtooltipbox(v)) return true;
465 v.x = pos.x + avoidplus.x;
466 if (m_testtooltipbox(v)) return true;
470 entity m_findtooltipitem(entity root, vector pos)
473 for (entity it = root; it.instanceOfContainer; )
475 while (it.instanceOfNexposee && it.focusedChild)
477 it = it.focusedChild;
478 pos = globalToBox(pos, it.Container_origin, it.Container_size);
480 if (it.instanceOfNexposee)
482 it = it.itemFromPoint(it, pos);
483 if (it.tooltip) best = it;
484 else if (menu_tooltips == 2 && (it.cvarName || it.onClickCommand)) best = it;
487 else if (it.instanceOfModalController)
489 it = it.focusedChild;
493 it = it.itemFromPoint(it, pos);
496 if (it.tooltip) best = it;
497 else if (menu_tooltips == 2 && (it.cvarName || it.onClickCommand)) best = it;
498 pos = globalToBox(pos, it.Container_origin, it.Container_size);
505 if (menu_tooltips == 2)
508 if (menuTooltipItem.cvarName)
510 if (getCvarsMulti(menuTooltipItem)) s =
511 strcat("[", menuTooltipItem.cvarName, " ", getCvarsMulti(menuTooltipItem), "]");
512 else s = strcat("[", menuTooltipItem.cvarName, "]");
514 else if (menuTooltipItem.onClickCommand)
516 s = strcat("<", menuTooltipItem.onClickCommand, ">");
520 return menuTooltipItem.tooltip;
522 if (menuTooltipItem.tooltip) return strcat(menuTooltipItem.tooltip, " ", s);
525 return menuTooltipItem.tooltip;
527 void m_tooltip(vector pos)
529 static string prev_tooltip;
531 menu_tooltips = cvar("menu_tooltips");
534 // don't return immediately, fade out the active tooltip first
535 if (menuTooltipItem == NULL) return;
537 menu_tooltips_old = menu_tooltips;
541 float f = bound(0, frametime * 2, 1);
542 menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + pos * f;
543 if (vdist(pos - menuTooltipAveragedMousePos, <, 0.01))
545 it = m_findtooltipitem(main, pos);
547 if (it.instanceOfListBox && it.isScrolling(it)) it = NULL;
549 if (it && prev_tooltip != it.tooltip)
551 // fade out if tooltip of a certain item has changed
552 menuTooltipState = 3;
553 if (prev_tooltip) strunzone(prev_tooltip);
554 prev_tooltip = strzone(it.tooltip);
556 else if (menuTooltipItem && !m_testmousetooltipbox(pos))
558 menuTooltipState = 3; // fade out if mouse touches it
566 vector fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
568 // float menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
569 if (it != menuTooltipItem)
571 switch (menuTooltipState)
576 // another item: fade out first
577 menuTooltipState = 2;
582 menuTooltipState = 1;
583 menuTooltipItem = it;
585 menuTooltipOrigin.x = -1; // unallocated
587 if (menuTooltipText) strunzone(menuTooltipText);
588 menuTooltipText = strzone(gettooltip());
592 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i)
594 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
597 float f = draw_TextWidth(s, false, fontsize);
600 menuTooltipSize.x = w + 2 * (SKINMARGIN_TOOLTIP_x / conwidth);
601 menuTooltipSize.y = i * fontsize.y + 2 * (SKINMARGIN_TOOLTIP_y / conheight);
602 menuTooltipSize.z = 0;
606 // changing item while fading in: fade out first
607 menuTooltipState = 2;
610 // changing item while fading out: can't
614 else if (menuTooltipState == 2) // re-fade in?
616 menuTooltipState = 1;
619 switch (menuTooltipState)
622 menuTooltipAlpha = bound(0, menuTooltipAlpha + 5 * frametime, 1);
623 if (menuTooltipAlpha == 1) menuTooltipState = 0;
626 case 3: // forced fade out
627 menuTooltipAlpha = bound(0, menuTooltipAlpha - 2 * frametime, 1);
628 if (menuTooltipAlpha == 0)
630 menuTooltipState = 0;
631 menuTooltipItem = NULL;
636 if (menuTooltipItem == NULL)
640 strunzone(menuTooltipText);
641 menuTooltipText = string_null;
647 if (menu_tooltips != menu_tooltips_old)
649 if (menu_tooltips != 0 && menu_tooltips_old != 0) menuTooltipItem = NULL; // reload tooltip next frame
650 menu_tooltips_old = menu_tooltips;
652 else if (menuTooltipOrigin.x < 0) // unallocated?
654 m_allocatetooltipbox(pos);
656 if (menuTooltipOrigin.x >= 0)
659 vector p = SKINBORDER_TOOLTIP;
661 p.y *= 1 / conheight;
662 draw_BorderPicture(menuTooltipOrigin, SKINGFX_TOOLTIP, menuTooltipSize, '1 1 1', menuTooltipAlpha, p);
663 p = menuTooltipOrigin;
664 p.x += SKINMARGIN_TOOLTIP_x / conwidth;
665 p.y += SKINMARGIN_TOOLTIP_y / conheight;
667 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i, p.y += fontsize.y)
669 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
672 draw_Text(p, s, fontsize, SKINCOLOR_TOOLTIP, SKINALPHA_TOOLTIP * menuTooltipAlpha, false);
678 float autocvar_menu_force_on_disconnection;
679 void m_draw(float width, float height)
681 if (autocvar_menu_force_on_disconnection > 0)
683 static float connected_time;
684 if (clientstate() == CS_DISCONNECTED)
686 if (connected_time && time - connected_time > autocvar_menu_force_on_disconnection)
693 connected_time = time;
698 execute_next_frame();
700 menuMouseMode = cvar("menu_mouse_absolute");
702 if (anim) anim.tickAll(anim);
704 UpdateConWidthHeight(width, height, cvar("vid_pixelheight"));
706 if (!menuInitialized)
708 // TODO draw an info image about this situation
712 if (!menuNotTheFirstFrame)
714 menuNotTheFirstFrame = true;
715 if (Menu_Active && !cvar("menu_video_played"))
717 localcmd("cd loop $menu_cdtrack; play sound/announcer/default/welcome.wav\n");
718 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME
720 // ALWAYS set this cvar; if we start but menu is not active, this means we want no background music!
721 localcmd("set menu_video_played 1\n");
725 float realFrametime = frametime = min(0.2, t - menuPrevTime);
729 t = cvar("menu_slowmo");
742 if (getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU)
743 && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
744 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
748 if (cvar("cl_capturevideo")) frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
750 prevMenuAlpha = menuAlpha;
753 if (menuAlpha == 0 && menuLogoAlpha < 2)
755 menuLogoAlpha += 2 * frametime;
759 menuAlpha = min(1, menuAlpha + 5 * frametime);
765 menuAlpha = max(0, menuAlpha - 5 * frametime);
769 draw_reset_cropped();
771 if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
773 if (menuLogoAlpha > 0)
776 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_BACKGROUND, 1);
777 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1), SKINALIGN_BACKGROUND, true);
778 draw_reset_cropped();
779 if (menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
781 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
782 draw_drawMousePointer(menuMousePos);
787 else if (SKINALPHA_BACKGROUND_INGAME)
792 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME,
793 SKINALIGN_BACKGROUND_INGAME, false);
794 draw_reset_cropped();
798 if (menuAlpha != prevMenuAlpha) cvar_set("_menu_alpha", ftos(menuAlpha));
800 draw_reset_cropped();
802 draw_reset_cropped();
806 if (prevMenuAlpha > 0) main.initializeDialog(main, main.firstChild);
807 draw_reset_cropped();
812 draw_alpha *= menuAlpha;
816 vector rawMousePos = getmousepos();
817 vector newMouse = globalToBox(rawMousePos, draw_shift, draw_scale);
818 if (rawMousePos != '0 0 0' && newMouse != menuMousePos)
820 menuMousePos = newMouse;
821 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
822 else main.mouseMove(main, menuMousePos);
825 else if (frametime > 0)
827 vector dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
828 if (dMouse != '0 0 0')
830 vector minpos = globalToBox('0 0 0', draw_shift, draw_scale);
831 vector maxpos = globalToBox(eX * (realconwidth - 1) + eY * (realconheight - 1), draw_shift, draw_scale);
832 dMouse = globalToBoxSize(dMouse, draw_scale);
833 menuMousePos += dMouse * cvar("menu_mouse_speed");
834 menuMousePos.x = bound(minpos.x, menuMousePos.x, maxpos.x);
835 menuMousePos.y = bound(minpos.y, menuMousePos.y, maxpos.y);
836 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
837 else main.mouseMove(main, menuMousePos);
842 m_tooltip(menuMousePos);
844 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
846 draw_drawMousePointer(menuMousePos);
848 draw_reset_cropped();
858 setkeydest(KEY_MENU);
859 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
861 if (!menuInitialized) return;
863 if (mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
864 mouseButtonsPressed = 0;
866 main.focusEnter(main);
867 main.showNotify(main);
873 setkeydest(KEY_GAME);
874 setmousetarget(MT_CLIENT);
876 if (!menuInitialized) return;
878 main.focusLeave(main);
879 main.hideNotify(main);
882 void m_toggle(int mode)
886 if (mode == 1) return;
891 if (mode == 0) return;
899 FOREACH_ENTITY_ORDERED(it.destroy, {
900 if (it.classname == "vtbl") continue;
905 void m_focus_item_chain(entity outermost, entity innermost)
907 if (innermost.parent != outermost) m_focus_item_chain(outermost, innermost.parent);
908 innermost.parent.setFocus(innermost.parent, innermost);
911 void m_activate_window(entity wnd)
913 entity par = wnd.parent;
914 if (par) m_activate_window(par);
916 if (par.instanceOfModalController)
918 if (wnd.tabSelectingButton)
920 TabButton_Click(wnd.tabSelectingButton, wnd);
923 par.initializeDialog(par, wnd);
925 else if (par.instanceOfNexposee)
927 // nexposee (sorry for violating abstraction here)
928 par.selectedChild = wnd;
929 par.animationState = 1;
930 Container_setFocus(par, NULL);
932 else if (par.instanceOfContainer)
935 if (par.focused) par.setFocus(par, wnd);
939 void m_setpointerfocus(entity wnd)
941 if (!wnd.instanceOfContainer) return;
942 entity focus = wnd.preferredFocusedGrandChild(wnd);
944 menuMousePos = focus.origin + 0.5 * focus.size;
945 menuMousePos.x *= 1 / conwidth;
946 menuMousePos.y *= 1 / conheight;
947 entity par = wnd.parent;
948 if (par.focused) par.setFocus(par, wnd);
949 if (wnd.focused) m_focus_item_chain(wnd, focus);
952 void m_goto(string itemname)
954 if (!menuInitialized)
956 if (m_goto_buffer) strunzone(m_goto_buffer);
957 m_goto_buffer = strzone(itemname);
960 if (itemname == "") // this can be called by GameCommand
962 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
968 m_activate_window(main.mainNexposee);
975 for (e = NULL; (e = find(e, name, itemname)); )
976 if (e.classname != "vtbl") break;
978 if ((e) && (!e.requiresConnection || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))))
981 m_activate_window(e);
982 m_setpointerfocus(e);
988 void m_play_focus_sound()
990 static float menuLastFocusSoundTime;
991 if (cvar("menu_sounds") < 2) return;
992 if (time - menuLastFocusSoundTime <= 0.25) return;
993 localsound(MENU_SOUND_FOCUS);
994 menuLastFocusSoundTime = time;
997 void m_play_click_sound(string soundfile)
999 if (!cvar("menu_sounds")) return;
1000 localsound(soundfile);