\#perminv, 2 of 2: implementation

Add new '|' command, aka #perminv, which allows the player to
send menu scrolling keystrokes to the persistent inventory window.

Implemented for X11, where its usefulness is limited, and for
curses, where it is more needed and also more fully functional.
The interface can either prompt for one keystroke, act upon it,
and return to normal play, or it can loop for multiple keystrokes
until player types <return> or <escape>.  X11 does the former if
the 'slow' application resource is False so that prompting uses
popups, and the latter when 'slow' is True where prompting is in
a fixed spot and doesn't end up causing the persistent inventory
window to be stacked behind the map window.  curses always does
the loop-until-done approach.  It also accepts up and down arrow
keys to scroll one line at a time.

Also adds two new menu scrolling commands, menu_shift_right (key
'}' by default) and menu_shift_left ('{') if wincap2 flags contain
WC2_MENU_SHIFT.  Shifting allows different substrings of too-long
lines to be seen.

For X11, neither works because their handling requires a horizontal
scrollbar and for some reason that escapes me our menus don't have
one of those.  If they did, shifts could work for all menus but a
shifted window would hide the selection letters.  So shifting would
be most usefully done as:  pan right, read more of any long lines,
immediately pan back to the left.

For curses, they only apply to the persistent inventory window.
Shift right redraws it with class headers and inventory letters
shown normally but the item descriptions omit their leftmost
portion, showing more text towards the end.  Shift left reverses
that and does nothing if the beginning is already in view.  Forward
and backward scrolling while shifted leave the shift in place.
This commit is contained in:
PatR
2021-03-13 18:18:53 -08:00
parent dd49431296
commit 946df19ea2
21 changed files with 784 additions and 110 deletions

View File

@@ -1019,6 +1019,7 @@ extern int count_unidentified(struct obj *);
extern void identify_pack(int, boolean);
extern void learn_unseen_invent(void);
extern void update_inventory(void);
extern int doperminv(void);
extern void prinv(const char *, struct obj *, long);
extern char *xprname(struct obj *, const char *, char, boolean, long, long);
extern int ddoinv(void);
@@ -1800,6 +1801,7 @@ extern void oc_to_str(char *, char *);
extern void add_menu_cmd_alias(char, char);
extern char get_menu_cmd_key(char);
extern char map_menu_cmd(char);
extern char *collect_menu_keys(char *, unsigned, boolean);
extern void show_menu_controls(winid, boolean);
extern void assign_warnings(uchar *);
extern char *nh_getenv(const char *);

View File

@@ -274,7 +274,7 @@ opt_##a,
NHOPTC(menu_last_page, 4, opt_in, set_in_config, No, Yes, No, No, NoAlias,
"jump to the last page in a menu")
NHOPTC(menu_next_page, 4, opt_in, set_in_config, No, Yes, No, No, NoAlias,
"goto the next menu page")
"go to the next menu page")
NHOPTB(menu_objsyms, 0, opt_in, set_in_game, Off, Yes, No, No, NoAlias,
&iflags.menu_head_objsym)
#ifdef TTY_GRAPHICS
@@ -285,13 +285,17 @@ opt_##a,
(boolean *) 0)
#endif
NHOPTC(menu_previous_page, 4, opt_in, set_in_config, No, Yes, No, No,
NoAlias, "goto the previous menu page")
NoAlias, "go to the previous menu page")
NHOPTC(menu_search, 4, opt_in, set_in_config, No, Yes, No, No, NoAlias,
"search for a menu item")
NHOPTC(menu_select_all, 4, opt_in, set_in_config, No, Yes, No, No, NoAlias,
"select all items in a menu")
NHOPTC(menu_select_page, 4, opt_in, set_in_config, No, Yes, No, No,
NoAlias, "select all items on this page of a menu")
NHOPTC(menu_shift_left, 4, opt_in, set_in_config, No, Yes, No, No,
NoAlias, "pan current menu page left")
NHOPTC(menu_shift_right, 4, opt_in, set_in_config, No, Yes, No, No,
NoAlias, "pan current menu page right")
NHOPTB(menu_tab_sep, 0, opt_in, set_wizonly, Off, Yes, No, No, NoAlias,
&iflags.menu_tab_sep)
NHOPTB(menucolors, 0, opt_in, set_in_game, Off, Yes, Yes, No, NoAlias,

View File

@@ -363,6 +363,7 @@ extern int x_event(int);
extern void menu_delete(Widget, XEvent *, String *, Cardinal *);
extern void menu_key(Widget, XEvent *, String *, Cardinal *);
extern void x11_no_perminv(struct xwindow *);
extern void x11_scroll_perminv(int);
extern void create_menu_window(struct xwindow *);
extern void destroy_menu_window(struct xwindow *);

View File

@@ -195,8 +195,9 @@ extern void curses_status_update(int, genericptr_t, int, int, int,
/* cursinvt.c */
extern void curses_update_inv(void);
extern void curses_add_inv(int, char, attr_t, const char *);
extern void curs_purge_perminv_data(boolean);
extern void curs_update_invt(int);
extern void curs_add_invt(int, char, attr_t, const char *);
/* cursinit.c */

View File

@@ -231,7 +231,8 @@ extern
* via non-display attribute flag */
#define WC2_SUPPRESS_HIST 0x8000L /* 16 putstr(WIN_MESSAGE) supports history
* suppression via non-disp attr */
/* 16 free bits */
#define WC2_MENU_SHIFT 0x010000L /* 17 horizontal menu scrolling */
/* 15 free bits */
#define ALIGN_LEFT 1
#define ALIGN_RIGHT 2

View File

@@ -110,12 +110,15 @@ typedef struct mi {
/* invalid winid */
#define WIN_ERR ((winid) -1)
/* menu window keyboard commands (may be mapped) */
/* menu window keyboard commands (may be mapped); menu_shift_right and
menu_shift_left are for interacting with persistent inventory window */
/* clang-format off */
#define MENU_FIRST_PAGE '^'
#define MENU_LAST_PAGE '|'
#define MENU_NEXT_PAGE '>'
#define MENU_PREVIOUS_PAGE '<'
#define MENU_SHIFT_RIGHT '}'
#define MENU_SHIFT_LEFT '{'
#define MENU_SELECT_ALL '.'
#define MENU_UNSELECT_ALL '-'
#define MENU_INVERT_ALL '@'