Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add side by side item comparison #52

Merged
merged 1 commit into from
Feb 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ std::string action_ident(action_id act)
return "peek";
case ACTION_INVENTORY:
return "inventory";
case ACTION_COMPARE:
return "compare";
case ACTION_ORGANIZE:
return "organize";
case ACTION_USE:
Expand Down Expand Up @@ -303,6 +305,8 @@ std::string action_name(action_id act)
return "Peek Around Corners";
case ACTION_INVENTORY:
return "Open Inventory";
case ACTION_COMPARE:
return "Compare two Items";
case ACTION_ORGANIZE:
return "Swap Inventory Letters";
case ACTION_USE:
Expand Down
1 change: 1 addition & 0 deletions action.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ACTION_LOOK,
ACTION_PEEK,
// Inventory Interaction (including quasi-inventories like bionics)
ACTION_INVENTORY,
ACTION_COMPARE,
ACTION_ORGANIZE,
ACTION_USE,
ACTION_USE_WIELDED,
Expand Down
4 changes: 4 additions & 0 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,10 @@ input_ret game::get_input(int timeout_ms)
} while (has);
refresh_all();
} break;

case ACTION_COMPARE:
compare();
break;

case ACTION_ORGANIZE:
reassign_item();
Expand Down
1 change: 1 addition & 0 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ class game
void pickup(int posx, int posy, int min);// Pickup items; ',' or via examine()
// Pick where to put liquid; false if it's left where it was
bool handle_liquid(item &liquid, bool from_ground, bool infinite);
void compare(); // Compare two Items 'I'
void drop(); // Drop an item 'd'
void drop_in_direction(); // Drop w/ direction 'D'
void reassign_item(); // Reassign the letter of an item '='
Expand Down
133 changes: 131 additions & 2 deletions inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void print_inv_statics(game *g, WINDOW* w_inv, std::string title,
g->u.weight_capacity());

// Print volume
mvwprintw(w_inv, 0, 60, "Volume: ");
mvwprintw(w_inv, 0, 62, "Volume: ");
if (g->u.volume_carried() > g->u.volume_capacity() - 2)
wprintz(w_inv, c_red, "%d", g->u.volume_carried());
else
Expand All @@ -37,7 +37,7 @@ void print_inv_statics(game *g, WINDOW* w_inv, std::string title,
n_items += ((g->u.inv.index_by_letter(ch) == -1) ? 0 : 1);
for(int ch='A'; ch <= 'Z'; ++ch)
n_items += ((g->u.inv.index_by_letter(ch) == -1) ? 0 : 1);
mvwprintw(w_inv, 1, 60, "Items: %d/52 ", n_items);
mvwprintw(w_inv, 1, 62, "Items: %d/52 ", n_items);

// Print our weapon
mvwprintz(w_inv, 2, 40, c_magenta, "WEAPON:");
Expand Down Expand Up @@ -477,3 +477,132 @@ std::vector<item> game::multidrop()
return ret;
}

