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 draw_setMousePointer(SKINGFX_CURSOR, SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
84 conwidth = conheight = -1;
86 UpdateConWidthHeight();
87 main = spawnMainWindow(); main.configureMainWindow(main);
88 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
91 menuMousePos = '0.5 0.5 0';
94 m_display(); // delayed menu display
97 void(float key, float ascii) m_keyup =
104 main.keyUp(main, key, ascii, menuShiftState);
105 if(key >= K_MOUSE1 && key <= K_MOUSE3)
107 --mouseButtonsPressed;
108 if(!mouseButtonsPressed)
109 main.mouseRelease(main, menuMousePos);
110 if(mouseButtonsPressed < 0)
112 mouseButtonsPressed = 0;
113 print("Warning: released an already released button\n");
116 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
117 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
118 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
121 void(float key, float ascii) m_keydown =
132 e.keyGrabbed(e, key, ascii);
137 if(!main.keyDown(main, key, ascii, menuShiftState))
139 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
140 m_hide(); // disable menu on unhandled ESC
141 if(key >= K_MOUSE1 && key <= K_MOUSE3)
142 if(!mouseButtonsPressed)
143 main.mousePress(main, menuMousePos);
145 if(key >= K_MOUSE1 && key <= K_MOUSE3)
147 ++mouseButtonsPressed;
148 if(mouseButtonsPressed > 10)
150 mouseButtonsPressed = 10;
151 print("Warning: pressed an already pressed button\n");
154 if(key == K_ALT) menuShiftState |= S_ALT;
155 if(key == K_CTRL) menuShiftState |= S_CTRL;
156 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
165 UpdateConWidthHeight();
167 if(!menuNotTheFirstFrame)
169 menuNotTheFirstFrame = 1;
171 if(!cvar("menu_video_played"))
173 localcmd("set menu_video_played 1; cd loop 1; play sound/announcer/male/welcome.ogg\n");
174 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
179 // TODO draw an info image about this situation
185 realFrametime = frametime = min(0.2, t - menuPrevTime);
191 if(getmousetarget() == MT_MENU && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
192 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
197 if(cvar("cl_capturevideo"))
198 frametime = 1 / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
203 gamestatus = gamestatus | GAME_ISSERVER;
204 if(clientstate() == CS_CONNECTED)
205 gamestatus = gamestatus | GAME_CONNECTED;
206 if(cvar("developer"))
207 gamestatus = gamestatus | GAME_DEVELOPER;
209 prevMenuAlpha = menuAlpha;
212 if(menuAlpha == 0 && menuLogoAlpha < 2)
214 menuLogoAlpha = menuLogoAlpha + frametime * 2;
218 menuAlpha = min(1, menuAlpha + frametime * 5);
224 menuAlpha = max(0, menuAlpha - frametime * 5);
230 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)) && menuLogoAlpha > 0)
234 sz = draw_PictureSize(SKINGFX_BACKGROUND);
235 // keep aspect of image
236 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
238 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
239 // match up the height
241 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
245 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
246 // match up the width
248 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
250 draw_Picture('0.5 0.5 0' - 0.5 * isz, SKINGFX_BACKGROUND, isz, '1 1 1', bound(0, menuLogoAlpha, 1));
251 if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
253 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
254 draw_drawMousePointer(menuMousePos);
265 if(prevMenuAlpha > 0)
266 main.initializeDialog(main, main.firstChild);
272 draw_alpha *= menuAlpha;
277 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
278 if(dMouse != '0 0 0')
280 dMouse = globalToBoxSize(dMouse, draw_scale);
281 menuMousePos += dMouse * 1; // TODO use a cvar here
282 menuMousePos_x = bound(0, menuMousePos_x, 1);
283 menuMousePos_y = bound(0, menuMousePos_y, 1);
284 if(mouseButtonsPressed)
285 main.mouseDrag(main, menuMousePos);
287 main.mouseMove(main, menuMousePos);
291 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
293 draw_drawMousePointer(menuMousePos);
304 setkeydest(KEY_MENU);
305 setmousetarget(MT_MENU);
310 if(mouseButtonsPressed)
311 main.mouseRelease(main, menuMousePos);
312 mouseButtonsPressed = 0;
314 main.focusEnter(main);
315 main.showNotify(main);
321 setkeydest(KEY_GAME);
322 setmousetarget(MT_CLIENT);
327 main.focusLeave(main);
328 main.hideNotify(main);
344 void(string itemname) m_goto =
349 if(itemname == "") // this can be called by GameCommand
351 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
355 main.initializeDialog(main, main.firstChild);
361 e = findstring(NULL, name, itemname);
362 if(e && e.parent == main)
365 main.initializeDialog(main, e);