1 ///////////////////////////////////////////////
3 ///////////////////////
4 // This file belongs to dpmod/darkplaces
5 // AK contains all menu functions (especially the required ones)
6 ///////////////////////////////////////////////
9 float mouseButtonsPressed;
22 draw_setMousePointer("gfx/cursor");
24 main = spawnMainWindow(); main.configureMainWindow(main);
26 main.resizeNotify(main, draw_shift, draw_scale, draw_shift, draw_scale);
31 void(float key, float ascii) m_keyup =
36 main.keyUp(main, key, ascii, shiftState);
37 if(key >= K_MOUSE1 && key <= K_MOUSE10)
39 --mouseButtonsPressed;
40 if(!mouseButtonsPressed)
41 main.mouseRelease(main, mousePos);
42 if(mouseButtonsPressed < 0)
44 mouseButtonsPressed = 0;
45 print("Warning: released an already released button\n");
48 if(key == K_ALT) shiftState -= (shiftState & S_ALT);
49 if(key == K_CTRL) shiftState -= (shiftState & S_CTRL);
50 if(key == K_SHIFT) shiftState -= (shiftState & S_SHIFT);
53 void(float key, float ascii) m_keydown =
58 if(!main.keyDown(main, key, ascii, shiftState))
60 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
61 m_hide(); // disable menu on unhandled ESC
62 if(key >= K_MOUSE1 && key <= K_MOUSE10)
64 if(!mouseButtonsPressed)
65 main.mousePress(main, mousePos);
66 ++mouseButtonsPressed;
67 if(mouseButtonsPressed > 10)
69 mouseButtonsPressed = 10;
70 print("Warning: pressed an already pressed button\n");
73 if(key == K_ALT) shiftState |= S_ALT;
74 if(key == K_CTRL) shiftState |= S_CTRL;
75 if(key == K_SHIFT) shiftState |= S_SHIFT;
83 realFrametime = frametime = min(0.2, t - prevTime);
86 if(cvar("cl_capturevideo"))
87 frametime = 1 / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
90 menuAlpha = min(1, menuAlpha + frametime * 5);
92 menuAlpha = max(0, menuAlpha - frametime * 5);
100 gamestatus = gamestatus | GAME_ISSERVER;
101 if(clientstate() == CS_CONNECTED)
102 gamestatus = gamestatus | GAME_CONNECTED;
103 if(cvar("developer"))
104 gamestatus = gamestatus | GAME_DEVELOPER;
107 draw_alpha *= menuAlpha;
110 dMouse = getmousepos();
111 dMouse *= frametime / realFrametime; // for capturevideo
112 if(dMouse != '0 0 0')
114 dMouse = globalToBoxSize(dMouse, draw_scale);
115 mousePos += dMouse * 1; // TODO use a cvar here
116 mousePos_x = bound(0, mousePos_x, 1);
117 mousePos_y = bound(0, mousePos_y, 1);
118 if(mouseButtonsPressed)
119 main.mouseDrag(main, mousePos);
121 main.mouseMove(main, mousePos);
124 draw_drawMousePointer(mousePos);
130 setkeydest(KEY_MENU);
131 setmousetarget(MT_MENU);
133 main.focusEnter(main);
139 setkeydest(KEY_GAME);
140 setmousetarget(MT_CLIENT);
142 main.focusLeave(main);