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;
25 void UpdateConWidthHeight()
27 float conwidth_s, conheight_s;
28 conwidth_s = conwidth;
29 conheight_s = conheight;
30 conwidth = cvar("vid_conwidth");
31 conheight = cvar("vid_conheight");
34 conheight *= 800 / conwidth;
39 conwidth *= 600 / conheight;
44 if(conwidth_s != conwidth || conheight_s != conheight)
47 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
52 void() m_init_delayed =
66 if(cvar_string("menu_skin") != "")
68 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
69 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
73 draw_currentSkin = "gfx/menu/default";
74 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
76 draw_currentSkin = strzone(draw_currentSkin);
77 while((s = fgets(fh)))
79 Skin_ApplySetting(argv(0), argv(1));
82 glob = search_begin(strcat(draw_currentSkin, "/*.tga"), TRUE, TRUE);
85 n = search_getsize(glob);
86 for(i = 0; i < n; ++i)
87 precache_pic(search_getfilename(glob, i));
91 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
93 conwidth = conheight = -1;
95 UpdateConWidthHeight();
96 main = spawnMainWindow(); main.configureMainWindow(main);
97 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
100 menuMousePos = '0.5 0.5 0';
103 m_display(); // delayed menu display
106 void(float key, float ascii) m_keyup =
113 main.keyUp(main, key, ascii, menuShiftState);
114 if(key >= K_MOUSE1 && key <= K_MOUSE3)
116 --mouseButtonsPressed;
117 if(!mouseButtonsPressed)
118 main.mouseRelease(main, menuMousePos);
119 if(mouseButtonsPressed < 0)
121 mouseButtonsPressed = 0;
122 print("Warning: released an already released button\n");
125 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
126 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
127 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
130 void(float key, float ascii) m_keydown =
141 e.keyGrabbed(e, key, ascii);
146 if(!main.keyDown(main, key, ascii, menuShiftState))
148 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
149 m_hide(); // disable menu on unhandled ESC
150 if(key >= K_MOUSE1 && key <= K_MOUSE3)
151 if(!mouseButtonsPressed)
152 main.mousePress(main, menuMousePos);
154 if(key >= K_MOUSE1 && key <= K_MOUSE3)
156 ++mouseButtonsPressed;
157 if(mouseButtonsPressed > 10)
159 mouseButtonsPressed = 10;
160 print("Warning: pressed an already pressed button\n");
163 if(key == K_ALT) menuShiftState |= S_ALT;
164 if(key == K_CTRL) menuShiftState |= S_CTRL;
165 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
174 UpdateConWidthHeight();
178 // TODO draw an info image about this situation
182 if(!menuNotTheFirstFrame)
184 menuNotTheFirstFrame = 1;
186 if(!cvar("menu_video_played"))
188 localcmd("set menu_video_played 1; cd loop 1; play sound/announcer/male/welcome.ogg\n");
189 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
194 realFrametime = frametime = min(0.2, t - menuPrevTime);
200 if(getmousetarget() == MT_MENU && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
201 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
206 if(cvar("cl_capturevideo"))
207 frametime = 1 / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
212 gamestatus = gamestatus | GAME_ISSERVER;
213 if(clientstate() == CS_CONNECTED)
214 gamestatus = gamestatus | GAME_CONNECTED;
215 if(cvar("developer"))
216 gamestatus = gamestatus | GAME_DEVELOPER;
218 prevMenuAlpha = menuAlpha;
221 if(menuAlpha == 0 && menuLogoAlpha < 2)
223 menuLogoAlpha = menuLogoAlpha + frametime * 2;
227 menuAlpha = min(1, menuAlpha + frametime * 5);
233 menuAlpha = max(0, menuAlpha - frametime * 5);
239 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)) && menuLogoAlpha > 0)
243 sz = draw_PictureSize(SKINGFX_BACKGROUND);
244 // keep aspect of image
245 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
247 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
248 // match up the height
250 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
254 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
255 // match up the width
257 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
259 draw_Picture('0.5 0.5 0' - 0.5 * isz, SKINGFX_BACKGROUND, isz, '1 1 1', bound(0, menuLogoAlpha, 1));
260 if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
262 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
263 draw_drawMousePointer(menuMousePos);
274 if(prevMenuAlpha > 0)
275 main.initializeDialog(main, main.firstChild);
281 draw_alpha *= menuAlpha;
286 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
287 if(dMouse != '0 0 0')
289 dMouse = globalToBoxSize(dMouse, draw_scale);
290 menuMousePos += dMouse * 1; // TODO use a cvar here
291 menuMousePos_x = bound(0, menuMousePos_x, 1);
292 menuMousePos_y = bound(0, menuMousePos_y, 1);
293 if(mouseButtonsPressed)
294 main.mouseDrag(main, menuMousePos);
296 main.mouseMove(main, menuMousePos);
300 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
302 draw_drawMousePointer(menuMousePos);
313 setkeydest(KEY_MENU);
314 setmousetarget(MT_MENU);
319 if(mouseButtonsPressed)
320 main.mouseRelease(main, menuMousePos);
321 mouseButtonsPressed = 0;
323 main.focusEnter(main);
324 main.showNotify(main);
330 setkeydest(KEY_GAME);
331 setmousetarget(MT_CLIENT);
336 main.focusLeave(main);
337 main.hideNotify(main);
353 void(string itemname) m_goto =
358 if(itemname == "") // this can be called by GameCommand
360 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
364 main.initializeDialog(main, main.firstChild);
370 e = findstring(NULL, name, itemname);
371 if(e && e.parent == main)
374 main.initializeDialog(main, e);