show items on your bill in a menu, and ask which to pay. returns the number of entries selected. */
| 1665 | /* show items on your bill in a menu, and ask which to pay. |
| 1666 | returns the number of entries selected. */ |
| 1667 | staticfn int |
| 1668 | menu_pick_pay_items( |
| 1669 | int ibillct, /* number of entries in ibill[] */ |
| 1670 | Bill *ibill) /* all used up items, if any, precede all intact items */ |
| 1671 | { |
| 1672 | struct obj *otmp; |
| 1673 | winid win; |
| 1674 | anything any; |
| 1675 | menu_item *pick_list = (menu_item *) 0; |
| 1676 | char *p, buf[BUFSZ]; |
| 1677 | long amt, largest_amt, save_quan; |
| 1678 | int i, j, n, amt_width; |
| 1679 | |
| 1680 | any = cg.zeroany; |
| 1681 | win = create_nhwindow(NHW_MENU); |
| 1682 | start_menu(win, MENU_BEHAVE_STANDARD); |
| 1683 | |
| 1684 | /* we go through ibill[] twice, first time to control price formatting |
| 1685 | during the second */ |
| 1686 | largest_amt = 0L; |
| 1687 | for (i = 0; i < ibillct; ++i) |
| 1688 | if (ibill[i].cost > largest_amt) |
| 1689 | largest_amt = ibill[i].cost; |
| 1690 | Sprintf(buf, "%ld", largest_amt); |
| 1691 | amt_width = (int) strlen(buf); |
| 1692 | |
| 1693 | /* show the "used up items" header if there are any used up items on |
| 1694 | the bill, no matter whether there are also any intact items; |
| 1695 | note: ibill[] has been sorted to hold used-up items first */ |
| 1696 | if (ibill[0].usedup <= PartlyUsedUp) { |
| 1697 | Sprintf(buf, "Used up item%s:", |
| 1698 | (ibillct > 1 && ibill[1].usedup <= PartlyUsedUp) ? "s" : ""); |
| 1699 | add_menu_heading(win, buf); |
| 1700 | } |
| 1701 | for (i = 0; i < ibillct; ++i) { |
| 1702 | /* the "unpaid items" header is only shown if the "used up items" |
| 1703 | one was shown before the first menu entry */ |
| 1704 | if (i > 0 && ibill[i - 1].usedup <= PartlyUsedUp |
| 1705 | && ibill[i].usedup >= PartlyIntact) { |
| 1706 | Sprintf(buf, "Unpaid item%s:", (i < ibillct - 1) ? "s" : ""); |
| 1707 | add_menu_heading(win, buf); |
| 1708 | } |
| 1709 | otmp = ibill[i].obj; |
| 1710 | save_quan = otmp->quan; |
| 1711 | otmp->quan = ibill[i].quan; /* in case it's partly used */ |
| 1712 | p = paydoname(otmp); |
| 1713 | otmp->quan = save_quan; |
| 1714 | amt = ibill[i].cost; |
| 1715 | /* this doesn't support hallucinatory currency because shopkeeper |
| 1716 | isn't hallucinating; also, that would mess up the alignment */ |
| 1717 | Snprintf(buf, sizeof buf, "%*ld Zm, %s", amt_width, amt, p); |
| 1718 | any.a_int = i + 1; /* +1: avoid 0 */ |
| 1719 | add_menu(win, &nul_glyphinfo, &any, 0, 0, ATR_NONE, NO_COLOR, buf, |
| 1720 | MENU_ITEMFLAGS_NONE); |
| 1721 | } |
| 1722 | |
| 1723 | end_menu(win, "Pay for which items?"); |
| 1724 | n = select_menu(win, PICK_ANY, &pick_list); |
no test coverage detected