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

Item List added filter option #89

Merged
merged 3 commits into from
Feb 22, 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
2 changes: 1 addition & 1 deletion construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ void construct::done_log(game *g, point p)

void construct::done_vehicle(game *g, point p)
{
std::string name = string_input_popup(20, "Enter new vehicle name");
std::string name = string_input_popup("Enter new vehicle name", 20);
vehicle *veh = g->m.add_vehicle (g, veh_custom, p.x, p.y, 270);
if (!veh)
{
Expand Down
2 changes: 1 addition & 1 deletion defense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ void defense_game::setup()
selection--;
refresh_setup(w, selection);
} else if (ch == '!') {
std::string name = string_input_popup(20, "Template Name:");
std::string name = string_input_popup("Template Name:", 20);
refresh_setup(w, selection);
} else if (ch == 'S')
return;
Expand Down
85 changes: 66 additions & 19 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5340,13 +5340,10 @@ point game::look_around()

void game::list_items()
{
int iInfoHeight = 12;
int iInfoHeight = 10;
WINDOW* w_items = newwin(25-iInfoHeight, 55, 0, 25);
WINDOW* w_item_info = newwin(iInfoHeight, 55, 25-iInfoHeight, 25);

wborder(w_items, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );

std::vector <item> here;
std::map<int, std::map<int, std::map<std::string, int> > > grounditems;
std::map<std::string, item> iteminfo;
Expand Down Expand Up @@ -5384,17 +5381,44 @@ void game::list_items()
int iActiveX = 0;
int iActiveY = 0;
long ch = '.';
std::string sFilter = "";
int iFilter = 0;

do {
if (iItemNum > 0) {
u.view_offset_x = 0;
u.view_offset_y = 0;

if (ch == 'I') {
if (ch == 'I' || ch == 'c' || ch == 'C') {
compare(iActiveX, iActiveY);
ch = '.';

} else if (ch == 'f' || ch == 'F') {
sFilter = string_input_popup("Filter:", 15, sFilter);
iActive = 0;
ch = '.';

} else if (ch == 'r' || ch == 'R') {
sFilter = "";
ch = '.';
}

if (ch == '.') {
wborder(w_items, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
LINE_OXXO, LINE_OOXX, LINE_XXXO, LINE_XOXX );

int iTempStart = 19;
if (sFilter != "") {
iTempStart = 15;
mvwprintz(w_items, 25-iInfoHeight-1, iTempStart + 19, c_ltgreen, " %s", "R");
wprintz(w_items, c_white, "%s", "eset ");
}

mvwprintz(w_items, 25-iInfoHeight-1, iTempStart, c_ltgreen, " %s", "C");
wprintz(w_items, c_white, "%s", "ompare ");

mvwprintz(w_items, 25-iInfoHeight-1, iTempStart + 10, c_ltgreen, " %s", "F");
wprintz(w_items, c_white, "%s", "ilter ");
}

switch(ch) {
Expand All @@ -5405,34 +5429,41 @@ void game::list_items()
break;
case KEY_DOWN:
iActive++;
if (iActive >= iItemNum)
iActive = iItemNum-1;
if (iActive >= iItemNum - iFilter)
iActive = iItemNum - iFilter-1;
break;
}

if (iItemNum > iMaxRows) {
if (iItemNum - iFilter > iMaxRows) {
iStartPos = iActive - (iMaxRows - 1) / 2;

if (iStartPos < 0)
iStartPos = 0;
else if (iStartPos + iMaxRows > iItemNum)
iStartPos = iItemNum - iMaxRows;
else if (iStartPos + iMaxRows > iItemNum - iFilter)
iStartPos = iItemNum - iFilter - iMaxRows;
}

for (int i = 0; i < iMaxRows; i++)
mvwprintz(w_items, 1 + i , 1, c_black, "%s", " ");

mvwprintz(w_items, 0, 23 + ((iItemNum > 9) ? 0 : 1), c_ltgreen, " %*d", ((iItemNum > 9) ? 2 : 1), iActive+1);
wprintz(w_items, c_white, " / %*d ", ((iItemNum > 9) ? 2 : 1), iItemNum);
mvwprintz(w_items, 1 + i, 1, c_black, "%s", " ");

int iNum = 0;
iFilter = 0;
iActiveX = 0;
iActiveY = 0;
std::string sActiveItemName;
std::stringstream sText;
std::string sFilterPre = "";
std::string sFilterTemp = sFilter;
if (sFilterTemp != "" && sFilter.substr(0, 1) == "-") {
sFilterPre = "-";
sFilterTemp = sFilterTemp.substr(1, sFilterTemp.size()-1);
}

for (int iRow = (iSearchY * -1); iRow <= iSearchY; iRow++) {
for (int iCol = (iSearchX * -1); iCol <= iSearchX; iCol++) {
for (std::map< std::string, int>::iterator iter=grounditems[iCol][iRow].begin(); iter!=grounditems[iCol][iRow].end(); ++iter) {
for (std::map< std::string, int>::iterator iter=grounditems[iCol][iRow].begin(); iter!=grounditems[iCol][iRow].end(); ++iter) {
if (sFilterTemp == "" || (sFilterTemp != "" && ((sFilterPre != "-" && iter->first.find(sFilterTemp) != std::string::npos) ||
(sFilterPre == "-" && iter->first.find(sFilterTemp) == std::string::npos)))) {
if (iNum >= iStartPos && iNum < iStartPos + ((iMaxRows > iItemNum) ? iItemNum : iMaxRows) ) {
if (iNum == iActive) {
iActiveX = iCol;
Expand All @@ -5452,14 +5483,30 @@ void game::list_items()
}

iNum++;
} else {
iFilter++;
}
}
}
}

mvwprintz(w_items, 0, 23 + ((iItemNum - iFilter > 9) ? 0 : 1), c_ltgreen, " %*d", ((iItemNum - iFilter > 9) ? 2 : 1), iActive+1);
wprintz(w_items, c_white, " / %*d ", ((iItemNum - iFilter > 9) ? 2 : 1), iItemNum - iFilter);

wclear(w_item_info);
mvwprintz(w_item_info, 0, 2, c_white, "%s", iteminfo[sActiveItemName].info().c_str());
wborder(w_item_info, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
mvwprintz(w_item_info, 0, 0, c_white, "%s", iteminfo[sActiveItemName].info().c_str());

for (int j=0; j < iInfoHeight-1; j++)
mvwputch(w_item_info, j, 0, c_ltgray, LINE_XOXO);

for (int j=0; j < iInfoHeight-1; j++)
mvwputch(w_item_info, j, 54, c_ltgray, LINE_XOXO);

for (int j=0; j < 54; j++)
mvwputch(w_item_info, iInfoHeight-1, j, c_ltgray, LINE_OXOX);

mvwputch(w_item_info, iInfoHeight-1, 0, c_ltgray, LINE_XXOO);
mvwputch(w_item_info, iInfoHeight-1, 54, c_ltgray, LINE_XOOX);

draw_ter();
std::vector<point> trajectory = line_to(u.posx, u.posy, u.posx + iActiveX, u.posy + iActiveY, 0);
Expand Down
23 changes: 12 additions & 11 deletions output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,23 @@ int query_int(const char *mes, ...)
return temp-48;
}

std::string string_input_popup(const char *mes, ...)
std::string string_input_popup(std::string title, int max_length, std::string input)
{
std::string ret;
va_list ap;
va_start(ap, mes);
char buff[1024];
vsprintf(buff, mes, ap);
va_end(ap);
int startx = strlen(buff) + 2;
std::string ret = input;

int startx = title.size() + 2;
WINDOW* w = newwin(3, 80, 11, 0);
wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );
mvwprintz(w, 1, 1, c_ltred, "%s", buff);
for (int i = startx + 1; i < 79; i++)
mvwputch(w, 1, i, c_ltgray, '_');
int posx = startx;

mvwprintz(w, 1, 1, c_ltred, "%s", title.c_str());

if (input != "")
mvwprintz(w, 1, startx, c_magenta, "%s", input.c_str());

int posx = startx + input.size();
mvwputch(w, 1, posx, h_ltgray, '_');
do {
wrefresh(w);
Expand All @@ -418,7 +419,7 @@ std::string string_input_popup(const char *mes, ...)
mvwputch(w, 1, posx, c_ltgray, '_');
posx--;
mvwputch(w, 1, posx, h_ltgray, '_');
} else {
} else if(ret.size() < max_length || max_length == 0) {
ret += ch;
mvwputch(w, 1, posx, c_magenta, ch);
posx++;
Expand Down
3 changes: 1 addition & 2 deletions output.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ void draw_tabs(WINDOW *w, int active_tab, ...);
void realDebugmsg(const char* name, const char* line, const char *mes, ...);
bool query_yn(const char *mes, ...);
int query_int(const char *mes, ...);
std::string string_input_popup(const char *mes, ...);
std::string string_input_popup(int max_length, const char *mes, ...);
std::string string_input_popup(std::string title, int max_length = 0, std::string input = "");
char popup_getkey(const char *mes, ...);
int menu_vec(const char *mes, std::vector<std::string> options);
int menu(const char *mes, ...);
Expand Down
2 changes: 1 addition & 1 deletion overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ point overmap::choose_point(game *g)
ret = point(-1, -1);
else if (ch == 'N') {
timeout(-1);
add_note(cursx, cursy, string_input_popup(49, "Enter note")); // 49 char max
add_note(cursx, cursy, string_input_popup("Enter note", 49)); // 49 char max
timeout(BLINK_SPEED);
} else if(ch == 'D'){
timeout(-1);
Expand Down
2 changes: 1 addition & 1 deletion veh_interact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void veh_interact::do_remove(int reason)

void veh_interact::do_rename(int reason)
{
std::string name = string_input_popup(20, "Enter new vehicle name");
std::string name = string_input_popup("Enter new vehicle name", 20);
(veh->name = name);
werase(w_stats);
werase(w_grid);
Expand Down