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;
18 string campaign_name_previous;
19 float campaign_won_previous;
28 void UpdateConWidthHeight()
30 float conwidth_s, conheight_s;
31 conwidth_s = conwidth;
32 conheight_s = conheight;
33 conwidth = cvar("vid_conwidth");
34 conheight = cvar("vid_conheight");
37 conheight *= 800 / conwidth;
42 conwidth *= 600 / conheight;
47 if(conwidth_s != conwidth || conheight_s != conheight)
50 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
55 void() m_init_delayed =
62 menuLoadedMaplist = 0;
64 if(!MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 1))
66 menuLoadedMaplist = 1;
71 if(cvar_string("menu_skin") != "")
73 draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin"));
74 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
78 draw_currentSkin = "gfx/menu/default";
79 fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ);
81 draw_currentSkin = strzone(draw_currentSkin);
82 while((s = fgets(fh)))
84 Skin_ApplySetting(argv(0), argv(1));
87 draw_setMousePointer("cursor", SKINSIZE_CURSOR, SKINOFFSET_CURSOR);
89 conwidth = conheight = -1;
91 UpdateConWidthHeight();
92 main = spawnMainWindow(); main.configureMainWindow(main);
93 main.resizeNotify(main, '0 0 0', eX * conwidth + eY * conheight, '0 0 0', eX * conwidth + eY * conheight);
96 menuMousePos = '0.5 0.5 0';
99 m_display(); // delayed menu display
102 void(float key, float ascii) m_keyup =
104 if(!menuLoadedMaplist)
109 main.keyUp(main, key, ascii, menuShiftState);
110 if(key >= K_MOUSE1 && key <= K_MOUSE3)
112 --mouseButtonsPressed;
113 if(!mouseButtonsPressed)
114 main.mouseRelease(main, menuMousePos);
115 if(mouseButtonsPressed < 0)
117 mouseButtonsPressed = 0;
118 print("Warning: released an already released button\n");
121 if(key == K_ALT) menuShiftState -= (menuShiftState & S_ALT);
122 if(key == K_CTRL) menuShiftState -= (menuShiftState & S_CTRL);
123 if(key == K_SHIFT) menuShiftState -= (menuShiftState & S_SHIFT);
126 void(float key, float ascii) m_keydown =
128 if(!menuLoadedMaplist)
137 e.keyGrabbed(e, key, ascii);
142 if(!main.keyDown(main, key, ascii, menuShiftState))
144 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) // don't back out to console only
145 m_hide(); // disable menu on unhandled ESC
146 if(key >= K_MOUSE1 && key <= K_MOUSE3)
147 if(!mouseButtonsPressed)
148 main.mousePress(main, menuMousePos);
150 if(key >= K_MOUSE1 && key <= K_MOUSE3)
152 ++mouseButtonsPressed;
153 if(mouseButtonsPressed > 10)
155 mouseButtonsPressed = 10;
156 print("Warning: pressed an already pressed button\n");
159 if(key == K_ALT) menuShiftState |= S_ALT;
160 if(key == K_CTRL) menuShiftState |= S_CTRL;
161 if(key == K_SHIFT) menuShiftState |= S_SHIFT;
170 UpdateConWidthHeight();
172 if(!menuNotTheFirstFrame)
174 menuNotTheFirstFrame = 1;
176 if(!cvar("menu_video_played"))
178 localcmd("set menu_video_played 1; cd loop 1; play sound/announcer/male/welcome.ogg\n");
179 menuLogoAlpha = -0.8; // no idea why, but when I start this at zero, it jumps instead of fading
182 if(!menuLoadedMaplist)
184 // TODO draw an info image about this situation
190 realFrametime = frametime = min(0.2, t - menuPrevTime);
194 if not(campaign_name_previous)
195 campaign_name_previous = strzone(strcat(campaign_name, "x")); // force unequal
196 if(campaign_name == campaign_name_previous)
198 if(cvar(strcat("g_campaign", campaign_name, "_won")))
200 if(!campaign_won_previous)
203 DialogOpenButton_Click_withCoords(NULL, main.winnerDialog, '0 0 0', '1 1 0');
205 campaign_won_previous = 1;
208 campaign_won_previous = 0;
212 strunzone(campaign_name_previous);
213 campaign_name_previous = strzone(campaign_name);
214 campaign_won_previous = cvar(strcat("g_campaign", campaign_name, "_won"));
219 if(getmousetarget() == MT_MENU && (getkeydest() == KEY_MENU || getkeydest() == KEY_MENU_GRABBED))
220 setkeydest(keyGrabber ? KEY_MENU_GRABBED : KEY_MENU);
225 if(cvar("cl_capturevideo"))
226 frametime = 1 / cvar("cl_capturevideo_fps"); // make capturevideo work smoothly
231 gamestatus = gamestatus | GAME_ISSERVER;
232 if(clientstate() == CS_CONNECTED)
233 gamestatus = gamestatus | GAME_CONNECTED;
234 if(cvar("developer"))
235 gamestatus = gamestatus | GAME_DEVELOPER;
237 prevMenuAlpha = menuAlpha;
240 if(menuAlpha == 0 && menuLogoAlpha < 2)
242 menuLogoAlpha = menuLogoAlpha + frametime * 2;
246 menuAlpha = min(1, menuAlpha + frametime * 5);
252 menuAlpha = max(0, menuAlpha - frametime * 5);
258 if(!(gamestatus & (GAME_CONNECTED | GAME_ISSERVER)) && menuLogoAlpha > 0)
262 sz = draw_PictureSize(SKINGFX_BACKGROUND);
263 // keep aspect of image
264 if(sz_x * draw_scale_y >= sz_y * draw_scale_x)
266 // that is, sz_x/sz_y >= draw_scale_x/draw_scale_y
267 // match up the height
269 isz_x = isz_y * (sz_x / sz_y) * (draw_scale_y / draw_scale_x);
273 // that is, sz_x/sz_y <= draw_scale_x/draw_scale_y
274 // match up the width
276 isz_y = isz_x * (sz_y / sz_x) * (draw_scale_x / draw_scale_y);
278 draw_Picture('0.5 0.5 0' - 0.5 * isz, SKINGFX_BACKGROUND, isz, '1 1 1', bound(0, menuLogoAlpha, 1));
279 if(menuAlpha <= 0 && SKINALPHA_CURSOR_INTRO > 0)
281 draw_alpha = SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1);
282 draw_drawMousePointer(menuMousePos);
289 if(prevMenuAlpha > 0)
290 main.initializeDialog(main, main.firstChild);
294 draw_alpha *= menuAlpha;
299 dMouse = getmousepos() * (frametime / realFrametime); // for capturevideo
300 if(dMouse != '0 0 0')
302 dMouse = globalToBoxSize(dMouse, draw_scale);
303 menuMousePos += dMouse * 1; // TODO use a cvar here
304 menuMousePos_x = bound(0, menuMousePos_x, 1);
305 menuMousePos_y = bound(0, menuMousePos_y, 1);
306 if(mouseButtonsPressed)
307 main.mouseDrag(main, menuMousePos);
309 main.mouseMove(main, menuMousePos);
313 draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
314 draw_drawMousePointer(menuMousePos);
322 setkeydest(KEY_MENU);
323 setmousetarget(MT_MENU);
325 if(!menuLoadedMaplist)
328 if(mouseButtonsPressed)
329 main.mouseRelease(main, menuMousePos);
330 mouseButtonsPressed = 0;
332 main.focusEnter(main);
333 main.showNotify(main);
339 setkeydest(KEY_GAME);
340 setmousetarget(MT_CLIENT);
342 if(!menuLoadedMaplist)
345 main.focusLeave(main);
346 main.hideNotify(main);
362 void(string itemname) m_goto =
365 if(!menuLoadedMaplist)
367 if(itemname == "") // this can be called by GameCommand
369 if(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))
373 main.initializeDialog(main, main.firstChild);
379 e = findstring(NULL, name, itemname);
380 if(e && e.parent == main)
383 main.initializeDialog(main, e);