From ba7321fcf5349bbdb95a39f3cbb2f8c90c2673bf Mon Sep 17 00:00:00 2001 From: OzoneH3 Date: Fri, 22 Feb 2013 18:58:12 +0100 Subject: [PATCH 1/2] Item List added filter option --- construction.cpp | 2 +- defense.cpp | 2 +- game.cpp | 77 ++++++++++++++++++++++++++++++++++++------------ output.cpp | 23 ++++++++------- output.h | 3 +- overmap.cpp | 2 +- veh_interact.cpp | 2 +- 7 files changed, 75 insertions(+), 36 deletions(-) diff --git a/construction.cpp b/construction.cpp index 2bbaec5dbc749..e50f623284eea 100644 --- a/construction.cpp +++ b/construction.cpp @@ -788,7 +788,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) { diff --git a/defense.cpp b/defense.cpp index 8cb6ad4e35a59..e44e963da555c 100644 --- a/defense.cpp +++ b/defense.cpp @@ -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; diff --git a/game.cpp b/game.cpp index db80d243aa8d8..7af1acf532ec3 100644 --- a/game.cpp +++ b/game.cpp @@ -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 here; std::map > > grounditems; std::map iteminfo; @@ -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) { @@ -5405,34 +5429,33 @@ 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; 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 (sFilter == "" || (sFilter != "" && iter->first.find(sFilter) != std::string::npos)) { if (iNum >= iStartPos && iNum < iStartPos + ((iMaxRows > iItemNum) ? iItemNum : iMaxRows) ) { if (iNum == iActive) { iActiveX = iCol; @@ -5452,14 +5475,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 trajectory = line_to(u.posx, u.posy, u.posx + iActiveX, u.posy + iActiveY, 0); diff --git a/output.cpp b/output.cpp index 437628bcae77c..15765371f3dd7 100644 --- a/output.cpp +++ b/output.cpp @@ -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); @@ -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++; diff --git a/output.h b/output.h index b7b399daeb449..25e79a48a4336 100644 --- a/output.h +++ b/output.h @@ -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 options); int menu(const char *mes, ...); diff --git a/overmap.cpp b/overmap.cpp index 0975495da0fd2..fd8f540228fc7 100644 --- a/overmap.cpp +++ b/overmap.cpp @@ -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); diff --git a/veh_interact.cpp b/veh_interact.cpp index 8ccbc034a021c..898b60b4b9cee 100644 --- a/veh_interact.cpp +++ b/veh_interact.cpp @@ -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); From 11322a02ac47a1002cfa7436a42195ae0eddb359 Mon Sep 17 00:00:00 2001 From: OzoneH3 Date: Fri, 22 Feb 2013 19:17:58 +0100 Subject: [PATCH 2/2] Item List, exclude items with (minus) -item --- game.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/game.cpp b/game.cpp index 7af1acf532ec3..8c6c782fb39ed 100644 --- a/game.cpp +++ b/game.cpp @@ -5452,10 +5452,18 @@ void game::list_items() 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) { - if (sFilter == "" || (sFilter != "" && iter->first.find(sFilter) != std::string::npos)) { + 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;