void game::compare()
{
u.sort_inv();
u.inv.restack(&u);
WINDOW* w_inv = newwin(25, 80, 0, 0);
const int maxitems = 20; // Number of items to show at one time.
int compare[u.inv.size()]; // Count of how many we'll drop from each stack
bool bFirst = false; // First Item selected
bool bShowCompare = false;
char cLastCh;
for (int i = 0; i < u.inv.size(); i++)
compare[i] = -1;
std::vector<char> weapon_and_armor; // Always single, not counted
print_inv_statics(this, w_inv, "Compare:", weapon_and_armor);
// Gun, ammo, weapon, armor, food, tool, book, other
std::vector<int> firsts = find_firsts(u.inv);

char ch = '.';
int start = 0, cur_it;
do {
if (ch == '<' && start > 0) {
for (int i = 1; i < 25; i++)
mvwprintz(w_inv, i, 0, c_black, " ");
start -= maxitems;
if (start < 0)
start = 0;
mvwprintw(w_inv, maxitems + 2, 0, " ");
}
if (ch == '>' && cur_it < u.inv.size()) {
start = cur_it;
mvwprintw(w_inv, maxitems + 2, 12, " ");
for (int i = 1; i < 25; i++)
mvwprintz(w_inv, i, 0, c_black, " ");
}
int cur_line = 2;
for (cur_it = start; cur_it < start + maxitems && cur_line < 23; cur_it++) {
// Clear the current line;
mvwprintw(w_inv, cur_line, 0, " ");
// Print category header
for (int i = 0; i < 8; i++) {
if (cur_it == firsts[i]) {
mvwprintz(w_inv, cur_line, 0, c_magenta, CATEGORIES[i].c_str());
cur_line++;
}
}
if (cur_it < u.inv.size()) {
mvwputch (w_inv, cur_line, 0, c_white, u.inv[cur_it].invlet);
char icon = '-';
if (compare[cur_it] == 0)
icon = '+';
nc_color col = (compare[cur_it] == -1 ? c_ltgray : c_white);
mvwprintz(w_inv, cur_line, 1, col, " %c %s", icon,
u.inv[cur_it].tname(this).c_str());
if (u.inv.stack_at(cur_it).size() > 1)
wprintz(w_inv, col, " [%d]", u.inv.stack_at(cur_it).size());
if (u.inv[cur_it].charges > 0)
wprintz(w_inv, col, " (%d)", u.inv[cur_it].charges);
else if (u.inv[cur_it].contents.size() == 1 &&
u.inv[cur_it].contents[0].charges > 0)
wprintw(w_inv, " (%d)", u.inv[cur_it].contents[0].charges);
}
cur_line++;
}
if (start > 0)
mvwprintw(w_inv, maxitems + 4, 0, "< Go Back");
if (cur_it < u.inv.size())
mvwprintw(w_inv, maxitems + 4, 12, "> More items");
wrefresh(w_inv);
ch = getch();
if (u.has_item(ch)) {
int index = u.inv.index_by_letter(ch);
if (index == -1) { // Not from inventory
int found = false;
for (int i = 0; i < weapon_and_armor.size() && !found; i++) {
if (weapon_and_armor[i] == ch) {
weapon_and_armor.erase(weapon_and_armor.begin() + i);
found = true;
bFirst = false;
print_inv_statics(this, w_inv, "Compare:", weapon_and_armor);
}
}
if (!found) {
if (ch == u.weapon.invlet && u.weapon.type->id > num_items &&
u.weapon.type->id < num_all_items) {
//Do Bionic stuff here?!
} else {
if (!bFirst)
{
weapon_and_armor.push_back(ch);
print_inv_statics(this, w_inv, "Compare:", weapon_and_armor);
bFirst = true;
cLastCh = ch;
} else {
bShowCompare = true;
}
}
}
} else {
if (compare[index] == 0)
{
compare[index] = -1;
bFirst = false;
} else {
if (!bFirst)
{
compare[index] = 0;
bFirst = true;
cLastCh = ch;
} else {
bShowCompare = true;
}
}
}
if (bShowCompare) {
split_screen_popup(true, u.i_at(cLastCh).tname(this).c_str(), u.i_at(cLastCh).info(true).c_str());
split_screen_popup(false, u.i_at(ch).tname(this).c_str(), u.i_at(ch).info(true).c_str());
wclear(w_inv);
print_inv_statics(this, w_inv, "Compare:", weapon_and_armor);
bShowCompare = false;
}
}
} while (ch != '\n' && ch != KEY_ESCAPE && ch != ' ');
werase(w_inv);
delwin(w_inv);
erase();
refresh_all();

std::vector<item> ret;
}
1 change: 1 addition & 0 deletions keypress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ peek X\n\
\n\
# INVENTORY & QUASI-INVENTORY INTERACTION\n\
inventory i\n\
compare I\n\
organize =\n\
apply a\n\
apply_wielded A\n\
Expand Down
61 changes: 61 additions & 0 deletions output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,67 @@ void full_screen_popup(const char* mes, ...)
refresh();
}

void split_screen_popup(bool bLeft, std::string sItemName, const char* mes, ...)
{
va_list ap;
va_start(ap, mes);
char buff[8192];
vsprintf(buff, mes, ap);
va_end(ap);
std::string tmp = buff;
WINDOW* w = newwin(25, 40, 0, (bLeft) ? 0 : 40);
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
size_t pos = tmp.find_first_of('\n');
mvwprintz(w, 1, 2, c_white, sItemName.c_str());
int line_num = 2;
while (pos != std::string::npos) {
std::string line = tmp.substr(0, pos);
line_num++;
if (line.size() > 36)
{
std::string sTemp;
do
{
sTemp += line;
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
line = " " + tmp.substr(0, pos);
} while (pos != std::string::npos);
sTemp += line;
while (sTemp.size() > 0)
{
size_t iPos = sTemp.find_last_of(' ', 36);
if (iPos == 0)
iPos = sTemp.size();
mvwprintz(w, line_num, 2, c_white, (sTemp.substr(0, iPos)).c_str());
line_num++;
sTemp = sTemp.substr(iPos+1, sTemp.size());
}
}
else
{
mvwprintz(w, line_num, 2, c_white, (line).c_str());
}
tmp = tmp.substr(pos + 1);
pos = tmp.find_first_of('\n');
}
line_num++;
mvwprintz(w, line_num, 2, c_white, tmp.c_str());
wrefresh(w);
if (!bLeft)
{
char ch;
do
ch = getch();
while(ch != ' ' && ch != '\n' && ch != KEY_ESCAPE);
werase(w);
wrefresh(w);
delwin(w);
refresh();
}
}

char rand_char()
{
switch (rng(0, 9)) {
Expand Down
1 change: 1 addition & 0 deletions output.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void popup_top(const char *mes, ...); // Displayed at the top of the screen
void popup(const char *mes, ...);
void popup_nowait(const char *mes, ...); // Doesn't wait for spacebar
void full_screen_popup(const char *mes, ...);
void split_screen_popup(bool bLeft, std::string sItemName, const char* mes, ...);

nc_color hilite(nc_color c);
nc_color invert_color(nc_color c);
Expand Down