show a menu of containers under hero, and one extra entry for choosing an inventory. returns ECMD_CANCEL if menu was canceled, ECMD_TIME if a container was picked, otherwise returns ECMD_OK. */
| 3502 | ECMD_TIME if a container was picked, |
| 3503 | otherwise returns ECMD_OK. */ |
| 3504 | staticfn int |
| 3505 | choose_tip_container_menu(void) |
| 3506 | { |
| 3507 | int n, i; |
| 3508 | winid win; |
| 3509 | anything any; |
| 3510 | menu_item *pick_list = (menu_item *) 0; |
| 3511 | struct obj dummyobj, *otmp; |
| 3512 | int clr = NO_COLOR; |
| 3513 | |
| 3514 | any = cg.zeroany; |
| 3515 | win = create_nhwindow(NHW_MENU); |
| 3516 | start_menu(win, MENU_BEHAVE_STANDARD); |
| 3517 | |
| 3518 | for (otmp = svl.level.objects[u.ux][u.uy], i = 0; otmp; |
| 3519 | otmp = otmp->nexthere) |
| 3520 | if (Is_container(otmp)) { |
| 3521 | ++i; |
| 3522 | any.a_obj = otmp; |
| 3523 | add_menu(win, &nul_glyphinfo, &any, 0, 0, ATR_NONE, |
| 3524 | clr, doname(otmp), MENU_ITEMFLAGS_NONE); |
| 3525 | } |
| 3526 | if (gi.invent) { |
| 3527 | add_menu_str(win, ""); |
| 3528 | any.a_obj = &dummyobj; |
| 3529 | /* use 'i' for inventory unless there are so many |
| 3530 | containers that it's already being used */ |
| 3531 | i = (i <= 'i' - 'a' && !flags.lootabc) ? 'i' : 0; |
| 3532 | add_menu(win, &nul_glyphinfo, &any, i, 0, ATR_NONE, |
| 3533 | clr, "tip something being carried", |
| 3534 | MENU_ITEMFLAGS_SELECTED); |
| 3535 | } |
| 3536 | end_menu(win, "Tip which container?"); |
| 3537 | n = select_menu(win, PICK_ONE, &pick_list); |
| 3538 | destroy_nhwindow(win); |
| 3539 | /* |
| 3540 | * Deal with quirk of preselected item in pick-one menu: |
| 3541 | * n == 0 => picked preselected entry, toggling it off; |
| 3542 | * n == 1 => accepted preselected choice via SPACE or RETURN; |
| 3543 | * n == 2 => picked something other than preselected entry; |
| 3544 | * n == -1 => cancelled via ESC; |
| 3545 | */ |
| 3546 | otmp = (n <= 0) ? (struct obj *) 0 : pick_list[0].item.a_obj; |
| 3547 | if (n > 1 && otmp == &dummyobj) |
| 3548 | otmp = pick_list[1].item.a_obj; |
| 3549 | if (pick_list) |
| 3550 | free((genericptr_t) pick_list); |
| 3551 | if (otmp && otmp != &dummyobj) { |
| 3552 | tipcontainer(otmp); |
| 3553 | return ECMD_TIME; |
| 3554 | } |
| 3555 | if (n == -1) |
| 3556 | return ECMD_CANCEL; |
| 3557 | return ECMD_OK; |
| 3558 | } |
| 3559 | |
| 3560 | /* #tip command -- empty container contents onto floor */ |
| 3561 | int |
no test coverage detected