MCPcopy Index your code
hub / github.com/NetHack/NetHack / ttyinv_render

Function ttyinv_render

win/tty/wintty.c:3263–3371  ·  view source on GitHub ↗

display persistent inventory from data collected by add_menu() */

Source from the content-addressed store, hash-verified

3261
3262/* display persistent inventory from data collected by add_menu() */
3263static void
3264ttyinv_render(winid window, struct WinDesc *cw)
3265{
3266 int row, col, slot, side, filled_count = 0, slot_limit;
3267 uint32 current_row_color = NO_COLOR;
3268 struct tty_perminvent_cell *cell;
3269 char invbuf[BUFSZ];
3270 boolean force_redraw = program_state.in_docrt ? TRUE : FALSE,
3271 inuse_only = (ttyinvmode & InvInUse) != 0,
3272 show_gold = (ttyinvmode & InvShowGold) != 0 && !inuse_only,
3273 sparse = (ttyinvmode & InvSparse) != 0 && !inuse_only;
3274 int rows_per_side = (inuse_only ? (cw->maxrow - 2)
3275 : !show_gold ? 26
3276 : 27);
3277
3278 slot_limit = SIZE(slot_tracker);
3279 if (inuse_only) {
3280 slot_limit = rows_per_side; /* assume one side */
3281 if (ttyinv_slots_used == 0 || ttyinv_slots_used >= rows_per_side)
3282 slot_limit *= 2; /* second side is populated */
3283 } else if (!show_gold) {
3284 slot_limit -= 2; /* there are two extra slots for gold and overflow;
3285 * blanking them for !show_gold would wrap back to
3286 * rows 1 and 2 and need non-existent third side */
3287 }
3288
3289 for (slot = 0; slot < slot_limit; ++slot)
3290 if (slot_tracker[slot])
3291 filled_count++;
3292 /* clear unused slots */
3293 for (slot = 0; slot < slot_limit; ++slot) {
3294 if (slot_tracker[slot])
3295 continue;
3296 if (slot == 0 && !filled_count) {
3297 Sprintf(invbuf, "%-4s[%s]", "",
3298 inuse_only ? "no items are in use"
3299 : (!show_gold && money_cnt(gi.invent)) ? "only gold"
3300 : "empty");
3301 } else if (sparse && filled_count) {
3302 Sprintf(invbuf, "%c", slot_to_invlet(slot, show_gold));
3303 } else {
3304 invbuf[0] = '\0'; /* "" => fill slot with spaces */
3305 }
3306 row = (slot % rows_per_side) + 1; /* +1: top border */
3307 /* side: left side panel or right side panel, not a window column */
3308 side = slot / rows_per_side;
3309 ttyinv_populate_slot(cw, row, side, invbuf, NO_COLOR, 0);
3310 }
3311
3312 /* inuse_only might switch from one panel to two or vice versa */
3313 if (inuse_only && filled_count != ttyinv_slots_used) {
3314 if (filled_count > rows_per_side
3315 && ttyinv_slots_used <= rows_per_side) {
3316 /* need second side; set up the middle border */
3317 /* done earlier, in add_menu():
3318 ttyinv_inuse_twosides(cw, rows_per_side);
3319 */
3320 } else if (filled_count <= rows_per_side

Callers 1

ttyinv_end_menuFunction · 0.85

Calls 9

money_cntFunction · 0.85
slot_to_invletFunction · 0.85
ttyinv_populate_slotFunction · 0.85
ttyinv_inuse_fulllinesFunction · 0.85
tty_print_glyphFunction · 0.85
end_glyphoutFunction · 0.85
tty_cursFunction · 0.85
term_end_colorFunction · 0.70
term_start_colorFunction · 0.70

Tested by

no test coverage detected