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);
72 if(cvar_defstring("menu_skin") != "")
74 draw_currentSkin = strcat("gfx/menu/", cvar_defstring("menu_skin"));
75 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
79 draw_currentSkin = "gfx/menu/default";
80 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
82 draw_currentSkin = strzone(draw_currentSkin);
83 while((s = fgets(fh)))
85 Skin_ApplySetting(argv(0), argv(1));
88 glob = search_begin(strcat(draw_currentSkin, "/*.tga"), TRUE, TRUE);
91 n = search_getsize(glob);
92 for(i = 0; i < n; ++i)
93 precache_pic(search_getfilename(glob, i));
97 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
99 conwidth = conheight = -1;
101 UpdateConWidthHeight();
102 main = spawnMainWindow(); main.configureMainWindow(main);
103 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
106 menuMousePos = '0.5 0.5 0';
109 m_display(); // delayed menu display
112 void(float key, float ascii) m_keyup =
119 main.keyUp(main, key, ascii, menuShiftState);
120 if(key >= K_MOUSE1 && key <= K_MOUSE3)
122 --mouseButtonsPressed;
123 if(!mouseButtonsPressed)
124 main.mouseRelease(main, menuMousePos);
125 if(mouseButtonsPressed < 0)
127 mouseButtonsPressed = 0;
128 print("Warning: released an already released button\n");
131 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
132 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
133 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
136 void(float key, float ascii) m_keydown =
147 e.keyGrabbed(e, key, ascii);
152 if(!main.keyDown(main, key, ascii, menuShiftState))
154 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
155 m_hide(); // disable menu on unhandled ESC
156 if(key >= K_MOUSE1 && key <= K_MOUSE3)
157 if(!mouseButtonsPressed)
158 main.mousePress(main, menuMousePos);
160 if(key >= K_MOUSE1 && key <= K_MOUSE3)
162 ++mouseButtonsPressed;
163 if(mouseButtonsPressed > 10)
165 mouseButtonsPressed = 10;
166 print("Warning: pressed an already pressed button\n");
169 if(key == K_ALT) menuShiftState |= S_ALT;
170 if(key == K_CTRL) menuShiftState |= S_CTRL;
171 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
174 void(string img, float a) drawBackground =
178 sz = draw_PictureSize(img);
179 // keep aspect of image
180 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
182 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
183 // match up the height
185 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
189 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
190 // match up the width
192 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
194 draw_Picture('0.5 0.5 0' - 0.5 * isz, img, isz, '1 1 1', a);
202 menuMouseMode = cvar("menu_mouse_absolute");
205 UpdateConWidthHeight();
209 // TODO draw an info image about this situation
213 if(!menuNotTheFirstFrame)
215 menuNotTheFirstFrame = 1;
217 if(!cvar("menu_video_played"))
219 localcmd("set menu_video_played 1; cd loop $menu_cdtrack; play sound/announcer/male/welcome.ogg\n");
220 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
225 realFrametime = frametime = min(0.2, t - menuPrevTime);
229 t = cvar("menu_slowmo");
240 if(getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU) && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
241 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
246 if(cvar("cl_capturevideo"))
247 frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
252 gamestatus = gamestatus | GAME_ISSERVER;
253 if(clientstate() == CS_CONNECTED)
254 gamestatus = gamestatus | GAME_CONNECTED;
255 if(cvar("developer"))
256 gamestatus = gamestatus | GAME_DEVELOPER;
258 prevMenuAlpha = menuAlpha;
261 if(menuAlpha == 0 && menuLogoAlpha < 2)
263 menuLogoAlpha = menuLogoAlpha + frametime * 2;
267 menuAlpha = min(1, menuAlpha + frametime * 5);
273 menuAlpha = max(0, menuAlpha - frametime * 5);
279 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
281 if(menuLogoAlpha > 0)
283 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1));
284 if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
286 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
287 draw_drawMousePointer(menuMousePos);
292 else if(SKINALPHA_BACKGROUND_INGAME)
295 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME);
304 if(prevMenuAlpha > 0)
305 main.initializeDialog(main, main.firstChild);
311 draw_alpha *= menuAlpha;
316 newMouse = globalToBoxSize(getmousepos(), draw_scale);
317 if(newMouse != '0 0 0')
318 if(newMouse != menuMousePos)
320 menuMousePos = newMouse;
321 if(mouseButtonsPressed)
322 main.mouseDrag(main, menuMousePos);
324 main.mouseMove(main, menuMousePos);
332 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
333 if(dMouse != '0 0 0')
335 dMouse = globalToBoxSize(dMouse, draw_scale);
336 menuMousePos += dMouse * cvar("menu_mouse_speed");
337 menuMousePos_x = bound(0, menuMousePos_x, 1);
338 menuMousePos_y = bound(0, menuMousePos_y, 1);
339 if(mouseButtonsPressed)
340 main.mouseDrag(main, menuMousePos);
342 main.mouseMove(main, menuMousePos);
347 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
349 draw_drawMousePointer(menuMousePos);
360 setkeydest(KEY_MENU);
361 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
366 if(mouseButtonsPressed)
367 main.mouseRelease(main, menuMousePos);
368 mouseButtonsPressed = 0;
370 main.focusEnter(main);
371 main.showNotify(main);
377 setkeydest(KEY_GAME);
378 setmousetarget(MT_CLIENT);
383 main.focusLeave(main);
384 main.hideNotify(main);
400 for(e = NULL; (e = nextent(e)) != NULL; )
407 void(string itemname) m_goto =
412 if(itemname == "") // this can be called by GameCommand
414 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
418 main.initializeDialog(main, main.firstChild);
424 e = findstring(NULL, name, itemname);
425 if(e && e.parent == main)
428 main.initializeDialog(main, e);