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::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()); } }