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 menuLoadedMaplist;
16 float menuNotTheFirstFrame;
25 void() m_init_delayed =
32 menuLoadedMaplist = 0;
34 if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 1))
36 menuLoadedMaplist = 1;
41 if(cvar_string("menu_skin") != "")
43 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
44 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
48 draw_currentSkin = "gfx/menu/default";
49 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
51 draw_currentSkin = strzone(draw_currentSkin);
52 while((s = fgets(fh)))
54 Skin_ApplySetting(argv(0), argv(1));
57 draw_setMousePointer("cursor");
59 main = spawnMainWindow(); main.configureMainWindow(main);
61 main.resizeNotify(main, draw_shift, draw_scale, draw_shift, draw_scale);
66 m_display(); // delayed menu display
69 void(float key, float ascii) m_keyup =
71 if(!menuLoadedMaplist)
76 main.keyUp(main, key, ascii, menuShiftState);
77 if(key >= K_MOUSE1 && key <= K_MOUSE3)
79 --mouseButtonsPressed;
80 if(!mouseButtonsPressed)
81 main.mouseRelease(main, menuMousePos);
82 if(mouseButtonsPressed < 0)
84 mouseButtonsPressed = 0;
85 print("Warning: released an already released button\n");
88 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
89 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
90 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
93 void(float key, float ascii) m_keydown =
95 if(!menuLoadedMaplist)
104 e.keyGrabbed(e, key, ascii);
109 if(!main.keyDown(main, key, ascii, menuShiftState))
111 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
112 m_hide(); // disable menu on unhandled ESC
113 if(key >= K_MOUSE1 && key <= K_MOUSE3)
114 if(!mouseButtonsPressed)
115 main.mousePress(main, menuMousePos);
117 if(key >= K_MOUSE1 && key <= K_MOUSE3)
119 ++mouseButtonsPressed;
120 if(mouseButtonsPressed > 10)
122 mouseButtonsPressed = 10;
123 print("Warning: pressed an already pressed button\n");
126 if(key == K_ALT) menuShiftState |= S_ALT;
127 if(key == K_CTRL) menuShiftState |= S_CTRL;
128 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
136 if(!menuNotTheFirstFrame)
138 menuNotTheFirstFrame = 1;
140 if(!cvar("menu_video_played"))
142 localcmd("set menu_video_played 1; cd loop 1; play sound/announcer/male/welcome.ogg\n");
143 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
146 if(!menuLoadedMaplist)
148 // TODO draw an info image about this situation
153 realFrametime = frametime = min(0.2, t - menuPrevTime);
159 if(getmousetarget() == MT_MENU && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
160 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
165 if(cvar("cl_capturevideo"))
166 frametime = 1 / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
171 gamestatus = gamestatus | GAME_ISSERVER;
172 if(clientstate() == CS_CONNECTED)
173 gamestatus = gamestatus | GAME_CONNECTED;
174 if(cvar("developer"))
175 gamestatus = gamestatus | GAME_DEVELOPER;
177 prevMenuAlpha = menuAlpha;
180 if(menuAlpha == 0 && menuLogoAlpha < 2)
182 menuLogoAlpha = menuLogoAlpha + frametime * 2;
186 menuAlpha = min(1, menuAlpha + frametime * 5);
192 menuAlpha = max(0, menuAlpha - frametime * 5);
198 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
202 sz = draw_PictureSize(SKINGFX_BACKGROUND);
203 // keep aspect of image
204 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
206 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
207 // match up the height
209 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
213 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
214 // match up the width
216 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
218 draw_Picture('0.5 0.5 0' - 0.5 * isz, SKINGFX_BACKGROUND, isz, '1 1 1', bound(0, menuLogoAlpha, 1));
223 if(prevMenuAlpha > 0)
224 main.initializeDialog(main, main.firstChild);
228 draw_alpha *= menuAlpha;
233 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
234 if(dMouse != '0 0 0')
236 dMouse = globalToBoxSize(dMouse, draw_scale);
237 menuMousePos += dMouse * 1; // TODO use a cvar here
238 menuMousePos_x = bound(0, menuMousePos_x, 1);
239 menuMousePos_y = bound(0, menuMousePos_y, 1);
240 if(mouseButtonsPressed)
241 main.mouseDrag(main, menuMousePos);
243 main.mouseMove(main, menuMousePos);
247 draw_drawMousePointer(menuMousePos);
255 setkeydest(KEY_MENU);
256 setmousetarget(MT_MENU);
258 if(!menuLoadedMaplist)
261 if(mouseButtonsPressed)
262 main.mouseRelease(main, menuMousePos);
263 mouseButtonsPressed = 0;
265 main.focusEnter(main);
266 main.showNotify(main);
272 setkeydest(KEY_GAME);
273 setmousetarget(MT_CLIENT);
275 if(!menuLoadedMaplist)
278 main.focusLeave(main);
279 main.hideNotify(main);
295 void(string itemname) m_goto =
298 if(!menuLoadedMaplist)
300 if(itemname == "") // this can be called by GameCommand
302 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
306 main.initializeDialog(main, main.firstChild);
312 e = findstring(NULL, name, itemname);
313 if(e && e.parent == main)
316 main.initializeDialog(main, e);