From: PatR Date: Thu, 10 Feb 2022 22:18:44 +0000 (-0800) Subject: number_pad menu hack X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f2a1ac002f60f253d3f664fe66447923cb459ce;p=nethack number_pad menu hack I don't try to toggle 'number_pad' very often, but when I do I almost always type '0' instead of 'a' for Off or '1' instead of 'b' for On on the first attempt. The menu shows | a - 0 (off) | b - 1 (on) | c - 2 (on, MSDOS compatible) | d - 3 (on, phone-style digit layout) | e - 4 (on, phone-style layout, MSDOS compatible) | f - -1 (off, 'z' to move upper-left, 'y' to zap wands) This change makes '0' through '4' be undocumented group accelerators for 'a' through 'e' (and '5' for 'f') in the sub-menu put up by 'O'. tty and X11 worked as-is for '0' and required what amounts to a pair of one-line changes to handle the other digits. It doesn't work for curses and Qt (no idea about Windows GUI) because they insist on treating any typed digit as the start of a count even if one or more menu entries include that digit as a group accelerator. (They also fail to support '0' as the group accelerator for iron-ball class in the menu for multiple-drop.) --- diff --git a/src/options.c b/src/options.c index a826ff481..6b73b64a1 100644 --- a/src/options.c +++ b/src/options.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 options.c $NHDT-Date: 1643491546 2022/01/29 21:25:46 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.535 $ */ +/* NetHack 3.7 options.c $NHDT-Date: 1644531493 2022/02/10 22:18:13 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.538 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Michael Allison, 2008. */ /* NetHack may be freely redistributed. See license for details. */ @@ -4528,8 +4528,8 @@ handler_number_pad(void) any = cg.zeroany; for (i = 0; i < SIZE(npchoices); i++) { any.a_int = i + 1; - add_menu(tmpwin, &nul_glyphinfo, &any, 'a' + i, - 0, ATR_NONE, npchoices[i], MENU_ITEMFLAGS_NONE); + add_menu(tmpwin, &nul_glyphinfo, &any, 'a' + i, '0' + i, + ATR_NONE, npchoices[i], MENU_ITEMFLAGS_NONE); } end_menu(tmpwin, "Select number_pad mode:"); if (select_menu(tmpwin, PICK_ONE, &mode_pick) > 0) { diff --git a/win/X11/winmenu.c b/win/X11/winmenu.c index 890dc33ae..d31b95a35 100644 --- a/win/X11/winmenu.c +++ b/win/X11/winmenu.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 winmenu.c $NHDT-Date: 1615911117 2021/03/16 16:11:57 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.48 $ */ +/* NetHack 3.7 winmenu.c $NHDT-Date: 1644531504 2022/02/10 22:18:24 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.50 $ */ /* Copyright (c) Dean Luick, 1992 */ /* NetHack may be freely redistributed. See license for details. */ @@ -271,8 +271,10 @@ menu_key(Widget w, XEvent *event, String *params, Cardinal *num_params) } ; /* accept */ } else if (digit(ch)) { - /* special case: '0' is also the default ball class */ - if (ch == '0' && !menu_info->counting + /* special case: '0' is also the default ball class; + some menus use digits as potential group accelerators + but their entries don't rely on counts */ + if (!menu_info->counting && index(menu_info->curr_menu.gacc, ch)) goto group_accel; menu_info->menu_count *= 10L; diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 8d1a77495..4f9b48452 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 wintty.c $NHDT-Date: 1643491577 2022/01/29 21:26:17 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.282 $ */ +/* NetHack 3.7 wintty.c $NHDT-Date: 1644531502 2022/02/10 22:18:22 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.283 $ */ /* Copyright (c) David Cohrs, 1991 */ /* NetHack may be freely redistributed. See license for details. */ @@ -2055,11 +2055,6 @@ process_menu_window(winid window, struct WinDesc *cw) switch (morc) { case '0': - /* special case: '0' is also the default ball class */ - if (!counting && index(gacc, morc)) - goto group_accel; - /* fall through to count the zero */ - /*FALLTHRU*/ case '1': case '2': case '3': @@ -2069,6 +2064,12 @@ process_menu_window(winid window, struct WinDesc *cw) case '7': case '8': case '9': + /* special case: '0' is also the default ball class; + some menus use digits as potential group accelerators + but their entries don't rely on counts */ + if (!counting && index(gacc, morc)) + goto group_accel; + count = (count * 10L) + (long) (morc - '0'); /* * It is debatable whether we should allow 0 to