/** * @brief sort_items * @param start * @return */ struct nodelist_item *sort_items( struct nodelist_item *start ){ if( start == NULL ){ return NULL; } start->next = sort_items(start->next); if( start->next != NULL && start->slot_gain > start->next->slot_gain ) { start = move_item( start ); } return start; }
/*! \brief Process the item menu * * This screen displays the list of items that the character has, then * waits for the player to select one. */ void camp_item_menu(void) { int stop = 0, ptr = 0, pptr = 0, sel = 0; item_act = 0; play_effect(SND_MENU, 128); while (!stop) { check_animation(); drawmap(); draw_itemmenu(ptr, pptr, sel); blit2screen(xofs, yofs); readcontrols(); if (sel == 0) { if (down) { unpress(); ptr++; if (ptr > 15) { ptr = 0; } play_effect(SND_CLICK, 128); } if (up) { unpress(); ptr--; if (ptr < 0) { ptr = 15; } play_effect(SND_CLICK, 128); } } if (right) { unpress(); if (sel == 0) { /* One of the 16 items in the list */ pptr++; if (pptr > MAX_INV / 16 - 1) { pptr = 0; } } else { /* Use / Sort / Drop */ item_act++; if (item_act > 2) { item_act = 0; } } play_effect(SND_CLICK, 128); } if (left) { unpress(); if (sel == 0) { /* One of the 16 items in the list */ pptr--; if (pptr < 0) { pptr = MAX_INV / 16 - 1; } } else { /* Use / Sort / Drop */ item_act--; if (item_act < 0) { item_act = 2; } } play_effect(SND_CLICK, 128); } if (balt) { unpress(); if (sel == 1) { if (item_act == 1) { sort_items(); } else { sel = 0; } } else { if (g_inv[pptr * 16 + ptr][0] > 0) { // Player's cursor was over the USE menu if (item_act == 0) { camp_item_targetting(pptr * 16 + ptr); } // Player's curor was over the DROP menu else { if (item_act == 2) { int stop2 = 0; /* Make sure the player really wants to drop the item specified. */ while (!stop2) { check_animation(); drawmap(); draw_itemmenu(ptr, pptr, sel); menubox(double_buffer, 72 + xofs, 204 + yofs, 20, 1, DARKBLUE); print_font(double_buffer, 104 + xofs, 212 + yofs, _("Confirm/Cancel"), FNORMAL); blit2screen(xofs, yofs); readcontrols(); if (balt) { unpress(); stop2 = 2; } if (bctrl) { unpress(); stop2 = 1; } } if (stop2 == 2) { // Drop ALL of the selected items remove_item(pptr * 16 + ptr, g_inv[pptr * 16 + ptr][1]); } } } } } } if (bctrl) { unpress(); if (sel == 0) { sel = 1; } else { stop = 1; } } } }