예제 #1
0
void inventory_selector::make_item_list(const indexed_invslice &slice, const item_category *def_cat)
{
    for( const auto &scit : slice ) {

        // That entry represents the item stack
        const itemstack_or_category item_entry(scit);
        const item_category *category = def_cat;
        if (category == NULL) {
            category = item_entry.category;
        }
        // Entry that represents the category header
        const itemstack_or_category cat_entry(category);
        itemstack_vector::iterator cat_iter = std::find(items.begin(), items.end(), cat_entry);
        if (cat_iter == items.end()) {
            // Category is not yet contained in the list, add it to the end
            items.push_back(cat_entry);
            cat_iter = items.end();
        } else {
            // Category is already contained, skip all the items that belong to the
            // category to insert the current item behind them (but before the next category)
            do {
                ++cat_iter;
            } while(cat_iter != items.end() && cat_iter->it != NULL);
        }
        items.insert(cat_iter, item_entry);
    }
}
예제 #2
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;
}
예제 #3
0
void inventory_selector::prepare_paging()
{
    if (items.size() == 0) {
        in_inventory = false;
    }

    prepare_paging(items);
    prepare_paging(worn);
}
예제 #4
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;
        }
    }
}
예제 #5
0
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
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;
}