MCPcopy Create free account
hub / github.com/NetHack/NetHack / ttyinv_add_menu

Function ttyinv_add_menu

win/tty/wintty.c:3048–3116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3046}
3047
3048static void
3049ttyinv_add_menu(
3050 winid window UNUSED,
3051 struct WinDesc *cw,
3052 char ch,
3053 int attr UNUSED, int clr,
3054 const char *str)
3055{
3056 char invbuf[BUFSZ];
3057 const char *text;
3058 boolean show_gold = (ttyinvmode & InvShowGold) != 0,
3059 inuse_only = (ttyinvmode & InvInUse) != 0,
3060 ignore = FALSE;
3061 int row, side, slot, startcolor_at = 0,
3062 rows_per_side = (inuse_only ? (cw->maxrow - 2)
3063 : !show_gold ? 26
3064 : 27);
3065
3066 if (!program_state.in_moveloop)
3067 return;
3068 slot = selector_to_slot(ch, ttyinvmode, &ignore);
3069 if (inuse_only && slot > 2 * rows_per_side)
3070 ignore = TRUE; /* left & right sides full; no 3rd 'side' available */
3071 if (!ignore) {
3072 slot_tracker[slot] = TRUE;
3073 /* if we need to expand inuse_only from one side to two, do so now;
3074 entries are shown in row 1 thru rows_per_side (with rows 0 and
3075 rows_per_side+1 containing boundary lines) but stored in
3076 slots 0 thru rows_per_side-1, so zero-based slot==rows_per_side
3077 is the entry that will be shown on first row of the second side
3078 (and one-base ttyinv_slots_used==rows_per_side means that on the
3079 previous inventory_update(), full lines filled all the rows;
3080 ttyinv_slots_used==0 means that we've just enabled perm_invent) */
3081 if (inuse_only && slot == rows_per_side
3082 && ttyinv_slots_used % rows_per_side == 0)
3083 ttyinv_inuse_twosides(cw, rows_per_side);
3084
3085 text = str; /* 'text' will switch to invbuf[] below */
3086 /* strip away "a"/"an"/"the" prefix to show a bit more of
3087 the interesting part of the object's description; this
3088 is inline version of pi_article_skip() from cursinvt.c;
3089 should move that to hacklib.c and use it here */
3090 if (text[0] == 'a') {
3091 if (text[1] == ' ')
3092 text += 2;
3093 else if (text[1] == 'n' && text[2] == ' ')
3094 text += 3;
3095 } else if (text[0] == 't') {
3096 if (text[1] == 'h' && text[2] == 'e' && text[3] == ' ')
3097 text += 4;
3098 }
3099 /*
3100 * TODO?
3101 * Replace "c - " prefix with "c: " or just "c " to have a bit more
3102 * room for 'text' (the item description). If this prefix gets
3103 * changed, the indentation for empty inventory in ttyinv_render()
3104 * should be changed to match.
3105 */

Callers 1

tty_add_menuFunction · 0.85

Calls 3

selector_to_slotFunction · 0.85
ttyinv_inuse_twosidesFunction · 0.85
ttyinv_populate_slotFunction · 0.85

Tested by

no test coverage detected