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;
26 void UpdateConWidthHeight()
28 float conwidth_s, conheight_s;
29 conwidth_s = conwidth;
30 conheight_s = conheight;
31 conwidth = cvar("vid_conwidth");
32 conheight = cvar("vid_conheight");
35 conheight *= 800 / conwidth;
40 conwidth *= 600 / conheight;
45 if(conwidth_s != conwidth || conheight_s != conheight)
48 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
53 void() m_init_delayed =
67 if(cvar_string("menu_skin") != "")
69 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
70 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
74 draw_currentSkin = "gfx/menu/default";
75 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
77 draw_currentSkin = strzone(draw_currentSkin);
78 while((s = fgets(fh)))
80 Skin_ApplySetting(argv(0), argv(1));
83 glob = search_begin(strcat(draw_currentSkin, "/*.tga"), TRUE, TRUE);
86 n = search_getsize(glob);
87 for(i = 0; i < n; ++i)
88 precache_pic(search_getfilename(glob, i));
92 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
94 conwidth = conheight = -1;
96 UpdateConWidthHeight();
97 main = spawnMainWindow(); main.configureMainWindow(main);
98 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
101 menuMousePos = '0.5 0.5 0';
104 m_display(); // delayed menu display
107 void(float key, float ascii) m_keyup =
114 main.keyUp(main, key, ascii, menuShiftState);
115 if(key >= K_MOUSE1 && key <= K_MOUSE3)
117 --mouseButtonsPressed;
118 if(!mouseButtonsPressed)
119 main.mouseRelease(main, menuMousePos);
120 if(mouseButtonsPressed < 0)
122 mouseButtonsPressed = 0;
123 print("Warning: released an already released button\n");
126 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
127 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
128 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
131 void(float key, float ascii) m_keydown =
142 e.keyGrabbed(e, key, ascii);
147 if(!main.keyDown(main, key, ascii, menuShiftState))
149 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
150 m_hide(); // disable menu on unhandled ESC
151 if(key >= K_MOUSE1 && key <= K_MOUSE3)
152 if(!mouseButtonsPressed)
153 main.mousePress(main, menuMousePos);
155 if(key >= K_MOUSE1 && key <= K_MOUSE3)
157 ++mouseButtonsPressed;
158 if(mouseButtonsPressed > 10)
160 mouseButtonsPressed = 10;
161 print("Warning: pressed an already pressed button\n");
164 if(key == K_ALT) menuShiftState |= S_ALT;
165 if(key == K_CTRL) menuShiftState |= S_CTRL;
166 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
169 void(string img, float a) drawBackground =
173 sz = draw_PictureSize(img);
174 // keep aspect of image
175 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
177 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
178 // match up the height
180 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
184 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
185 // match up the width
187 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
189 draw_Picture('0.5 0.5 0' - 0.5 * isz, img, isz, '1 1 1', a);
197 menuMouseMode = cvar("menu_mouse_absolute");
200 UpdateConWidthHeight();
204 // TODO draw an info image about this situation
208 if(!menuNotTheFirstFrame)
210 menuNotTheFirstFrame = 1;
212 if(!cvar("menu_video_played"))
214 localcmd("set menu_video_played 1; cd loop 1; play sound/announcer/male/welcome.ogg\n");
215 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
220 realFrametime = frametime = min(0.2, t - menuPrevTime);
224 t = cvar("menu_slowmo");
235 if(getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU) && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
236 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
241 if(cvar("cl_capturevideo"))
242 frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
247 gamestatus = gamestatus | GAME_ISSERVER;
248 if(clientstate() == CS_CONNECTED)
249 gamestatus = gamestatus | GAME_CONNECTED;
250 if(cvar("developer"))
251 gamestatus = gamestatus | GAME_DEVELOPER;
253 prevMenuAlpha = menuAlpha;
256 if(menuAlpha == 0 && menuLogoAlpha < 2)
258 menuLogoAlpha = menuLogoAlpha + frametime * 2;
262 menuAlpha = min(1, menuAlpha + frametime * 5);
268 menuAlpha = max(0, menuAlpha - frametime * 5);
274 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
276 if(menuLogoAlpha > 0)
278 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1));
279 if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
281 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
282 draw_drawMousePointer(menuMousePos);
287 else if(SKINALPHA_BACKGROUND_INGAME)
290 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME);
299 if(prevMenuAlpha > 0)
300 main.initializeDialog(main, main.firstChild);
306 draw_alpha *= menuAlpha;
311 newMouse = globalToBoxSize(getmousepos(), draw_scale);
312 if(newMouse != '0 0 0')
313 if(newMouse != menuMousePos)
315 menuMousePos = newMouse;
316 if(mouseButtonsPressed)
317 main.mouseDrag(main, menuMousePos);
319 main.mouseMove(main, menuMousePos);
327 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
328 if(dMouse != '0 0 0')
330 dMouse = globalToBoxSize(dMouse, draw_scale);
331 menuMousePos += dMouse * cvar("menu_mouse_speed");
332 menuMousePos_x = bound(0, menuMousePos_x, 1);
333 menuMousePos_y = bound(0, menuMousePos_y, 1);
334 if(mouseButtonsPressed)
335 main.mouseDrag(main, menuMousePos);
337 main.mouseMove(main, menuMousePos);
342 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
345 draw_drawMousePointer(menuMousePos);
356 setkeydest(KEY_MENU);
357 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
362 if(mouseButtonsPressed)
363 main.mouseRelease(main, menuMousePos);
364 mouseButtonsPressed = 0;
366 main.focusEnter(main);
367 main.showNotify(main);
373 setkeydest(KEY_GAME);
374 setmousetarget(MT_CLIENT);
379 main.focusLeave(main);
380 main.hideNotify(main);
396 void(string itemname) m_goto =
401 if(itemname == "") // this can be called by GameCommand
403 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
407 main.initializeDialog(main, main.firstChild);
413 e = findstring(NULL, name, itemname);
414 if(e && e.parent == main)
417 main.initializeDialog(main, e);