extend TTYINV to other interfaces

Make the experimental perm_invent control via TTYINV in player's
environment work for any interface that supports persisntent inventory
(only tested with curses), not just for tty+TTY_PERM_INVENT.  The
value is a bitmap but the only combination value that makes any sense
is 3 for tty.

0 - normal
1 - show gold
2 - 'sparse' (list all 52 letters; ones not is use show blank item)
4 - only items in use (approximation of '*' command)

Note that the bits were set up for tty use, and 'normal' for tty is
to hide gold instead of show it.  When there's no value for TTYINV in
the environment, the default value is 0 for tty and 1 for others to
retain existing behavior.

Sparse has no effect for non-tty.  In-use will display gold even if
the show-gold bit is clear if gold happens to be quivered or wielded.
(That fixes current tty misbehavior.)
This commit is contained in:
PatR
2022-08-18 19:12:27 -07:00
parent 8038f7108d
commit 07a0d2a3a1
+50 -31
View File
@@ -3197,7 +3197,10 @@ display_pickinv(
boolean want_reply, /* True: select an item, False: just display */ boolean want_reply, /* True: select an item, False: just display */
long *out_cnt) /* optional; count player entered when selecting an item */ long *out_cnt) /* optional; count player entered when selecting an item */
{ {
static const char not_carrying_anything[] = "Not carrying anything"; static const char /* potential entries for perm_invent window */
not_carrying_anything[] = "Not carrying anything",
not_using_anything[] = "Not using any items",
only_carrying_gold[] = "Only carrying gold";
struct obj *otmp, wizid_fakeobj; struct obj *otmp, wizid_fakeobj;
char ilet, ret, *formattedobj; char ilet, ret, *formattedobj;
const char *invlet = flags.inv_order; const char *invlet = flags.inv_order;
@@ -3210,15 +3213,17 @@ display_pickinv(
boolean wizid = (wizard && iflags.override_ID), gotsomething = FALSE; boolean wizid = (wizard && iflags.override_ID), gotsomething = FALSE;
int clr = 0, menu_behavior = MENU_BEHAVE_STANDARD; int clr = 0, menu_behavior = MENU_BEHAVE_STANDARD;
boolean show_gold = TRUE, sparse = FALSE, inuse_only = FALSE, boolean show_gold = TRUE, sparse = FALSE, inuse_only = FALSE,
skipped_gold = FALSE, skipped_noninuse = FALSE,
doing_perm_invent = FALSE, save_flags_sortpack = flags.sortpack; doing_perm_invent = FALSE, save_flags_sortpack = flags.sortpack;
if (lets && !*lets) if (lets && !*lets)
lets = 0; /* simplify tests: (lets) instead of (lets && *lets) */ lets = 0; /* simplify tests: (lets) instead of (lets && *lets) */
if ((iflags.perm_invent && (lets || xtra_choice || wizid)) if (!iflags.perm_invent
#ifdef TTY_PERM_INVENT #ifdef TTY_PERM_INVENT
|| !g.in_sync_perminvent || !g.in_sync_perminvent
#endif #endif
|| (lets || xtra_choice || wizid || want_reply)
|| WIN_INVEN == WIN_ERR) { || WIN_INVEN == WIN_ERR) {
/* partial inventory in perm_invent setting; don't operate on /* partial inventory in perm_invent setting; don't operate on
full inventory window, use an alternate one instead; create full inventory window, use an alternate one instead; create
@@ -3367,11 +3372,19 @@ display_pickinv(
if (!flags.sortpack || otmp->oclass == *invlet) { if (!flags.sortpack || otmp->oclass == *invlet) {
if (wizid && !not_fully_identified(otmp)) if (wizid && !not_fully_identified(otmp))
continue; continue;
if (doing_perm_invent if (doing_perm_invent) {
&& ((otmp->invlet == GOLD_SYM && !show_gold) /* when showing equipment in use, gold shouldn't be excluded
|| ((otmp->invlet != GOLD_SYM) just because !show_gold is set; it might be quivered */
&& (!otmp->owornmask && inuse_only)))) if (inuse_only) {
continue; if (!otmp->owornmask) {
skipped_noninuse = TRUE;
continue;
}
} else if (otmp->invlet == GOLD_SYM && !show_gold) {
skipped_gold = TRUE;
continue;
}
}
any = cg.zeroany; /* all bits zero */ any = cg.zeroany; /* all bits zero */
ilet = otmp->invlet; ilet = otmp->invlet;
if (flags.sortpack && !classcount) { if (flags.sortpack && !classcount) {
@@ -3422,14 +3435,16 @@ display_pickinv(
gotsomething = TRUE; gotsomething = TRUE;
} }
unsortloot(&sortedinvent); unsortloot(&sortedinvent);
/* for permanent inventory where we intend to show everything but /* for permanent inventory where nothing has been listed (because
nothing has been listed (because there isn't anyhing to list; there isn't applicable anyhing to list; the n==0 case above
the n==0 case above gets skipped for perm_invent), put something gets skipped for perm_invent), put something into the menu */
into the menu */
if (iflags.perm_invent && !lets && !gotsomething) { if (iflags.perm_invent && !lets && !gotsomething) {
any = cg.zeroany; any = cg.zeroany;
add_menu(win, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, add_menu(win, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr,
not_carrying_anything, MENU_ITEMFLAGS_NONE); (inuse_only && skipped_noninuse) ? not_using_anything
: (!show_gold && skipped_gold) ? only_carrying_gold
: not_carrying_anything,
MENU_ITEMFLAGS_NONE);
want_reply = FALSE; want_reply = FALSE;
} }
#ifdef TTY_PERM_INVENT #ifdef TTY_PERM_INVENT
@@ -3631,8 +3646,10 @@ count_buc(struct obj *list, int type, boolean (*filterfunc)(OBJ_P))
/* similar to count_buc(), but tallies all states at once /* similar to count_buc(), but tallies all states at once
rather than looking for a specific type */ rather than looking for a specific type */
void void
tally_BUCX(struct obj *list, boolean by_nexthere, tally_BUCX(
int *bcp, int *ucp, int *ccp, int *xcp, int *ocp, int *jcp) struct obj *list,
boolean by_nexthere,
int *bcp, int *ucp, int *ccp, int *xcp, int *ocp, int *jcp)
{ {
/* Future extensions: /* Future extensions:
* Skip current_container when list is invent, uchain when * Skip current_container when list is invent, uchain when
@@ -3669,14 +3686,15 @@ tally_BUCX(struct obj *list, boolean by_nexthere,
/* count everything inside a container, or just shop-owned items inside */ /* count everything inside a container, or just shop-owned items inside */
long long
count_contents(struct obj *container, count_contents(
boolean nested, /* include contents of any nested containers */ struct obj *container,
boolean quantity, /* count all vs count separate stacks */ boolean nested, /* include contents of any nested containers */
boolean everything, /* all objects vs only unpaid objects */ boolean quantity, /* count all vs count separate stacks */
boolean newdrop) /* on floor, but hero-owned items haven't boolean everything, /* all objects vs only unpaid objects */
* been marked no_charge yet and shop-owned boolean newdrop) /* on floor, but hero-owned items haven't
* items are still marked unpaid -- used * been marked no_charge yet and shop-owned
* when asking the player whether to sell */ * items are still marked unpaid -- used
* when asking the player whether to sell */
{ {
struct obj *otmp, *topc; struct obj *otmp, *topc;
boolean shoppy = FALSE; boolean shoppy = FALSE;
@@ -5414,16 +5432,17 @@ prepare_perminvent(winid window)
win_request_info *wri; win_request_info *wri;
if (!done_setting_perminv_flags) { if (!done_setting_perminv_flags) {
wri_info = zerowri; /*TEMPORARY*/
#if defined(TTY_PERM_INVENT) char *envtmp = nh_getenv("TTYINV");
if (WINDOWPORT(tty)) { /* default for non-tty includes gold, for tty excludes gold;
/*TEMPORARY*/ if non-tty specifies any value, gold will be excluded unless
char *envtmp = nh_getenv("TTYINV"); that value includes the show-gold bit (1) */
int invmode = envtmp ? atoi(envtmp)
: !WINDOWPORT(tty) ? InvShowGold
: InvNormal;
wri_info.fromcore.invmode = envtmp ? atoi(envtmp) : InvNormal; wri_info = zerowri;
} else wri_info.fromcore.invmode = invmode;
#endif
wri_info.fromcore.invmode = InvShowGold;
/* relay the mode settings to the window port */ /* relay the mode settings to the window port */
wri = ctrl_nhwindow(window, set_mode, &wri_info); wri = ctrl_nhwindow(window, set_mode, &wri_info);
nhUse(wri); nhUse(wri);