menu.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "quakedef.h"
  16. #include "winquake.h"
  17. void (*vid_menudrawfn)(void);
  18. void (*vid_menukeyfn)(int key);
  19. enum {m_none, m_main, m_singleplayer, m_load, m_save, m_multiplayer, m_setup, m_net, m_options, m_video, m_keys, m_help, m_quit, m_serialconfig, m_modemconfig, m_lanconfig, m_gameoptions, m_search, m_slist} m_state;
  20. void M_Menu_Main_f (void);
  21. void M_Menu_SinglePlayer_f (void);
  22. void M_Menu_Load_f (void);
  23. void M_Menu_Save_f (void);
  24. void M_Menu_MultiPlayer_f (void);
  25. void M_Menu_Setup_f (void);
  26. void M_Menu_Net_f (void);
  27. void M_Menu_Options_f (void);
  28. void M_Menu_Keys_f (void);
  29. void M_Menu_Video_f (void);
  30. void M_Menu_Help_f (void);
  31. void M_Menu_Quit_f (void);
  32. void M_Menu_SerialConfig_f (void);
  33. void M_Menu_ModemConfig_f (void);
  34. void M_Menu_LanConfig_f (void);
  35. void M_Menu_GameOptions_f (void);
  36. void M_Menu_Search_f (void);
  37. void M_Menu_ServerList_f (void);
  38. void M_Main_Draw (void);
  39. void M_SinglePlayer_Draw (void);
  40. void M_Load_Draw (void);
  41. void M_Save_Draw (void);
  42. void M_MultiPlayer_Draw (void);
  43. void M_Setup_Draw (void);
  44. void M_Net_Draw (void);
  45. void M_Options_Draw (void);
  46. void M_Keys_Draw (void);
  47. void M_Video_Draw (void);
  48. void M_Help_Draw (void);
  49. void M_Quit_Draw (void);
  50. void M_SerialConfig_Draw (void);
  51. void M_ModemConfig_Draw (void);
  52. void M_LanConfig_Draw (void);
  53. void M_GameOptions_Draw (void);
  54. void M_Search_Draw (void);
  55. void M_ServerList_Draw (void);
  56. void M_Main_Key (int key);
  57. void M_SinglePlayer_Key (int key);
  58. void M_Load_Key (int key);
  59. void M_Save_Key (int key);
  60. void M_MultiPlayer_Key (int key);
  61. void M_Setup_Key (int key);
  62. void M_Net_Key (int key);
  63. void M_Options_Key (int key);
  64. void M_Keys_Key (int key);
  65. void M_Video_Key (int key);
  66. void M_Help_Key (int key);
  67. void M_Quit_Key (int key);
  68. void M_SerialConfig_Key (int key);
  69. void M_ModemConfig_Key (int key);
  70. void M_LanConfig_Key (int key);
  71. void M_GameOptions_Key (int key);
  72. void M_Search_Key (int key);
  73. void M_ServerList_Key (int key);
  74. qboolean m_entersound; // play after drawing a frame, so caching
  75. // won't disrupt the sound
  76. qboolean m_recursiveDraw;
  77. int m_return_state;
  78. qboolean m_return_onerror;
  79. char m_return_reason [32];
  80. #define StartingGame (m_multiplayer_cursor == 1)
  81. #define JoiningGame (m_multiplayer_cursor == 0)
  82. #define SerialConfig (m_net_cursor == 0)
  83. #define DirectConfig (m_net_cursor == 1)
  84. #define IPXConfig (m_net_cursor == 2)
  85. #define TCPIPConfig (m_net_cursor == 3)
  86. void M_ConfigureNetSubsystem(void);
  87. //=============================================================================
  88. /* Support Routines */
  89. /*
  90. ================
  91. M_DrawCharacter
  92. Draws one solid graphics character
  93. ================
  94. */
  95. void M_DrawCharacter (int cx, int line, int num)
  96. {
  97. Draw_Character ( cx + ((vid.width - 320)>>1), line, num);
  98. }
  99. void M_Print (int cx, int cy, char *str)
  100. {
  101. while (*str)
  102. {
  103. M_DrawCharacter (cx, cy, (*str)+128);
  104. str++;
  105. cx += 8;
  106. }
  107. }
  108. void M_PrintWhite (int cx, int cy, char *str)
  109. {
  110. while (*str)
  111. {
  112. M_DrawCharacter (cx, cy, *str);
  113. str++;
  114. cx += 8;
  115. }
  116. }
  117. void M_DrawTransPic (int x, int y, qpic_t *pic)
  118. {
  119. Draw_TransPic (x + ((vid.width - 320)>>1), y, pic);
  120. }
  121. void M_DrawPic (int x, int y, qpic_t *pic)
  122. {
  123. Draw_Pic (x + ((vid.width - 320)>>1), y, pic);
  124. }
  125. byte identityTable[256];
  126. byte translationTable[256];
  127. void M_BuildTranslationTable(int top, int bottom)
  128. {
  129. int j;
  130. byte *dest, *source;
  131. for (j = 0; j < 256; j++)
  132. identityTable[j] = j;
  133. dest = translationTable;
  134. source = identityTable;
  135. memcpy (dest, source, 256);
  136. if (top < 128) // the artists made some backwards ranges. sigh.
  137. memcpy (dest + TOP_RANGE, source + top, 16);
  138. else
  139. for (j=0 ; j<16 ; j++)
  140. dest[TOP_RANGE+j] = source[top+15-j];
  141. if (bottom < 128)
  142. memcpy (dest + BOTTOM_RANGE, source + bottom, 16);
  143. else
  144. for (j=0 ; j<16 ; j++)
  145. dest[BOTTOM_RANGE+j] = source[bottom+15-j];
  146. }
  147. void M_DrawTransPicTranslate (int x, int y, qpic_t *pic)
  148. {
  149. Draw_TransPicTranslate (x + ((vid.width - 320)>>1), y, pic, translationTable);
  150. }
  151. void M_DrawTextBox (int x, int y, int width, int lines)
  152. {
  153. qpic_t *p;
  154. int cx, cy;
  155. int n;
  156. // draw left side
  157. cx = x;
  158. cy = y;
  159. p = Draw_CachePic ("gfx/box_tl.lmp");
  160. M_DrawTransPic (cx, cy, p);
  161. p = Draw_CachePic ("gfx/box_ml.lmp");
  162. for (n = 0; n < lines; n++)
  163. {
  164. cy += 8;
  165. M_DrawTransPic (cx, cy, p);
  166. }
  167. p = Draw_CachePic ("gfx/box_bl.lmp");
  168. M_DrawTransPic (cx, cy+8, p);
  169. // draw middle
  170. cx += 8;
  171. while (width > 0)
  172. {
  173. cy = y;
  174. p = Draw_CachePic ("gfx/box_tm.lmp");
  175. M_DrawTransPic (cx, cy, p);
  176. p = Draw_CachePic ("gfx/box_mm.lmp");
  177. for (n = 0; n < lines; n++)
  178. {
  179. cy += 8;
  180. if (n == 1)
  181. p = Draw_CachePic ("gfx/box_mm2.lmp");
  182. M_DrawTransPic (cx, cy, p);
  183. }
  184. p = Draw_CachePic ("gfx/box_bm.lmp");
  185. M_DrawTransPic (cx, cy+8, p);
  186. width -= 2;
  187. cx += 16;
  188. }
  189. // draw right side
  190. cy = y;
  191. p = Draw_CachePic ("gfx/box_tr.lmp");
  192. M_DrawTransPic (cx, cy, p);
  193. p = Draw_CachePic ("gfx/box_mr.lmp");
  194. for (n = 0; n < lines; n++)
  195. {
  196. cy += 8;
  197. M_DrawTransPic (cx, cy, p);
  198. }
  199. p = Draw_CachePic ("gfx/box_br.lmp");
  200. M_DrawTransPic (cx, cy+8, p);
  201. }
  202. //=============================================================================
  203. int m_save_demonum;
  204. /*
  205. ================
  206. M_ToggleMenu_f
  207. ================
  208. */
  209. void M_ToggleMenu_f (void)
  210. {
  211. m_entersound = true;
  212. if (key_dest == key_menu)
  213. {
  214. if (m_state != m_main)
  215. {
  216. M_Menu_Main_f ();
  217. return;
  218. }
  219. key_dest = key_game;
  220. m_state = m_none;
  221. return;
  222. }
  223. if (key_dest == key_console)
  224. {
  225. Con_ToggleConsole_f ();
  226. }
  227. else
  228. {
  229. M_Menu_Main_f ();
  230. }
  231. }
  232. //=============================================================================
  233. /* MAIN MENU */
  234. int m_main_cursor;
  235. #define MAIN_ITEMS 5
  236. void M_Menu_Main_f (void)
  237. {
  238. if (key_dest != key_menu)
  239. {
  240. m_save_demonum = cls.demonum;
  241. cls.demonum = -1;
  242. }
  243. key_dest = key_menu;
  244. m_state = m_main;
  245. m_entersound = true;
  246. }
  247. void M_Main_Draw (void)
  248. {
  249. int f;
  250. qpic_t *p;
  251. M_DrawTransPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
  252. p = Draw_CachePic ("gfx/ttl_main.lmp");
  253. M_DrawPic ( (320-p->width)/2, 4, p);
  254. M_DrawTransPic (72, 32, Draw_CachePic ("gfx/mainmenu.lmp") );
  255. f = (int)(realtime * 10)%6;
  256. M_DrawTransPic (54, 32 + m_main_cursor * 20,Draw_CachePic( va("gfx/menudot%i.lmp", f+1 ) ) );
  257. }
  258. void M_Main_Key (int key)
  259. {
  260. switch (key)
  261. {
  262. case K_ESCAPE:
  263. key_dest = key_game;
  264. m_state = m_none;
  265. cls.demonum = m_save_demonum;
  266. if (cls.demonum != -1 && !cls.demoplayback && cls.state == ca_disconnected)
  267. CL_NextDemo ();
  268. break;
  269. case K_DOWNARROW:
  270. S_LocalSound ("misc/menu1.wav");
  271. if (++m_main_cursor >= MAIN_ITEMS)
  272. m_main_cursor = 0;
  273. break;
  274. case K_UPARROW:
  275. S_LocalSound ("misc/menu1.wav");
  276. if (--m_main_cursor < 0)
  277. m_main_cursor = MAIN_ITEMS - 1;
  278. break;
  279. case K_ENTER:
  280. m_entersound = true;
  281. switch (m_main_cursor)
  282. {
  283. case 0:
  284. M_Menu_SinglePlayer_f ();
  285. break;
  286. case 1:
  287. M_Menu_MultiPlayer_f ();
  288. break;
  289. case 2:
  290. M_Menu_Options_f ();
  291. break;
  292. case 3:
  293. M_Menu_Help_f ();
  294. break;
  295. case 4:
  296. M_Menu_Quit_f ();
  297. break;
  298. }
  299. }
  300. }
  301. //=============================================================================
  302. /* OPTIONS MENU */
  303. #define OPTIONS_ITEMS 16
  304. #define SLIDER_RANGE 10
  305. int options_cursor;
  306. void M_Menu_Options_f (void)
  307. {
  308. key_dest = key_menu;
  309. m_state = m_options;
  310. m_entersound = true;
  311. }
  312. void M_AdjustSliders (int dir)
  313. {
  314. S_LocalSound ("misc/menu3.wav");
  315. switch (options_cursor)
  316. {
  317. case 3: // screen size
  318. scr_viewsize.value += dir * 10;
  319. if (scr_viewsize.value < 30)
  320. scr_viewsize.value = 30;
  321. if (scr_viewsize.value > 120)
  322. scr_viewsize.value = 120;
  323. Cvar_SetValue ("viewsize", scr_viewsize.value);
  324. break;
  325. case 4: // gamma
  326. v_gamma.value -= dir * 0.05;
  327. if (v_gamma.value < 0.5)
  328. v_gamma.value = 0.5;
  329. if (v_gamma.value > 1)
  330. v_gamma.value = 1;
  331. Cvar_SetValue ("gamma", v_gamma.value);
  332. break;
  333. case 5: // mouse speed
  334. sensitivity.value += dir * 0.5;
  335. if (sensitivity.value < 1)
  336. sensitivity.value = 1;
  337. if (sensitivity.value > 11)
  338. sensitivity.value = 11;
  339. Cvar_SetValue ("sensitivity", sensitivity.value);
  340. break;
  341. case 6: // music volume
  342. #ifdef _WIN32
  343. bgmvolume.value += dir * 1.0;
  344. #else
  345. bgmvolume.value += dir * 0.1;
  346. #endif
  347. if (bgmvolume.value < 0)
  348. bgmvolume.value = 0;
  349. if (bgmvolume.value > 1)
  350. bgmvolume.value = 1;
  351. Cvar_SetValue ("bgmvolume", bgmvolume.value);
  352. break;
  353. case 7: // sfx volume
  354. volume.value += dir * 0.1;
  355. if (volume.value < 0)
  356. volume.value = 0;
  357. if (volume.value > 1)
  358. volume.value = 1;
  359. Cvar_SetValue ("volume", volume.value);
  360. break;
  361. case 8: // allways run
  362. if (cl_forwardspeed.value > 200)
  363. {
  364. Cvar_SetValue ("cl_forwardspeed", 200);
  365. Cvar_SetValue ("cl_backspeed", 200);
  366. }
  367. else
  368. {
  369. Cvar_SetValue ("cl_forwardspeed", 400);
  370. Cvar_SetValue ("cl_backspeed", 400);
  371. }
  372. break;
  373. case 9: // invert mouse
  374. Cvar_SetValue ("m_pitch", -m_pitch.value);
  375. break;
  376. case 10: // lookspring
  377. Cvar_SetValue ("lookspring", !lookspring.value);
  378. break;
  379. case 11: // lookstrafe
  380. Cvar_SetValue ("lookstrafe", !lookstrafe.value);
  381. break;
  382. case 12:
  383. Cvar_SetValue ("cl_sbar", !cl_sbar.value);
  384. break;
  385. case 13:
  386. Cvar_SetValue ("cl_hudswap", !cl_hudswap.value);
  387. case 15: // _windowed_mouse
  388. Cvar_SetValue ("_windowed_mouse", !_windowed_mouse.value);
  389. break;
  390. }
  391. }
  392. void M_DrawSlider (int x, int y, float range)
  393. {
  394. int i;
  395. if (range < 0)
  396. range = 0;
  397. if (range > 1)
  398. range = 1;
  399. M_DrawCharacter (x-8, y, 128);
  400. for (i=0 ; i<SLIDER_RANGE ; i++)
  401. M_DrawCharacter (x + i*8, y, 129);
  402. M_DrawCharacter (x+i*8, y, 130);
  403. M_DrawCharacter (x + (SLIDER_RANGE-1)*8 * range, y, 131);
  404. }
  405. void M_DrawCheckbox (int x, int y, int on)
  406. {
  407. #if 0
  408. if (on)
  409. M_DrawCharacter (x, y, 131);
  410. else
  411. M_DrawCharacter (x, y, 129);
  412. #endif
  413. if (on)
  414. M_Print (x, y, "on");
  415. else
  416. M_Print (x, y, "off");
  417. }
  418. void M_Options_Draw (void)
  419. {
  420. float r;
  421. qpic_t *p;
  422. M_DrawTransPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
  423. p = Draw_CachePic ("gfx/p_option.lmp");
  424. M_DrawPic ( (320-p->width)/2, 4, p);
  425. M_Print (16, 32, " Customize controls");
  426. M_Print (16, 40, " Go to console");
  427. M_Print (16, 48, " Reset to defaults");
  428. M_Print (16, 56, " Screen size");
  429. r = (scr_viewsize.value - 30) / (120 - 30);
  430. M_DrawSlider (220, 56, r);
  431. M_Print (16, 64, " Brightness");
  432. r = (1.0 - v_gamma.value) / 0.5;
  433. M_DrawSlider (220, 64, r);
  434. M_Print (16, 72, " Mouse Speed");
  435. r = (sensitivity.value - 1)/10;
  436. M_DrawSlider (220, 72, r);
  437. M_Print (16, 80, " CD Music Volume");
  438. r = bgmvolume.value;
  439. M_DrawSlider (220, 80, r);
  440. M_Print (16, 88, " Sound Volume");
  441. r = volume.value;
  442. M_DrawSlider (220, 88, r);
  443. M_Print (16, 96, " Always Run");
  444. M_DrawCheckbox (220, 96, cl_forwardspeed.value > 200);
  445. M_Print (16, 104, " Invert Mouse");
  446. M_DrawCheckbox (220, 104, m_pitch.value < 0);
  447. M_Print (16, 112, " Lookspring");
  448. M_DrawCheckbox (220, 112, lookspring.value);
  449. M_Print (16, 120, " Lookstrafe");
  450. M_DrawCheckbox (220, 120, lookstrafe.value);
  451. M_Print (16, 128, " Use old status bar");
  452. M_DrawCheckbox (220, 128, cl_sbar.value);
  453. M_Print (16, 136, " HUD on left side");
  454. M_DrawCheckbox (220, 136, cl_hudswap.value);
  455. if (vid_menudrawfn)
  456. M_Print (16, 144, " Video Options");
  457. #ifdef _WIN32
  458. if (modestate == MS_WINDOWED)
  459. {
  460. #endif
  461. M_Print (16, 152, " Use Mouse");
  462. M_DrawCheckbox (220, 152, _windowed_mouse.value);
  463. #ifdef _WIN32
  464. }
  465. #endif
  466. // cursor
  467. M_DrawCharacter (200, 32 + options_cursor*8, 12+((int)(realtime*4)&1));
  468. }
  469. void M_Options_Key (int k)
  470. {
  471. switch (k)
  472. {
  473. case K_ESCAPE:
  474. M_Menu_Main_f ();
  475. break;
  476. case K_ENTER:
  477. m_entersound = true;
  478. switch (options_cursor)
  479. {
  480. case 0:
  481. M_Menu_Keys_f ();
  482. break;
  483. case 1:
  484. m_state = m_none;
  485. Con_ToggleConsole_f ();
  486. break;
  487. case 2:
  488. Cbuf_AddText ("exec default.cfg\n");
  489. break;
  490. case 14:
  491. M_Menu_Video_f ();
  492. break;
  493. default:
  494. M_AdjustSliders (1);
  495. break;
  496. }
  497. return;
  498. case K_UPARROW:
  499. S_LocalSound ("misc/menu1.wav");
  500. options_cursor--;
  501. if (options_cursor < 0)
  502. options_cursor = OPTIONS_ITEMS-1;
  503. break;
  504. case K_DOWNARROW:
  505. S_LocalSound ("misc/menu1.wav");
  506. options_cursor++;
  507. if (options_cursor >= OPTIONS_ITEMS)
  508. options_cursor = 0;
  509. break;
  510. case K_LEFTARROW:
  511. M_AdjustSliders (-1);
  512. break;
  513. case K_RIGHTARROW:
  514. M_AdjustSliders (1);
  515. break;
  516. }
  517. if (options_cursor == 14 && vid_menudrawfn == NULL)
  518. {
  519. if (k == K_UPARROW)
  520. options_cursor = 13;
  521. else
  522. options_cursor = 0;
  523. }
  524. if ((options_cursor == 15)
  525. #ifdef _WIN32
  526. && (modestate != MS_WINDOWED)
  527. #endif
  528. )
  529. {
  530. if (k == K_UPARROW)
  531. options_cursor = 14;
  532. else
  533. options_cursor = 0;
  534. }
  535. }
  536. //=============================================================================
  537. /* KEYS MENU */
  538. char *bindnames[][2] =
  539. {
  540. {"+attack", "attack"},
  541. {"impulse 10", "change weapon"},
  542. {"+jump", "jump / swim up"},
  543. {"+forward", "walk forward"},
  544. {"+back", "backpedal"},
  545. {"+left", "turn left"},
  546. {"+right", "turn right"},
  547. {"+speed", "run"},
  548. {"+moveleft", "step left"},
  549. {"+moveright", "step right"},
  550. {"+strafe", "sidestep"},
  551. {"+lookup", "look up"},
  552. {"+lookdown", "look down"},
  553. {"centerview", "center view"},
  554. {"+mlook", "mouse look"},
  555. {"+klook", "keyboard look"},
  556. {"+moveup", "swim up"},
  557. {"+movedown", "swim down"}
  558. };
  559. #define NUMCOMMANDS (sizeof(bindnames)/sizeof(bindnames[0]))
  560. int keys_cursor;
  561. int bind_grab;
  562. void M_Menu_Keys_f (void)
  563. {
  564. key_dest = key_menu;
  565. m_state = m_keys;
  566. m_entersound = true;
  567. }
  568. void M_FindKeysForCommand (char *command, int *twokeys)
  569. {
  570. int count;
  571. int j;
  572. int l;
  573. char *b;
  574. twokeys[0] = twokeys[1] = -1;
  575. l = strlen(command);
  576. count = 0;
  577. for (j=0 ; j<256 ; j++)
  578. {
  579. b = keybindings[j];
  580. if (!b)
  581. continue;
  582. if (!strncmp (b, command, l) )
  583. {
  584. twokeys[count] = j;
  585. count++;
  586. if (count == 2)
  587. break;
  588. }
  589. }
  590. }
  591. void M_UnbindCommand (char *command)
  592. {
  593. int j;
  594. int l;
  595. char *b;
  596. l = strlen(command);
  597. for (j=0 ; j<256 ; j++)
  598. {
  599. b = keybindings[j];
  600. if (!b)
  601. continue;
  602. if (!strncmp (b, command, l) )
  603. Key_SetBinding (j, "");
  604. }
  605. }
  606. void M_Keys_Draw (void)
  607. {
  608. int i, l;
  609. int keys[2];
  610. char *name;
  611. int x, y;
  612. qpic_t *p;
  613. p = Draw_CachePic ("gfx/ttl_cstm.lmp");
  614. M_DrawPic ( (320-p->width)/2, 4, p);
  615. if (bind_grab)
  616. M_Print (12, 32, "Press a key or button for this action");
  617. else
  618. M_Print (18, 32, "Enter to change, backspace to clear");
  619. // search for known bindings
  620. for (i=0 ; i<NUMCOMMANDS ; i++)
  621. {
  622. y = 48 + 8*i;
  623. M_Print (16, y, bindnames[i][1]);
  624. l = strlen (bindnames[i][0]);
  625. M_FindKeysForCommand (bindnames[i][0], keys);
  626. if (keys[0] == -1)
  627. {
  628. M_Print (140, y, "???");
  629. }
  630. else
  631. {
  632. name = Key_KeynumToString (keys[0]);
  633. M_Print (140, y, name);
  634. x = strlen(name) * 8;
  635. if (keys[1] != -1)
  636. {
  637. M_Print (140 + x + 8, y, "or");
  638. M_Print (140 + x + 32, y, Key_KeynumToString (keys[1]));
  639. }
  640. }
  641. }
  642. if (bind_grab)
  643. M_DrawCharacter (130, 48 + keys_cursor*8, '=');
  644. else
  645. M_DrawCharacter (130, 48 + keys_cursor*8, 12+((int)(realtime*4)&1));
  646. }
  647. void M_Keys_Key (int k)
  648. {
  649. char cmd[80];
  650. int keys[2];
  651. if (bind_grab)
  652. { // defining a key
  653. S_LocalSound ("misc/menu1.wav");
  654. if (k == K_ESCAPE)
  655. {
  656. bind_grab = false;
  657. }
  658. else if (k != '`')
  659. {
  660. sprintf (cmd, "bind %s \"%s\"\n", Key_KeynumToString (k), bindnames[keys_cursor][0]);
  661. Cbuf_InsertText (cmd);
  662. }
  663. bind_grab = false;
  664. return;
  665. }
  666. switch (k)
  667. {
  668. case K_ESCAPE:
  669. M_Menu_Options_f ();
  670. break;
  671. case K_LEFTARROW:
  672. case K_UPARROW:
  673. S_LocalSound ("misc/menu1.wav");
  674. keys_cursor--;
  675. if (keys_cursor < 0)
  676. keys_cursor = NUMCOMMANDS-1;
  677. break;
  678. case K_DOWNARROW:
  679. case K_RIGHTARROW:
  680. S_LocalSound ("misc/menu1.wav");
  681. keys_cursor++;
  682. if (keys_cursor >= NUMCOMMANDS)
  683. keys_cursor = 0;
  684. break;
  685. case K_ENTER: // go into bind mode
  686. M_FindKeysForCommand (bindnames[keys_cursor][0], keys);
  687. S_LocalSound ("misc/menu2.wav");
  688. if (keys[1] != -1)
  689. M_UnbindCommand (bindnames[keys_cursor][0]);
  690. bind_grab = true;
  691. break;
  692. case K_BACKSPACE: // delete bindings
  693. case K_DEL: // delete bindings
  694. S_LocalSound ("misc/menu2.wav");
  695. M_UnbindCommand (bindnames[keys_cursor][0]);
  696. break;
  697. }
  698. }
  699. //=============================================================================
  700. /* VIDEO MENU */
  701. void M_Menu_Video_f (void)
  702. {
  703. key_dest = key_menu;
  704. m_state = m_video;
  705. m_entersound = true;
  706. }
  707. void M_Video_Draw (void)
  708. {
  709. (*vid_menudrawfn) ();
  710. }
  711. void M_Video_Key (int key)
  712. {
  713. (*vid_menukeyfn) (key);
  714. }
  715. //=============================================================================
  716. /* HELP MENU */
  717. int help_page;
  718. #define NUM_HELP_PAGES 6
  719. void M_Menu_Help_f (void)
  720. {
  721. key_dest = key_menu;
  722. m_state = m_help;
  723. m_entersound = true;
  724. help_page = 0;
  725. }
  726. void M_Help_Draw (void)
  727. {
  728. M_DrawPic (0, 0, Draw_CachePic ( va("gfx/help%i.lmp", help_page)) );
  729. }
  730. void M_Help_Key (int key)
  731. {
  732. switch (key)
  733. {
  734. case K_ESCAPE:
  735. M_Menu_Main_f ();
  736. break;
  737. case K_UPARROW:
  738. case K_RIGHTARROW:
  739. m_entersound = true;
  740. if (++help_page >= NUM_HELP_PAGES)
  741. help_page = 0;
  742. break;
  743. case K_DOWNARROW:
  744. case K_LEFTARROW:
  745. m_entersound = true;
  746. if (--help_page < 0)
  747. help_page = NUM_HELP_PAGES-1;
  748. break;
  749. }
  750. }
  751. //=============================================================================
  752. /* QUIT MENU */
  753. int msgNumber;
  754. int m_quit_prevstate;
  755. qboolean wasInMenus;
  756. char *quitMessage [] =
  757. {
  758. /* .........1.........2.... */
  759. " Are you gonna quit ",
  760. " this game just like ",
  761. " everything else? ",
  762. " ",
  763. " Milord, methinks that ",
  764. " thou art a lowly ",
  765. " quitter. Is this true? ",
  766. " ",
  767. " Do I need to bust your ",
  768. " face open for trying ",
  769. " to quit? ",
  770. " ",
  771. " Man, I oughta smack you",
  772. " for trying to quit! ",
  773. " Press Y to get ",
  774. " smacked out. ",
  775. " Press Y to quit like a ",
  776. " big loser in life. ",
  777. " Press N to stay proud ",
  778. " and successful! ",
  779. " If you press Y to ",
  780. " quit, I will summon ",
  781. " Satan all over your ",
  782. " hard drive! ",
  783. " Um, Asmodeus dislikes ",
  784. " his children trying to ",
  785. " quit. Press Y to return",
  786. " to your Tinkertoys. ",
  787. " If you quit now, I'll ",
  788. " throw a blanket-party ",
  789. " for you next time! ",
  790. " "
  791. };
  792. void M_Menu_Quit_f (void)
  793. {
  794. if (m_state == m_quit)
  795. return;
  796. wasInMenus = (key_dest == key_menu);
  797. key_dest = key_menu;
  798. m_quit_prevstate = m_state;
  799. m_state = m_quit;
  800. m_entersound = true;
  801. msgNumber = rand()&7;
  802. }
  803. void M_Quit_Key (int key)
  804. {
  805. switch (key)
  806. {
  807. case K_ESCAPE:
  808. case 'n':
  809. case 'N':
  810. if (wasInMenus)
  811. {
  812. m_state = m_quit_prevstate;
  813. m_entersound = true;
  814. }
  815. else
  816. {
  817. key_dest = key_game;
  818. m_state = m_none;
  819. }
  820. break;
  821. case 'Y':
  822. case 'y':
  823. key_dest = key_console;
  824. CL_Disconnect ();
  825. Sys_Quit ();
  826. break;
  827. default:
  828. break;
  829. }
  830. }
  831. void M_Menu_SinglePlayer_f (void) {
  832. m_state = m_singleplayer;
  833. }
  834. void M_SinglePlayer_Draw (void) {
  835. qpic_t *p;
  836. M_DrawTransPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
  837. // M_DrawTransPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
  838. p = Draw_CachePic ("gfx/ttl_sgl.lmp");
  839. M_DrawPic ( (320-p->width)/2, 4, p);
  840. // M_DrawTransPic (72, 32, Draw_CachePic ("gfx/sp_menu.lmp") );
  841. M_DrawTextBox (60, 10*8, 23, 4);
  842. M_PrintWhite (92, 12*8, "QuakeWorld is for");
  843. M_PrintWhite (88, 13*8, "Internet play only");
  844. }
  845. void M_SinglePlayer_Key (key) {
  846. if (key == K_ESCAPE || key==K_ENTER)
  847. m_state = m_main;
  848. }
  849. void M_Menu_MultiPlayer_f (void) {
  850. m_state = m_multiplayer;
  851. }
  852. void M_MultiPlayer_Draw (void) {
  853. qpic_t *p;
  854. M_DrawTransPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
  855. // M_DrawTransPic (16, 4, Draw_CachePic ("gfx/qplaque.lmp") );
  856. p = Draw_CachePic ("gfx/p_multi.lmp");
  857. M_DrawPic ( (320-p->width)/2, 4, p);
  858. // M_DrawTransPic (72, 32, Draw_CachePic ("gfx/sp_menu.lmp") );
  859. M_DrawTextBox (46, 8*8, 27, 9);
  860. M_PrintWhite (72, 10*8, "If you want to find QW ");
  861. M_PrintWhite (72, 11*8, "games, head on over to: ");
  862. M_Print (72, 12*8, " www.quakeworld.net ");
  863. M_PrintWhite (72, 13*8, " or ");
  864. M_Print (72, 14*8, " www.quakespy.com ");
  865. M_PrintWhite (72, 15*8, "For pointers on getting ");
  866. M_PrintWhite (72, 16*8, " started! ");
  867. }
  868. void M_MultiPlayer_Key (key) {
  869. if (key == K_ESCAPE || key==K_ENTER)
  870. m_state = m_main;
  871. }
  872. void M_Quit_Draw (void)
  873. {
  874. #define VSTR(x) #x
  875. #define VSTR2(x) VSTR(x)
  876. char *cmsg[] = {
  877. // 0123456789012345678901234567890123456789
  878. "0 QuakeWorld",
  879. "1 version " VSTR2(VERSION) " by id Software",
  880. "0Programming",
  881. "1 John Carmack Michael Abrash",
  882. "1 John Cash Christian Antkow",
  883. "0Additional Programming",
  884. "1 Dave 'Zoid' Kirsch",
  885. "1 Jack 'morbid' Mathews",
  886. "0Id Software is not responsible for",
  887. "0providing technical support for",
  888. "0QUAKEWORLD(tm). (c)1996 Id Software,",
  889. "0Inc. All Rights Reserved.",
  890. "0QUAKEWORLD(tm) is a trademark of Id",
  891. "0Software, Inc.",
  892. "1NOTICE: THE COPYRIGHT AND TRADEMARK",
  893. "1NOTICES APPEARING IN YOUR COPY OF",
  894. "1QUAKE(r) ARE NOT MODIFIED BY THE USE",
  895. "1OF QUAKEWORLD(tm) AND REMAIN IN FULL",
  896. "1FORCE.",
  897. "0NIN(r) is a registered trademark",
  898. "0licensed to Nothing Interactive, Inc.",
  899. "0All rights reserved. Press y to exit",
  900. NULL };
  901. char **p;
  902. int y;
  903. if (wasInMenus)
  904. {
  905. m_state = m_quit_prevstate;
  906. m_recursiveDraw = true;
  907. M_Draw ();
  908. m_state = m_quit;
  909. }
  910. #if 1
  911. M_DrawTextBox (0, 0, 38, 23);
  912. y = 12;
  913. for (p = cmsg; *p; p++, y += 8) {
  914. if (**p == '0')
  915. M_PrintWhite (16, y, *p + 1);
  916. else
  917. M_Print (16, y, *p + 1);
  918. }
  919. #else
  920. M_DrawTextBox (56, 76, 24, 4);
  921. M_Print (64, 84, quitMessage[msgNumber*4+0]);
  922. M_Print (64, 92, quitMessage[msgNumber*4+1]);
  923. M_Print (64, 100, quitMessage[msgNumber*4+2]);
  924. M_Print (64, 108, quitMessage[msgNumber*4+3]);
  925. #endif
  926. }
  927. //=============================================================================
  928. /* Menu Subsystem */
  929. void M_Init (void)
  930. {
  931. Cmd_AddCommand ("togglemenu", M_ToggleMenu_f);
  932. Cmd_AddCommand ("menu_main", M_Menu_Main_f);
  933. Cmd_AddCommand ("menu_options", M_Menu_Options_f);
  934. Cmd_AddCommand ("menu_keys", M_Menu_Keys_f);
  935. Cmd_AddCommand ("menu_video", M_Menu_Video_f);
  936. Cmd_AddCommand ("help", M_Menu_Help_f);
  937. Cmd_AddCommand ("menu_quit", M_Menu_Quit_f);
  938. }
  939. void M_Draw (void)
  940. {
  941. if (m_state == m_none || key_dest != key_menu)
  942. return;
  943. if (!m_recursiveDraw)
  944. {
  945. scr_copyeverything = 1;
  946. if (scr_con_current)
  947. {
  948. Draw_ConsoleBackground (vid.height);
  949. VID_UnlockBuffer ();
  950. S_ExtraUpdate ();
  951. VID_LockBuffer ();
  952. }
  953. else
  954. Draw_FadeScreen ();
  955. scr_fullupdate = 0;
  956. }
  957. else
  958. {
  959. m_recursiveDraw = false;
  960. }
  961. switch (m_state)
  962. {
  963. case m_none:
  964. break;
  965. case m_main:
  966. M_Main_Draw ();
  967. break;
  968. case m_singleplayer:
  969. M_SinglePlayer_Draw ();
  970. break;
  971. case m_load:
  972. // M_Load_Draw ();
  973. break;
  974. case m_save:
  975. // M_Save_Draw ();
  976. break;
  977. case m_multiplayer:
  978. M_MultiPlayer_Draw ();
  979. break;
  980. case m_setup:
  981. // M_Setup_Draw ();
  982. break;
  983. case m_net:
  984. // M_Net_Draw ();
  985. break;
  986. case m_options:
  987. M_Options_Draw ();
  988. break;
  989. case m_keys:
  990. M_Keys_Draw ();
  991. break;
  992. case m_video:
  993. M_Video_Draw ();
  994. break;
  995. case m_help:
  996. M_Help_Draw ();
  997. break;
  998. case m_quit:
  999. M_Quit_Draw ();
  1000. break;
  1001. case m_serialconfig:
  1002. // M_SerialConfig_Draw ();
  1003. break;
  1004. case m_modemconfig:
  1005. // M_ModemConfig_Draw ();
  1006. break;
  1007. case m_lanconfig:
  1008. // M_LanConfig_Draw ();
  1009. break;
  1010. case m_gameoptions:
  1011. // M_GameOptions_Draw ();
  1012. break;
  1013. case m_search:
  1014. // M_Search_Draw ();
  1015. break;
  1016. case m_slist:
  1017. // M_ServerList_Draw ();
  1018. break;
  1019. }
  1020. if (m_entersound)
  1021. {
  1022. S_LocalSound ("misc/menu2.wav");
  1023. m_entersound = false;
  1024. }
  1025. VID_UnlockBuffer ();
  1026. S_ExtraUpdate ();
  1027. VID_LockBuffer ();
  1028. }
  1029. void M_Keydown (int key)
  1030. {
  1031. switch (m_state)
  1032. {
  1033. case m_none:
  1034. return;
  1035. case m_main:
  1036. M_Main_Key (key);
  1037. return;
  1038. case m_singleplayer:
  1039. M_SinglePlayer_Key (key);
  1040. return;
  1041. case m_load:
  1042. // M_Load_Key (key);
  1043. return;
  1044. case m_save:
  1045. // M_Save_Key (key);
  1046. return;
  1047. case m_multiplayer:
  1048. M_MultiPlayer_Key (key);
  1049. return;
  1050. case m_setup:
  1051. // M_Setup_Key (key);
  1052. return;
  1053. case m_net:
  1054. // M_Net_Key (key);
  1055. return;
  1056. case m_options:
  1057. M_Options_Key (key);
  1058. return;
  1059. case m_keys:
  1060. M_Keys_Key (key);
  1061. return;
  1062. case m_video:
  1063. M_Video_Key (key);
  1064. return;
  1065. case m_help:
  1066. M_Help_Key (key);
  1067. return;
  1068. case m_quit:
  1069. M_Quit_Key (key);
  1070. return;
  1071. case m_serialconfig:
  1072. // M_SerialConfig_Key (key);
  1073. return;
  1074. case m_modemconfig:
  1075. // M_ModemConfig_Key (key);
  1076. return;
  1077. case m_lanconfig:
  1078. // M_LanConfig_Key (key);
  1079. return;
  1080. case m_gameoptions:
  1081. // M_GameOptions_Key (key);
  1082. return;
  1083. case m_search:
  1084. // M_Search_Key (key);
  1085. break;
  1086. case m_slist:
  1087. // M_ServerList_Key (key);
  1088. return;
  1089. }
  1090. }