1 ///////////////////////////////////////////////
3 ///////////////////////
4 // This file belongs to dpmod/darkplaces
5 // AK contains all menu functions (especially the required ones)
6 ///////////////////////////////////////////////
8 float mouseButtonsPressed;
14 float menuLoadedMaplist;
15 float menuNotTheFirstFrame;
24 void() m_init_delayed =
28 menuLoadedMaplist = 0;
30 if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 1))
32 menuLoadedMaplist = 1;
36 if(cvar("developer") == 42)
37 draw_currentSkin = "qcsrc/menu-div0test/xawskin";
39 draw_currentSkin = "qcsrc/menu-div0test/defaultskin";
40 // TODO load SKIN constants from file later
42 draw_setMousePointer("cursor");
44 main = spawnMainWindow(); main.configureMainWindow(main);
46 main.resizeNotify(main, draw_shift, draw_scale, draw_shift, draw_scale);
51 m_display(); // delayed menu display
54 void(float key, float ascii) m_keyup =
56 if(!menuLoadedMaplist)
61 main.keyUp(main, key, ascii, menuShiftState);
62 if(key >= K_MOUSE1 && key <= K_MOUSE3)
64 --mouseButtonsPressed;
65 if(!mouseButtonsPressed)
66 main.mouseRelease(main, menuMousePos);
67 if(mouseButtonsPressed < 0)
69 mouseButtonsPressed = 0;
70 print("Warning: released an already released button\n");
73 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
74 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
75 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
78 void(float key, float ascii) m_keydown =
80 if(!menuLoadedMaplist)
89 e.keyGrabbed(e, key, ascii);
94 if(!main.keyDown(main, key, ascii, menuShiftState))
96 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
97 m_hide(); // disable menu on unhandled ESC
98 if(key >= K_MOUSE1 && key <= K_MOUSE3)
99 if(!mouseButtonsPressed)
100 main.mousePress(main, menuMousePos);
102 if(key >= K_MOUSE1 && key <= K_MOUSE3)
104 ++mouseButtonsPressed;
105 if(mouseButtonsPressed > 10)
107 mouseButtonsPressed = 10;
108 print("Warning: pressed an already pressed button\n");
111 if(key == K_ALT) menuShiftState |= S_ALT;
112 if(key == K_CTRL) menuShiftState |= S_CTRL;
113 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
120 if(!menuNotTheFirstFrame)
122 menuNotTheFirstFrame = 1;
124 if(!cvar("menu_video_played"))
125 localcmd("set menu_video_played 1; playvideo logo; cd loop 1; play sound/announcer/male/welcome.ogg\n");
127 if(!menuLoadedMaplist)
129 // TODO draw an info image about this situation
134 realFrametime = frametime = min(0.2, t - menuPrevTime);
138 if(getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED)
140 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
145 if(getmousetarget() != MT_MENU)
149 if(cvar("cl_capturevideo"))
150 frametime = 1 / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
152 prevMenuAlpha = menuAlpha;
154 menuAlpha = min(1, menuAlpha + frametime * 5);
156 menuAlpha = max(0, menuAlpha - frametime * 5);
160 if(prevMenuAlpha > 0)
161 main.initializeDialog(main, main.firstChild);
168 gamestatus = gamestatus | GAME_ISSERVER;
169 if(clientstate() == CS_CONNECTED)
170 gamestatus = gamestatus | GAME_CONNECTED;
171 if(cvar("developer"))
172 gamestatus = gamestatus | GAME_DEVELOPER;
175 draw_alpha *= menuAlpha;
177 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)))
181 sz = draw_PictureSize(SKINGFX_BACKGROUND);
182 // keep aspect of image
183 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
185 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
186 // match up the height
188 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
192 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
193 // match up the width
195 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
197 draw_Picture('0.5 0.5 0' - 0.5 * isz, SKINGFX_BACKGROUND, isz, '1 1 1', 1);
203 dMouse = getmousepos();
204 dMouse *= frametime / realFrametime; // for capturevideo
205 if(dMouse != '0 0 0')
207 dMouse = globalToBoxSize(dMouse, draw_scale);
208 menuMousePos += dMouse * 1; // TODO use a cvar here
209 menuMousePos_x = bound(0, menuMousePos_x, 1);
210 menuMousePos_y = bound(0, menuMousePos_y, 1);
211 if(mouseButtonsPressed)
212 main.mouseDrag(main, menuMousePos);
214 main.mouseMove(main, menuMousePos);
218 draw_drawMousePointer(menuMousePos);
226 setkeydest(KEY_MENU);
227 setmousetarget(MT_MENU);
229 if(!menuLoadedMaplist)
232 if(mouseButtonsPressed)
233 main.mouseRelease(main, menuMousePos);
234 mouseButtonsPressed = 0;
236 main.focusEnter(main);
237 main.showNotify(main);
243 setkeydest(KEY_GAME);
244 setmousetarget(MT_CLIENT);
246 if(!menuLoadedMaplist)
249 main.focusLeave(main);
250 main.hideNotify(main);
266 void(string itemname) m_goto =
269 if(!menuLoadedMaplist)
271 if(itemname == "") // this can be called by GameCommand
273 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
277 main.initializeDialog(main, main.firstChild);
283 e = findstring(NULL, name, itemname);
284 if(e && e.parent == main)
287 main.initializeDialog(main, e);