]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/menu.qc
fix menu display at non-4:3 aspect ratio by drawing multiple background layers
[divverent/nexuiz.git] / data / qcsrc / menu / menu.qc
1 ///////////////////////////////////////////////
2 // Menu Source File
3 ///////////////////////
4 // This file belongs to dpmod/darkplaces
5 // AK contains all menu functions (especially the required ones)
6 ///////////////////////////////////////////////
7
8 float mouseButtonsPressed;
9 vector menuMousePos;
10 float menuShiftState;
11 float menuPrevTime;
12 float menuAlpha;
13 float menuLogoAlpha;
14 float prevMenuAlpha;
15 float menuInitialized;
16 float menuNotTheFirstFrame;
17 float menuMouseMode;
18
19 void SUB_Null() { };
20
21 void() m_init =
22 {
23         dprint_load();
24         check_unacceptable_compiler_bugs();
25
26         // list all game dirs (TEST)
27         if(cvar("developer"))
28         {
29                 float i;
30                 string s;
31                 for(i = 0; ; ++i)
32                 {
33                         s = getgamedirinfo(i, GETGAMEDIRINFO_NAME);
34                         if not(s)
35                                 break;
36                         print(s, ": ", getgamedirinfo(i, GETGAMEDIRINFO_DESCRIPTION));
37                 }
38         }
39 }
40
41 void UpdateConWidthHeight()
42 {
43         float conwidth_s, conheight_s;
44         conwidth_s = conwidth;
45         conheight_s = conheight;
46         conwidth = cvar("vid_conwidth");
47         conheight = cvar("vid_conheight");
48         if(conwidth < 800)
49         {
50                 conheight *= 800 / conwidth;
51                 conwidth = 800;
52         }
53         if(conheight < 600)
54         {
55                 conwidth *= 600 / conheight;
56                 conheight = 600;
57         }
58         if(main)
59         {
60                 if(conwidth_s != conwidth || conheight_s != conheight)
61                 {
62                         draw_reset();
63                         main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
64                 }
65         }
66 }
67
68 void() m_init_delayed =
69 {
70         float fh, glob, n, i;
71         string s;
72
73         dprint_load();
74
75         menuInitialized = 0;
76         if(!preMenuInit())
77                 return;
78         menuInitialized = 1;
79         GameCommand_Init();
80
81         RegisterWeapons();
82
83         fh = -1;
84         if(cvar_string("menu_skin") != "")
85         {
86                 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
87                 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
88         }
89         if(fh < 0)
90         if(cvar_defstring("menu_skin") != "")
91         {
92                 draw_currentSkin = strcat("gfx/menu/", cvar_defstring("menu_skin"));
93                 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
94         }
95         if(fh < 0)
96         {
97                 draw_currentSkin = "gfx/menu/default";
98                 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
99         }
100         draw_currentSkin = strzone(draw_currentSkin);
101         while((s = fgets(fh)))
102         {
103                 // these two are handled by skinlist.qc
104                 if(substring(s, 0, 6) == "title ")
105                         continue;
106                 if(substring(s, 0, 7) == "author ")
107                         continue;
108                 n = tokenize_console(s);
109                 if(n >= 2)
110                         Skin_ApplySetting(argv(0), substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
111         }
112         fclose(fh);
113
114         glob = search_begin(strcat(draw_currentSkin, "/*.tga"), TRUE, TRUE);
115         if(glob >= 0)
116         {
117                 n = search_getsize(glob);
118                 for(i = 0; i < n; ++i)
119                         precache_pic(search_getfilename(glob, i));
120                 search_end(glob);
121         }
122
123         draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
124
125         conwidth = conheight = -1;
126         draw_reset();
127         UpdateConWidthHeight();
128
129         loadTooltips();
130         main = spawnMainWindow(); main.configureMainWindow(main);
131         unloadTooltips();
132
133         main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
134         main.focused = 1;
135         menuShiftState = 0;
136         menuMousePos = '0.5 0.5 0';
137
138         if(Menu_Active)
139                 m_display(); // delayed menu display
140 };
141
142 void(float key, float ascii) m_keyup =
143 {
144         if(!menuInitialized)
145                 return;
146         if(!Menu_Active)
147                 return;
148         draw_reset();
149         main.keyUp(main, key, ascii, menuShiftState);
150         if(key >= K_MOUSE1 && key <= K_MOUSE3)
151         {
152                 --mouseButtonsPressed;
153                 if(!mouseButtonsPressed)
154                         main.mouseRelease(main, menuMousePos);
155                 if(mouseButtonsPressed < 0)
156                 {
157                         mouseButtonsPressed = 0;
158                         print("Warning: released an already released button\n");
159                 }
160         }
161         if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
162         if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
163         if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
164 };
165
166 void(float key, float ascii) m_keydown =
167 {
168         if(!menuInitialized)
169                 return;
170         if(!Menu_Active)
171                 return;
172         if(keyGrabber)
173         {
174                 entity e;
175                 e = keyGrabber;
176                 keyGrabber = NULL;
177                 e.keyGrabbed(e, key, ascii);
178         }
179         else
180         {
181                 draw_reset();
182                 if(key >= K_MOUSE1 && key <= K_MOUSE3)
183                         if(!mouseButtonsPressed)
184                                 main.mousePress(main, menuMousePos);
185                 if(!main.keyDown(main, key, ascii, menuShiftState))
186                         if(key == K_ESCAPE)
187                                 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
188                                         m_hide(); // disable menu on unhandled ESC
189         }
190         if(key >= K_MOUSE1 && key <= K_MOUSE3)
191         {
192                 ++mouseButtonsPressed;
193                 if(mouseButtonsPressed > 10)
194                 {
195                         mouseButtonsPressed = 10;
196                         print("Warning: pressed an already pressed button\n");
197                 }
198         }
199         if(key == K_ALT) menuShiftState |= S_ALT;
200         if(key == K_CTRL) menuShiftState |= S_CTRL;
201         if(key == K_SHIFT) menuShiftState |= S_SHIFT;
202 };
203
204 void(string img, float a, float algn, float force1) drawBackground =
205 {
206         vector sz;
207         vector isz;
208         vector tl, ce, br;
209         vector v;
210         string s;
211         float i, f;
212         sz = draw_PictureSize(img);
213         // keep aspect of image
214         if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
215         {
216                 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
217                 // match up the height
218                 isz_y = 1;
219                 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
220         }
221         else
222         {
223                 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
224                 // match up the width
225                 isz_x = 1;
226                 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
227         }
228         tl = '0 0 0';
229         ce = '0.5 0.5 0' - 0.5 * isz;
230         br = '1 1 0' - isz;
231
232         s = ftos(algn);
233         v_z = 0;
234         for(i = 0; i < strlen(s); ++i)
235         {
236                 f = stof(substring(s, i, 1));
237                 switch(f)
238                 {
239                         case 1: case 4: case 7: v_x = tl_x; break;
240                         case 2: case 5: case 8: v_x = ce_x; break;
241                         case 3: case 6: case 9: v_x = br_x; break;
242                         default: v_x = tl_x + (br_x - tl_x) * random(); break;
243                 }
244                 switch(f)
245                 {
246                         case 7: case 8: case 9: v_y = tl_y; break;
247                         case 4: case 5: case 6: v_y = ce_y; break;
248                         case 1: case 2: case 3: v_y = br_y; break;
249                         default: v_y = tl_y + (br_y - tl_y) * random(); break;
250                 }
251                 if(i == 0)
252                         draw_Picture(v, img, isz, '1 1 1', a);
253                 else if(force1)
254                         // force all secondary layers to use alpha 1. Prevents ugly issues
255                         // with overlap. It's a flag because it cannot be used for the
256                         // ingame background
257                         draw_Picture(v, strcat(img, "_l", ftos(i+1)), isz, '1 1 1', 1);
258                 else
259                         draw_Picture(v, strcat(img, "_l", ftos(i+1)), isz, '1 1 1', a);
260         }
261 }
262
263 vector menuTooltipAveragedMousePos;
264 entity menuTooltipItem;
265 vector menuTooltipOrigin;
266 vector menuTooltipSize;
267 float menuTooltipAlpha;
268 float menuTooltipState; // 0: no tooltip, 1: fading in, 2: displaying, 3: fading out
269 float m_testmousetooltipbox(vector pos)
270 {
271         if(pos_x >= menuTooltipOrigin_x && pos_x < menuTooltipOrigin_x + menuTooltipSize_x)
272         if(pos_y >= menuTooltipOrigin_y && pos_y < menuTooltipOrigin_y + menuTooltipSize_y)
273                 return FALSE;
274         return TRUE;
275 }
276 float m_testtooltipbox(vector tooltippos)
277 {
278         if(tooltippos_x < 0)
279                 return FALSE;
280         if(tooltippos_y < 0)
281                 return FALSE;
282         if(tooltippos_x + menuTooltipSize_x > 1)
283                 return FALSE;
284         if(tooltippos_y + menuTooltipSize_y > 1)
285                 return FALSE;
286         /*
287         menuTooltipOrigin_x = rint(tooltippos_x * cvar("vid_width")) / cvar("vid_width");
288         menuTooltipOrigin_y = rint(tooltippos_y * cvar("vid_height")) / cvar("vid_height");
289         menuTooltipOrigin_z = 0;
290         */
291         menuTooltipOrigin = tooltippos;
292         return TRUE;
293 }
294 float m_allocatetooltipbox(vector pos)
295 {
296         vector avoidplus, avoidminus;
297         vector v;
298
299         avoidplus_x = (SKINAVOID_TOOLTIP_x + SKINSIZE_CURSOR_x - SKINOFFSET_CURSOR_x) / conwidth;
300         avoidplus_y = (SKINAVOID_TOOLTIP_y + SKINSIZE_CURSOR_y - SKINOFFSET_CURSOR_y) / conheight;
301         avoidplus_z = 0;
302
303         avoidminus_x = (SKINAVOID_TOOLTIP_x + SKINOFFSET_CURSOR_x) / conwidth + menuTooltipSize_x;
304         avoidminus_y = (SKINAVOID_TOOLTIP_y + SKINOFFSET_CURSOR_y) / conheight + menuTooltipSize_y;
305         avoidminus_z = 0;
306
307         // bottom right
308         v = pos + avoidplus;
309         if(m_testtooltipbox(v))
310                 return TRUE;
311         
312         // bottom center
313         v_x = pos_x - menuTooltipSize_x * 0.5;
314         if(m_testtooltipbox(v))
315                 return TRUE;
316
317         // bottom left
318         v_x = pos_x - avoidminus_x;
319         if(m_testtooltipbox(v))
320                 return TRUE;
321
322         // top left
323         v_y = pos_y - avoidminus_y;
324         if(m_testtooltipbox(v))
325                 return TRUE;
326
327         // top center
328         v_x = pos_x - menuTooltipSize_x * 0.5;
329         if(m_testtooltipbox(v))
330                 return TRUE;
331         
332         // top right
333         v_x = pos_x + avoidplus_x;
334         if(m_testtooltipbox(v))
335                 return TRUE;
336         
337         return FALSE;
338 }
339 entity m_findtooltipitem(entity root, vector pos)
340 {
341         entity it;
342         entity best;
343
344         best = world;
345         it = root;
346
347         while(it.instanceOfContainer)
348         {
349                 while(it.instanceOfNexposee && it.focusedChild)
350                 {
351                         it = it.focusedChild;
352                         pos = globalToBox(pos, it.Container_origin, it.Container_size);
353                 }
354                 if(it.instanceOfNexposee)
355                 {
356                         it = it.itemFromPoint(it, pos);
357                         if(it.tooltip)
358                                 best = it;
359                         it = world;
360                 }
361                 else if(it.instanceOfModalController)
362                         it = it.focusedChild;
363                 else
364                         it = it.itemFromPoint(it, pos);
365                 if(!it)
366                         break;
367                 if(it.tooltip)
368                         best = it;
369                 pos = globalToBox(pos, it.Container_origin, it.Container_size);
370         }
371
372         return best;
373 }
374 void m_tooltip(vector pos)
375 {
376         float f, i, w;
377         entity it;
378         vector fontsize, p;
379         string s;
380
381         fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
382
383         f = bound(0, frametime * 2, 1);
384         menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + pos * f;
385         f = vlen(pos - menuTooltipAveragedMousePos);
386
387         if(f < 0.01)
388                 it = m_findtooltipitem(main, pos);
389         else    
390                 it = world;
391
392         // float menuTooltipState; // 0: static, 1: fading in, 2: fading out
393         if(it != menuTooltipItem)
394         {
395                 switch(menuTooltipState)
396                 {
397                         case 0:
398                                 if(menuTooltipItem)
399                                 {
400                                         // another item: fade out first
401                                         menuTooltipState = 2;
402                                 }
403                                 else
404                                 {
405                                         // new item: fade in
406                                         menuTooltipState = 1;
407                                         menuTooltipItem = it;
408
409                                         menuTooltipOrigin_x = -1; // unallocated
410                                         i = 0;
411                                         w =  0;
412                                         getWrappedLine_remaining = it.tooltip;
413                                         while(getWrappedLine_remaining)
414                                         {
415                                                 s = getWrappedLine(SKINWIDTH_TOOLTIP / fontsize_x, draw_TextWidth_WithoutColors);
416                                                 ++i;
417                                                 f = draw_TextWidth(s, FALSE);
418                                                 if(f > w)
419                                                         w = f;
420                                         }
421                                         menuTooltipSize_x = w * fontsize_x + 2 * (SKINMARGIN_TOOLTIP_x / conwidth);
422                                         menuTooltipSize_y = i * fontsize_y + 2 * (SKINMARGIN_TOOLTIP_y / conheight);
423                                         menuTooltipSize_z = 0;
424                                 }
425                                 break;
426                         case 1:
427                                 // changing item while fading in: fade out first
428                                 menuTooltipState = 2;
429                                 break;
430                         case 2:
431                                 // changing item while fading out: can't
432                                 break;
433                 }
434         }
435         else if(menuTooltipState == 2) // re-fade in?
436                 menuTooltipState = 1;
437
438         if(menuTooltipItem)
439                 if(!m_testmousetooltipbox(pos))
440                         menuTooltipState = 2; // fade out if mouse touches it
441
442         switch(menuTooltipState)
443         {
444                 case 1:
445                         menuTooltipAlpha = bound(0, menuTooltipAlpha + 5 * frametime, 1);
446                         if(menuTooltipAlpha == 1)
447                                 menuTooltipState = 0;
448                         break;
449                 case 2:
450                         menuTooltipAlpha = bound(0, menuTooltipAlpha - 2 * frametime, 1);
451                         if(menuTooltipAlpha == 0)
452                         {
453                                 menuTooltipState = 0;
454                                 menuTooltipItem = world;
455                         }
456                         break;
457         }
458
459         if(menuTooltipItem)
460         {
461                 if(menuTooltipOrigin_x < 0) // unallocated?
462                         m_allocatetooltipbox(pos);
463
464                 if(menuTooltipOrigin_x >= 0)
465                 {
466                         // draw the tooltip!
467                         p = SKINBORDER_TOOLTIP;
468                         p_x *= 1 / conwidth;
469                         p_y *= 1 / conheight;
470                         draw_BorderPicture(menuTooltipOrigin, SKINGFX_TOOLTIP, menuTooltipSize, '1 1 1', menuTooltipAlpha, p);
471                         p = menuTooltipOrigin;
472                         p_x += SKINMARGIN_TOOLTIP_x / conwidth;
473                         p_y += SKINMARGIN_TOOLTIP_y / conheight;
474                         getWrappedLine_remaining = menuTooltipItem.tooltip;
475                         while(getWrappedLine_remaining)
476                         {
477                                 s = getWrappedLine(SKINWIDTH_TOOLTIP / fontsize_x, draw_TextWidth_WithoutColors);
478                                 draw_Text(p, s, fontsize, '1 1 1', SKINALPHA_TOOLTIP * menuTooltipAlpha, FALSE);
479                                 p_y += fontsize_y;
480                         }
481                 }
482         }
483 }
484
485 void() m_draw =
486 {
487         float t;
488         float realFrametime;
489
490         menuMouseMode = cvar("menu_mouse_absolute");
491
492         if(main)
493                 UpdateConWidthHeight();
494
495         if(!menuInitialized)
496         {
497                 // TODO draw an info image about this situation
498                 m_init_delayed();
499                 return;
500         }
501         if(!menuNotTheFirstFrame)
502         {
503                 menuNotTheFirstFrame = 1;
504                 if(Menu_Active)
505                 if(!cvar("menu_video_played"))
506                 {
507                         localcmd("set menu_video_played 1; cd loop $menu_cdtrack; play sound/announcer/male/welcome.ogg\n");
508                         menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
509                 }
510         }
511
512         t = gettime();
513         realFrametime = frametime = min(0.2, t - menuPrevTime);
514         menuPrevTime = t;
515         time += frametime;
516
517         t = cvar("menu_slowmo");
518         if(t)
519         {
520                 frametime *= t;
521                 realFrametime *= t;
522         }
523         else
524                 t = 1;
525
526         if(Menu_Active)
527         {
528                 if(getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU) && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
529                         setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
530                 else
531                         m_hide();
532         }
533
534         if(cvar("cl_capturevideo"))
535                 frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
536
537         dprint_load();
538         gamestatus = 0;
539         if(isserver())
540                 gamestatus = gamestatus | GAME_ISSERVER;
541         if(clientstate() == CS_CONNECTED)
542                 gamestatus = gamestatus | GAME_CONNECTED;
543         if(cvar("developer"))
544                 gamestatus = gamestatus | GAME_DEVELOPER;
545
546         prevMenuAlpha = menuAlpha;
547         if(Menu_Active)
548         {
549                 if(menuAlpha == 0 && menuLogoAlpha < 2)
550                 {
551                         menuLogoAlpha = menuLogoAlpha + frametime * 2;
552                 }
553                 else
554                 {
555                         menuAlpha = min(1, menuAlpha + frametime * 5);
556                         menuLogoAlpha = 2;
557                 }
558         }
559         else
560         {
561                 menuAlpha = max(0, menuAlpha - frametime * 5);
562                 menuLogoAlpha = 2;
563         }
564
565         draw_reset();
566
567         if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
568         {
569                 if(menuLogoAlpha > 0)
570                 {
571                         drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1), SKINALIGN_BACKGROUND, TRUE);
572                         if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
573                         {
574                                 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
575                                 draw_drawMousePointer(menuMousePos);
576                                 draw_alpha = 1;
577                         }
578                 }
579         }
580         else if(SKINALPHA_BACKGROUND_INGAME)
581         {
582                 if(menuAlpha > 0)
583                         drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME, SKINALIGN_BACKGROUND_INGAME, FALSE);
584         }
585
586         draw_reset();
587         preMenuDraw();
588         draw_reset();
589
590         if(menuAlpha <= 0)
591         {
592                 if(prevMenuAlpha > 0)
593                         main.initializeDialog(main, main.firstChild);
594                 draw_reset();
595                 postMenuDraw();
596                 return;
597         }
598
599         draw_alpha *= menuAlpha;
600
601         if(menuMouseMode)
602         {
603                 vector newMouse;
604                 newMouse = globalToBoxSize(getmousepos(), draw_scale);
605                 if(newMouse != '0 0 0')
606                         if(newMouse != menuMousePos)
607                         {
608                                 menuMousePos = newMouse;
609                                 if(mouseButtonsPressed)
610                                         main.mouseDrag(main, menuMousePos);
611                                 else
612                                         main.mouseMove(main, menuMousePos);
613                         }
614         }
615         else
616         {
617                 if(frametime > 0)
618                 {
619                         vector dMouse;
620                         dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
621                         if(dMouse != '0 0 0')
622                         {
623                                 dMouse = globalToBoxSize(dMouse, draw_scale);
624                                 menuMousePos += dMouse * cvar("menu_mouse_speed");
625                                 menuMousePos_x = bound(0, menuMousePos_x, 1);
626                                 menuMousePos_y = bound(0, menuMousePos_y, 1);
627                                 if(mouseButtonsPressed)
628                                         main.mouseDrag(main, menuMousePos);
629                                 else
630                                         main.mouseMove(main, menuMousePos);
631                         }
632                 }
633         }
634         main.draw(main);
635
636         m_tooltip(menuMousePos);
637
638         draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
639
640         draw_drawMousePointer(menuMousePos);
641
642         draw_reset();
643         postMenuDraw();
644
645         frametime = 0;
646 };
647
648 void() m_display =
649 {
650         Menu_Active = true;
651         setkeydest(KEY_MENU);
652         setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
653
654         if(!menuInitialized)
655                 return;
656
657         if(mouseButtonsPressed)
658                 main.mouseRelease(main, menuMousePos);
659         mouseButtonsPressed = 0;
660
661         main.focusEnter(main);
662         main.showNotify(main);
663 };
664
665 void() m_hide =
666 {
667         Menu_Active = false;
668         setkeydest(KEY_GAME);
669         setmousetarget(MT_CLIENT);
670
671         if(!menuInitialized)
672                 return;
673
674         main.focusLeave(main);
675         main.hideNotify(main);
676 };
677
678 void() m_toggle =
679 {
680         if(Menu_Active)
681                 m_hide();
682         else
683                 m_display();
684 };
685
686 void() m_shutdown =
687 {
688         entity e;
689
690         m_hide();
691         for(e = NULL; (e = nextent(e)) != NULL; )
692         {
693                 if(e.destroy)
694                         e.destroy(e);
695         }
696 };
697
698 void m_focus_item_chain(entity outermost, entity innermost)
699 {
700         if(innermost.parent != outermost)
701                 m_focus_item_chain(outermost, innermost.parent);
702         innermost.parent.setFocus(innermost.parent, innermost);
703 }
704
705 void m_activate_window(entity wnd)
706 {
707         entity par;
708         par = wnd.parent;
709         if(par)
710                 m_activate_window(par);
711
712         if(par.instanceOfModalController)
713         {
714                 if(wnd.tabSelectingButton)
715                         // tabs
716                         TabButton_Click(wnd.tabSelectingButton, wnd);
717                 else
718                         // root
719                         par.initializeDialog(par, wnd);
720         }
721         else if(par.instanceOfNexposee)
722         {
723                 // nexposee (sorry for violating abstraction here)
724                 par.selectedChild = wnd;
725                 par.animationState = 1;
726                 setFocusContainer(par, NULL);
727         }
728         else if(par.instanceOfContainer)
729         {
730                 // other containers
731                 if(par.focused)
732                         par.setFocus(par, wnd);
733         }
734 }
735
736 void m_setpointerfocus(entity wnd)
737 {
738         if(wnd.instanceOfContainer)
739         {
740                 entity focus = wnd.preferredFocusedGrandChild(wnd);
741                 if(focus)
742                 {
743                         menuMousePos = focus.origin + 0.5 * focus.size;
744                         menuMousePos_x *= 1 / conwidth;
745                         menuMousePos_y *= 1 / conheight;
746                         if(wnd.focused) // why does this never happen?
747                                 m_focus_item_chain(wnd, focus);
748                 }
749         }
750 }
751
752 void(string itemname) m_goto =
753 {
754         entity e;
755         if(!menuInitialized)
756                 return;
757         if(itemname == "") // this can be called by GameCommand
758         {
759                 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
760                         m_hide();
761                 else
762                 {
763                         m_activate_window(main.mainNexposee);
764                         m_display();
765                 }
766         }
767         else
768         {
769                 e = findstring(NULL, name, itemname);
770                 if(e)
771                 {
772                         m_hide();
773                         m_activate_window(e);
774                         m_setpointerfocus(e);
775                         m_display();
776                 }
777         }
778 }
779
780 void() m_goto_skin_selector =
781 {
782         if(!menuInitialized)
783                 return;
784         // TODO add code to switch back to the skin selector (no idea how to do it now)
785         m_goto("skinselector");
786 }