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;
35 // Used for having effects only execute once in main menu, not for every reload
36 // 0: never been in main menu before. 1: coming back to main menu. 2: in main menu.
37 int menuNotTheFirstFrame;
38 bool autocvar_menu_no_music_nor_welcome;
40 float conwidth_s, conheight_s;
41 float vidwidth_s, vidheight_s, vidpixelheight_s;
42 float realconwidth, realconheight;
47 vidwidth_s = vidheight_s = vidpixelheight_s = 0; // Force updateConwidths on next draw
55 if (isserver()) gamestatus |= GAME_ISSERVER;
56 if (clientstate() == CS_CONNECTED || isdemo()) gamestatus |= GAME_CONNECTED;
57 if (cvar("developer") > 0) gamestatus |= GAME_DEVELOPER;
62 bool restarting = false;
63 cvar_set("_menu_alpha", "0");
64 prvm_language = cvar_string("prvm_language");
65 if (prvm_language == "")
68 cvar_set("prvm_language", prvm_language);
69 localcmd("\nmenu_restart\n");
72 prvm_language = strzone(prvm_language);
73 cvar_set("_menu_prvm_language", prvm_language);
76 LOG_TRACEF("^4MQC Build information: ^1%s", WATERMARK);
79 // list all game dirs (TEST)
80 if (cvar("developer") > 0)
82 for (int i = 0; ; ++i)
84 string s = getgamedirinfo(i, GETGAMEDIRINFO_NAME);
86 LOG_TRACE(s, ": ", getgamedirinfo(i, GETGAMEDIRINFO_DESCRIPTION));
90 registercvar("_menu_cmd_closemenu_available", "0", 0);
91 cvar_set("_menu_cmd_closemenu_available", "1");
93 // needs to be done so early because of the constants they create
96 static_init_precache();
98 RegisterSLCategories();
100 float ddsload = cvar("r_texture_dds_load");
101 float texcomp = cvar("gl_texturecompression");
103 if (ddsload != cvar("r_texture_dds_load") || texcomp != cvar("gl_texturecompression")) localcmd("\nr_restart\n");
107 if (cvar("_menu_initialized")) // always show menu after menu_restart
110 cvar_set("_menu_initialized", "1");
114 const float MENU_ASPECT = 1280 / 1024;
116 void draw_reset_cropped()
118 draw_reset(conwidth, conheight, 0.5 * (realconwidth - conwidth), 0.5 * (realconheight - conheight));
120 void draw_reset_full()
122 draw_reset(realconwidth, realconheight, 0, 0);
125 void UpdateConWidthHeight(float w, float h, float p)
127 if (w != vidwidth_s || h != vidheight_s || p != vidpixelheight_s)
129 if (updateConwidths(w, h, p)) localcmd(sprintf("\nexec %s\n", cvar_string("menu_font_cfg")));
132 vidpixelheight_s = p;
134 conwidth_s = conwidth;
135 conheight_s = conheight;
136 realconwidth = cvar("vid_conwidth");
137 realconheight = cvar("vid_conheight");
138 if (realconwidth / realconheight > MENU_ASPECT)
141 conwidth = realconheight * MENU_ASPECT;
142 conheight = realconheight;
147 conwidth = realconwidth;
148 conheight = realconwidth / MENU_ASPECT;
152 if (conwidth_s != conwidth || conheight_s != conheight)
154 draw_reset_cropped();
155 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
160 vidwidth_s = vidheight_s = vidpixelheight_s = 0; // retry next frame
164 string m_goto_buffer;
165 void m_init_delayed()
167 draw_reset_cropped();
169 menuInitialized = false;
170 if (!preMenuInit()) return;
171 menuInitialized = true;
174 if (cvar_string("menu_skin") != "")
176 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
177 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
179 if (fh < 0 && cvar_defstring("menu_skin") != "")
181 cvar_set("menu_skin", cvar_defstring("menu_skin"));
182 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
183 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
187 draw_currentSkin = "gfx/menu/default";
188 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
190 if (fh < 0) error("cannot load any menu skin\n");
191 draw_currentSkin = strzone(draw_currentSkin);
192 for (string s; (s = fgets(fh)); )
194 // these two are handled by skinlist.qc
195 if (substring(s, 0, 6) == "title ") continue;
196 if (substring(s, 0, 7) == "author ") continue;
197 int n = tokenize_console(s);
199 Skin_ApplySetting(argv(0), substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
203 int glob = search_begin(strcat(draw_currentSkin, "/*.tga"), true, true);
206 for (int i = 0, n = search_getsize(glob); i < n; ++i)
207 precache_pic(search_getfilename(glob, i));
211 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
213 anim = NEW(AnimHost);
214 main = NEW(MainWindow);
215 main.configureMainWindow(main);
217 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
220 menuMousePos = '0.5 0.5 0';
226 m_goto(m_goto_buffer);
227 strfree(m_goto_buffer);
230 if (Menu_Active) m_display(); // delayed menu display
232 cvar_set("_menu_initialized", "2");
235 void m_keyup(float key, float ascii)
237 if (!menuInitialized) return;
238 if (!Menu_Active) return;
239 draw_reset_cropped();
240 main.keyUp(main, key, ascii, menuShiftState);
241 if (key >= K_MOUSE1 && key <= K_MOUSE3)
243 --mouseButtonsPressed;
244 if (!mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
245 if (mouseButtonsPressed < 0)
247 mouseButtonsPressed = 0;
248 LOG_TRACE("Warning: released an already released button");
251 if (key == K_ALT) menuShiftState &= ~S_ALT;
252 if (key == K_CTRL) menuShiftState &= ~S_CTRL;
253 if (key == K_SHIFT) menuShiftState &= ~S_SHIFT;
256 void m_keydown(float key, float ascii)
258 if (!menuInitialized) return;
259 if (!Menu_Active) return;
261 if (menuMouseMode && key >= K_MOUSE1 && key <= K_MOUSE3)
263 // detect a click outside of the game window
264 vector p = getmousepos();
265 if (p.x < 0 || p.x > realconwidth || p.y < 0 || p.y > realconheight)
267 ++mouseButtonsPressed;
274 entity e = keyGrabber;
276 e.keyGrabbed(e, key, ascii);
280 draw_reset_cropped();
281 if (!mouseButtonsPressed && key >= K_MOUSE1 && key <= K_MOUSE3)
282 main.mousePress(main, menuMousePos);
283 if (!main.keyDown(main, key, ascii, menuShiftState))
285 // disable menu on unhandled ESC
287 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
291 if (key >= K_MOUSE1 && key <= K_MOUSE3)
293 ++mouseButtonsPressed;
294 if (mouseButtonsPressed > 10)
296 mouseButtonsPressed = 10;
297 LOG_TRACE("Warning: pressed an already pressed button");
300 if (key == K_ALT) menuShiftState |= S_ALT;
301 if (key == K_CTRL) menuShiftState |= S_CTRL;
302 if (key == K_SHIFT) menuShiftState |= S_SHIFT;
312 void draw_Picture_Aligned(vector algn, float scalemode, string img, float a)
314 vector sz = draw_PictureSize(img);
315 bool width_is_larger = (sz.x * draw_scale.y >= sz.y * draw_scale.x);
316 vector isz_w = '1 0 0' + '0 1 0' * ((sz.y / sz.x) * (draw_scale.x / draw_scale.y));
317 vector isz_h = '0 1 0' + '1 0 0' * ((sz.x / sz.y) * (draw_scale.y / draw_scale.x));
323 isz = (width_is_larger ? isz_h : isz_w);
325 case SCALEMODE_LETTERBOX:
326 isz = (width_is_larger ? isz_w : isz_h);
328 case SCALEMODE_WIDTH:
331 case SCALEMODE_HEIGHT:
334 case SCALEMODE_STRETCH:
338 vector org = eX * (algn.x * (1 - isz.x)) + eY * (algn.y * (1 - isz.y));
339 draw_Picture(org, img, isz, '1 1 1', a);
342 void drawBackground(string img, float a, string algn, float force1)
344 if (main.mainNexposee.ModalController_state == 0) return;
346 int scalemode = SCALEMODE_CROP;
347 int len = strlen(algn);
348 for (int i = 0, l = 0; i < len; ++i)
350 string c = substring(algn, i, 1);
354 scalemode = SCALEMODE_CROP;
357 scalemode = SCALEMODE_LETTERBOX;
360 scalemode = SCALEMODE_HEIGHT;
363 scalemode = SCALEMODE_WIDTH;
366 scalemode = SCALEMODE_STRETCH;
368 case "1": case "4": case "7":
371 case "2": case "5": case "8":
374 case "3": case "6": case "9":
383 case "7": case "8": case "9":
386 case "4": case "5": case "6":
389 case "1": case "2": case "3":
398 draw_Picture_Aligned(v, scalemode, img, a);
402 // force all secondary layers to use alpha 1. Prevents ugly issues
403 // with overlap. It's a flag because it cannot be used for the
405 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), 1);
409 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), a);
417 int menu_tooltips_old;
418 vector menuTooltipAveragedMousePos;
419 entity menuTooltipItem;
420 vector menuTooltipOrigin;
421 vector menuTooltipSize;
422 float menuTooltipAlpha;
423 string menuTooltipText;
424 int menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
425 bool m_testmousetooltipbox(vector pos)
428 (pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x)
429 && (pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y)
432 bool m_testtooltipbox(vector tooltippos)
434 if (tooltippos.x < 0) return false;
435 if (tooltippos.y < 0) return false;
436 if (tooltippos.x + menuTooltipSize.x > 1) return false;
437 if (tooltippos.y + menuTooltipSize.y > 1) return false;
438 menuTooltipOrigin = tooltippos;
441 bool m_allocatetooltipbox(vector pos)
444 avoidplus.x = (SKINAVOID_TOOLTIP_x + SKINSIZE_CURSOR_x - SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth;
445 avoidplus.y = (SKINAVOID_TOOLTIP_y + SKINSIZE_CURSOR_y - SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight;
449 avoidminus.x = (SKINAVOID_TOOLTIP_x + SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth + menuTooltipSize.x;
450 avoidminus.y = (SKINAVOID_TOOLTIP_y + SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight + menuTooltipSize.y;
454 vector v = pos + avoidplus;
455 if (m_testtooltipbox(v)) return true;
458 v.x = pos.x - menuTooltipSize.x * 0.5;
459 if (m_testtooltipbox(v)) return true;
462 v.x = pos.x - avoidminus.x;
463 if (m_testtooltipbox(v)) return true;
466 v.y = pos.y - avoidminus.y;
467 if (m_testtooltipbox(v)) return true;
470 v.x = pos.x - menuTooltipSize.x * 0.5;
471 if (m_testtooltipbox(v)) return true;
474 v.x = pos.x + avoidplus.x;
475 if (m_testtooltipbox(v)) return true;
479 entity m_findtooltipitem(entity root, vector pos)
482 for (entity it = root; it.instanceOfContainer; )
484 while (it.instanceOfNexposee && it.focusedChild)
486 it = it.focusedChild;
487 pos = globalToBox(pos, it.Container_origin, it.Container_size);
489 if (it.instanceOfNexposee)
491 it = it.itemFromPoint(it, pos);
492 if (it.tooltip) best = it;
493 else if (menu_tooltips == 2 && (it.controlledCvar || it.onClickCommand)) best = it;
496 else if (it.instanceOfModalController)
498 it = it.focusedChild;
502 it = it.itemFromPoint(it, pos);
505 if (it.tooltip) best = it;
506 else if (menu_tooltips == 2 && (it.controlledCvar || it.onClickCommand)) best = it;
507 pos = globalToBox(pos, it.Container_origin, it.Container_size);
514 if (menu_tooltips == 2)
517 if (menuTooltipItem.controlledCvar)
519 string cvar_list = getCvarsMulti(menuTooltipItem);
521 cvar_list = strcat(menuTooltipItem.controlledCvar, " ", cvar_list);
523 cvar_list = menuTooltipItem.controlledCvar;
524 s = strcat("[", cvar_list, " \"", cvar_string(menuTooltipItem.controlledCvar), "\"]");
526 else if (menuTooltipItem.onClickCommand)
528 s = strcat("<", menuTooltipItem.onClickCommand, ">");
532 return menuTooltipItem.tooltip;
534 if (menuTooltipItem.tooltip) return strcat(menuTooltipItem.tooltip, " ", s);
537 return menuTooltipItem.tooltip;
539 void m_tooltip(vector pos)
541 static string prev_tooltip;
543 menu_tooltips = cvar("menu_tooltips");
546 // don't return immediately, fade out the active tooltip first
547 if (menuTooltipItem == NULL) return;
549 menu_tooltips_old = menu_tooltips;
553 float f = bound(0, frametime * 2, 1);
554 menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + pos * f;
555 if (vdist(pos - menuTooltipAveragedMousePos, <, 0.01))
557 it = m_findtooltipitem(main, pos);
559 if (it.instanceOfListBox && it.isScrolling(it)) it = NULL;
561 if (it && prev_tooltip != it.tooltip)
563 // fade out if tooltip of a certain item has changed
564 menuTooltipState = 3;
565 strcpy(prev_tooltip, it.tooltip);
567 else if (menuTooltipItem && !m_testmousetooltipbox(pos))
569 menuTooltipState = 3; // fade out if mouse touches it
577 vector fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
579 // float menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
580 if (it != menuTooltipItem)
582 switch (menuTooltipState)
587 // another item: fade out first
588 menuTooltipState = 2;
593 menuTooltipState = 1;
594 menuTooltipItem = it;
596 menuTooltipOrigin.x = -1; // unallocated
598 strcpy(menuTooltipText, gettooltip());
602 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i)
604 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
607 float f = draw_TextWidth(s, false, fontsize);
610 menuTooltipSize.x = w + 2 * (SKINMARGIN_TOOLTIP_x / conwidth);
611 menuTooltipSize.y = i * fontsize.y + 2 * (SKINMARGIN_TOOLTIP_y / conheight);
612 menuTooltipSize.z = 0;
616 // changing item while fading in: fade out first
617 menuTooltipState = 2;
620 // changing item while fading out: can't
624 else if (menuTooltipState == 2) // re-fade in?
626 menuTooltipState = 1;
629 switch (menuTooltipState)
632 menuTooltipAlpha = bound(0, menuTooltipAlpha + 5 * frametime, 1);
633 if (menuTooltipAlpha == 1) menuTooltipState = 0;
636 case 3: // forced fade out
637 menuTooltipAlpha = bound(0, menuTooltipAlpha - 2 * frametime, 1);
638 if (menuTooltipAlpha == 0)
640 menuTooltipState = 0;
641 menuTooltipItem = NULL;
646 if (menuTooltipItem == NULL)
648 strfree(menuTooltipText);
653 if (menu_tooltips != menu_tooltips_old)
655 if (menu_tooltips != 0 && menu_tooltips_old != 0) menuTooltipItem = NULL; // reload tooltip next frame
656 menu_tooltips_old = menu_tooltips;
658 else if (menuTooltipOrigin.x < 0) // unallocated?
660 m_allocatetooltipbox(pos);
662 if (menuTooltipOrigin.x >= 0)
665 vector p = SKINBORDER_TOOLTIP;
667 p.y *= 1 / conheight;
668 draw_BorderPicture(menuTooltipOrigin, SKINGFX_TOOLTIP, menuTooltipSize, '1 1 1', menuTooltipAlpha, p);
669 p = menuTooltipOrigin;
670 p.x += SKINMARGIN_TOOLTIP_x / conwidth;
671 p.y += SKINMARGIN_TOOLTIP_y / conheight;
673 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i, p.y += fontsize.y)
675 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
678 draw_Text(p, s, fontsize, SKINCOLOR_TOOLTIP, SKINALPHA_TOOLTIP * menuTooltipAlpha, false);
684 const int MIN_DISCONNECTION_TIME = 1;
685 bool autocvar_g_campaign;
686 void m_draw(float width, float height)
688 static float connected_time;
689 if (clientstate() == CS_DISCONNECTED)
691 // avoid a bug where the main menu re-opens when changing maps
692 // potentially exclusive to `map <mapname>` cmd?
693 if (connected_time && time - connected_time > MIN_DISCONNECTION_TIME)
695 if (autocvar_g_campaign)
697 // in the case player uses the disconnect command (in the console or with a key)
698 // reset g_campaign and update menu items to reflect cvar values that may have been restored after quiting the campaign
699 // see also LEAVEMATCH_CMD
700 cvar_set("g_campaign", "0");
704 // reload the menu so that disconnecting players don't
705 // have to press ESC to open it again
708 localcmd("\nmenu_cmd directmenu Welcome RESET\n");
712 // FIXME?: find out if anything should be done to reset it more,
713 // this is just a fix to make main menu music replay nicely
714 menuNotTheFirstFrame = 1;
718 connected_time = time;
722 execute_next_frame();
724 menuMouseMode = cvar("menu_mouse_absolute");
726 if (anim) anim.tickAll(anim);
728 UpdateConWidthHeight(width, height, cvar("vid_pixelheight"));
730 if (!menuInitialized)
732 // TODO draw an info image about this situation
737 if (menuNotTheFirstFrame == 0) // only fade the menu in once ever
738 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME
740 if (menuNotTheFirstFrame <= 1) // only once per menu reload
742 if (Menu_Active && !autocvar_menu_no_music_nor_welcome)
744 localcmd("cd loop $menu_cdtrack\n");
746 // TODO: enable this when we have a welcome sound
747 // FIXME: change the file used according to the selected announcer
748 // Only play the welcome announcement once, not on any menu reloads
749 //if (menuNotTheFirstFrame == 0)
750 //localcmd("play sound/announcer/default/welcome.wav\n");
753 menuNotTheFirstFrame = 2;
757 float realFrametime = frametime = min(0.2, t - menuPrevTime);
761 t = cvar("menu_slowmo");
774 if (getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU)
775 && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
776 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
780 if (cvar("cl_capturevideo")) frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
782 prevMenuAlpha = menuAlpha;
785 if (menuAlpha == 0 && menuLogoAlpha < 2)
787 menuLogoAlpha += 2 * frametime;
791 menuAlpha = min(1, menuAlpha + 5 * frametime);
797 menuAlpha = max(0, menuAlpha - 5 * frametime);
801 draw_reset_cropped();
803 if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
805 if (menuLogoAlpha > 0)
808 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_BACKGROUND, 1);
809 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1), SKINALIGN_BACKGROUND, true);
810 draw_reset_cropped();
811 if (menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
813 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
814 draw_drawMousePointer(menuMousePos);
819 else if (SKINALPHA_BACKGROUND_INGAME)
824 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME,
825 SKINALIGN_BACKGROUND_INGAME, false);
826 draw_reset_cropped();
830 if (menuAlpha != prevMenuAlpha) cvar_set("_menu_alpha", ftos(menuAlpha));
832 draw_reset_cropped();
834 draw_reset_cropped();
838 if (prevMenuAlpha > 0) main.initializeDialog(main, main.firstChild);
839 draw_reset_cropped();
844 draw_alpha *= menuAlpha;
848 vector rawMousePos = getmousepos();
849 vector newMouse = globalToBox(rawMousePos, draw_shift, draw_scale);
850 if (rawMousePos != '0 0 0' && newMouse != menuMousePos)
852 menuMousePos = newMouse;
853 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
854 else main.mouseMove(main, menuMousePos);
857 else if (frametime > 0)
859 vector dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
860 if (dMouse != '0 0 0')
862 vector minpos = globalToBox('0 0 0', draw_shift, draw_scale);
863 vector maxpos = globalToBox(eX * (realconwidth - 1) + eY * (realconheight - 1), draw_shift, draw_scale);
864 dMouse = globalToBoxSize(dMouse, draw_scale);
865 menuMousePos += dMouse * cvar("menu_mouse_speed");
866 menuMousePos.x = bound(minpos.x, menuMousePos.x, maxpos.x);
867 menuMousePos.y = bound(minpos.y, menuMousePos.y, maxpos.y);
868 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
869 else main.mouseMove(main, menuMousePos);
874 m_tooltip(menuMousePos);
876 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
878 draw_drawMousePointer(menuMousePos);
880 draw_reset_cropped();
890 setkeydest(KEY_MENU);
891 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
893 if (!menuInitialized) return;
895 if (mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
896 mouseButtonsPressed = 0;
898 main.focusEnter(main);
899 main.showNotify(main);
905 setkeydest(KEY_GAME);
906 setmousetarget(MT_CLIENT);
908 if (!menuInitialized) return;
910 main.focusLeave(main);
911 main.hideNotify(main);
914 void m_toggle(int mode)
918 if (mode == 1) return;
923 if (mode == 0) return;
931 FOREACH_ENTITY_ORDERED(it.destroy, {
932 if (it.classname == "vtbl") continue;
935 cvar_set("_menu_cmd_closemenu_available", "0");
938 void m_focus_item_chain(entity outermost, entity innermost)
940 if (innermost.parent != outermost) m_focus_item_chain(outermost, innermost.parent);
941 innermost.parent.setFocus(innermost.parent, innermost);
944 void m_activate_window(entity wnd)
946 entity par = wnd.parent;
947 if (par) m_activate_window(par);
949 if (par.instanceOfModalController)
951 if (wnd.tabSelectingButton)
953 TabButton_Click(wnd.tabSelectingButton, wnd);
956 par.initializeDialog(par, wnd);
958 else if (par.instanceOfNexposee)
960 // nexposee (sorry for violating abstraction here)
961 par.selectedChild = wnd;
962 par.animationState = 1;
963 Container_setFocus(par, NULL);
965 else if (par.instanceOfContainer)
968 if (par.focused) par.setFocus(par, wnd);
972 void m_setpointerfocus(entity wnd)
974 if (!wnd.instanceOfContainer) return;
975 entity focus = wnd.preferredFocusedGrandChild(wnd);
977 menuMousePos = focus.origin + 0.5 * focus.size;
978 menuMousePos.x *= 1 / conwidth;
979 menuMousePos.y *= 1 / conheight;
980 entity par = wnd.parent;
981 if (par.focused) par.setFocus(par, wnd);
982 if (wnd.focused) m_focus_item_chain(wnd, focus);
985 void m_goto(string itemname)
987 if (!menuInitialized)
989 strcpy(m_goto_buffer, itemname);
992 if (itemname == "") // this can be called by GameCommand
994 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
999 itemname = "nexposee";
1002 if (itemname == "nexposee")
1004 // unlike 'togglemenu 1', this closes modal and root dialogs if opened
1005 m_activate_window(main.mainNexposee);
1011 for (e = NULL; (e = find(e, name, itemname)); )
1012 if (e.classname != "vtbl") break;
1014 if ((e) && (!e.requiresConnection || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))))
1017 e.hideMenuOnClose = true;
1019 m_activate_window(e);
1020 m_setpointerfocus(e);
1026 void m_play_focus_sound()
1028 static float menuLastFocusSoundTime;
1029 if (cvar("menu_sounds") < 2) return;
1030 if (time - menuLastFocusSoundTime <= 0.25) return;
1031 localsound(MENU_SOUND_FOCUS);
1032 menuLastFocusSoundTime = time;
1035 void m_play_click_sound(string soundfile)
1037 if (!cvar("menu_sounds")) return;
1038 localsound(soundfile);