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 // these two are handled by skinlist.qc
87 if(substring(s, 0, 6) == "title ")
89 if(substring(s, 0, 7) == "author ")
93 Skin_ApplySetting(argv(0), substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)));
97 glob = search_begin(strcat(draw_currentSkin, "/*.tga"), TRUE, TRUE);
100 n = search_getsize(glob);
101 for(i = 0; i < n; ++i)
102 precache_pic(search_getfilename(glob, i));
106 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
108 conwidth = conheight = -1;
110 UpdateConWidthHeight();
111 main = spawnMainWindow(); main.configureMainWindow(main);
112 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
115 menuMousePos = '0.5 0.5 0';
118 m_display(); // delayed menu display
121 void(float key, float ascii) m_keyup =
128 main.keyUp(main, key, ascii, menuShiftState);
129 if(key >= K_MOUSE1 && key <= K_MOUSE3)
131 --mouseButtonsPressed;
132 if(!mouseButtonsPressed)
133 main.mouseRelease(main, menuMousePos);
134 if(mouseButtonsPressed < 0)
136 mouseButtonsPressed = 0;
137 print("Warning: released an already released button\n");
140 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
141 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
142 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
145 void(float key, float ascii) m_keydown =
156 e.keyGrabbed(e, key, ascii);
161 if(key >= K_MOUSE1 && key <= K_MOUSE3)
162 if(!mouseButtonsPressed)
163 main.mousePress(main, menuMousePos);
164 if(!main.keyDown(main, key, ascii, menuShiftState))
166 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
167 m_hide(); // disable menu on unhandled ESC
169 if(key >= K_MOUSE1 && key <= K_MOUSE3)
171 ++mouseButtonsPressed;
172 if(mouseButtonsPressed > 10)
174 mouseButtonsPressed = 10;
175 print("Warning: pressed an already pressed button\n");
178 if(key == K_ALT) menuShiftState |= S_ALT;
179 if(key == K_CTRL) menuShiftState |= S_CTRL;
180 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
183 void(string img, float a) drawBackground =
187 sz = draw_PictureSize(img);
188 // keep aspect of image
189 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
191 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
192 // match up the height
194 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
198 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
199 // match up the width
201 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
203 draw_Picture('0.5 0.5 0' - 0.5 * isz, img, isz, '1 1 1', a);
211 menuMouseMode = cvar("menu_mouse_absolute");
214 UpdateConWidthHeight();
218 // TODO draw an info image about this situation
222 if(!menuNotTheFirstFrame)
224 menuNotTheFirstFrame = 1;
226 if(!cvar("menu_video_played"))
228 localcmd("set menu_video_played 1; cd loop $menu_cdtrack; play sound/announcer/male/welcome.ogg\n");
229 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
234 realFrametime = frametime = min(0.2, t - menuPrevTime);
238 t = cvar("menu_slowmo");
249 if(getmousetarget() == (menuMouseMode ? MT_CLIENT : MT_MENU) && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
250 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
255 if(cvar("cl_capturevideo"))
256 frametime = t / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
261 gamestatus = gamestatus | GAME_ISSERVER;
262 if(clientstate() == CS_CONNECTED)
263 gamestatus = gamestatus | GAME_CONNECTED;
264 if(cvar("developer"))
265 gamestatus = gamestatus | GAME_DEVELOPER;
267 prevMenuAlpha = menuAlpha;
270 if(menuAlpha == 0 && menuLogoAlpha < 2)
272 menuLogoAlpha = menuLogoAlpha + frametime * 2;
276 menuAlpha = min(1, menuAlpha + frametime * 5);
282 menuAlpha = max(0, menuAlpha - frametime * 5);
288 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
290 if(menuLogoAlpha > 0)
292 drawBackground(SKINGFX_BACKGROUND, bound(0, menuLogoAlpha, 1));
293 if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
295 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
296 draw_drawMousePointer(menuMousePos);
301 else if(SKINALPHA_BACKGROUND_INGAME)
304 drawBackground(SKINGFX_BACKGROUND_INGAME, menuAlpha * SKINALPHA_BACKGROUND_INGAME);
313 if(prevMenuAlpha > 0)
314 main.initializeDialog(main, main.firstChild);
320 draw_alpha *= menuAlpha;
325 newMouse = globalToBoxSize(getmousepos(), draw_scale);
326 if(newMouse != '0 0 0')
327 if(newMouse != menuMousePos)
329 menuMousePos = newMouse;
330 if(mouseButtonsPressed)
331 main.mouseDrag(main, menuMousePos);
333 main.mouseMove(main, menuMousePos);
341 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
342 if(dMouse != '0 0 0')
344 dMouse = globalToBoxSize(dMouse, draw_scale);
345 menuMousePos += dMouse * cvar("menu_mouse_speed");
346 menuMousePos_x = bound(0, menuMousePos_x, 1);
347 menuMousePos_y = bound(0, menuMousePos_y, 1);
348 if(mouseButtonsPressed)
349 main.mouseDrag(main, menuMousePos);
351 main.mouseMove(main, menuMousePos);
356 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
358 draw_drawMousePointer(menuMousePos);
369 setkeydest(KEY_MENU);
370 setmousetarget((menuMouseMode ? MT_CLIENT : MT_MENU));
375 if(mouseButtonsPressed)
376 main.mouseRelease(main, menuMousePos);
377 mouseButtonsPressed = 0;
379 main.focusEnter(main);
380 main.showNotify(main);
386 setkeydest(KEY_GAME);
387 setmousetarget(MT_CLIENT);
392 main.focusLeave(main);
393 main.hideNotify(main);
409 for(e = NULL; (e = nextent(e)) != NULL; )
416 void m_activate_window(entity wnd)
421 m_activate_window(par);
423 if(par.instanceOfModalController)
425 if(wnd.tabSelectingButton)
427 TabButton_Click(wnd.tabSelectingButton, wnd);
430 par.initializeDialog(par, wnd);
432 else if(par.instanceOfNexposee)
434 // nexposee (sorry for violating abstraction here)
435 par.selectedChild = wnd;
436 par.animationState = 1;
437 setFocusContainer(par, NULL);
439 else if(par.instanceOfContainer)
443 par.setFocus(par, wnd);
447 void(string itemname) m_goto =
452 if(itemname == "") // this can be called by GameCommand
454 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
458 m_activate_window(main.mainNexposee);
464 e = findstring(NULL, name, itemname);
468 m_activate_window(e);
474 void() m_goto_skin_selector =
478 // TODO add code to switch back to the skin selector (no idea how to do it now)
479 m_goto("skinselector");