| 756 | /* Display a nethack menu, and return a selection, if applicable */ |
| 757 | |
| 758 | int |
| 759 | curses_display_nhmenu( |
| 760 | winid wid, |
| 761 | int how, |
| 762 | MENU_ITEM_P **_selected) |
| 763 | { |
| 764 | nhmenu *current_menu = get_menu(wid); |
| 765 | nhmenu_item *menu_item_ptr; |
| 766 | int num_chosen, count; |
| 767 | WINDOW *win; |
| 768 | MENU_ITEM_P *selected = NULL; |
| 769 | |
| 770 | *_selected = NULL; |
| 771 | |
| 772 | if (current_menu == NULL) { |
| 773 | impossible( |
| 774 | "curses_display_nhmenu: attempt to display nonexistent menu"); |
| 775 | return -1; /* not ESC which falsely claims 27 items were selected */ |
| 776 | } |
| 777 | |
| 778 | menu_item_ptr = current_menu->entries; |
| 779 | |
| 780 | if (menu_item_ptr == NULL) { |
| 781 | impossible("curses_display_nhmenu: attempt to display empty menu"); |
| 782 | return -1; |
| 783 | } |
| 784 | |
| 785 | /* Reset items to unselected to clear out selections from previous |
| 786 | invocations of this menu, and preselect appropriate items */ |
| 787 | while (menu_item_ptr != NULL) { |
| 788 | menu_item_ptr->selected = menu_item_ptr->presel; |
| 789 | menu_item_ptr = menu_item_ptr->next_item; |
| 790 | } |
| 791 | |
| 792 | menu_win_size(current_menu); |
| 793 | menu_determine_pages(current_menu); |
| 794 | |
| 795 | /* Display pre and post-game menus centered */ |
| 796 | if (svm.moves == 0 || program_state.gameover) { |
| 797 | win = curses_create_window(wid, current_menu->width, |
| 798 | current_menu->height, CENTER); |
| 799 | } else { /* Display during-game menus on the right out of the way */ |
| 800 | win = curses_create_window(wid, current_menu->width, |
| 801 | current_menu->height, RIGHT); |
| 802 | } |
| 803 | |
| 804 | curses_set_wid_colors(wid, win); |
| 805 | num_chosen = menu_get_selections(win, current_menu, how); |
| 806 | curses_destroy_win(win); |
| 807 | |
| 808 | if (num_chosen > 0) { |
| 809 | selected = (MENU_ITEM_P *) alloc((unsigned) |
| 810 | (num_chosen * sizeof (MENU_ITEM_P))); |
| 811 | count = 0; |
| 812 | menu_item_ptr = current_menu->entries; |
| 813 | |
| 814 | while (menu_item_ptr != NULL) { |
| 815 | if (menu_item_ptr->selected) { |
no test coverage detected