From cf2f42ea6a07e82651f9acc349be0b80628631c7 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 1 Feb 2002 17:32:40 +0000 Subject: [PATCH] make it so menu items can get called for any keypress. this is optionally done by setting the allkeys param to 1. when this is the case, if the menu item function returns 0, normal processing is done, otherwise processing stops. --- cs-code/menu.qc | 26 +++++++++++++++----------- cs-code/menu_def.qc | 2 +- cs-code/options.qc | 27 +++++++++++++++------------ libs/console/menu.c | 11 +++++++++++ 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/cs-code/menu.qc b/cs-code/menu.qc index 0a5d4d78d..fd41ea2ce 100644 --- a/cs-code/menu.qc +++ b/cs-code/menu.qc @@ -133,16 +133,18 @@ void () scan_saves = } }; -void (string text, integer key) load_f = +integer (string text, integer key) load_f = { scan_saves (); Menu_SelectMenu ("load"); + return 0; }; -void (string text, integer key) save_f = +integer (string text, integer key) save_f = { scan_saves (); Menu_SelectMenu ("save"); + return 0; }; integer () load_draw = @@ -241,9 +243,10 @@ integer () quit = return 0; }; -void (string text, integer key) quit_f = +integer (string text, integer key) quit_f = { quit (); + return 0; }; integer (integer key, integer unicode, integer down) quit_keyevent = @@ -278,7 +281,7 @@ void () quit_menu = Menu_End (); }; -void (string text, integer key) sp_start = +integer (string text, integer key) sp_start = { Menu_SelectMenu (NIL); Cbuf_AddText ("disconnect\n"); @@ -290,6 +293,7 @@ void (string text, integer key) sp_start = Cbuf_AddText ("noexit 0\n"); Cbuf_AddText ("samelevel 0\n"); Cbuf_AddText ("map start\n"); + return 0; }; void () single_player_menu = @@ -300,9 +304,9 @@ void () single_player_menu = Menu_CenterPic (160, 4, "gfx/ttl_sgl.lmp"); Menu_Pic (72, 32, "gfx/sp_menu.lmp"); Menu_Cursor (spinner); - Menu_Item (54, 32, "", sp_start); - Menu_Item (54, 52, "", load_f); - Menu_Item (54, 72, "", save_f); + Menu_Item (54, 32, "", sp_start, 0); + Menu_Item (54, 52, "", load_f, 0); + Menu_Item (54, 72, "", save_f, 0); Menu_End (); }; @@ -443,8 +447,8 @@ void () multi_player_menu = Menu_KeyEvent (multi_player_keyevent); join_menu (); if (do_single_player) - Menu_Item (54, 52, "", quit_f); - Menu_Item (54, 72, "", quit_f); + Menu_Item (54, 52, "", quit_f, 0); + Menu_Item (54, 72, "", quit_f, 0); Menu_Cursor (spinner); Menu_End (); }; @@ -453,7 +457,7 @@ void () multi_player_menu = void () help_menu = { - Menu_Item (54, 92, "", quit_f); + Menu_Item (54, 92, "", quit_f, 0); }; void () main_menu = @@ -469,7 +473,7 @@ void () main_menu = multi_player_menu (); options_menu (); help_menu (); - Menu_Item (54, 112, "", quit_f); + Menu_Item (54, 112, "", quit_f, 0); Menu_End (); }; diff --git a/cs-code/menu_def.qc b/cs-code/menu_def.qc index 04a1a20b9..bcd759992 100644 --- a/cs-code/menu_def.qc +++ b/cs-code/menu_def.qc @@ -3,7 +3,7 @@ void (integer val) Menu_FadeScreen = #0; void (integer () func) Menu_Draw = #0; void (integer x, integer y, string name) Menu_Pic = #0; void (integer x, integer y, string name) Menu_CenterPic = #0; -void (integer x, integer y, string text, void (string text, integer key) func) Menu_Item = #0; +void (integer x, integer y, string text, integer (string text, integer key) func, integer allkeys) Menu_Item = #0; void (void (integer x, integer y) func) Menu_Cursor = #0; void (integer (integer key, integer unicode, integer down) func) Menu_KeyEvent = #0; void () Menu_End = #0; diff --git a/cs-code/options.qc b/cs-code/options.qc index 4665e3aa2..43499852b 100644 --- a/cs-code/options.qc +++ b/cs-code/options.qc @@ -10,7 +10,7 @@ void (integer x, integer y) opt_cursor = Draw_Character (x, y, 12 + (integer (time * 4) & 1)); }; -void (string text, integer key) video_options_f = +integer (string text, integer key) video_options_f = { local integer selected_crosshair; local float gamma; @@ -44,13 +44,15 @@ void (string text, integer key) video_options_f = cvar_set("vid_gamma", ftos(gamma)); break; } + return 0; }; -void (string text, integer key) control_options_f = + +integer (string text, integer key) control_options_f = { switch (text) { case "in_grab": Cbuf_AddText ("toggle in_grab\n"); - return; + break; case "autorun": if(cvar("cl_forwardspeed") < 400) { Cbuf_AddText ("set cl_forwardspeed 400\n"); @@ -59,7 +61,7 @@ void (string text, integer key) control_options_f = Cbuf_AddText ("set cl_forwardspeed 200\n"); Cbuf_AddText ("set cl_backspeed 200\n"); } - return; + break; case "set_key": if(set_key_flag) { set_key_flag = 0; @@ -68,6 +70,7 @@ void (string text, integer key) control_options_f = } break; } + return 0; }; @@ -212,11 +215,11 @@ void () options_controls_menu = Menu_CenterPic (160, 4, "gfx/p_option.lmp"); Menu_Draw (options_controls_draw); Menu_KeyEvent (options_controls_keyevent); - Menu_Item (54, 60, "in_grab", control_options_f); - Menu_Item (54, 70, "autorun", control_options_f); - Menu_Item (54, 90, "set_key", control_options_f); - Menu_Item (54, 100, "set_key", control_options_f); - Menu_Item (54, 110, "set_key", control_options_f); + Menu_Item (54, 60, "in_grab", control_options_f, 0); + Menu_Item (54, 70, "autorun", control_options_f, 0); + Menu_Item (54, 90, "set_key", control_options_f, 0); + Menu_Item (54, 100, "set_key", control_options_f, 0); + Menu_Item (54, 110, "set_key", control_options_f, 0); Menu_End (); }; @@ -256,9 +259,9 @@ void () options_video_menu = Menu_Draw (options_video_draw); Menu_KeyEvent (options_video_keyevent); - Menu_Item (54, 60, "fullscreen", video_options_f); - Menu_Item (54, 70, "crosshair", video_options_f); - Menu_Item (54, 80, "gamma", video_options_f); + Menu_Item (54, 60, "fullscreen", video_options_f, 0); + Menu_Item (54, 70, "crosshair", video_options_f, 0); + Menu_Item (54, 80, "gamma", video_options_f, 0); Menu_End (); }; diff --git a/libs/console/menu.c b/libs/console/menu.c index 2df9220b1..817344a0c 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -62,6 +62,7 @@ typedef struct menu_item_s { func_t keyevent; func_t draw; unsigned fadescreen:1; + unsigned allkeys:1; const char *text; menu_pic_t *pics; } menu_item_t; @@ -204,6 +205,7 @@ bi_Menu_Item (progs_t *pr) int y = G_INT (pr, OFS_PARM1); const char *text = G_STRING (pr, OFS_PARM2); func_t func = G_FUNCTION (pr, OFS_PARM3); + int allkeys = G_INT (pr, OFS_PARM4); menu_item_t *mi = calloc (sizeof (menu_item_t), 1); mi->x = x; @@ -211,6 +213,7 @@ bi_Menu_Item (progs_t *pr) mi->text = strdup (text); mi->func = func; mi->parent = menu; + mi->allkeys = allkeys; menu_add_item (menu, mi); } @@ -465,6 +468,14 @@ Menu_KeyEvent (knum_t key, short unicode, qboolean down) PR_ExecuteProgram (&menu_pr_state, menu->keyevent); if (G_INT (&menu_pr_state, OFS_RETURN)) return; + } else if (menu->items && menu->items[menu->cur_item]->func + && menu->items[menu->cur_item]->allkeys) { + G_INT (&menu_pr_state, OFS_PARM0) = key; + G_INT (&menu_pr_state, OFS_PARM1) = unicode; + G_INT (&menu_pr_state, OFS_PARM2) = down; + PR_ExecuteProgram (&menu_pr_state, menu->items[menu->cur_item]->func); + if (G_INT (&menu_pr_state, OFS_RETURN)) + return; } if (!menu || !menu->items) return;