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/checkextension.qh>
21 #include <common/items/_mod.qh>
22 #include <common/weapons/_all.qh>
23 #include <common/mapinfo.qh>
24 #include <common/mutators/base.qh>
26 int mouseButtonsPressed;
36 // Used for having effects only execute once in main menu, not for every reload
37 // 0: never been in main menu before. 1: coming back to main menu. 2: in main menu.
38 int menuNotTheFirstFrame;
39 bool autocvar_menu_no_music_nor_welcome;
41 float conwidth_s, conheight_s;
42 float vidwidth_s, vidheight_s, vidpixelheight_s;
43 float realconwidth, realconheight;
48 vidwidth_s = vidheight_s = vidpixelheight_s = 0; // Force updateConwidths on next draw
56 if (isserver()) gamestatus |= GAME_ISSERVER;
57 if (clientstate() == CS_CONNECTED || isdemo()) gamestatus |= GAME_CONNECTED;
58 if (cvar("developer") > 0) gamestatus |= GAME_DEVELOPER;
63 bool restarting = false;
64 cvar_set("_menu_alpha", "0");
65 prvm_language = cvar_string("prvm_language");
66 if (prvm_language == "")
69 cvar_set("prvm_language", prvm_language);
70 localcmd("\nmenu_restart\n");
73 prvm_language = strzone(prvm_language);
74 cvar_set("_menu_prvm_language", prvm_language);
77 LOG_TRACEF("^4MQC Build information: ^1%s", WATERMARK);
80 CheckEngineExtensions();
82 // list all game dirs (TEST)
83 if (cvar("developer") > 0)
85 for (int i = 0; ; ++i)
87 string s = getgamedirinfo(i, GETGAMEDIRINFO_NAME);
89 LOG_TRACE(s, ": ", getgamedirinfo(i, GETGAMEDIRINFO_DESCRIPTION));
93 registercvar("_menu_cmd_closemenu_available", "0", 0);
94 cvar_set("_menu_cmd_closemenu_available", "1");
96 // needs to be done so early because of the constants they create
99 static_init_precache();
101 RegisterSLCategories();
103 float ddsload = cvar("r_texture_dds_load");
104 float texcomp = cvar("gl_texturecompression");
106 if (ddsload != cvar("r_texture_dds_load") || texcomp != cvar("gl_texturecompression")) localcmd("\nr_restart\n");
110 if (cvar("_menu_initialized")) // always show menu after menu_restart
113 cvar_set("_menu_initialized", "1");
117 const float MENU_ASPECT = 1280 / 1024;
119 void draw_reset_cropped()
121 draw_reset(conwidth, conheight, 0.5 * (realconwidth - conwidth), 0.5 * (realconheight - conheight));
123 void draw_reset_full()
125 draw_reset(realconwidth, realconheight, 0, 0);
128 void UpdateConWidthHeight(float w, float h, float p)
130 if (w != vidwidth_s || h != vidheight_s || p != vidpixelheight_s)
132 if (updateConwidths(w, h, p) && menuNotTheFirstFrame)
133 localcmd(sprintf("\nexec %s\n", cvar_string("menu_font_cfg")));
136 vidpixelheight_s = p;
138 conwidth_s = conwidth;
139 conheight_s = conheight;
140 realconwidth = cvar("vid_conwidth");
141 realconheight = cvar("vid_conheight");
142 if (realconwidth / realconheight > MENU_ASPECT)
145 conwidth = realconheight * MENU_ASPECT;
146 conheight = realconheight;
151 conwidth = realconwidth;
152 conheight = realconwidth / MENU_ASPECT;
156 if (conwidth_s != conwidth || conheight_s != conheight)
158 draw_reset_cropped();
159 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
164 vidwidth_s = vidheight_s = vidpixelheight_s = 0; // retry next frame
168 string m_goto_buffer;
169 void m_init_delayed()
171 draw_reset_cropped();
173 menuInitialized = false;
174 if (!preMenuInit()) return;
175 menuInitialized = true;
178 if (cvar_string("menu_skin") != "")
180 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
181 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
183 if (fh < 0 && cvar_defstring("menu_skin") != "")
185 cvar_set("menu_skin", cvar_defstring("menu_skin"));
186 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
187 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
191 draw_currentSkin = "gfx/menu/default";
192 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
194 if (fh < 0) error("cannot load any menu skin\n");
195 draw_currentSkin = strzone(draw_currentSkin);
196 for (string s; (s = fgets(fh)); )
198 // these two are handled by skinlist.qc
199 if (substring(s, 0, 6) == "title ") continue;
200 if (substring(s, 0, 7) == "author ") continue;
201 int n = tokenize_console(s);
203 Skin_ApplySetting(argv(0), substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
207 int glob = search_begin(strcat(draw_currentSkin, "/*.tga"), true, true);
210 for (int i = 0, n = search_getsize(glob); i < n; ++i)
211 precache_pic(search_getfilename(glob, i));
215 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
217 anim = NEW(AnimHost);
218 main = NEW(MainWindow);
219 main.configureMainWindow(main);
221 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
224 menuMousePos = '0.5 0.5 0';
230 m_goto(m_goto_buffer);
231 strfree(m_goto_buffer);
234 if (Menu_Active) m_display(); // delayed menu display
236 cvar_set("_menu_initialized", "2");
239 void m_keyup(float key, float ascii)
241 if (!menuInitialized) return;
242 if (!Menu_Active) return;
243 draw_reset_cropped();
244 main.keyUp(main, key, ascii, menuShiftState);
245 if (key >= K_MOUSE1 && key <= K_MOUSE3)
247 --mouseButtonsPressed;
248 if (!mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
249 if (mouseButtonsPressed < 0)
251 mouseButtonsPressed = 0;
252 LOG_TRACE("Warning: released an already released button");
255 if (key == K_ALT) menuShiftState &= ~S_ALT;
256 if (key == K_CTRL) menuShiftState &= ~S_CTRL;
257 if (key == K_SHIFT) menuShiftState &= ~S_SHIFT;
260 void m_keydown(float key, float ascii)
262 if (!menuInitialized) return;
263 if (!Menu_Active) return;
265 if (menuMouseMode && key >= K_MOUSE1 && key <= K_MOUSE3)
267 // detect a click outside of the game window
268 vector p = getmousepos();
269 if (p.x < 0 || p.x > realconwidth || p.y < 0 || p.y > realconheight)
271 ++mouseButtonsPressed;
278 entity e = keyGrabber;
280 e.keyGrabbed(e, key, ascii);
284 draw_reset_cropped();
285 if (!mouseButtonsPressed && key >= K_MOUSE1 && key <= K_MOUSE3)
286 main.mousePress(main, menuMousePos);
287 if (!main.keyDown(main, key, ascii, menuShiftState))
289 // disable menu on unhandled ESC
291 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
295 if (key >= K_MOUSE1 && key <= K_MOUSE3)
297 ++mouseButtonsPressed;
298 if (mouseButtonsPressed > 10)
300 mouseButtonsPressed = 10;
301 LOG_TRACE("Warning: pressed an already pressed button");
304 if (key == K_ALT) menuShiftState |= S_ALT;
305 if (key == K_CTRL) menuShiftState |= S_CTRL;
306 if (key == K_SHIFT) menuShiftState |= S_SHIFT;
316 void draw_Picture_Aligned(vector algn, float scalemode, string img, float a)
318 vector sz = draw_PictureSize(img);
319 bool width_is_larger = (sz.x * draw_scale.y >= sz.y * draw_scale.x);
320 vector isz_w = '1 0 0' + '0 1 0' * ((sz.y / sz.x) * (draw_scale.x / draw_scale.y));
321 vector isz_h = '0 1 0' + '1 0 0' * ((sz.x / sz.y) * (draw_scale.y / draw_scale.x));
327 isz = (width_is_larger ? isz_h : isz_w);
329 case SCALEMODE_LETTERBOX:
330 isz = (width_is_larger ? isz_w : isz_h);
332 case SCALEMODE_WIDTH:
335 case SCALEMODE_HEIGHT:
338 case SCALEMODE_STRETCH:
342 vector org = eX * (algn.x * (1 - isz.x)) + eY * (algn.y * (1 - isz.y));
343 draw_Picture(org, img, isz, '1 1 1', a);
346 void drawBackground(string img, float a, string algn, float force1)
348 if (main.mainNexposee.ModalController_state == 0) return;
350 int scalemode = SCALEMODE_CROP;
351 int len = strlen(algn);
352 for (int i = 0, l = 0; i < len; ++i)
354 string c = substring(algn, i, 1);
358 scalemode = SCALEMODE_CROP;
361 scalemode = SCALEMODE_LETTERBOX;
364 scalemode = SCALEMODE_HEIGHT;
367 scalemode = SCALEMODE_WIDTH;
370 scalemode = SCALEMODE_STRETCH;
372 case "1": case "4": case "7":
375 case "2": case "5": case "8":
378 case "3": case "6": case "9":
387 case "7": case "8": case "9":
390 case "4": case "5": case "6":
393 case "1": case "2": case "3":
402 draw_Picture_Aligned(v, scalemode, img, a);
406 // force all secondary layers to use alpha 1. Prevents ugly issues
407 // with overlap. It's a flag because it cannot be used for the
409 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), 1);
413 draw_Picture_Aligned(v, scalemode, strcat(img, "_l", ftos(l + 1)), a);
421 int menu_tooltips_old;
422 vector menuTooltipAveragedMousePos;
423 entity menuTooltipItem;
424 vector menuTooltipOrigin;
425 vector menuTooltipSize;
426 float menuTooltipAlpha;
427 string menuTooltipText;
428 int menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
429 bool m_testmousetooltipbox(vector pos)
432 (pos.x >= menuTooltipOrigin.x && pos.x < menuTooltipOrigin.x + menuTooltipSize.x)
433 && (pos.y >= menuTooltipOrigin.y && pos.y < menuTooltipOrigin.y + menuTooltipSize.y)
436 bool m_testtooltipbox(vector tooltippos)
438 if (tooltippos.x < 0) return false;
439 if (tooltippos.y < 0) return false;
440 if (tooltippos.x + menuTooltipSize.x > 1) return false;
441 if (tooltippos.y + menuTooltipSize.y > 1) return false;
442 menuTooltipOrigin = tooltippos;
445 bool m_allocatetooltipbox(vector pos)
448 avoidplus.x = (SKINAVOID_TOOLTIP_x + SKINSIZE_CURSOR_x - SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth;
449 avoidplus.y = (SKINAVOID_TOOLTIP_y + SKINSIZE_CURSOR_y - SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight;
453 avoidminus.x = (SKINAVOID_TOOLTIP_x + SKINOFFSET_CURSOR_x * SKINSIZE_CURSOR_x) / conwidth + menuTooltipSize.x;
454 avoidminus.y = (SKINAVOID_TOOLTIP_y + SKINOFFSET_CURSOR_y * SKINSIZE_CURSOR_y) / conheight + menuTooltipSize.y;
458 vector v = pos + avoidplus;
459 if (m_testtooltipbox(v)) return true;
462 v.x = pos.x - menuTooltipSize.x * 0.5;
463 if (m_testtooltipbox(v)) return true;
466 v.x = pos.x - avoidminus.x;
467 if (m_testtooltipbox(v)) return true;
470 v.y = pos.y - avoidminus.y;
471 if (m_testtooltipbox(v)) return true;
474 v.x = pos.x - menuTooltipSize.x * 0.5;
475 if (m_testtooltipbox(v)) return true;
478 v.x = pos.x + avoidplus.x;
479 if (m_testtooltipbox(v)) return true;
483 entity m_findtooltipitem(entity root, vector pos)
486 for (entity it = root; it.instanceOfContainer; )
488 while (it.instanceOfNexposee && it.focusedChild)
490 it = it.focusedChild;
491 pos = globalToBox(pos, it.Container_origin, it.Container_size);
493 if (it.instanceOfNexposee)
495 it = it.itemFromPoint(it, pos);
496 if (it.tooltip) best = it;
497 else if (menu_tooltips == 2 && (it.controlledCvar || it.onClickCommand)) best = it;
500 else if (it.instanceOfModalController)
502 it = it.focusedChild;
506 it = it.itemFromPoint(it, pos);
509 if (it.tooltip) best = it;
510 else if (menu_tooltips == 2 && (it.controlledCvar || it.onClickCommand)) best = it;
511 pos = globalToBox(pos, it.Container_origin, it.Container_size);
518 if (menu_tooltips == 2)
521 if (menuTooltipItem.controlledCvar)
523 string cvar_list = getCvarsMulti(menuTooltipItem);
525 cvar_list = strcat(menuTooltipItem.controlledCvar, " ", cvar_list);
527 cvar_list = menuTooltipItem.controlledCvar;
528 s = strcat("[", cvar_list, " \"", cvar_string(menuTooltipItem.controlledCvar), "\"]");
530 else if (menuTooltipItem.onClickCommand)
532 s = strcat("<", menuTooltipItem.onClickCommand, ">");
536 return menuTooltipItem.tooltip;
538 if (menuTooltipItem.tooltip) return strcat(menuTooltipItem.tooltip, " ", s);
541 return menuTooltipItem.tooltip;
543 void m_tooltip(vector pos)
545 static string prev_tooltip;
547 menu_tooltips = cvar("menu_tooltips");
550 // don't return immediately, fade out the active tooltip first
551 if (menuTooltipItem == NULL) return;
553 menu_tooltips_old = menu_tooltips;
557 float f = bound(0, frametime * 2, 1);
558 menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + pos * f;
559 if (vdist(pos - menuTooltipAveragedMousePos, <, 0.01))
561 it = m_findtooltipitem(main, pos);
563 if (it.instanceOfListBox && it.isScrolling(it)) it = NULL;
565 if (it && prev_tooltip != it.tooltip)
567 // fade out if tooltip of a certain item has changed
568 menuTooltipState = 3;
569 strcpy(prev_tooltip, it.tooltip);
571 else if (menuTooltipItem && !m_testmousetooltipbox(pos))
573 menuTooltipState = 3; // fade out if mouse touches it
581 vector fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
583 // float menuTooltipState; // 0: static, 1: fading in, 2: fading out, 3: forced fading out
584 if (it != menuTooltipItem)
586 switch (menuTooltipState)
591 // another item: fade out first
592 menuTooltipState = 2;
597 menuTooltipState = 1;
598 menuTooltipItem = it;
600 menuTooltipOrigin.x = -1; // unallocated
602 strcpy(menuTooltipText, gettooltip());
606 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i)
608 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
611 float f = draw_TextWidth(s, false, fontsize);
614 menuTooltipSize.x = w + 2 * (SKINMARGIN_TOOLTIP_x / conwidth);
615 menuTooltipSize.y = i * fontsize.y + 2 * (SKINMARGIN_TOOLTIP_y / conheight);
616 menuTooltipSize.z = 0;
620 // changing item while fading in: fade out first
621 menuTooltipState = 2;
624 // changing item while fading out: can't
628 else if (menuTooltipState == 2) // re-fade in?
630 menuTooltipState = 1;
633 switch (menuTooltipState)
636 menuTooltipAlpha = bound(0, menuTooltipAlpha + 5 * frametime, 1);
637 if (menuTooltipAlpha == 1) menuTooltipState = 0;
640 case 3: // forced fade out
641 menuTooltipAlpha = bound(0, menuTooltipAlpha - 2 * frametime, 1);
642 if (menuTooltipAlpha == 0)
644 menuTooltipState = 0;
645 menuTooltipItem = NULL;
650 if (menuTooltipItem == NULL)
652 strfree(menuTooltipText);
657 if (menu_tooltips != menu_tooltips_old)
659 if (menu_tooltips != 0 && menu_tooltips_old != 0) menuTooltipItem = NULL; // reload tooltip next frame
660 menu_tooltips_old = menu_tooltips;
662 else if (menuTooltipOrigin.x < 0) // unallocated?
664 m_allocatetooltipbox(pos);
666 if (menuTooltipOrigin.x >= 0)
669 vector p = SKINBORDER_TOOLTIP;
671 p.y *= 1 / conheight;
672 draw_BorderPicture(menuTooltipOrigin, SKINGFX_TOOLTIP, menuTooltipSize, '1 1 1', menuTooltipAlpha, p);
673 p = menuTooltipOrigin;
674 p.x += SKINMARGIN_TOOLTIP_x / conwidth;
675 p.y += SKINMARGIN_TOOLTIP_y / conheight;
677 for (getWrappedLine_remaining = menuTooltipText; getWrappedLine_remaining && i <= 16; ++i, p.y += fontsize.y)
679 string s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
682 draw_Text(p, s, fontsize, SKINCOLOR_TOOLTIP, SKINALPHA_TOOLTIP * menuTooltipAlpha, false);
688 const int MIN_DISCONNECTION_TIME = 1;
689 bool autocvar_g_campaign;
690 void m_draw(float width, float height)
692 static float connected_time;
693 if (clientstate() == CS_DISCONNECTED)
695 // avoid a bug where the main menu re-opens when changing maps
696 // potentially exclusive to `map <mapname>` cmd?
697 if (connected_time && time - connected_time > MIN_DISCONNECTION_TIME)
699 if (autocvar_g_campaign)
701 // in the case player uses the disconnect command (in the console or with a key)
702 // reset g_campaign and update menu items to reflect cvar values that may have been restored after quiting the campaign
703 // see also LEAVEMATCH_CMD
704 cvar_set("g_campaign", "0");
708 // reload the menu so that disconnecting players don't
709 // have to press ESC to open it again
712 localcmd("\nmenu_cmd directmenu Welcome RESET\n");
716 // FIXME?: find out if anything should be done to reset it more,
717 // this is just a fix to make main menu music replay nicely
718 menuNotTheFirstFrame = 1;
722 connected_time = time;
726 execute_next_frame();
728 menuMouseMode = cvar("menu_mouse_absolute");
730 if (anim) anim.tickAll(anim);
732 UpdateConWidthHeight(width, height, cvar("vid_pixelheight"));
734 if (!menuInitialized)
736 // TODO draw an info image about this situation
741 if (menuNotTheFirstFrame == 0) // only fade the menu in once ever
742 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading FIXME
744 if (menuNotTheFirstFrame <= 1) // only once per menu reload
746 if (Menu_Active && !autocvar_menu_no_music_nor_welcome)
748 localcmd("cd loop $menu_cdtrack\n");
750 // TODO: enable this when we have a welcome sound
751 // FIXME: change the file used according to the selected announcer
752 // Only play the welcome announcement once, not on any menu reloads
753 //if (menuNotTheFirstFrame == 0)
754 //localcmd("play sound/announcer/default/welcome.wav\n");
757 menuNotTheFirstFrame = 2;
761 float realFrametime = frametime = min(0.2, t - menuPrevTime);
765 t = cvar("menu_slowmo");
778 if (getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU)
779 && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
780 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
784 if (cvar("cl_capturevideo")) frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
786 prevMenuAlpha = menuAlpha;
789 if (menuAlpha == 0 && menuLogoAlpha < 2)
791 menuLogoAlpha += 2 * frametime;
795 menuAlpha = min(1, menuAlpha + 5 * frametime);
801 menuAlpha = max(0, menuAlpha - 5 * frametime);
805 draw_reset_cropped();
807 if (!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
809 if (menuLogoAlpha > 0)
812 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_BACKGROUND, 1);
813 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1), SKINALIGN_BACKGROUND, true);
814 draw_reset_cropped();
815 if (menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
817 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
818 draw_drawMousePointer(menuMousePos);
823 else if (SKINALPHA_BACKGROUND_INGAME)
828 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME,
829 SKINALIGN_BACKGROUND_INGAME, false);
830 draw_reset_cropped();
834 if (menuAlpha != prevMenuAlpha) cvar_set("_menu_alpha", ftos(menuAlpha));
836 draw_reset_cropped();
838 draw_reset_cropped();
842 if (prevMenuAlpha > 0) main.initializeDialog(main, main.firstChild);
843 draw_reset_cropped();
848 draw_alpha *= menuAlpha;
852 vector rawMousePos = getmousepos();
853 vector newMouse = globalToBox(rawMousePos, draw_shift, draw_scale);
854 if (rawMousePos != '0 0 0' && newMouse != menuMousePos)
856 menuMousePos = newMouse;
857 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
858 else main.mouseMove(main, menuMousePos);
861 else if (frametime > 0)
863 vector dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
864 if (dMouse != '0 0 0')
866 vector minpos = globalToBox('0 0 0', draw_shift, draw_scale);
867 vector maxpos = globalToBox(eX * (realconwidth - 1) + eY * (realconheight - 1), draw_shift, draw_scale);
868 dMouse = globalToBoxSize(dMouse, draw_scale);
869 menuMousePos += dMouse * cvar("menu_mouse_speed");
870 menuMousePos.x = bound(minpos.x, menuMousePos.x, maxpos.x);
871 menuMousePos.y = bound(minpos.y, menuMousePos.y, maxpos.y);
872 if (mouseButtonsPressed) main.mouseDrag(main, menuMousePos);
873 else main.mouseMove(main, menuMousePos);
878 m_tooltip(menuMousePos);
880 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
882 draw_drawMousePointer(menuMousePos);
884 draw_reset_cropped();
894 setkeydest(KEY_MENU);
895 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
897 if (!menuInitialized) return;
899 if (mouseButtonsPressed) main.mouseRelease(main, menuMousePos);
900 mouseButtonsPressed = 0;
902 main.focusEnter(main);
903 main.showNotify(main);
909 setkeydest(KEY_GAME);
910 setmousetarget(MT_CLIENT);
912 if (!menuInitialized) return;
914 main.focusLeave(main);
915 main.hideNotify(main);
918 void m_toggle(int mode)
922 if (mode == 1) return;
923 // when togglemenu is called without arguments (mode is -1)
924 // the menu is closed only when connected
925 if (mode == -1 && !(gamestatus & GAME_CONNECTED)) return;
926 // togglemenu 0 always closes the menu
931 if (mode == 0) return;
939 FOREACH_ENTITY_ORDERED(it.destroy, {
940 if (it.classname == "vtbl") continue;
943 cvar_set("_menu_cmd_closemenu_available", "0");
946 void m_focus_item_chain(entity outermost, entity innermost)
948 if (innermost.parent != outermost) m_focus_item_chain(outermost, innermost.parent);
949 innermost.parent.setFocus(innermost.parent, innermost);
952 void m_activate_window(entity wnd)
954 entity par = wnd.parent;
955 if (par) m_activate_window(par);
957 if (par.instanceOfModalController)
959 if (wnd.tabSelectingButton)
961 TabButton_Click(wnd.tabSelectingButton, wnd);
964 par.initializeDialog(par, wnd);
966 else if (par.instanceOfNexposee)
968 // nexposee (sorry for violating abstraction here)
969 par.selectedChild = wnd;
970 par.animationState = 1;
971 Container_setFocus(par, NULL);
973 else if (par.instanceOfContainer)
976 if (par.focused) par.setFocus(par, wnd);
980 void m_setpointerfocus(entity wnd)
982 if (!wnd.instanceOfContainer) return;
983 entity focus = wnd.preferredFocusedGrandChild(wnd);
985 menuMousePos = focus.origin + 0.5 * focus.size;
986 menuMousePos.x *= 1 / conwidth;
987 menuMousePos.y *= 1 / conheight;
988 entity par = wnd.parent;
989 if (par.focused) par.setFocus(par, wnd);
990 if (wnd.focused) m_focus_item_chain(wnd, focus);
993 void m_goto(string itemname)
995 if (!menuInitialized)
997 strcpy(m_goto_buffer, itemname);
1000 if (itemname == "") // this can be called by GameCommand
1002 if (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
1007 itemname = "nexposee";
1010 if (itemname == "nexposee")
1012 // unlike 'togglemenu 1', this closes modal and root dialogs if opened
1013 m_activate_window(main.mainNexposee);
1019 for (e = NULL; (e = find(e, name, itemname)); )
1020 if (e.classname != "vtbl") break;
1022 if ((e) && (!e.requiresConnection || (gamestatus & (GAME_ISSERVER | GAME_CONNECTED))))
1025 e.hideMenuOnClose = true;
1027 m_activate_window(e);
1028 m_setpointerfocus(e);
1034 void m_play_focus_sound()
1036 static float menuLastFocusSoundTime;
1037 if (cvar("menu_sounds") < 2) return;
1038 if (time - menuLastFocusSoundTime <= 0.25) return;
1039 localsound(MENU_SOUND_FOCUS);
1040 menuLastFocusSoundTime = time;
1043 void m_play_click_sound(string soundfile)
1045 if (!cvar("menu_sounds")) return;
1046 localsound(soundfile);