void inventory_selector::remove_dropping_items( player &u ) const { // We iterate backwards because deletion will invalidate later indices. for( inventory_selector::drop_map::const_reverse_iterator a = dropping.rbegin(); a != dropping.rend(); ++a ) { if( a->first < 0 ) { // weapon or armor, handled separately continue; } const int count = a->second; item &tmpit = u.inv.find_item( a->first ); if( tmpit.count_by_charges() ) { long charges = tmpit.charges; if( count != -1 && count < charges ) { tmpit.charges -= count; } else { u.inv.remove_item( a->first ); } } else { size_t max_count = u.inv.const_stack( a->first ).size(); if( count != -1 && ( size_t )count < max_count ) { max_count = count; } for( size_t i = 0; i < max_count; i++ ) { u.inv.remove_item( a->first ); } } } }
void inventory_selector::set_drop_count(int it_pos, int count, const item &it) { // "dropping" when comparing means select for comparison, valid for bionics if (it_pos == -1 && g->u.weapon.has_flag("NO_UNWIELD") && !compare) { if (!warned_about_bionic) { popup(_("You cannot drop your %s."), g->u.weapon.tname().c_str()); warned_about_bionic = true; } return; } // count 0 means toggle, if already selected for dropping, drop none drop_map::iterator iit = dropping.find(it_pos); if (count == 0 && iit != dropping.end()) { dropping.erase(iit); if (first_item == &it) { first_item = second_item; second_item = NULL; } else if (second_item == &it) { second_item = NULL; } } else { // allow only -1 or anything > 0 dropping[it_pos] = (count <= 0) ? -1 : count; if (first_item == NULL || first_item == &it) { first_item = const_cast<item *>(&it); } else { second_item = const_cast<item *>(&it); } } }
void inventory_selector::print_right_column() const { if (right_column_width == 0) { return; } player &u = g->u; int drp_line = 1; drop_map::const_iterator dit = dropping.find(-1); if (dit != dropping.end()) { std::string item_name = u.weapname(); if (dit->second == -1) { item_name.insert(0, "+ "); } else { item_name = string_format("# %s {%d}", item_name.c_str(), dit->second); } const char invlet = invlet_or_space(u.weapon); item_name = trim_to(item_name, right_column_width - 2); // 2 for the invlet & space mvwprintz(w_inv, drp_line, right_column_offset, c_ltblue, "%c %s", invlet, item_name.c_str()); drp_line++; } for (size_t k = 0; k < u.worn.size(); k++) { // worn items can not be dropped partially if (dropping.count(player::worn_position_to_index(k)) == 0) { continue; } const char invlet = invlet_or_space(u.worn[k]); std::string item_name = trim_to(u.worn[k].display_name(), right_column_width - 4); // 2 for the invlet '+' & 2 space mvwprintz(w_inv, drp_line, right_column_offset, c_cyan, "%c + %s", invlet, item_name.c_str()); drp_line++; } for (drop_map::const_iterator a = dropping.begin(); a != dropping.end(); ++a) { if (a->first < 0) { // worn or wielded item, already displayed above continue; } const std::list<item> &stack = u.inv.const_stack(a->first); const item &it = stack.front(); const char invlet = invlet_or_space(it); const int count = a->second; const int display_count = (count == -1) ? (it.charges >= 0) ? it.charges : stack.size() : count; const nc_color col = it.color_in_inventory(); std::string item_name = it.tname( display_count ); if (count == -1) { if (stack.size() > 1) { item_name = string_format("%d %s", stack.size(), item_name.c_str()); } else { item_name.insert(0, "+ "); } } else { item_name = string_format("# %s {%d}", item_name.c_str(), count); } item_name = trim_to(item_name, right_column_width - 2); // 2 for the invlet & space mvwprintz(w_inv, drp_line, right_column_offset, col, "%c %s", invlet, item_name.c_str()); drp_line++; } }
void inventory_selector::display() const { const size_t ¤t_page_offset = in_inventory ? current_page_offset_i : current_page_offset_w; werase(w_inv); mvwprintw(w_inv, 0, 0, title.c_str()); if (multidrop) { mvwprintw(w_inv, 1, 0, _("To drop x items, type a number and then the item hotkey.")); } std::string msg_str; nc_color msg_color; if (inCategoryMode) { msg_str = _("Category selection; Press [TAB] to switch the mode."); msg_color = c_white_red; } else { msg_str = _("Item selection; Press [TAB] to switch the mode."); msg_color = h_white; } mvwprintz(w_inv, items_per_page + 4, FULL_SCREEN_WIDTH - utf8_width(msg_str.c_str()), msg_color, msg_str.c_str()); print_left_column(); print_middle_column(); print_right_column(); const size_t max_size = in_inventory ? items.size() : worn.size(); const size_t max_pages = (max_size + items_per_page - 1) / items_per_page; mvwprintw(w_inv, items_per_page + 4, 1, _("Page %d/%d"), current_page_offset / items_per_page + 1, max_pages); if (multidrop) { // Make copy, remove to be dropped items from that // copy and let the copy recalculate the volume capacity // (can be affected by various traits). player tmp = g->u; // first round: remove weapon & worn items, start with larges worn index for (drop_map::const_iterator a = dropping.begin(); a != dropping.end(); ++a) { if (a->first == -1 && a->second == -1) { tmp.remove_weapon(); } else if (a->first == -1 && a->second != -1) { tmp.weapon.charges -= a->second; } else if (a->first < 0) { tmp.worn.erase(tmp.worn.begin() + player::worn_position_to_index(a->first)); } } remove_dropping_items(tmp); print_inv_weight_vol(tmp.weight_carried(), tmp.volume_carried(), tmp.volume_capacity()); } else { print_inv_weight_vol(g->u.weight_carried(), g->u.volume_carried(), g->u.volume_capacity()); } if (!multidrop && !compare) { mvwprintw(w_inv, 1, 61, _("Hotkeys: %d/%d "), g->u.allocated_invlets().size(), inv_chars.size()); } wrefresh(w_inv); }
std::string inventory_selector::get_drop_icon(drop_map::const_iterator dit) const { if (!multidrop && !compare) { return ""; } else if (dit == dropping.end()) { return "- "; } else if (dit->second == -1) { return "+ "; } else { return "# "; } }
void inventory_selector::print_column(const itemstack_vector &items, size_t y, size_t w, size_t selected, size_t current_page_offset) const { nc_color selected_line_color = inCategoryMode ? c_white_red : h_white; if ((&items == &this->items) != in_inventory) { selected_line_color = inCategoryMode ? c_ltgray_red : h_ltgray; } int cur_line = 2; for (size_t a = 0; a + current_page_offset < items.size() && a < items_per_page; a++, cur_line++) { const itemstack_or_category &cur_entry = items[a + current_page_offset]; if (cur_entry.category == NULL) { continue; } if (cur_entry.it == NULL) { const std::string name = trim_to(cur_entry.category->name, w); mvwprintz(w_inv, cur_line, y, c_magenta, "%s", name.c_str()); continue; } const item &it = *cur_entry.it; std::string item_name = it.display_name(); if (cur_entry.slice != NULL) { const size_t count = cur_entry.slice->size(); if (count > 1) { item_name = string_format("%d %s", count, it.display_name(count).c_str()); } } nc_color name_color = it.color_in_inventory(); nc_color invlet_color = c_white; if (g->u.assigned_invlet.count(it.invlet)) { invlet_color = c_yellow; } if (a + current_page_offset == selected) { name_color = selected_line_color; invlet_color = selected_line_color; } item_name = get_drop_icon(dropping.find(cur_entry.item_pos)) + item_name; if (it.invlet != 0) { mvwputch(w_inv, cur_line, y, invlet_color, it.invlet); } if (OPTIONS["ITEM_SYMBOLS"]) { item_name = string_format("%c %s", it.symbol(), item_name.c_str()); } trim_and_print(w_inv, cur_line, y + 2, w - 2, name_color, "%s", item_name.c_str()); } }