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;
23 void() m_init_delayed =
27 menuLoadedMaplist = 0;
29 if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 1))
31 menuLoadedMaplist = 1;
35 if(cvar("developer") == 42)
36 draw_currentSkin = "qcsrc/menu-div0test/xawskin";
38 draw_currentSkin = "qcsrc/menu-div0test/defaultskin";
39 // TODO load SKIN constants from file later
41 draw_setMousePointer("cursor");
43 main = spawnMainWindow(); main.configureMainWindow(main);
45 main.resizeNotify(main, draw_shift, draw_scale, draw_shift, draw_scale);
50 m_display(); // delayed menu display
53 void(float key, float ascii) m_keyup =
55 if(!menuLoadedMaplist)
60 main.keyUp(main, key, ascii, menuShiftState);
61 if(key >= K_MOUSE1 && key <= K_MOUSE3)
63 --mouseButtonsPressed;
64 if(!mouseButtonsPressed)
65 main.mouseRelease(main, menuMousePos);
66 if(mouseButtonsPressed < 0)
68 mouseButtonsPressed = 0;
69 print("Warning: released an already released button\n");
72 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
73 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
74 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
77 void(float key, float ascii) m_keydown =
79 if(!menuLoadedMaplist)
88 e.keyGrabbed(e, key, ascii);
93 if(!main.keyDown(main, key, ascii, menuShiftState))
95 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
96 m_hide(); // disable menu on unhandled ESC
97 if(key >= K_MOUSE1 && key <= K_MOUSE3)
98 if(!mouseButtonsPressed)
99 main.mousePress(main, menuMousePos);
101 if(key >= K_MOUSE1 && key <= K_MOUSE3)
103 ++mouseButtonsPressed;
104 if(mouseButtonsPressed > 10)
106 mouseButtonsPressed = 10;
107 print("Warning: pressed an already pressed button\n");
110 if(key == K_ALT) menuShiftState |= S_ALT;
111 if(key == K_CTRL) menuShiftState |= S_CTRL;
112 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
119 if(!menuLoadedMaplist)
121 // TODO draw an info image about this situation
126 realFrametime = frametime = min(0.2, t - menuPrevTime);
131 if(getkeydest() != KEY_MENU || getmousetarget() != MT_MENU)
134 if(cvar("cl_capturevideo"))
135 frametime = 1 / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
137 prevMenuAlpha = menuAlpha;
139 menuAlpha = min(1, menuAlpha + frametime * 5);
141 menuAlpha = max(0, menuAlpha - frametime * 5);
145 if(prevMenuAlpha > 0)
146 main.initializeDialog(main, main.firstChild);
153 gamestatus = gamestatus | GAME_ISSERVER;
154 if(clientstate() == CS_CONNECTED)
155 gamestatus = gamestatus | GAME_CONNECTED;
156 if(cvar("developer"))
157 gamestatus = gamestatus | GAME_DEVELOPER;
160 draw_alpha *= menuAlpha;
165 dMouse = getmousepos();
166 dMouse *= frametime / realFrametime; // for capturevideo
167 if(dMouse != '0 0 0')
169 dMouse = globalToBoxSize(dMouse, draw_scale);
170 menuMousePos += dMouse * 1; // TODO use a cvar here
171 menuMousePos_x = bound(0, menuMousePos_x, 1);
172 menuMousePos_y = bound(0, menuMousePos_y, 1);
173 if(mouseButtonsPressed)
174 main.mouseDrag(main, menuMousePos);
176 main.mouseMove(main, menuMousePos);
180 draw_drawMousePointer(menuMousePos);
188 setkeydest(KEY_MENU);
189 setmousetarget(MT_MENU);
191 if(!menuLoadedMaplist)
194 if(mouseButtonsPressed)
195 main.mouseRelease(main, menuMousePos);
196 mouseButtonsPressed = 0;
198 main.focusEnter(main);
199 main.showNotify(main);
205 setkeydest(KEY_GAME);
206 setmousetarget(MT_CLIENT);
208 if(!menuLoadedMaplist)
211 main.focusLeave(main);
212 main.hideNotify(main);
228 void(string itemname) m_goto =
231 if(!menuLoadedMaplist)
233 if(itemname == "") // this can be called by GameCommand
235 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
239 main.initializeDialog(main, main.firstChild);
245 e = findstring(NULL, name, itemname);
246 if(e && e.parent == main)
249 main.initializeDialog(main, e);