示例#1
0
void inventory_selector::display(bool show_worn) const
{
    const size_t &current_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; [TAB] switches mode, arrows select.");
        msg_color = c_white_red;
    } else {
        msg_str = _("Item selection; [TAB] switches mode, arrows select.");
        msg_color = h_white;
    }
    mvwprintz(w_inv, items_per_page + 4, FULL_SCREEN_WIDTH - utf8_width(msg_str),
              msg_color, msg_str.c_str());
    print_left_column();
    if(show_worn) {
        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( const auto &elem : dropping ) {
            if( elem.first == -1 && elem.second == -1 ) {
                tmp.remove_weapon();
            } else if( elem.first == -1 && elem.second != -1 ) {
                tmp.weapon.charges -= elem.second;
            } else if( elem.first < 0 ) {
                tmp.i_rem( elem.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);
}
示例#2
0
void inventory_selector::select_item_by_position(const int &position)
{
    if (position != INT_MIN) {
        int pos = position;

        if (pos == -1) {
            //weapon
            in_inventory = false;
            return;

        } else if (pos < -1) {
            //worn
            in_inventory = false;
            pos = abs(position) - ((g->u.weapon.is_null()) ? 2 : 1);
        }

        const itemstack_vector &items = in_inventory ? this->items : this->worn;
        size_t &selected = in_inventory ? selected_i : selected_w;
        size_t &current_page_offset = in_inventory ? current_page_offset_i : current_page_offset_w;

        //skip headers
        int iHeaderOffset = 0;
        for (size_t i = 0; i < items.size(); ++i) {
            if (items[i].it == NULL) {
                iHeaderOffset++;

            } else if (items[i].item_pos == pos) {
                break;
            }
        }

        selected = pos + iHeaderOffset;
        current_page_offset = selected - (selected % items_per_page);
    }
}
示例#3
0
int inventory_selector::get_selected_item_position() const
{
    const itemstack_vector &items = in_inventory ? this->items : this->worn;
    const size_t &selected = in_inventory ? selected_i : selected_w;
    if (selected < items.size() && items[selected].it != NULL) {
        return items[selected].item_pos;
    }
    return INT_MIN;
}
示例#4
0
void inventory_selector::prepare_paging()
{
    if (items.size() == 0) {
        in_inventory = false;
    }

    prepare_paging(items);
    prepare_paging(worn);
}
void inventory_selector::set_selected_to_drop(int count)
{
    const itemstack_vector &items = in_inventory ? this->items : this->worn;
    const size_t &selected = in_inventory ? selected_i: selected_w;
    if (selected >= items.size()) {
        return;
    }
    const itemstack_or_category &cur_entry = items[selected];
    if (cur_entry.it != NULL && cur_entry.slice != NULL) {
        set_drop_count(cur_entry.item_pos, count, *cur_entry.slice);
    } else if (cur_entry.it != NULL) {
        set_drop_count(cur_entry.item_pos, count, *cur_entry.it);
    }
}
示例#6
0
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());
    }
}
示例#7
0
void inventory_selector::prepare_paging(itemstack_vector &items)
{
    const item_category *prev_category = NULL;
    for (size_t a = 0; a < items.size(); a++) {
        const itemstack_or_category &cur_entry = items[a];
        if (cur_entry.category != NULL) {
            prev_category = cur_entry.category;
        }
        if (cur_entry.it == NULL && a % items_per_page == items_per_page - 1) {
            // last entry on a page is a category, insert empty entry
            // to move category header to next page
            items.insert(items.begin() + a, itemstack_or_category());
            continue;
        }
        if (cur_entry.it != NULL && a > 0 && a % items_per_page == 0) {
            // first entry on a page and is not a category, insert previous category
            items.insert(items.begin() + a, itemstack_or_category(prev_category));
            continue;
        }
    }
}
示例#8
0
bool inventory_selector::handle_movement(const std::string &action)
{
    const itemstack_vector &items = in_inventory ? this->items : this->worn;
    size_t &selected = in_inventory ? selected_i : selected_w;
    size_t &current_page_offset = in_inventory ? current_page_offset_i : current_page_offset_w;
    const item_category *cur_cat = (selected < items.size()) ? items[selected].category : NULL;

    if (action == "CATEGORY_SELECTION") {
        inCategoryMode = !inCategoryMode;
    } else if (action == "LEFT") {
        if (this->items.size() > 0) {
            in_inventory = !in_inventory;
        }
    } else if (action == "DOWN") {
        selected++;
        if (inCategoryMode) {
            while (selected < items.size() && items[selected].category == cur_cat) {
                selected++;
            }
        }
        // skip non-item entries, those can not be selected!
        while (selected < items.size() && items[selected].it == NULL) {
            selected++;
        }
        if (selected >= items.size()) { // wrap around
            selected = 1; // first is the category!
        }
        current_page_offset = selected - (selected % items_per_page);
    } else if (action == "UP") {
        selected--;
        if (inCategoryMode && selected == 0) {
            selected = items.size() - 1;
        }
        if (inCategoryMode) {
            while (selected < items.size() && items[selected].category == cur_cat) {
                selected--;
            }
        }
        // skip non-item entries, those can not be selected!
        while (selected < items.size() && items[selected].it == NULL) {
            selected--;
        }
        if (selected >= items.size()) { // wrap around, actually overflow
            selected = items.size() - 1; // the last is always an item entry
        }
        current_page_offset = selected - (selected % items_per_page);
    } else if (action == "NEXT_TAB") {
        selected += items_per_page;
        // skip non-item entries, those can not be selected!
        while (selected < items.size() && items[selected].it == NULL) {
            selected++;
        }
        if (selected >= items.size()) { // wrap around
            selected = 1; // first is the category!
        }
        current_page_offset = selected - (selected % items_per_page);
    } else if (action == "PREV_TAB") {
        selected -= items_per_page;
        // skip non-item entries, those can not be selected!
        while (selected < items.size() && items[selected].it == NULL) {
            selected--;
        }
        if (selected >= items.size()) { // wrap around, actually overflow
            selected = items.size() - 1; // the last is always an item entry
        }
        current_page_offset = selected - (selected % items_per_page);
    } else {
        return false;
    }
    return true;
}