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);
96 Skin_ApplySetting(argv(0), substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
100 glob = search_begin(strcat(draw_currentSkin, "/*.tga"), TRUE, TRUE);
103 n = search_getsize(glob);
104 for(i = 0; i < n; ++i)
105 precache_pic(search_getfilename(glob, i));
109 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
111 conwidth = conheight = -1;
113 UpdateConWidthHeight();
114 main = spawnMainWindow(); main.configureMainWindow(main);
115 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
118 menuMousePos = '0.5 0.5 0';
121 m_display(); // delayed menu display
124 void(float key, float ascii) m_keyup =
131 main.keyUp(main, key, ascii, menuShiftState);
132 if(key >= K_MOUSE1 && key <= K_MOUSE3)
134 --mouseButtonsPressed;
135 if(!mouseButtonsPressed)
136 main.mouseRelease(main, menuMousePos);
137 if(mouseButtonsPressed < 0)
139 mouseButtonsPressed = 0;
140 print("Warning: released an already released button\n");
143 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
144 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
145 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
148 void(float key, float ascii) m_keydown =
159 e.keyGrabbed(e, key, ascii);
164 if(key >= K_MOUSE1 && key <= K_MOUSE3)
165 if(!mouseButtonsPressed)
166 main.mousePress(main, menuMousePos);
167 if(!main.keyDown(main, key, ascii, menuShiftState))
169 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
170 m_hide(); // disable menu on unhandled ESC
172 if(key >= K_MOUSE1 && key <= K_MOUSE3)
174 ++mouseButtonsPressed;
175 if(mouseButtonsPressed > 10)
177 mouseButtonsPressed = 10;
178 print("Warning: pressed an already pressed button\n");
181 if(key == K_ALT) menuShiftState |= S_ALT;
182 if(key == K_CTRL) menuShiftState |= S_CTRL;
183 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
186 void(string img, float a) drawBackground =
190 sz = draw_PictureSize(img);
191 // keep aspect of image
192 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
194 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
195 // match up the height
197 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
201 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
202 // match up the width
204 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
206 draw_Picture('0.5 0.5 0' - 0.5 * isz, img, isz, '1 1 1', a);
214 menuMouseMode = cvar("menu_mouse_absolute");
217 UpdateConWidthHeight();
221 // TODO draw an info image about this situation
225 if(!menuNotTheFirstFrame)
227 menuNotTheFirstFrame = 1;
229 if(!cvar("menu_video_played"))
231 localcmd("set menu_video_played 1; cd loop $menu_cdtrack; play sound/announcer/male/welcome.ogg\n");
232 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
237 realFrametime = frametime = min(0.2, t - menuPrevTime);
241 t = cvar("menu_slowmo");
252 if(getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU) && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
253 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
258 if(cvar("cl_capturevideo"))
259 frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
264 gamestatus = gamestatus | GAME_ISSERVER;
265 if(clientstate() == CS_CONNECTED)
266 gamestatus = gamestatus | GAME_CONNECTED;
267 if(cvar("developer"))
268 gamestatus = gamestatus | GAME_DEVELOPER;
270 prevMenuAlpha = menuAlpha;
273 if(menuAlpha == 0 && menuLogoAlpha < 2)
275 menuLogoAlpha = menuLogoAlpha + frametime * 2;
279 menuAlpha = min(1, menuAlpha + frametime * 5);
285 menuAlpha = max(0, menuAlpha - frametime * 5);
291 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
293 if(menuLogoAlpha > 0)
295 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1));
296 if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
298 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
299 draw_drawMousePointer(menuMousePos);
304 else if(SKINALPHA_BACKGROUND_INGAME)
307 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME);
316 if(prevMenuAlpha > 0)
317 main.initializeDialog(main, main.firstChild);
323 draw_alpha *= menuAlpha;
328 newMouse = globalToBoxSize(getmousepos(), draw_scale);
329 if(newMouse != '0 0 0')
330 if(newMouse != menuMousePos)
332 menuMousePos = newMouse;
333 if(mouseButtonsPressed)
334 main.mouseDrag(main, menuMousePos);
336 main.mouseMove(main, menuMousePos);
344 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
345 if(dMouse != '0 0 0')
347 dMouse = globalToBoxSize(dMouse, draw_scale);
348 menuMousePos += dMouse * cvar("menu_mouse_speed");
349 menuMousePos_x = bound(0, menuMousePos_x, 1);
350 menuMousePos_y = bound(0, menuMousePos_y, 1);
351 if(mouseButtonsPressed)
352 main.mouseDrag(main, menuMousePos);
354 main.mouseMove(main, menuMousePos);
359 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
361 draw_drawMousePointer(menuMousePos);
372 setkeydest(KEY_MENU);
373 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
378 if(mouseButtonsPressed)
379 main.mouseRelease(main, menuMousePos);
380 mouseButtonsPressed = 0;
382 main.focusEnter(main);
383 main.showNotify(main);
389 setkeydest(KEY_GAME);
390 setmousetarget(MT_CLIENT);
395 main.focusLeave(main);
396 main.hideNotify(main);
412 for(e = NULL; (e = nextent(e)) != NULL; )
419 void m_focus_item_chain(entity outermost, entity innermost)
421 if(innermost.parent != outermost)
422 m_focus_item_chain(outermost, innermost.parent);
423 innermost.parent.setFocus(innermost.parent, innermost);
426 void m_activate_window(entity wnd)
431 m_activate_window(par);
433 if(par.instanceOfModalController)
435 if(wnd.tabSelectingButton)
437 TabButton_Click(wnd.tabSelectingButton, wnd);
440 par.initializeDialog(par, wnd);
442 else if(par.instanceOfNexposee)
444 // nexposee (sorry for violating abstraction here)
445 par.selectedChild = wnd;
446 par.animationState = 1;
447 setFocusContainer(par, NULL);
449 else if(par.instanceOfContainer)
453 par.setFocus(par, wnd);
457 void m_setpointerfocus(entity wnd)
459 if(wnd.instanceOfContainer)
461 entity focus = wnd.preferredFocusedGrandChild(wnd);
464 menuMousePos = focus.origin + 0.5 * focus.size;
465 menuMousePos_x *= 1 / conwidth;
466 menuMousePos_y *= 1 / conheight;
467 if(wnd.focused) // why does this never happen?
468 m_focus_item_chain(wnd, focus);
473 void(string itemname) m_goto =
478 if(itemname == "") // this can be called by GameCommand
480 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
484 m_activate_window(main.mainNexposee);
490 e = findstring(NULL, name, itemname);
494 m_activate_window(e);
495 m_setpointerfocus(e);
501 void() m_goto_skin_selector =
505 // TODO add code to switch back to the skin selector (no idea how to do it now)
506 m_goto("skinselector");