本文整理汇总了C++中inventory::sort方法的典型用法代码示例。如果您正苦于以下问题:C++ inventory::sort方法的具体用法?C++ inventory::sort怎么用?C++ inventory::sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory
的用法示例。
在下文中一共展示了inventory::sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: inv
char game::inv(inventory& inv, std::string title)
{
WINDOW* w_inv = newwin(TERRAIN_WINDOW_HEIGHT, TERRAIN_WINDOW_WIDTH + (use_narrow_sidebar() ? 45 : 55), VIEW_OFFSET_Y, VIEW_OFFSET_X);
const int maxitems = TERRAIN_WINDOW_HEIGHT - 5;
int ch = (int)'.';
int start = 0, cur_it = 0, max_it;
inv.sort();
std::vector<char> null_vector;
print_inv_statics(this, w_inv, title, null_vector);
// Gun, ammo, weapon, armor, food, tool, book, other
invslice slice = inv.slice(0, inv.size());
std::vector<int> firsts = find_firsts(slice);
int selected =- 1;
int selected_char = (int)' ';
do {
if (( ch == '<' || ch == KEY_PPAGE ) && start > 0) { // Clear lines and shift
for (int i = 1; i < maxitems+4; i++)
mvwprintz(w_inv, i, 0, c_black, " ");
start -= maxitems;
if (start < 0)
start = 0;
mvwprintw(w_inv, maxitems + 4, 0, " ");
if ( selected > -1 ) selected = start; // oy, the cheese
}
if (( ch == '>' || ch == KEY_NPAGE ) && cur_it < inv.size()) { // Clear lines and shift
start = cur_it;
mvwprintw(w_inv, maxitems + 4, 12, " ");
for (int i = 1; i < maxitems+4; i++)
mvwprintz(w_inv, i, 0, c_black, " ");
if ( selected < start && selected > -1 ) selected = start;
}
int cur_line = 2;
max_it = 0;
for (cur_it = start; cur_it < start + maxitems && cur_line < maxitems+3; cur_it++) {
// Clear the current line;
mvwprintw(w_inv, cur_line, 0, " ");
for (int i = 1; i < iCategorieNum; i++) {
if (cur_it == firsts[i-1]) {
mvwprintz(w_inv, cur_line, 0, c_magenta, _(CATEGORIES[i].c_str()));
cur_line++;
}
}
if (cur_it < slice.size())
{
item& it = slice[cur_it]->front();
if(cur_it==selected) selected_char=(int)it.invlet;
mvwputch (w_inv, cur_line, 0, (cur_it == selected ? h_white : c_white), it.invlet);
mvwprintz(w_inv, cur_line, 1, (cur_it == selected ? h_white : it.color_in_inventory(&u) ), " %s",
it.tname(this).c_str());
if (slice[cur_it]->size() > 1)
wprintw(w_inv, " [%d]", slice[cur_it]->size());
if (it.charges > 0)
wprintw(w_inv, " (%d)", it.charges);
else if (it.contents.size() == 1 &&
it.contents[0].charges > 0)
wprintw(w_inv, " (%d)", it.contents[0].charges);
cur_line++;
max_it=cur_it;
}
// cur_line++;
}
if (start > 0)
mvwprintw(w_inv, maxitems + 4, 0, _("< Go Back"));
if (cur_it < inv.size())
mvwprintw(w_inv, maxitems + 4, 12, _("> More items"));
wrefresh(w_inv);
ch = getch();
if ( ch == KEY_DOWN ) {
if ( selected < 0 ) {
selected = start;
} else {
selected++;
}
if ( selected > max_it ) {
if( cur_it < u.inv.size() ) {
ch='>';
} else {
selected = u.inv.size() - 1; // wraparound?
}
}
} else if ( ch == KEY_UP ) {
selected--;
if ( selected < -1 ) {
selected = -1; // wraparound?
} else if ( selected < start ) {
if ( start > 0 ) {
for (int i = 1; i < maxitems+4; i++)
mvwprintz(w_inv, i, 0, c_black, " ");
start -= maxitems;
if (start < 0)
start = 0;
mvwprintw(w_inv, maxitems + 4, 0, " ");
}
//.........这里部分代码省略.........