1 ///////////////////////////////////////////////
3 ///////////////////////
4 // This file belongs to dpmod/darkplaces
5 // AK contains all menu functions (especially the required ones)
6 ///////////////////////////////////////////////
8 float mouseButtonsPressed;
15 float menuInitialized;
16 float menuNotTheFirstFrame;
24 check_unacceptable_compiler_bugs();
27 void UpdateConWidthHeight()
29 float conwidth_s, conheight_s;
30 conwidth_s = conwidth;
31 conheight_s = conheight;
32 conwidth = cvar("vid_conwidth");
33 conheight = cvar("vid_conheight");
36 conheight *= 800 / conwidth;
41 conwidth *= 600 / conheight;
46 if(conwidth_s != conwidth || conheight_s != conheight)
49 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
54 void() m_init_delayed =
70 if(cvar_string("menu_skin") != "")
72 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
73 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
76 if(cvar_defstring("menu_skin") != "")
78 draw_currentSkin = strcat("gfx/menu/", cvar_defstring("menu_skin"));
79 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
83 draw_currentSkin = "gfx/menu/default";
84 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
86 draw_currentSkin = strzone(draw_currentSkin);
87 while((s = fgets(fh)))
89 // these two are handled by skinlist.qc
90 if(substring(s, 0, 6) == "title ")
92 if(substring(s, 0, 7) == "author ")
94 n = tokenize_console(s);
98 s2 = substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
99 Skin_ApplySetting(s1, s2); // fteqcc sucks
104 glob = search_begin(strcat(draw_currentSkin, "/*.tga"), TRUE, TRUE);
107 n = search_getsize(glob);
108 for(i = 0; i < n; ++i)
109 precache_pic(search_getfilename(glob, i));
113 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
115 conwidth = conheight = -1;
117 UpdateConWidthHeight();
118 main = spawnMainWindow(); main.configureMainWindow(main);
119 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
122 menuMousePos = '0.5 0.5 0';
125 m_display(); // delayed menu display
128 void(float key, float ascii) m_keyup =
135 main.keyUp(main, key, ascii, menuShiftState);
136 if(key >= K_MOUSE1 && key <= K_MOUSE3)
138 --mouseButtonsPressed;
139 if(!mouseButtonsPressed)
140 main.mouseRelease(main, menuMousePos);
141 if(mouseButtonsPressed < 0)
143 mouseButtonsPressed = 0;
144 print("Warning: released an already released button\n");
147 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
148 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
149 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
152 void(float key, float ascii) m_keydown =
163 e.keyGrabbed(e, key, ascii);
168 if(key >= K_MOUSE1 && key <= K_MOUSE3)
169 if(!mouseButtonsPressed)
170 main.mousePress(main, menuMousePos);
171 if(!main.keyDown(main, key, ascii, menuShiftState))
173 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
174 m_hide(); // disable menu on unhandled ESC
176 if(key >= K_MOUSE1 && key <= K_MOUSE3)
178 ++mouseButtonsPressed;
179 if(mouseButtonsPressed > 10)
181 mouseButtonsPressed = 10;
182 print("Warning: pressed an already pressed button\n");
185 if(key == K_ALT) menuShiftState |= S_ALT;
186 if(key == K_CTRL) menuShiftState |= S_CTRL;
187 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
190 void(string img, float a) drawBackground =
194 sz = draw_PictureSize(img);
195 // keep aspect of image
196 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
198 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
199 // match up the height
201 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
205 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
206 // match up the width
208 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
210 draw_Picture('0.5 0.5 0' - 0.5 * isz, img, isz, '1 1 1', a);
218 menuMouseMode = cvar("menu_mouse_absolute");
221 UpdateConWidthHeight();
225 // TODO draw an info image about this situation
229 if(!menuNotTheFirstFrame)
231 menuNotTheFirstFrame = 1;
233 if(!cvar("menu_video_played"))
235 localcmd("set menu_video_played 1; cd loop $menu_cdtrack; play sound/announcer/male/welcome.ogg\n");
236 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
241 realFrametime = frametime = min(0.2, t - menuPrevTime);
245 t = cvar("menu_slowmo");
256 if(getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU) && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
257 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
262 if(cvar("cl_capturevideo"))
263 frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
268 gamestatus = gamestatus | GAME_ISSERVER;
269 if(clientstate() == CS_CONNECTED)
270 gamestatus = gamestatus | GAME_CONNECTED;
271 if(cvar("developer"))
272 gamestatus = gamestatus | GAME_DEVELOPER;
274 prevMenuAlpha = menuAlpha;
277 if(menuAlpha == 0 && menuLogoAlpha < 2)
279 menuLogoAlpha = menuLogoAlpha + frametime * 2;
283 menuAlpha = min(1, menuAlpha + frametime * 5);
289 menuAlpha = max(0, menuAlpha - frametime * 5);
295 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
297 if(menuLogoAlpha > 0)
299 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1));
300 if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
302 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
303 draw_drawMousePointer(menuMousePos);
308 else if(SKINALPHA_BACKGROUND_INGAME)
311 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME);
320 if(prevMenuAlpha > 0)
321 main.initializeDialog(main, main.firstChild);
327 draw_alpha *= menuAlpha;
332 newMouse = globalToBoxSize(getmousepos(), draw_scale);
333 if(newMouse != '0 0 0')
334 if(newMouse != menuMousePos)
336 menuMousePos = newMouse;
337 if(mouseButtonsPressed)
338 main.mouseDrag(main, menuMousePos);
340 main.mouseMove(main, menuMousePos);
348 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
349 if(dMouse != '0 0 0')
351 dMouse = globalToBoxSize(dMouse, draw_scale);
352 menuMousePos += dMouse * cvar("menu_mouse_speed");
353 menuMousePos_x = bound(0, menuMousePos_x, 1);
354 menuMousePos_y = bound(0, menuMousePos_y, 1);
355 if(mouseButtonsPressed)
356 main.mouseDrag(main, menuMousePos);
358 main.mouseMove(main, menuMousePos);
363 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
365 draw_drawMousePointer(menuMousePos);
376 setkeydest(KEY_MENU);
377 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
382 if(mouseButtonsPressed)
383 main.mouseRelease(main, menuMousePos);
384 mouseButtonsPressed = 0;
386 main.focusEnter(main);
387 main.showNotify(main);
393 setkeydest(KEY_GAME);
394 setmousetarget(MT_CLIENT);
399 main.focusLeave(main);
400 main.hideNotify(main);
416 for(e = NULL; (e = nextent(e)) != NULL; )
423 void m_focus_item_chain(entity outermost, entity innermost)
425 if(innermost.parent != outermost)
426 m_focus_item_chain(outermost, innermost.parent);
427 innermost.parent.setFocus(innermost.parent, innermost);
430 void m_activate_window(entity wnd)
435 m_activate_window(par);
437 if(par.instanceOfModalController)
439 if(wnd.tabSelectingButton)
441 TabButton_Click(wnd.tabSelectingButton, wnd);
444 par.initializeDialog(par, wnd);
446 else if(par.instanceOfNexposee)
448 // nexposee (sorry for violating abstraction here)
449 par.selectedChild = wnd;
450 par.animationState = 1;
451 setFocusContainer(par, NULL);
453 else if(par.instanceOfContainer)
457 par.setFocus(par, wnd);
461 void m_setpointerfocus(entity wnd)
463 if(wnd.instanceOfContainer)
465 entity focus = wnd.preferredFocusedGrandChild(wnd);
468 menuMousePos = focus.origin + 0.5 * focus.size;
469 menuMousePos_x *= 1 / conwidth;
470 menuMousePos_y *= 1 / conheight;
471 if(wnd.focused) // why does this never happen?
472 m_focus_item_chain(wnd, focus);
477 void(string itemname) m_goto =
482 if(itemname == "") // this can be called by GameCommand
484 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
488 m_activate_window(main.mainNexposee);
494 e = findstring(NULL, name, itemname);
498 m_activate_window(e);
499 m_setpointerfocus(e);
505 void() m_goto_skin_selector =
509 // TODO add code to switch back to the skin selector (no idea how to do it now)
510 m_goto("skinselector");