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);
73 if(cvar_defstring("menu_skin") != "")
75 draw_currentSkin = strcat("gfx/menu/", cvar_defstring("menu_skin"));
76 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
80 draw_currentSkin = "gfx/menu/default";
81 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
83 draw_currentSkin = strzone(draw_currentSkin);
84 while((s = fgets(fh)))
86 Skin_ApplySetting(argv(0), argv(1));
89 glob = search_begin(strcat(draw_currentSkin, "/*.tga"), TRUE, TRUE);
92 n = search_getsize(glob);
93 for(i = 0; i < n; ++i)
94 precache_pic(search_getfilename(glob, i));
98 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
100 conwidth = conheight = -1;
102 UpdateConWidthHeight();
103 main = spawnMainWindow(); main.configureMainWindow(main);
104 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
107 menuMousePos = '0.5 0.5 0';
110 m_display(); // delayed menu display
113 void(float key, float ascii) m_keyup =
120 main.keyUp(main, key, ascii, menuShiftState);
121 if(key >= K_MOUSE1 && key <= K_MOUSE3)
123 --mouseButtonsPressed;
124 if(!mouseButtonsPressed)
125 main.mouseRelease(main, menuMousePos);
126 if(mouseButtonsPressed < 0)
128 mouseButtonsPressed = 0;
129 print("Warning: released an already released button\n");
132 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
133 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
134 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
137 void(float key, float ascii) m_keydown =
148 e.keyGrabbed(e, key, ascii);
153 if(!main.keyDown(main, key, ascii, menuShiftState))
155 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
156 m_hide(); // disable menu on unhandled ESC
157 if(key >= K_MOUSE1 && key <= K_MOUSE3)
158 if(!mouseButtonsPressed)
159 main.mousePress(main, menuMousePos);
161 if(key >= K_MOUSE1 && key <= K_MOUSE3)
163 ++mouseButtonsPressed;
164 if(mouseButtonsPressed > 10)
166 mouseButtonsPressed = 10;
167 print("Warning: pressed an already pressed button\n");
170 if(key == K_ALT) menuShiftState |= S_ALT;
171 if(key == K_CTRL) menuShiftState |= S_CTRL;
172 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
175 void(string img, float a) drawBackground =
179 sz = draw_PictureSize(img);
180 // keep aspect of image
181 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
183 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
184 // match up the height
186 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
190 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
191 // match up the width
193 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
195 draw_Picture('0.5 0.5 0' - 0.5 * isz, img, isz, '1 1 1', a);
203 menuMouseMode = cvar("menu_mouse_absolute");
206 UpdateConWidthHeight();
210 // TODO draw an info image about this situation
214 if(!menuNotTheFirstFrame)
216 menuNotTheFirstFrame = 1;
218 if(!cvar("menu_video_played"))
220 localcmd("set menu_video_played 1; cd loop $menu_cdtrack; play sound/announcer/male/welcome.ogg\n");
221 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
226 realFrametime = frametime = min(0.2, t - menuPrevTime);
230 t = cvar("menu_slowmo");
241 if(getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU) && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
242 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
247 if(cvar("cl_capturevideo"))
248 frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
253 gamestatus = gamestatus | GAME_ISSERVER;
254 if(clientstate() == CS_CONNECTED)
255 gamestatus = gamestatus | GAME_CONNECTED;
256 if(cvar("developer"))
257 gamestatus = gamestatus | GAME_DEVELOPER;
259 prevMenuAlpha = menuAlpha;
262 if(menuAlpha == 0 && menuLogoAlpha < 2)
264 menuLogoAlpha = menuLogoAlpha + frametime * 2;
268 menuAlpha = min(1, menuAlpha + frametime * 5);
274 menuAlpha = max(0, menuAlpha - frametime * 5);
280 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
282 if(menuLogoAlpha > 0)
284 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1));
285 if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
287 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
288 draw_drawMousePointer(menuMousePos);
293 else if(SKINALPHA_BACKGROUND_INGAME)
296 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME);
305 if(prevMenuAlpha > 0)
306 main.initializeDialog(main, main.firstChild);
312 draw_alpha *= menuAlpha;
317 newMouse = globalToBoxSize(getmousepos(), draw_scale);
318 if(newMouse != '0 0 0')
319 if(newMouse != menuMousePos)
321 menuMousePos = newMouse;
322 if(mouseButtonsPressed)
323 main.mouseDrag(main, menuMousePos);
325 main.mouseMove(main, menuMousePos);
333 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
334 if(dMouse != '0 0 0')
336 dMouse = globalToBoxSize(dMouse, draw_scale);
337 menuMousePos += dMouse * cvar("menu_mouse_speed");
338 menuMousePos_x = bound(0, menuMousePos_x, 1);
339 menuMousePos_y = bound(0, menuMousePos_y, 1);
340 if(mouseButtonsPressed)
341 main.mouseDrag(main, menuMousePos);
343 main.mouseMove(main, menuMousePos);
348 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
350 draw_drawMousePointer(menuMousePos);
361 setkeydest(KEY_MENU);
362 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
367 if(mouseButtonsPressed)
368 main.mouseRelease(main, menuMousePos);
369 mouseButtonsPressed = 0;
371 main.focusEnter(main);
372 main.showNotify(main);
378 setkeydest(KEY_GAME);
379 setmousetarget(MT_CLIENT);
384 main.focusLeave(main);
385 main.hideNotify(main);
401 for(e = NULL; (e = nextent(e)) != NULL; )
408 void(string itemname) m_goto =
413 if(itemname == "") // this can be called by GameCommand
415 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
419 main.initializeDialog(main, main.firstChild);
425 e = findstring(NULL, name, itemname);
426 if(e && e.parent == main)
429 main.initializeDialog(main, e);