void worldfactory::draw_mod_list( WINDOW *w, int &start, int &cursor, const std::vector<std::string> &mods, bool is_active_list, const std::string &text_if_empty ) { werase( w ); calcStartPos( start, cursor, getmaxy( w ), mods.size() ); if( mods.empty() ) { center_print( w, 0, c_red, "%s", text_if_empty.c_str() ); } else { const size_t wwidth = getmaxx( w ) - 1 - 3; // border (1) + ">> " (3) for( size_t i = start, c = 0; i < mods.size() && (int)c < getmaxy( w ); ++i, ++c ) { auto mod = mman->mod_map[mods[i]]; if( (int)i != cursor ) { mvwprintw( w, c, 1, " " ); } else { if( is_active_list ) { mvwprintz( w, c, 1, c_yellow, ">> " ); } else { mvwprintz( w, c, 1, c_blue, ">> " ); } } const std::string name = utf8_truncate( mod->name, wwidth ); #ifndef LUA if ( mod->need_lua ) { mvwprintz( w, c, 4, c_dkgray, "%s", name.c_str() ); } else { mvwprintz( w, c, 4, c_white, "%s", name.c_str() ); } #else mvwprintz( w, c, 4, c_white, "%s", name.c_str() ); #endif } } draw_scrollbar( w, cursor, getmaxy( w ), mods.size(), 0, 0 ); wrefresh( w ); }
/* * Generate and refresh output */ void uimenu::show() { if (!started) { setup(); } std::string padspaces = std::string(w_width - 2 - pad_left - pad_right, ' '); const int text_lines = textformatted.size(); for ( int i = 0; i < text_lines; i++ ) { mvwprintz(window, 1 + i, 2, text_color, "%s", textformatted[i].c_str()); } mvwputch(window, text_lines + 1, 0, border_color, LINE_XXXO); for ( int i = 1; i < w_width - 1; ++i) { mvwputch(window, text_lines + 1, i, border_color, LINE_OXOX); } mvwputch(window, text_lines + 1, w_width - 1, border_color, LINE_XOXX); int estart = text_lines + 2; calcStartPos( vshift, fselected, vmax, fentries.size() ); for ( int fei = vshift, si = 0; si < vmax; fei++, si++ ) { if ( fei < (int)fentries.size() ) { int ei = fentries [ fei ]; nc_color co = ( ei == selected ? hilight_color : ( entries[ ei ].enabled ? entries[ ei ].text_color : disabled_color ) ); if ( hilight_full ) { mvwprintz(window, estart + si, pad_left + 1, co , "%s", padspaces.c_str()); } if(entries[ ei ].enabled && entries[ ei ].hotkey >= 33 && entries[ ei ].hotkey < 126 ) { mvwprintz( window, estart + si, pad_left + 2, ( ei == selected ) ? hilight_color : hotkey_color , "%c", entries[ ei ].hotkey ); } mvwprintz(window, estart + si, pad_left + 4, co, "%s", entries[ ei ].txt.c_str() ); if ( !entries[ei].extratxt.txt.empty() ) { mvwprintz( window, estart + si, pad_left + 1 + entries[ ei ].extratxt.left, entries[ ei ].extratxt.color, "%s", entries[ ei ].extratxt.txt.c_str() ); } if ( callback != NULL && ei == selected ) { callback->select(ei, this); } } else { mvwprintz(window, estart + si, pad_left + 1, c_ltgray , "%s", padspaces.c_str()); } } if ( !filter.empty() ) { mvwprintz( window, w_height - 1, 2, border_color, "< %s >", filter.c_str() ); mvwprintz( window, w_height - 1, 4, text_color, "%s", filter.c_str() ); } apply_scrollbar(); this->refresh(true); }
int worldfactory::show_worldgen_tab_options(WINDOW *win, WORLDPTR world) { const int iTooltipHeight = 4; const int iContentHeight = FULL_SCREEN_HEIGHT - 5 - iTooltipHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; WINDOW *w_options = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iTooltipHeight + 4 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_optionsptr( w_options ); WINDOW *w_options_tooltip = newwin(iTooltipHeight - 2, FULL_SCREEN_WIDTH - 2, 3 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_options_tooltipptr( w_options_tooltip ); WINDOW *w_options_header = newwin(1, FULL_SCREEN_WIDTH - 2, iTooltipHeight + 3 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_options_headerptr( w_options_header ); std::stringstream sTemp; std::map<int, bool> mapLines; mapLines[4] = true; mapLines[60] = true; for( auto &mapLine : mapLines ) { mvwputch( win, FULL_SCREEN_HEIGHT - 1, mapLine.first + 1, BORDER_COLOR, LINE_XXOX ); // _|_ } for (int i = 0; i < 78; i++) { if (mapLines[i]) { mvwputch(w_options_header, 0, i, BORDER_COLOR, LINE_OXXX); } else { mvwputch(w_options_header, 0, i, BORDER_COLOR, LINE_OXOX); // Draw header line } } mvwputch(win, iTooltipHeight + 3, 0, BORDER_COLOR, LINE_XXXO); // |- mvwputch(win, iTooltipHeight + 3, 79, BORDER_COLOR, LINE_XOXX); // -| wrefresh(win); wrefresh(w_options_header); input_context ctxt("WORLDGEN_OPTION_DIALOG"); ctxt.register_cardinal(); ctxt.register_action("HELP_KEYBINDINGS"); ctxt.register_action("QUIT"); ctxt.register_action("NEXT_TAB"); ctxt.register_action("PREV_TAB"); int iStartPos = 0; int iCurrentLine = 0; do { for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { if (mapLines[j]) { mvwputch(w_options, i, j, BORDER_COLOR, LINE_XOXO); } else { mvwputch(w_options, i, j, c_black, ' '); } if (i < iTooltipHeight) { mvwputch(w_options_tooltip, i, j, c_black, ' '); } } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, mPageItems[iWorldOptPage].size()); //Draw options int iBlankOffset = 0; for (int i = iStartPos; i < iStartPos + ((iContentHeight > (int)mPageItems[iWorldOptPage].size()) ? (int)mPageItems[iWorldOptPage].size() : iContentHeight); i++) { nc_color cLineColor = c_ltgreen; if (world->world_options[mPageItems[iWorldOptPage][i]].getMenuText() == "") { iBlankOffset++; continue; } sTemp.str(""); sTemp << i + 1 - iBlankOffset; mvwprintz(w_options, i - iStartPos, 1, c_white, sTemp.str().c_str()); mvwprintz(w_options, i - iStartPos, 5, c_white, ""); if (iCurrentLine == i) { wprintz(w_options, c_yellow, ">> "); } else { wprintz(w_options, c_yellow, " "); } wprintz(w_options, c_white, "%s", (world->world_options[mPageItems[iWorldOptPage][i]].getMenuText()).c_str()); if (world->world_options[mPageItems[iWorldOptPage][i]].getValue() == "false") { cLineColor = c_ltred; } mvwprintz(w_options, i - iStartPos, 62, (iCurrentLine == i) ? hilite(cLineColor) : cLineColor, "%s", (world->world_options[mPageItems[iWorldOptPage][i]].getValueName()).c_str()); } //Draw Scrollbar draw_scrollbar(win, iCurrentLine, iContentHeight, mPageItems[iWorldOptPage].size(), iTooltipHeight + 4, 0, BORDER_COLOR); fold_and_print(w_options_tooltip, 0, 0, 78, c_white, "%s #%s", world->world_options[mPageItems[iWorldOptPage][iCurrentLine]].getTooltip().c_str(), world->world_options[mPageItems[iWorldOptPage][iCurrentLine]].getDefaultText().c_str()); wrefresh(w_options_tooltip); wrefresh(w_options); refresh(); const std::string action = ctxt.handle_input(); if (action == "DOWN") { do { iCurrentLine++; if (iCurrentLine >= (int)mPageItems[iWorldOptPage].size()) { iCurrentLine = 0; } } while(world->world_options[mPageItems[iWorldOptPage][iCurrentLine]].getMenuText() == ""); } else if (action == "UP") { do { iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = mPageItems[iWorldOptPage].size() - 1; } } while(world->world_options[mPageItems[iWorldOptPage][iCurrentLine]].getMenuText() == ""); } else if (!mPageItems[iWorldOptPage].empty() && action == "RIGHT") { world->world_options[mPageItems[iWorldOptPage][iCurrentLine]].setNext(); } else if (!mPageItems[iWorldOptPage].empty() && action == "LEFT") { world->world_options[mPageItems[iWorldOptPage][iCurrentLine]].setPrev(); } else if (action == "PREV_TAB") { return -1; } else if (action == "NEXT_TAB") { return 1; } else if (action == "QUIT") { return -999; } } while (true); return 0; }
void test_pattern(int iCurrentPage, int iCurrentLine) { std::vector<std::string> vMatchingItems; std::string sItemName = ""; if (vAutoPickupRules[iCurrentPage][iCurrentLine].sRule == "") { return; } //Loop through all itemfactory items //TODO: somehow generate damaged, fitting or container items for (int i = 0; i < standard_itype_ids.size(); i++) { sItemName = item_controller->find_template(standard_itype_ids[i])->name; if (vAutoPickupRules[iCurrentPage][iCurrentLine].bActive && auto_pickup_match(sItemName, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule)) { vMatchingItems.push_back(sItemName); } } const int iOffsetX = 15 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0); const int iOffsetY = 5 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0); int iStartPos = 0; const int iContentHeight = FULL_SCREEN_HEIGHT - 8; const int iContentWidth = FULL_SCREEN_WIDTH - 30; char ch; std::stringstream sTemp; WINDOW* w_test_rule_border = newwin(iContentHeight + 2, iContentWidth, iOffsetY, iOffsetX); WINDOW* w_test_rule_content = newwin(iContentHeight, iContentWidth - 2, 1 + iOffsetY, 1 + iOffsetX); wborder(w_test_rule_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); int nmatch = vMatchingItems.size(); std::string buf = string_format(ngettext("%1$d item matches: %2$s", "%1$d items match: %2$s", nmatch), nmatch, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule.c_str()); mvwprintz(w_test_rule_border, 0, iContentWidth/2 - utf8_width(buf.c_str())/2, hilite(c_white), buf.c_str()); mvwprintz(w_test_rule_border, iContentHeight + 1, 1, red_background(c_white), _("Won't display damaged, fits and can/bottle items")); wrefresh(w_test_rule_border); iCurrentLine = 0; do { // Clear the lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { mvwputch(w_test_rule_content, i, j, c_black, ' '); } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, vMatchingItems.size()); // display auto pickup for (int i = iStartPos; i < vMatchingItems.size(); i++) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > vMatchingItems.size()) ? vMatchingItems.size() : iContentHeight)) { nc_color cLineColor = c_white; sTemp.str(""); sTemp << i + 1; mvwprintz(w_test_rule_content, i - iStartPos, 0, cLineColor, sTemp.str().c_str()); mvwprintz(w_test_rule_content, i - iStartPos, 4, cLineColor, ""); if (iCurrentLine == i) { wprintz(w_test_rule_content, c_yellow, ">> "); } else { wprintz(w_test_rule_content, c_yellow, " "); } wprintz(w_test_rule_content, (iCurrentLine == i) ? hilite(cLineColor) : cLineColor, vMatchingItems[i].c_str()); } } wrefresh(w_test_rule_content); ch = (char)input(); switch(ch) { case 'j': //move down iCurrentLine++; if (iCurrentLine >= vMatchingItems.size()) { iCurrentLine = 0; } break; case 'k': //move up iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = vMatchingItems.size()-1; } break; } } while(ch == 'j' || ch == 'k'); werase(w_test_rule_border); werase(w_test_rule_content); }
void show_auto_pickup() { save_reset_changes(false); const int iHeaderHeight = 4; const int iContentHeight = FULL_SCREEN_HEIGHT-2-iHeaderHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0; std::map<int, bool> mapLines; mapLines[3] = true; mapLines[50] = true; mapLines[54] = true; const int iTotalCols = mapLines.size()-1; WINDOW* w_auto_pickup_options = newwin(FULL_SCREEN_HEIGHT/2, FULL_SCREEN_WIDTH/2, iOffsetY + (FULL_SCREEN_HEIGHT/2)/2, iOffsetX + (FULL_SCREEN_WIDTH/2)/2); WINDOW* w_auto_pickup_help = newwin((FULL_SCREEN_HEIGHT/2)-2, FULL_SCREEN_WIDTH * 3/4, 8 + iOffsetY + (FULL_SCREEN_HEIGHT/2)/2, iOffsetX + 19/2); WINDOW* w_auto_pickup_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX); WINDOW* w_auto_pickup_header = newwin(iHeaderHeight, FULL_SCREEN_WIDTH - 2, 1 + iOffsetY, 1 + iOffsetX); WINDOW* w_auto_pickup = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iHeaderHeight + 1 + iOffsetY, 1 + iOffsetX); wborder(w_auto_pickup_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); mvwputch(w_auto_pickup_border, 3, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_auto_pickup_border, 3, 79, c_ltgray, LINE_XOXX); // -| for (std::map<int, bool>::iterator iter = mapLines.begin(); iter != mapLines.end(); ++iter) { mvwputch(w_auto_pickup_border, FULL_SCREEN_HEIGHT-1, iter->first + 1, c_ltgray, LINE_XXOX); // _|_ } mvwprintz(w_auto_pickup_border, 0, 29, c_ltred, _(" AUTO PICKUP MANAGER ")); wrefresh(w_auto_pickup_border); int tmpx = 0; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<A>dd"))+2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<R>emove"))+2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<C>opy"))+2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<M>ove"))+2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<E>nable"))+2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<D>isable"))+2; shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<T>est")); tmpx = 0; tmpx += shortcut_print(w_auto_pickup_header, 1, tmpx, c_white, c_ltgreen, _("<+-> Move up/down"))+2; tmpx += shortcut_print(w_auto_pickup_header, 1, tmpx, c_white, c_ltgreen, _("<Enter>-Edit"))+2; shortcut_print(w_auto_pickup_header, 1, tmpx, c_white, c_ltgreen, _("<Tab>-Switch Page")); for (int i = 0; i < 78; i++) { if (mapLines[i]) { mvwputch(w_auto_pickup_header, 2, i, c_ltgray, LINE_OXXX); mvwputch(w_auto_pickup_header, 3, i, c_ltgray, LINE_XOXO); } else { mvwputch(w_auto_pickup_header, 2, i, c_ltgray, LINE_OXOX); // Draw line under header } } mvwprintz(w_auto_pickup_header, 3, 0, c_white, "#"); mvwprintz(w_auto_pickup_header, 3, 7, c_white, _("Rules")); mvwprintz(w_auto_pickup_header, 3, 51, c_white, _("I/E")); wrefresh(w_auto_pickup_header); int iCurrentPage = 1; int iCurrentLine = 0; int iCurrentCol = 1; int iStartPos = 0; bool bStuffChanged = false; char ch = ' '; std::stringstream sTemp; do { int locx = 17; locx += shortcut_print(w_auto_pickup_header, 2, locx, c_white, (iCurrentPage == 1) ? hilite(c_white) : c_white, _("[<Global>]"))+1; shortcut_print(w_auto_pickup_header, 2, locx, c_white, (iCurrentPage == 2) ? hilite(c_white) : c_white, _("[<Character>]")); wrefresh(w_auto_pickup_header); // Clear the lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { if (mapLines[j]) { mvwputch(w_auto_pickup, i, j, c_ltgray, LINE_XOXO); } else { mvwputch(w_auto_pickup, i, j, c_black, ' '); } } } if (iCurrentPage == 1 || iCurrentPage == 2) { if (iCurrentPage == 2 && g->u.name == "") { vAutoPickupRules[2].clear(); mvwprintz(w_auto_pickup, 8, 15, c_white, _("Please load a character first to use this page!")); } //Draw Scrollbar draw_scrollbar(w_auto_pickup_border, iCurrentLine, iContentHeight, vAutoPickupRules[iCurrentPage].size(), 5); calcStartPos(iStartPos, iCurrentLine, iContentHeight, vAutoPickupRules[iCurrentPage].size()); // display auto pickup for (int i = iStartPos; i < vAutoPickupRules[iCurrentPage].size(); i++) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > vAutoPickupRules[iCurrentPage].size()) ? vAutoPickupRules[iCurrentPage].size() : iContentHeight)) { nc_color cLineColor = (vAutoPickupRules[iCurrentPage][i].bActive) ? c_white : c_ltgray; sTemp.str(""); sTemp << i + 1; mvwprintz(w_auto_pickup, i - iStartPos, 0, cLineColor, sTemp.str().c_str()); mvwprintz(w_auto_pickup, i - iStartPos, 4, cLineColor, ""); if (iCurrentLine == i) { wprintz(w_auto_pickup, c_yellow, ">> "); } else { wprintz(w_auto_pickup, c_yellow, " "); } wprintz(w_auto_pickup, (iCurrentLine == i && iCurrentCol == 1) ? hilite(cLineColor) : cLineColor, "%s", ((vAutoPickupRules[iCurrentPage][i].sRule == "") ? _("<empty rule>") : vAutoPickupRules[iCurrentPage][i].sRule).c_str()); mvwprintz(w_auto_pickup, i - iStartPos, 52, (iCurrentLine == i && iCurrentCol == 2) ? hilite(cLineColor) : cLineColor, "%s", ((vAutoPickupRules[iCurrentPage][i].bExclude) ? rm_prefix(_("<Exclude>E")).c_str() : rm_prefix(_("<Include>I")).c_str())); } } wrefresh(w_auto_pickup); } else if (iCurrentPage == 3) { wborder(w_auto_pickup_options, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); mvwprintz(w_auto_pickup_options, 5, 10, c_white, _("Under construction!")); wrefresh(w_auto_pickup); wrefresh(w_auto_pickup_options); } ch = (char)input(); if (iCurrentPage == 3) { switch(ch) { case '\t': //Switch to next Page iCurrentPage++; if (iCurrentPage > 3) { iCurrentPage = 1; iCurrentLine = 0; } break; } } else if (iCurrentPage == 1 || iCurrentPage == 2) { if (iCurrentPage == 2 && g->u.name == "" && ch != '\t') { //Only allow loaded games to use the char sheet } else if (vAutoPickupRules[iCurrentPage].size() > 0 || ch == 'a' || ch == '\t') { switch(ch) { case 'j': //move down iCurrentLine++; iCurrentCol = 1; if (iCurrentLine >= vAutoPickupRules[iCurrentPage].size()) { iCurrentLine = 0; } break; case 'k': //move up iCurrentLine--; iCurrentCol = 1; if (iCurrentLine < 0) { iCurrentLine = vAutoPickupRules[iCurrentPage].size()-1; } break; case 'a': //add new rule case 'A': bStuffChanged = true; vAutoPickupRules[iCurrentPage].push_back(cPickupRules("", true, false)); iCurrentLine = vAutoPickupRules[iCurrentPage].size()-1; break; case 'r': //remove rule case 'R': bStuffChanged = true; vAutoPickupRules[iCurrentPage].erase(vAutoPickupRules[iCurrentPage].begin() + iCurrentLine); if (iCurrentLine > vAutoPickupRules[iCurrentPage].size()-1) { iCurrentLine--; } break; case 'c': //copy rule case 'C': bStuffChanged = true; vAutoPickupRules[iCurrentPage].push_back(cPickupRules(vAutoPickupRules[iCurrentPage][iCurrentLine].sRule, vAutoPickupRules[iCurrentPage][iCurrentLine].bActive, vAutoPickupRules[iCurrentPage][iCurrentLine].bExclude)); iCurrentLine = vAutoPickupRules[iCurrentPage].size()-1; break; case 'm': //move rule global <-> character case 'M': if ((iCurrentPage == 1 && g->u.name != "") || iCurrentPage == 2) { bStuffChanged = true; //copy over vAutoPickupRules[(iCurrentPage == 1) ? 2 : 1].push_back(cPickupRules(vAutoPickupRules[iCurrentPage][iCurrentLine].sRule, vAutoPickupRules[iCurrentPage][iCurrentLine].bActive, vAutoPickupRules[iCurrentPage][iCurrentLine].bExclude)); //remove old vAutoPickupRules[iCurrentPage].erase(vAutoPickupRules[iCurrentPage].begin() + iCurrentLine); iCurrentLine = vAutoPickupRules[(iCurrentPage == 1) ? 2 : 1].size()-1; iCurrentPage = (iCurrentPage == 1) ? 2 : 1; } break; case '\t': //Switch to next Page iCurrentPage++; if (iCurrentPage > 2) { iCurrentPage = 1; iCurrentLine = 0; } break; case '\n': //Edit Col in current line bStuffChanged = true; if (iCurrentCol == 1) { fold_and_print(w_auto_pickup_help, 1, 1, 999, c_white, _( "* is used as a Wildcard. A few Examples:\n" "\n" "wood arrow matches the itemname exactly\n" "wood ar* matches items beginning with wood ar\n" "*rrow matches items ending with rrow\n" "*avy fle*fi*arrow multible * are allowed\n" "heAVY*woOD*arrOW case insesitive search\n" "") ); wborder(w_auto_pickup_help, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); wrefresh(w_auto_pickup_help); vAutoPickupRules[iCurrentPage][iCurrentLine].sRule = trim_rule(string_input_popup(_("Pickup Rule:"), 30, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule)); } else if (iCurrentCol == 2) { vAutoPickupRules[iCurrentPage][iCurrentLine].bExclude = !vAutoPickupRules[iCurrentPage][iCurrentLine].bExclude; } break; case 'e': //enable rule case 'E': bStuffChanged = true; vAutoPickupRules[iCurrentPage][iCurrentLine].bActive = true; break; case 'd': //disable rule case 'D': bStuffChanged = true; vAutoPickupRules[iCurrentPage][iCurrentLine].bActive = false; break; case 'h': //move left iCurrentCol--; if (iCurrentCol < 1) { iCurrentCol = iTotalCols; } break; case 'l': //move right iCurrentCol++; if (iCurrentCol > iTotalCols) { iCurrentCol = 1; } break; case '+': //move rule up bStuffChanged = true; if (iCurrentLine < vAutoPickupRules[iCurrentPage].size()-1) { std::swap(vAutoPickupRules[iCurrentPage][iCurrentLine], vAutoPickupRules[iCurrentPage][iCurrentLine+1]); iCurrentLine++; iCurrentCol = 1; } break; case '-': //move rule down bStuffChanged = true; if (iCurrentLine > 0) { std::swap(vAutoPickupRules[iCurrentPage][iCurrentLine], vAutoPickupRules[iCurrentPage][iCurrentLine-1]); iCurrentLine--; iCurrentCol = 1; } break; case 't': //test rule case 'T': test_pattern(iCurrentPage, iCurrentLine); break; } } } } while(ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE); if (bStuffChanged) { if(query_yn(_("Save changes?"))) { save_auto_pickup(false); if (g->u.name != "") { save_auto_pickup(true); } } else { save_reset_changes(true); } } werase(w_auto_pickup); werase(w_auto_pickup_border); werase(w_auto_pickup_header); werase(w_auto_pickup_options); werase(w_auto_pickup_help); }
int worldfactory::show_worldgen_tab_modselection(WINDOW *win, WORLDPTR world) { // Use active_mod_order of the world, // saves us from writting 'world->active_mod_order' all the time. std::vector<std::string> &active_mod_order = world->active_mod_order; { std::vector<std::string> tmp_mod_order; // clear active_mod_order and re-add all the mods, his ensures // that changes (like changing depencies) get updated tmp_mod_order.swap(active_mod_order); for(size_t i = 0; i < tmp_mod_order.size(); i++) { mman_ui->try_add(tmp_mod_order[i], active_mod_order); } } const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; // lots of small windows so that each section can be drawn to independently of the others as necessary WINDOW *w_header1, *w_header2, *w_shift, *w_list, *w_active, *w_description; w_header1 = newwin(1, FULL_SCREEN_WIDTH / 2 - 5, 3 + iOffsetY, 1 + iOffsetX); w_header2 = newwin(1, FULL_SCREEN_WIDTH / 2 - 4, 3 + iOffsetY, FULL_SCREEN_WIDTH / 2 + 3 + iOffsetX); w_shift = newwin(13, 5, 3 + iOffsetY, FULL_SCREEN_WIDTH / 2 - 3 + iOffsetX); w_list = newwin(11, FULL_SCREEN_WIDTH / 2 - 4, 5 + iOffsetY, iOffsetX); w_active = newwin(11, FULL_SCREEN_WIDTH / 2 - 4, 5 + iOffsetY, FULL_SCREEN_WIDTH / 2 + 2 + iOffsetX); w_description = newwin(4, FULL_SCREEN_WIDTH - 2, 19 + iOffsetY, 1 + iOffsetX); draw_modselection_borders(win); std::vector<std::string> headers; headers.push_back(_("Mod List")); headers.push_back(_("Mod Load Order")); std::vector<WINDOW *> header_windows; header_windows.push_back(w_header1); header_windows.push_back(w_header2); int tab_output = 0; int last_active_header = 0; size_t active_header = 0; size_t useable_mod_count = mman_ui->usable_mods.size(); int startsel[2] = {0, 0}; int cursel[2] = {0, 0}; bool redraw_headers = true; bool redraw_shift = true; bool redraw_description = true; bool redraw_list = true; bool redraw_active = true; bool selection_changed = false; input_context ctxt("MODMANAGER_DIALOG"); ctxt.register_cardinal(); ctxt.register_action("HELP_KEYBINDINGS"); ctxt.register_action("QUIT"); ctxt.register_action("NEXT_TAB"); ctxt.register_action("PREV_TAB"); ctxt.register_action("CONFIRM"); ctxt.register_action("ADD_MOD"); ctxt.register_action("REMOVE_MOD"); ctxt.register_action("SAVE_DEFAULT_MODS"); while (tab_output == 0) { if (redraw_headers) { for (size_t i = 0; i < headers.size(); ++i) { werase(header_windows[i]); const int header_x = (getmaxx(header_windows[i]) - headers[i].size()) / 2; mvwprintz(header_windows[i], 0, header_x , c_cyan, "%s", headers[i].c_str()); if (active_header == i) { mvwputch(header_windows[i], 0, header_x - 3, c_red, '<'); mvwputch(header_windows[i], 0, header_x + headers[i].size() + 2, c_red, '>'); } wrefresh(header_windows[i]); } redraw_list = true; redraw_active = true; redraw_shift = true; redraw_headers = false; } if (selection_changed) { if (active_header == 0) { redraw_list = true; } if (active_header == 1) { redraw_shift = true; redraw_active = true; } selection_changed = false; redraw_description = true; } if (redraw_description) { werase(w_description); MOD_INFORMATION *selmod = NULL; if (mman_ui->usable_mods.empty()) { // Do nothing, leave selmod == NULL } else if (active_header == 0) { selmod = mman->mod_map[mman_ui->usable_mods[cursel[0]]]; } else if (!active_mod_order.empty()) { selmod = mman->mod_map[active_mod_order[cursel[1]]]; } if (selmod != NULL) { fold_and_print(w_description, 0, 1, getmaxx(w_description) - 1, c_white, mman_ui->get_information(selmod)); } redraw_description = false; wrefresh(w_description); } if (redraw_list) { werase(w_list); calcStartPos(startsel[0], cursel[0], getmaxy(w_list), useable_mod_count); if (useable_mod_count == 0) { center_print(w_list, 0, c_red, _("--NO AVAILABLE MODS--")); } else { std::stringstream list_output; for( size_t i = startsel[0], c = 0; i < useable_mod_count && c < getmaxy(w_list); ++i, ++c ) { if ((int)i != cursel[0]) { list_output << std::string(3, ' '); } else { if (active_header == 0) { list_output << "<color_yellow>"; } else { list_output << "<color_blue>"; } list_output << ">></color> "; } list_output << mman->mod_map[mman_ui->usable_mods[i]]->name << "\n"; } fold_and_print(w_list, 0, 1, getmaxx(w_list) - 1, c_white, list_output.str()); } draw_scrollbar(w_list, cursel[0], getmaxy(w_list), useable_mod_count, 0, 0); wrefresh(w_list); } if (redraw_active) { werase(w_active); const int active_count = active_mod_order.size(); calcStartPos(startsel[1], cursel[1], getmaxy(w_active), active_count); if (active_count == 0) { center_print(w_active, 0, c_red, _("--NO ACTIVE MODS--")); } else { std::stringstream list_output; for (int i = startsel[1], c = 0; i < active_count && c < getmaxy(w_active); ++i, ++c) { if (i != cursel[1]) { list_output << std::string(3, ' '); } else { if (active_header == 1) { list_output << "<color_yellow>"; } else { list_output << "<color_blue>"; } list_output << ">></color> "; } list_output << mman->mod_map[active_mod_order[i]]->name << "\n"; } fold_and_print(w_active, 0, 1, getmaxx(w_active) - 1, c_white, list_output.str()); } draw_scrollbar(w_active, cursel[1], getmaxy(w_active), active_count, 0, 0); wrefresh(w_active); } if (redraw_shift) { werase(w_shift); if (active_header == 1) { std::stringstream shift_display; // get shift information for whatever is visible in the active list for (size_t i = startsel[1], c = 0; i < active_mod_order.size() && c < getmaxy(w_active); ++i, ++c) { if (mman_ui->can_shift_up(i, active_mod_order)) { shift_display << "<color_blue>+</color> "; } else { shift_display << "<color_dkgray>+</color> "; } if (mman_ui->can_shift_down(i, active_mod_order)) { shift_display << "<color_blue>-</color>"; } else { shift_display << "<color_dkgray>-</color>"; } shift_display << "\n"; } fold_and_print(w_shift, 2, 1, getmaxx(w_shift), c_white, shift_display.str()); } redraw_shift = false; wrefresh(w_shift); } refresh(); last_active_header = active_header; const int next_header = (active_header == 1) ? 0 : 1; const int prev_header = (active_header == 0) ? 1 : 0; int selection = (active_header == 0) ? cursel[0] : cursel[1]; int last_selection = selection; unsigned int next_selection = selection + 1; int prev_selection = selection - 1; if (active_header == 0) { next_selection = (next_selection >= useable_mod_count) ? 0 : next_selection; prev_selection = (prev_selection < 0) ? useable_mod_count - 1 : prev_selection; } else { next_selection = (next_selection >= active_mod_order.size()) ? 0 : next_selection; prev_selection = (prev_selection < 0) ? active_mod_order.size() - 1 : prev_selection; } const std::string action = ctxt.handle_input(); if (action == "DOWN") { selection = next_selection; } else if (action == "UP") { selection = prev_selection; } else if (action == "RIGHT") { active_header = next_header; } else if (action == "LEFT") { active_header = prev_header; } else if (action == "CONFIRM") { if (active_header == 0 && !mman_ui->usable_mods.empty()) { // try-add mman_ui->try_add(mman_ui->usable_mods[cursel[0]], active_mod_order); redraw_active = true; redraw_shift = true; } else if (active_header == 1 && !active_mod_order.empty()) { // try-rem mman_ui->try_rem(cursel[1], active_mod_order); redraw_active = true; redraw_shift = true; if (active_mod_order.empty()) { // switch back to other list, we can't change // anything in the empty active mods list. active_header = 0; } } } else if (action == "ADD_MOD") { if (active_header == 1 && active_mod_order.size() > 1) { mman_ui->try_shift('+', cursel[1], active_mod_order); redraw_active = true; redraw_shift = true; } } else if (action == "REMOVE_MOD") { if (active_header == 1 && active_mod_order.size() > 1) { mman_ui->try_shift('-', cursel[1], active_mod_order); redraw_active = true; redraw_shift = true; } } else if (action == "NEXT_TAB") { tab_output = 1; } else if (action == "PREV_TAB") { tab_output = -1; } else if (action == "SAVE_DEFAULT_MODS") { if(mman->set_default_mods(active_mod_order)) { popup(_("Saved list of active mods as default")); draw_modselection_borders(win); redraw_headers = true; } } else if (action == "QUIT") { tab_output = -999; } // RESOLVE INPUTS if (last_active_header != (int)active_header) { redraw_headers = true; redraw_shift = true; redraw_description = true; } if (last_selection != selection) { if (active_header == 0) { redraw_list = true; cursel[0] = selection; } else { redraw_active = true; redraw_shift = true; cursel[1] = selection; } redraw_description = true; } if (active_mod_order.empty()) { redraw_active = true; cursel[1] = 0; } if (active_header == 1) { if (active_mod_order.empty()) { cursel[1] = 0; } else { if (cursel[1] < 0) { cursel[1] = 0; } else if (cursel[1] >= (int)active_mod_order.size()) { cursel[1] = active_mod_order.size() - 1; } } } // end RESOLVE INPUTS } werase(w_header1); werase(w_header2); werase(w_shift); werase(w_list); werase(w_active); werase(w_description); delwin(w_header1); delwin(w_header2); delwin(w_shift); delwin(w_list); delwin(w_active); delwin(w_description); return tab_output; }
void safemode::show( const std::string &custom_name_in, bool is_safemode_in ) { auto global_rules_old = global_rules; auto character_rules_old = character_rules; const int header_height = 4; const int content_height = FULL_SCREEN_HEIGHT - 2 - header_height; const int offset_x = ( TERMX > FULL_SCREEN_WIDTH ) ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0; const int offset_y = ( TERMY > FULL_SCREEN_HEIGHT ) ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0; enum Columns : int { COLUMN_RULE, COLUMN_ATTITUDE, COLUMN_PROXIMITY, COLUMN_WHITE_BLACKLIST, }; std::map<int, int> column_pos; column_pos[COLUMN_RULE] = 4; column_pos[COLUMN_ATTITUDE] = 48; column_pos[COLUMN_PROXIMITY] = 59; column_pos[COLUMN_WHITE_BLACKLIST] = 66; const int num_columns = column_pos.size(); WINDOW *w_help = newwin( ( FULL_SCREEN_HEIGHT / 2 ) - 2, FULL_SCREEN_WIDTH * 3 / 4, 7 + offset_y + ( FULL_SCREEN_HEIGHT / 2 ) / 2, offset_x + 19 / 2 ); WINDOW_PTR w_helpptr( w_help ); WINDOW *w_border = newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, offset_y, offset_x ); WINDOW_PTR w_borderptr( w_border ); WINDOW *w_header = newwin( header_height, FULL_SCREEN_WIDTH - 2, 1 + offset_y, 1 + offset_x ); WINDOW_PTR w_headerptr( w_header ); WINDOW *w = newwin( content_height, FULL_SCREEN_WIDTH - 2, header_height + 1 + offset_y, 1 + offset_x ); WINDOW_PTR wptr( w ); draw_border( w_border, BORDER_COLOR, custom_name_in ); mvwputch( w_border, 3, 0, c_ltgray, LINE_XXXO ); // |- mvwputch( w_border, 3, 79, c_ltgray, LINE_XOXX ); // -| for( auto &column : column_pos ) { mvwputch( w_border, FULL_SCREEN_HEIGHT - 1, column.second + 1, c_ltgray, LINE_XXOX ); // _|_ } wrefresh( w_border ); static const std::vector<std::string> hotkeys = {{ _( "<A>dd" ), _( "<R>emove" ), _( "<C>opy" ), _( "<M>ove" ), _( "<E>nable" ), _( "<D>isable" ), _( "<T>est" ) } }; int tmpx = 0; for( auto &hotkey : hotkeys ) { tmpx += shortcut_print( w_header, 0, tmpx, c_white, c_ltgreen, hotkey ) + 2; } tmpx = 0; tmpx += shortcut_print( w_header, 1, tmpx, c_white, c_ltgreen, _( "<+-> Move up/down" ) ) + 2; tmpx += shortcut_print( w_header, 1, tmpx, c_white, c_ltgreen, _( "<Enter>-Edit" ) ) + 2; shortcut_print( w_header, 1, tmpx, c_white, c_ltgreen, _( "<Tab>-Switch Page" ) ); for( int i = 0; i < 78; i++ ) { mvwputch( w_header, 2, i, c_ltgray, LINE_OXOX ); // Draw line under header } for( auto &pos : column_pos ) { mvwputch( w_header, 2, pos.second, c_ltgray, LINE_OXXX ); mvwputch( w_header, 3, pos.second, c_ltgray, LINE_XOXO ); } mvwprintz( w_header, 3, 1, c_white, "#" ); mvwprintz( w_header, 3, column_pos[COLUMN_RULE] + 4, c_white, _( "Rules" ) ); mvwprintz( w_header, 3, column_pos[COLUMN_ATTITUDE] + 2, c_white, _( "Attitude" ) ); mvwprintz( w_header, 3, column_pos[COLUMN_PROXIMITY] + 2, c_white, _( "Dist" ) ); mvwprintz( w_header, 3, column_pos[COLUMN_WHITE_BLACKLIST] + 2, c_white, _( "B/W" ) ); wrefresh( w_header ); int tab = GLOBAL_TAB; int line = 0; int column = 0; int start_pos = 0; bool changes_made = false; input_context ctxt( "SAFEMODE" ); ctxt.register_cardinal(); ctxt.register_action( "CONFIRM" ); ctxt.register_action( "QUIT" ); ctxt.register_action( "NEXT_TAB" ); ctxt.register_action( "PREV_TAB" ); ctxt.register_action( "ADD_DEFAULT_RULESET" ); ctxt.register_action( "ADD_RULE" ); ctxt.register_action( "REMOVE_RULE" ); ctxt.register_action( "COPY_RULE" ); ctxt.register_action( "ENABLE_RULE" ); ctxt.register_action( "DISABLE_RULE" ); ctxt.register_action( "MOVE_RULE_UP" ); ctxt.register_action( "MOVE_RULE_DOWN" ); ctxt.register_action( "TEST_RULE" ); ctxt.register_action( "HELP_KEYBINDINGS" ); if( is_safemode_in ) { ctxt.register_action( "SWITCH_SAFEMODE_OPTION" ); ctxt.register_action( "SWAP_RULE_GLOBAL_CHAR" ); } while( true ) { int locx = 17; locx += shortcut_print( w_header, 2, locx, c_white, ( tab == GLOBAL_TAB ) ? hilite( c_white ) : c_white, _( "[<Global>]" ) ) + 1; shortcut_print( w_header, 2, locx, c_white, ( tab == CHARACTER_TAB ) ? hilite( c_white ) : c_white, _( "[<Character>]" ) ); locx = 55; mvwprintz( w_header, 0, locx, c_white, _( "Safe Mode enabled:" ) ); locx += shortcut_print( w_header, 1, locx, ( ( get_option<bool>( "SAFEMODE" ) ) ? c_ltgreen : c_ltred ), c_white, ( ( get_option<bool>( "SAFEMODE" ) ) ? _( "True" ) : _( "False" ) ) ); locx += shortcut_print( w_header, 1, locx, c_white, c_ltgreen, " " ); locx += shortcut_print( w_header, 1, locx, c_white, c_ltgreen, _( "<S>witch" ) ); shortcut_print( w_header, 1, locx, c_white, c_ltgreen, " " ); wrefresh( w_header ); // Clear the lines for( int i = 0; i < content_height; i++ ) { for( int j = 0; j < 79; j++ ) { mvwputch( w, i, j, c_black, ' ' ); } for( auto &pos : column_pos ) { mvwputch( w, i, pos.second, c_ltgray, LINE_XOXO ); } } auto ¤t_tab = ( tab == GLOBAL_TAB ) ? global_rules : character_rules; if( tab == CHARACTER_TAB && g->u.name.empty() ) { character_rules.clear(); mvwprintz( w, 8, 15, c_white, _( "Please load a character first to use this page!" ) ); } else if( empty() ) { mvwprintz( w, 8, 15, c_white, _( "Safe Mode manager currently inactive." ) ); mvwprintz( w, 9, 15, c_white, _( "Default rules are used. Add a rule to activate." ) ); mvwprintz( w, 10, 15, c_white, _( "Press ~ to add a default ruleset to get started." ) ); } draw_scrollbar( w_border, line, content_height, current_tab.size(), 5 ); wrefresh( w_border ); calcStartPos( start_pos, line, content_height, current_tab.size() ); // display safe mode for( int i = start_pos; i < ( int )current_tab.size(); i++ ) { if( i >= start_pos && i < start_pos + std::min( content_height, static_cast<int>( current_tab.size() ) ) ) { auto rule = current_tab[i]; nc_color line_color = ( rule.active ) ? c_white : c_ltgray; mvwprintz( w, i - start_pos, 1, line_color, "%d", i + 1 ); mvwprintz( w, i - start_pos, 5, c_yellow, ( line == i ) ? ">> " : " " ); auto draw_column = [&]( Columns column_in, std::string text_in ) { mvwprintz( w, i - start_pos, column_pos[column_in] + 2, ( line == i && column == column_in ) ? hilite( line_color ) : line_color, "%s", text_in.c_str() ); }; draw_column( COLUMN_RULE, ( rule.rule.empty() ) ? _( "<empty rule>" ) : rule.rule ); draw_column( COLUMN_ATTITUDE, Creature::get_attitude_ui_data( rule.attitude ).first ); draw_column( COLUMN_PROXIMITY, ( !rule.whitelist ) ? to_string( rule.proximity ).c_str() : "---" ); draw_column( COLUMN_WHITE_BLACKLIST, ( rule.whitelist ) ? _( "Whitelist" ) : _( "Blacklist" ) ); } } wrefresh( w ); const std::string action = ctxt.handle_input(); if( action == "NEXT_TAB" ) { tab++; if( tab >= MAX_TAB ) { tab = 0; line = 0; } } else if( action == "PREV_TAB" ) { tab--; if( tab < 0 ) { tab = MAX_TAB - 1; line = 0; } } else if( action == "QUIT" ) { break; } else if( tab == CHARACTER_TAB && g->u.name.empty() ) { //Only allow loaded games to use the char sheet } else if( action == "DOWN" ) { line++; if( line >= ( int )current_tab.size() ) { line = 0; } } else if( action == "UP" ) { line--; if( line < 0 ) { line = current_tab.size() - 1; } } else if( action == "ADD_DEFAULT_RULESET" ) { changes_made = true; current_tab.push_back( rules_class( "*", true, false, Creature::A_HOSTILE, 0 ) ); line = current_tab.size() - 1; } else if( action == "ADD_RULE" ) { changes_made = true; current_tab.push_back( rules_class( "", true, false, Creature::A_HOSTILE, get_option<int>( "SAFEMODEPROXIMITY" ) ) ); line = current_tab.size() - 1; } else if( action == "REMOVE_RULE" && !current_tab.empty() ) { changes_made = true; current_tab.erase( current_tab.begin() + line ); if( line > ( int )current_tab.size() - 1 ) { line--; } if( line < 0 ) { line = 0; } } else if( action == "COPY_RULE" && !current_tab.empty() ) { changes_made = true; current_tab.push_back( current_tab[line] ); line = current_tab.size() - 1; } else if( action == "SWAP_RULE_GLOBAL_CHAR" && !current_tab.empty() ) { if( ( tab == GLOBAL_TAB && !g->u.name.empty() ) || tab == CHARACTER_TAB ) { changes_made = true; //copy over auto &temp_rules_from = ( tab == GLOBAL_TAB ) ? global_rules : character_rules; auto &temp_rules_to = ( tab == GLOBAL_TAB ) ? character_rules : global_rules; temp_rules_to.push_back( temp_rules_from[line] ); //remove old temp_rules_from.erase( temp_rules_from.begin() + line ); line = temp_rules_from.size() - 1; tab = ( tab == GLOBAL_TAB ) ? CHARACTER_TAB : GLOBAL_TAB; } } else if( action == "CONFIRM" && !current_tab.empty() ) { changes_made = true; if( column == COLUMN_RULE ) { fold_and_print( w_help, 1, 1, 999, c_white, _( "* is used as a Wildcard. A few Examples:\n" "\n" "human matches every NPC\n" "zombie matches the monster name exactly\n" "acidic zo* matches monsters beginning with 'acidic zo'\n" "*mbie matches monsters ending with 'mbie'\n" "*cid*zo*ie multiple * are allowed\n" "AcI*zO*iE case insensitive search" ) ); draw_border( w_help ); wrefresh( w_help ); current_tab[line].rule = wildcard_trim_rule( string_input_popup() .title( _( "Safe Mode Rule:" ) ) .width( 30 ) .text( current_tab[line].rule ) .query_string() ); } else if( column == COLUMN_WHITE_BLACKLIST ) { current_tab[line].whitelist = !current_tab[line].whitelist; } else if( column == COLUMN_ATTITUDE ) { auto &attitude = current_tab[line].attitude; switch( attitude ) { case Creature::A_HOSTILE: attitude = Creature::A_NEUTRAL; break; case Creature::A_NEUTRAL: attitude = Creature::A_FRIENDLY; break; case Creature::A_FRIENDLY: attitude = Creature::A_ANY; break; case Creature::A_ANY: attitude = Creature::A_HOSTILE; } } else if( column == COLUMN_PROXIMITY && !current_tab[line].whitelist ) { const auto text = string_input_popup() .title( _( "Proximity Distance (0=max viewdistance)" ) ) .width( 4 ) .text( to_string( current_tab[line].proximity ) ) .description( _( "Option: " ) + to_string( get_option<int>( "SAFEMODEPROXIMITY" ) ) + " " + get_options().get_option( "SAFEMODEPROXIMITY" ).getDefaultText() ) .max_length( 3 ) .only_digits( true ) .query_string(); if( text.empty() ) { current_tab[line].proximity = get_option<int>( "SAFEMODEPROXIMITY" ); } else { //Let the options class handle the validity of the new value auto temp_option = get_options().get_option( "SAFEMODEPROXIMITY" ); temp_option.setValue( text ); current_tab[line].proximity = atoi( temp_option.getValue().c_str() ); } } } else if( action == "ENABLE_RULE" && !current_tab.empty() ) { changes_made = true; current_tab[line].active = true; } else if( action == "DISABLE_RULE" && !current_tab.empty() ) { changes_made = true; current_tab[line].active = false; } else if( action == "LEFT" ) { column--; if( column < 0 ) { column = num_columns - 1; } } else if( action == "RIGHT" ) { column++; if( column >= num_columns ) { column = 0; } } else if( action == "MOVE_RULE_UP" && !current_tab.empty() ) { changes_made = true; if( line < ( int )current_tab.size() - 1 ) { std::swap( current_tab[line], current_tab[line + 1] ); line++; column = 0; } } else if( action == "MOVE_RULE_DOWN" && !current_tab.empty() ) { changes_made = true; if( line > 0 ) { std::swap( current_tab[line], current_tab[line - 1] ); line--; column = 0; } } else if( action == "TEST_RULE" && !current_tab.empty() ) { test_pattern( tab, line ); } else if( action == "SWITCH_SAFEMODE_OPTION" ) { get_options().get_option( "SAFEMODE" ).setNext(); get_options().save(); } } if( !changes_made ) { return; } if( query_yn( _( "Save changes?" ) ) ) { if( is_safemode_in ) { save_global(); if( !g->u.name.empty() ) { save_character(); } } else { create_rules(); } } else { global_rules = global_rules_old; character_rules = character_rules_old; } }
void safemode::test_pattern( const int tab_in, const int row_in ) { std::vector<std::string> creature_list; std::string creature_name; auto &temp_rules = ( tab_in == GLOBAL_TAB ) ? global_rules : character_rules; if( temp_rules[row_in].rule.empty() ) { return; } if( g->u.name.empty() ) { popup( _( "No monsters loaded. Please start a game first." ) ); return; } //Loop through all monster mtypes for( const auto &mtype : MonsterGenerator::generator().get_all_mtypes() ) { creature_name = mtype.nname(); if( wildcard_match( creature_name, temp_rules[row_in].rule ) ) { creature_list.push_back( creature_name ); } } const int offset_x = 15 + ( ( TERMX > FULL_SCREEN_WIDTH ) ? ( TERMX - FULL_SCREEN_WIDTH ) / 2 : 0 ); const int offset_y = 5 + ( ( TERMY > FULL_SCREEN_HEIGHT ) ? ( TERMY - FULL_SCREEN_HEIGHT ) / 2 : 0 ); int start_pos = 0; const int content_height = FULL_SCREEN_HEIGHT - 8; const int content_width = FULL_SCREEN_WIDTH - 30; WINDOW *w_test_rule_border = newwin( content_height + 2, content_width, offset_y, offset_x ); WINDOW_PTR w_test_rule_borderptr( w_test_rule_border ); WINDOW *w_test_rule_content = newwin( content_height, content_width - 2, 1 + offset_y, 1 + offset_x ); WINDOW_PTR w_test_rule_contentptr( w_test_rule_content ); draw_border( w_test_rule_border ); int nmatch = creature_list.size(); std::string buf = string_format( ngettext( "%1$d monster matches: %2$s", "%1$d monsters match: %2$s", nmatch ), nmatch, temp_rules[row_in].rule.c_str() ); mvwprintz( w_test_rule_border, 0, content_width / 2 - utf8_width( buf ) / 2, hilite( c_white ), "%s", buf.c_str() ); mvwprintz( w_test_rule_border, content_height + 1, 1, red_background( c_white ), _( "Lists monsters regardless of their attitude." ) ); wrefresh( w_test_rule_border ); int line = 0; input_context ctxt( "SAFEMODE_TEST" ); ctxt.register_updown(); ctxt.register_action( "QUIT" ); while( true ) { // Clear the lines for( int i = 0; i < content_height; i++ ) { for( int j = 0; j < 79; j++ ) { mvwputch( w_test_rule_content, i, j, c_black, ' ' ); } } calcStartPos( start_pos, line, content_height, creature_list.size() ); // display safe mode for( int i = start_pos; i < ( int )creature_list.size(); i++ ) { if( i >= start_pos && i < start_pos + std::min( content_height, static_cast<int>( creature_list.size() ) ) ) { nc_color line_color = c_white; mvwprintz( w_test_rule_content, i - start_pos, 0, line_color, "%d", i + 1 ); mvwprintz( w_test_rule_content, i - start_pos, 4, line_color, "" ); wprintz( w_test_rule_content, c_yellow, ( line == i ) ? ">> " : " " ); wprintz( w_test_rule_content, ( line == i ) ? hilite( line_color ) : line_color, "%s", creature_list[i].c_str() ); } } wrefresh( w_test_rule_content ); const std::string action = ctxt.handle_input(); if( action == "DOWN" ) { line++; if( line >= ( int )creature_list.size() ) { line = 0; } } else if( action == "UP" ) { line--; if( line < 0 ) { line = creature_list.size() - 1; } } else { break; } } }
/** * Generate and refresh output */ void uimenu::show() { if (!started) { setup(); } werase(window); draw_border(window, border_color); if( !title.empty() ) { mvwprintz(window, 0, 1, border_color, "< "); wprintz( window, title_color, title ); wprintz(window, border_color, " >"); } std::string padspaces = std::string(w_width - 2 - pad_left - pad_right, ' '); const int text_lines = textformatted.size(); int estart = 1; if( !textformatted.empty() ) { for ( int i = 0; i < text_lines; i++ ) { trim_and_print( window, 1 + i, 2, getmaxx( window ) - 4, text_color, textformatted[i] ); } mvwputch(window, text_lines + 1, 0, border_color, LINE_XXXO); for ( int i = 1; i < w_width - 1; ++i) { mvwputch(window, text_lines + 1, i, border_color, LINE_OXOX); } mvwputch(window, text_lines + 1, w_width - 1, border_color, LINE_XOXX); estart += text_lines + 1; // +1 for the horizontal line. } calcStartPos( vshift, fselected, vmax, fentries.size() ); for ( int fei = vshift, si = 0; si < vmax; fei++, si++ ) { if ( fei < (int)fentries.size() ) { int ei = fentries [ fei ]; nc_color co = ( ei == selected ? hilight_color : ( entries[ ei ].enabled || entries[ei].force_color ? entries[ ei ].text_color : disabled_color ) ); if ( hilight_full ) { mvwprintz( window, estart + si, pad_left + 1, co, padspaces ); } if( entries[ ei ].hotkey >= 33 && entries[ ei ].hotkey < 126 ) { const nc_color hotkey_co = ei == selected ? hilight_color : hotkey_color; mvwprintz( window, estart + si, pad_left + 2, entries[ ei ].enabled ? hotkey_co : co, "%c", entries[ ei ].hotkey ); } if( padspaces.size() > 3 ) { // padspaces's length indicates the maximal width of the entry, it is used above to // activate the highlighting, it is used to override previous text there, but in both // cases printing starts at pad_left+1, here it starts at pad_left+4, so 3 cells less // to be used. const auto entry = utf8_wrapper( ei == selected ? remove_color_tags( entries[ ei ].txt ) : entries[ ei ].txt ); trim_and_print( window, estart + si, pad_left + 4, max_entry_len, co, "%s", entry.c_str() ); if( max_column_len && !entries[ ei ].ctxt.empty() ) { const auto centry = utf8_wrapper( ei == selected ? remove_color_tags( entries[ ei ].ctxt ) : entries[ ei ].ctxt ); trim_and_print( window, estart + si, getmaxx( window ) - max_column_len - 2, max_column_len, co, "%s", centry.c_str() ); } } mvwzstr menu_entry_extra_text = entries[ei].extratxt; if ( !menu_entry_extra_text.txt.empty() ) { mvwprintz( window, estart + si, pad_left + 1 + menu_entry_extra_text.left, menu_entry_extra_text.color, menu_entry_extra_text.txt ); } if ( menu_entry_extra_text.sym != 0 ) { mvwputch ( window, estart + si, pad_left + 1 + menu_entry_extra_text.left, menu_entry_extra_text.color, menu_entry_extra_text.sym ); } if ( callback != NULL && ei == selected ) { callback->select(ei, this); } } else { mvwprintz( window, estart + si, pad_left + 1, c_light_gray, padspaces ); } } if ( desc_enabled ) { // draw border mvwputch(window, w_height - desc_lines - 2, 0, border_color, LINE_XXXO); for ( int i = 1; i < w_width - 1; ++i) { mvwputch(window, w_height - desc_lines - 2, i, border_color, LINE_OXOX); } mvwputch(window, w_height - desc_lines - 2, w_width - 1, border_color, LINE_XOXX); // clear previous desc the ugly way for ( int y = desc_lines + 1; y > 1; --y ) { for ( int x = 2; x < w_width - 2; ++x) { mvwputch(window, w_height - y, x, text_color, " "); } } if( static_cast<size_t>( selected ) < entries.size() ){ fold_and_print( window, w_height - desc_lines - 1, 2, w_width - 4, text_color, entries[selected].desc ); } } if ( !filter.empty() ) { mvwprintz( window, w_height - 1, 2, border_color, "< %s >", filter.c_str() ); mvwprintz( window, w_height - 1, 4, text_color, filter ); } apply_scrollbar(); this->refresh(true); }
void game::show_options() { std::map<std::string, cOpt> OPTIONS_OLD = OPTIONS; const int iTooltipHeight = 3; const int iContentHeight = FULL_SCREEN_HEIGHT-3-iTooltipHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX-FULL_SCREEN_WIDTH)/2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY-FULL_SCREEN_HEIGHT)/2 : 0; std::map<int, bool> mapLines; mapLines[3] = true; mapLines[60] = true; //mapLines[68] = true; WINDOW* w_options_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX); WINDOW* w_options_tooltip = newwin(iTooltipHeight, FULL_SCREEN_WIDTH - 2, 1 + iOffsetY, 1 + iOffsetX); WINDOW* w_options_header = newwin(1, FULL_SCREEN_WIDTH - 2, 1 + iTooltipHeight + iOffsetY, 1 + iOffsetX); WINDOW* w_options = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iTooltipHeight + 2 + iOffsetY, 1 + iOffsetX); wborder(w_options_border, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX); mvwputch(w_options_border, 4, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_options_border, 4, 79, c_ltgray, LINE_XOXX); // -| for (std::map<int, bool>::iterator iter = mapLines.begin(); iter != mapLines.end(); ++iter) { mvwputch(w_options_border, FULL_SCREEN_HEIGHT-1, iter->first + 1, c_ltgray, LINE_XXOX); // _|_ } mvwprintz(w_options_border, 0, 36, c_ltred, _(" OPTIONS ")); wrefresh(w_options_border); for (int i = 0; i < 78; i++) { if (mapLines[i]) { mvwputch(w_options_header, 0, i, c_ltgray, LINE_OXXX); } else { mvwputch(w_options_header, 0, i, c_ltgray, LINE_OXOX); // Draw header line } } //mvwprintz(w_options_header, 3, 0, c_white, "#"); //mvwprintz(w_options_header, 3, 7, c_white, _("Option")); //mvwprintz(w_options_header, 3, 52, c_white, _("Value")); wrefresh(w_options_header); int iCurrentPage = 0; int iCurrentLine = 0; int iStartPos = 0; bool bStuffChanged = false; char ch = ' '; std::stringstream sTemp; do { //Clear the lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { if (mapLines[j]) { mvwputch(w_options, i, j, c_ltgray, LINE_XOXO); } else { mvwputch(w_options, i, j, c_black, ' '); } if (i < iTooltipHeight) { mvwputch(w_options_tooltip, i, j, c_black, ' '); } } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, mPageItems[iCurrentPage].size()); //Draw options for (int i = iStartPos; i < iStartPos + ((iContentHeight > mPageItems[iCurrentPage].size()) ? mPageItems[iCurrentPage].size() : iContentHeight); i++) { nc_color cLineColor = c_ltgreen; sTemp.str(""); sTemp << i + 1; mvwprintz(w_options, i - iStartPos, 0, c_white, sTemp.str().c_str()); mvwprintz(w_options, i - iStartPos, 4, c_white, ""); if (iCurrentLine == i) { wprintz(w_options, c_yellow, ">> "); } else { wprintz(w_options, c_yellow, " "); } wprintz(w_options, c_white, "%s", (OPTIONS[mPageItems[iCurrentPage][i]].getMenuText()).c_str()); if (OPTIONS[mPageItems[iCurrentPage][i]].getValue() == "false") { cLineColor = c_ltred; } mvwprintz(w_options, i - iStartPos, 62, (iCurrentLine == i) ? hilite(cLineColor) : cLineColor, "%s", (OPTIONS[mPageItems[iCurrentPage][i]].getName()).c_str()); } //Draw Scrollbar draw_scrollbar(w_options_border, iCurrentLine, iContentHeight, mPageItems[iCurrentPage].size(), 5); //Draw Tabs mvwprintz(w_options_header, 0, 7, c_white, ""); for (int i = 0; i < vPages.size(); i++) { if (mPageItems[i].size() > 0) { //skip empty pages wprintz(w_options_header, c_white, "["); wprintz(w_options_header, (iCurrentPage == i) ? hilite(c_ltgreen) : c_ltgreen, (vPages[i].second).c_str()); wprintz(w_options_header, c_white, "]"); wputch(w_options_header, c_white, LINE_OXOX); } } wrefresh(w_options_header); fold_and_print(w_options_tooltip, 0, 0, 78, c_white, "%s", (OPTIONS[mPageItems[iCurrentPage][iCurrentLine]].getTooltip() + " #" + OPTIONS[mPageItems[iCurrentPage][iCurrentLine]].getDefaultText()).c_str()); wrefresh(w_options_tooltip); wrefresh(w_options); ch = input(); if (mPageItems[iCurrentPage].size() > 0 || ch == '\t') { switch(ch) { case 'j': //move down iCurrentLine++; if (iCurrentLine >= mPageItems[iCurrentPage].size()) { iCurrentLine = 0; } break; case 'k': //move up iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = mPageItems[iCurrentPage].size()-1; } break; case 'l': //set to prev value OPTIONS[mPageItems[iCurrentPage][iCurrentLine]].setNext(); bStuffChanged = true; break; case 'h': //set to next value OPTIONS[mPageItems[iCurrentPage][iCurrentLine]].setPrev(); bStuffChanged = true; break; case '>': case '\t': //Switch to next Page iCurrentLine = 0; do { //skip empty pages iCurrentPage++; if (iCurrentPage >= vPages.size()) { iCurrentPage = 0; } } while(mPageItems[iCurrentPage].size() == 0); break; case '<': iCurrentLine = 0; do { //skip empty pages iCurrentPage--; if (iCurrentPage < 0) { iCurrentPage = vPages.size()-1; } } while(mPageItems[iCurrentPage].size() == 0); break; } } } while(ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE); if (bStuffChanged) { if(query_yn(_("Save changes?"))) { save_options(); } else { OPTIONS = OPTIONS_OLD; } } werase(w_options); werase(w_options_border); werase(w_options_header); werase(w_options_tooltip); }
void color_manager::show_gui() { const int iHeaderHeight = 4; const int iContentHeight = FULL_SCREEN_HEIGHT - 2 - iHeaderHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; std::vector<int> vLines; vLines.push_back(-1); vLines.push_back(48); const int iTotalCols = vLines.size(); WINDOW *w_colors_help = newwin((FULL_SCREEN_HEIGHT / 2) - 2, FULL_SCREEN_WIDTH * 3 / 4, 7 + iOffsetY + (FULL_SCREEN_HEIGHT / 2) / 2, iOffsetX + 19 / 2); WINDOW_PTR w_colors_helpptr( w_colors_help ); WINDOW *w_colors_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX); WINDOW_PTR w_colors_borderptr( w_colors_border ); WINDOW *w_colors_header = newwin(iHeaderHeight, FULL_SCREEN_WIDTH - 2, 1 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_colors_headerptr( w_colors_header ); WINDOW *w_colors = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iHeaderHeight + 1 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_colorsptr( w_colors ); draw_border( w_colors_border, BORDER_COLOR, _( " COLOR MANAGER " ) ); mvwputch(w_colors_border, 3, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_colors_border, 3, 79, c_ltgray, LINE_XOXX); // -| for (int i = 0; i < 78; i++) { mvwputch(w_colors_header, 2, i, c_ltgray, LINE_OXOX); // Draw line under header } for( auto &iCol : vLines ) { if ( iCol > -1 ) { mvwputch(w_colors_border, FULL_SCREEN_HEIGHT - 1, iCol + 1, c_ltgray, LINE_XXOX); // _|_ mvwputch(w_colors_header, 2, iCol, c_ltgray, LINE_OXXX); mvwputch(w_colors_header, 3, iCol, c_ltgray, LINE_XOXO); } } wrefresh(w_colors_border); int tmpx = 0; tmpx += shortcut_print(w_colors_header, 0, tmpx, c_white, c_ltgreen, _("<R>emove custom color")) + 2; tmpx += shortcut_print(w_colors_header, 0, tmpx, c_white, c_ltgreen, _("<Arrow Keys> To navigate")) + 2; tmpx += shortcut_print(w_colors_header, 0, tmpx, c_white, c_ltgreen, _("<Enter>-Edit")) + 2; shortcut_print(w_colors_header, 0, tmpx, c_white, c_ltgreen, _("Load <T>emplate")); mvwprintz(w_colors_header, 1, 0, c_white, _("Some color changes may require a restart.")); mvwprintz(w_colors_header, 3, 3, c_white, _("Colorname")); mvwprintz(w_colors_header, 3, 21, c_white, _("Normal")); mvwprintz(w_colors_header, 3, 52, c_white, _("Invert")); wrefresh(w_colors_header); int iCurrentLine = 0; int iCurrentCol = 1; int iStartPos = 0; const int iMaxColors = color_array.size(); bool bStuffChanged = false; input_context ctxt("COLORS"); ctxt.register_cardinal(); ctxt.register_action("CONFIRM"); ctxt.register_action("QUIT"); ctxt.register_action("REMOVE_CUSTOM"); ctxt.register_action("LOAD_TEMPLATE"); ctxt.register_action("HELP_KEYBINDINGS"); std::map<std::string, color_struct> name_color_map; for( const auto &pr : name_map ) { name_color_map[pr.first] = color_array[pr.second]; } while(true) { // Clear all lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { mvwputch(w_colors, i, j, c_black, ' '); for( auto &iCol : vLines ) { if ( iCol == j ) { mvwputch(w_colors, i, j, c_ltgray, LINE_XOXO); } } } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, iMaxColors); draw_scrollbar(w_colors_border, iCurrentLine, iContentHeight, iMaxColors, 5); wrefresh(w_colors_border); auto iter = name_color_map.begin(); std::advance( iter, iStartPos ); std::string sActive = ""; // display colormanager for (int i=iStartPos; iter != name_color_map.end(); ++iter, ++i) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > iMaxColors) ? iMaxColors : iContentHeight)) { auto &entry = iter->second; if (iCurrentLine == i) { sActive = iter->first; mvwprintz(w_colors, i - iStartPos, vLines[iCurrentCol-1] + 2, c_yellow, ">"); } mvwprintz(w_colors, i - iStartPos, 3, c_white, iter->first.c_str()); //colorname mvwprintz(w_colors, i - iStartPos, 21, entry.color, _("default")); //default color if ( !entry.name_custom.empty() ) { mvwprintz(w_colors, i - iStartPos, 30, name_color_map[entry.name_custom].color, entry.name_custom.c_str()); //custom color } mvwprintz(w_colors, i - iStartPos, 52, entry.invert, _("default")); //invert default color if ( !entry.name_invert_custom.empty() ) { mvwprintz(w_colors, i - iStartPos, 61, name_color_map[entry.name_invert_custom].color, entry.name_invert_custom.c_str()); //invert custom color } } } wrefresh(w_colors); const std::string action = ctxt.handle_input(); if (action == "QUIT") { break; } else if (action == "UP") { iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = iMaxColors - 1; } } else if (action == "DOWN") { iCurrentLine++; if (iCurrentLine >= (int)iMaxColors) { iCurrentLine = 0; } } else if (action == "LEFT") { iCurrentCol--; if (iCurrentCol < 1) { iCurrentCol = iTotalCols; } } else if (action == "RIGHT") { iCurrentCol++; if (iCurrentCol > iTotalCols) { iCurrentCol = 1; } } else if (action == "REMOVE_CUSTOM") { auto &entry = name_color_map[sActive]; if ( iCurrentCol == 1 && !entry.name_custom.empty() ) { bStuffChanged = true; entry.name_custom = ""; } else if ( iCurrentCol == 2 && !entry.name_invert_custom.empty() ) { bStuffChanged = true; entry.name_invert_custom = ""; } finalize(); // Need to recalculate caches } else if (action == "LOAD_TEMPLATE") { auto vFiles = get_files_from_path(".json", FILENAMES["color_templates"], false, true); if ( vFiles.size() > 0 ) { uimenu ui_templates; ui_templates.w_y = iHeaderHeight + 1 + iOffsetY; ui_templates.w_height = 18; ui_templates.return_invalid = true; ui_templates.text = _("Color templates:"); for ( const auto& filename : vFiles ) { ui_templates.addentry( filename.substr(filename.find_last_of("/") + 1) ); } ui_templates.addentry(std::string(_("Cancel"))); ui_templates.query(); if ( (size_t)ui_templates.ret < vFiles.size() ) { bStuffChanged = true; clear(); load_default(); load_custom(vFiles[ui_templates.ret]); name_color_map.clear(); for( const auto &pr : name_map ) { name_color_map[pr.first] = color_array[pr.second]; } } } finalize(); // Need to recalculate caches } else if (action == "CONFIRM") { uimenu ui_colors; ui_colors.w_y = iHeaderHeight + 1 + iOffsetY; ui_colors.w_height = 18; ui_colors.return_invalid = true; std::string sColorType = _("Normal"); std::string sSelected = name_color_map[sActive].name_custom; if ( iCurrentCol == 2 ) { sColorType = _("Invert"); sSelected = name_color_map[sActive].name_invert_custom; } ui_colors.text = string_format( _("Custom %s color:"), sColorType.c_str() ); int i = 0; for ( auto &iter : name_color_map ) { std::string sColor = iter.first; std::string sType = _("default"); std::string name_custom = ""; if ( sSelected == sColor ) { ui_colors.selected = i; } if ( !iter.second.name_custom.empty() ) { name_custom = " <color_" + iter.second.name_custom + ">" + iter.second.name_custom + "</color>"; } ui_colors.addentry(string_format( "%-17s <color_%s>%s</color>%s", iter.first.c_str(), sColor.c_str(), sType.c_str(), name_custom.c_str() ) ); i++; } ui_colors.addentry(std::string(_("Cancel"))); ui_colors.query(); if ( (size_t)ui_colors.ret < name_color_map.size() ) { bStuffChanged = true; iter = name_color_map.begin(); std::advance( iter, ui_colors.ret ); auto &entry = name_color_map[sActive]; if ( iCurrentCol == 1 ) { entry.name_custom = iter->first; } else if ( iCurrentCol == 2 ) { entry.name_invert_custom = iter->first; } } finalize(); // Need to recalculate caches } } if( bStuffChanged && query_yn(_("Save changes?") ) ) { for( const auto &pr : name_color_map ) { color_id id = name_to_id( pr.first ); color_array[id].name_custom = pr.second.name_custom; color_array[id].name_invert_custom = pr.second.name_invert_custom; } finalize(); save_custom(); clear(); load_default(); load_custom(); } }
void test_pattern(int iCurrentPage, int iCurrentLine) { std::vector<std::string> vMatchingItems; std::string sItemName = ""; if (vAutoPickupRules[iCurrentPage][iCurrentLine].sRule == "") { return; } //Loop through all itemfactory items //APU now ignores prefixes, bottled items and suffix combinations still not generated for( auto &p : item_controller->get_all_itypes() ) { sItemName = p.second->nname(1); if (vAutoPickupRules[iCurrentPage][iCurrentLine].bActive && auto_pickup_match(sItemName, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule)) { vMatchingItems.push_back(sItemName); } } const int iOffsetX = 15 + ((TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0); const int iOffsetY = 5 + ((TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0); int iStartPos = 0; const int iContentHeight = FULL_SCREEN_HEIGHT - 8; const int iContentWidth = FULL_SCREEN_WIDTH - 30; std::stringstream sTemp; WINDOW *w_test_rule_border = newwin(iContentHeight + 2, iContentWidth, iOffsetY, iOffsetX); WINDOW_PTR w_test_rule_borderptr( w_test_rule_border ); WINDOW *w_test_rule_content = newwin(iContentHeight, iContentWidth - 2, 1 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_test_rule_contentptr( w_test_rule_content ); draw_border(w_test_rule_border); int nmatch = vMatchingItems.size(); std::string buf = string_format(ngettext("%1$d item matches: %2$s", "%1$d items match: %2$s", nmatch), nmatch, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule.c_str()); mvwprintz(w_test_rule_border, 0, iContentWidth / 2 - utf8_width(buf.c_str()) / 2, hilite(c_white), "%s", buf.c_str()); mvwprintz(w_test_rule_border, iContentHeight + 1, 1, red_background(c_white), _("Won't display bottled and suffixes=(fits)")); wrefresh(w_test_rule_border); iCurrentLine = 0; input_context ctxt("AUTO_PICKUP_TEST"); ctxt.register_updown(); ctxt.register_action("QUIT"); while(true) { // Clear the lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { mvwputch(w_test_rule_content, i, j, c_black, ' '); } } calcStartPos(iStartPos, iCurrentLine, iContentHeight, vMatchingItems.size()); // display auto pickup for (int i = iStartPos; i < (int)vMatchingItems.size(); i++) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > (int)vMatchingItems.size()) ? (int)vMatchingItems.size() : iContentHeight)) { nc_color cLineColor = c_white; sTemp.str(""); sTemp << i + 1; mvwprintz(w_test_rule_content, i - iStartPos, 0, cLineColor, "%s", sTemp.str().c_str()); mvwprintz(w_test_rule_content, i - iStartPos, 4, cLineColor, ""); if (iCurrentLine == i) { wprintz(w_test_rule_content, c_yellow, ">> "); } else { wprintz(w_test_rule_content, c_yellow, " "); } wprintz(w_test_rule_content, (iCurrentLine == i) ? hilite(cLineColor) : cLineColor, vMatchingItems[i].c_str()); } } wrefresh(w_test_rule_content); const std::string action = ctxt.handle_input(); if (action == "DOWN") { iCurrentLine++; if (iCurrentLine >= (int)vMatchingItems.size()) { iCurrentLine = 0; } } else if (action == "UP") { iCurrentLine--; if (iCurrentLine < 0) { iCurrentLine = vMatchingItems.size() - 1; } } else { break; } } }
void show_auto_pickup() { save_reset_changes(false); const int iHeaderHeight = 4; const int iContentHeight = FULL_SCREEN_HEIGHT - 2 - iHeaderHeight; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; std::map<int, bool> mapLines; mapLines[4] = true; mapLines[50] = true; mapLines[54] = true; const int iTotalCols = mapLines.size() - 1; WINDOW *w_auto_pickup_help = newwin((FULL_SCREEN_HEIGHT / 2) - 2, FULL_SCREEN_WIDTH * 3 / 4, 7 + iOffsetY + (FULL_SCREEN_HEIGHT / 2) / 2, iOffsetX + 19 / 2); WINDOW_PTR w_auto_pickup_helpptr( w_auto_pickup_help ); WINDOW *w_auto_pickup_border = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX); WINDOW_PTR w_auto_pickup_borderptr( w_auto_pickup_border ); WINDOW *w_auto_pickup_header = newwin(iHeaderHeight, FULL_SCREEN_WIDTH - 2, 1 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_auto_pickup_headerptr( w_auto_pickup_header ); WINDOW *w_auto_pickup = newwin(iContentHeight, FULL_SCREEN_WIDTH - 2, iHeaderHeight + 1 + iOffsetY, 1 + iOffsetX); WINDOW_PTR w_auto_pickupptr( w_auto_pickup ); draw_border(w_auto_pickup_border); mvwputch(w_auto_pickup_border, 3, 0, c_ltgray, LINE_XXXO); // |- mvwputch(w_auto_pickup_border, 3, 79, c_ltgray, LINE_XOXX); // -| for( auto &mapLine : mapLines ) { mvwputch( w_auto_pickup_border, FULL_SCREEN_HEIGHT - 1, mapLine.first + 1, c_ltgray, LINE_XXOX ); // _|_ } mvwprintz(w_auto_pickup_border, 0, 29, c_ltred, _(" AUTO PICKUP MANAGER ")); wrefresh(w_auto_pickup_border); int tmpx = 0; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<A>dd")) + 2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<R>emove")) + 2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<C>opy")) + 2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<M>ove")) + 2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<E>nable")) + 2; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<D>isable")) + 2; shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<T>est")); tmpx = 0; tmpx += shortcut_print(w_auto_pickup_header, 1, tmpx, c_white, c_ltgreen, _("<+-> Move up/down")) + 2; tmpx += shortcut_print(w_auto_pickup_header, 1, tmpx, c_white, c_ltgreen, _("<Enter>-Edit")) + 2; shortcut_print(w_auto_pickup_header, 1, tmpx, c_white, c_ltgreen, _("<Tab>-Switch Page")); for (int i = 0; i < 78; i++) { if (mapLines[i]) { mvwputch(w_auto_pickup_header, 2, i, c_ltgray, LINE_OXXX); mvwputch(w_auto_pickup_header, 3, i, c_ltgray, LINE_XOXO); } else { mvwputch(w_auto_pickup_header, 2, i, c_ltgray, LINE_OXOX); // Draw line under header } } mvwprintz(w_auto_pickup_header, 3, 1, c_white, "#"); mvwprintz(w_auto_pickup_header, 3, 8, c_white, _("Rules")); mvwprintz(w_auto_pickup_header, 3, 51, c_white, _("I/E")); wrefresh(w_auto_pickup_header); int iCurrentPage = 1; int iCurrentLine = 0; int iCurrentCol = 1; int iStartPos = 0; bool bStuffChanged = false; input_context ctxt("AUTO_PICKUP"); ctxt.register_cardinal(); ctxt.register_action("CONFIRM"); ctxt.register_action("QUIT"); ctxt.register_action("NEXT_TAB"); ctxt.register_action("PREV_TAB"); ctxt.register_action("ADD_RULE"); ctxt.register_action("REMOVE_RULE"); ctxt.register_action("COPY_RULE"); ctxt.register_action("SWAP_RULE_GLOBAL_CHAR"); ctxt.register_action("ENABLE_RULE"); ctxt.register_action("DISABLE_RULE"); ctxt.register_action("MOVE_RULE_UP"); ctxt.register_action("MOVE_RULE_DOWN"); ctxt.register_action("TEST_RULE"); ctxt.register_action("SWITCH_AUTO_PICKUP_OPTION"); ctxt.register_action("HELP_KEYBINDINGS"); std::stringstream sTemp; while(true) { int locx = 17; locx += shortcut_print(w_auto_pickup_header, 2, locx, c_white, (iCurrentPage == 1) ? hilite(c_white) : c_white, _("[<Global>]")) + 1; shortcut_print(w_auto_pickup_header, 2, locx, c_white, (iCurrentPage == 2) ? hilite(c_white) : c_white, _("[<Character>]")); locx = 55; mvwprintz(w_auto_pickup_header, 0, locx, c_white, _("Auto pickup enabled:")); locx += shortcut_print(w_auto_pickup_header, 1, locx, ((OPTIONS["AUTO_PICKUP"]) ? c_ltgreen : c_ltred), c_white, ((OPTIONS["AUTO_PICKUP"]) ? _("True") : _("False"))); locx += shortcut_print(w_auto_pickup_header, 1, locx, c_white, c_ltgreen, " "); locx += shortcut_print(w_auto_pickup_header, 1, locx, c_white, c_ltgreen, _("<S>witch")); shortcut_print(w_auto_pickup_header, 1, locx, c_white, c_ltgreen, " "); wrefresh(w_auto_pickup_header); // Clear the lines for (int i = 0; i < iContentHeight; i++) { for (int j = 0; j < 79; j++) { if (mapLines[j]) { mvwputch(w_auto_pickup, i, j, c_ltgray, LINE_XOXO); } else { mvwputch(w_auto_pickup, i, j, c_black, ' '); } } } const bool currentPageNonEmpty = !vAutoPickupRules[iCurrentPage].empty(); if (iCurrentPage == 2 && g->u.name == "") { vAutoPickupRules[2].clear(); mvwprintz(w_auto_pickup, 8, 15, c_white, _("Please load a character first to use this page!")); } //Draw Scrollbar draw_scrollbar(w_auto_pickup_border, iCurrentLine, iContentHeight, vAutoPickupRules[iCurrentPage].size(), 5); calcStartPos(iStartPos, iCurrentLine, iContentHeight, vAutoPickupRules[iCurrentPage].size()); // display auto pickup for (int i = iStartPos; i < (int)vAutoPickupRules[iCurrentPage].size(); i++) { if (i >= iStartPos && i < iStartPos + ((iContentHeight > (int)vAutoPickupRules[iCurrentPage].size()) ? (int)vAutoPickupRules[iCurrentPage].size() : iContentHeight)) { nc_color cLineColor = (vAutoPickupRules[iCurrentPage][i].bActive) ? c_white : c_ltgray; sTemp.str(""); sTemp << i + 1; mvwprintz(w_auto_pickup, i - iStartPos, 1, cLineColor, "%s", sTemp.str().c_str()); mvwprintz(w_auto_pickup, i - iStartPos, 5, cLineColor, ""); if (iCurrentLine == i) { wprintz(w_auto_pickup, c_yellow, ">> "); } else { wprintz(w_auto_pickup, c_yellow, " "); } wprintz(w_auto_pickup, (iCurrentLine == i && iCurrentCol == 1) ? hilite(cLineColor) : cLineColor, "%s", ((vAutoPickupRules[iCurrentPage][i].sRule == "") ? _("<empty rule>") : vAutoPickupRules[iCurrentPage][i].sRule).c_str()); mvwprintz(w_auto_pickup, i - iStartPos, 52, (iCurrentLine == i && iCurrentCol == 2) ? hilite(cLineColor) : cLineColor, "%s", ((vAutoPickupRules[iCurrentPage][i].bExclude) ? rm_prefix(_("<Exclude>E")).c_str() : rm_prefix( _("<Include>I")).c_str())); } } wrefresh(w_auto_pickup); const std::string action = ctxt.handle_input(); if (action == "NEXT_TAB") { iCurrentPage++; if (iCurrentPage > 2) { iCurrentPage = 1; iCurrentLine = 0; } } else if (action == "PREV_TAB") { iCurrentPage--; if (iCurrentPage < 1) { iCurrentPage = 2; iCurrentLine = 0; } } else if (action == "QUIT") { break; } else if (iCurrentPage == 2 && g->u.name.empty()) { //Only allow loaded games to use the char sheet } else if (action == "DOWN") { iCurrentLine++; iCurrentCol = 1; if (iCurrentLine >= (int)vAutoPickupRules[iCurrentPage].size()) { iCurrentLine = 0; } } else if (action == "UP") { iCurrentLine--; iCurrentCol = 1; if (iCurrentLine < 0) { iCurrentLine = vAutoPickupRules[iCurrentPage].size() - 1; } } else if (action == "ADD_RULE") { bStuffChanged = true; vAutoPickupRules[iCurrentPage].push_back(cPickupRules("", true, false)); iCurrentLine = vAutoPickupRules[iCurrentPage].size() - 1; } else if (action == "REMOVE_RULE" && currentPageNonEmpty) { bStuffChanged = true; vAutoPickupRules[iCurrentPage].erase(vAutoPickupRules[iCurrentPage].begin() + iCurrentLine); if (iCurrentLine > (int)vAutoPickupRules[iCurrentPage].size() - 1) { iCurrentLine--; } if(iCurrentLine < 0){ iCurrentLine = 0; } } else if (action == "COPY_RULE" && currentPageNonEmpty) { bStuffChanged = true; vAutoPickupRules[iCurrentPage].push_back(cPickupRules( vAutoPickupRules[iCurrentPage][iCurrentLine].sRule, vAutoPickupRules[iCurrentPage][iCurrentLine].bActive, vAutoPickupRules[iCurrentPage][iCurrentLine].bExclude)); iCurrentLine = vAutoPickupRules[iCurrentPage].size() - 1; } else if (action == "SWAP_RULE_GLOBAL_CHAR" && currentPageNonEmpty) { if ((iCurrentPage == 1 && g->u.name != "") || iCurrentPage == 2) { bStuffChanged = true; //copy over vAutoPickupRules[(iCurrentPage == 1) ? 2 : 1].push_back(cPickupRules( vAutoPickupRules[iCurrentPage][iCurrentLine].sRule, vAutoPickupRules[iCurrentPage][iCurrentLine].bActive, vAutoPickupRules[iCurrentPage][iCurrentLine].bExclude)); //remove old vAutoPickupRules[iCurrentPage].erase(vAutoPickupRules[iCurrentPage].begin() + iCurrentLine); iCurrentLine = vAutoPickupRules[(iCurrentPage == 1) ? 2 : 1].size() - 1; iCurrentPage = (iCurrentPage == 1) ? 2 : 1; } } else if (action == "CONFIRM" && currentPageNonEmpty) { bStuffChanged = true; if (iCurrentCol == 1) { fold_and_print(w_auto_pickup_help, 1, 1, 999, c_white, _( "* is used as a Wildcard. A few Examples:\n" "\n" "wooden arrow matches the itemname exactly\n" "wooden ar* matches items beginning with wood ar\n" "*rrow matches items ending with rrow\n" "*avy fle*fi*arrow multiple * are allowed\n" "heAVY*woOD*arrOW case insensitive search\n" "") ); draw_border(w_auto_pickup_help); wrefresh(w_auto_pickup_help); vAutoPickupRules[iCurrentPage][iCurrentLine].sRule = trim_rule(string_input_popup(_("Pickup Rule:"), 30, vAutoPickupRules[iCurrentPage][iCurrentLine].sRule)); } else if (iCurrentCol == 2) { vAutoPickupRules[iCurrentPage][iCurrentLine].bExclude = !vAutoPickupRules[iCurrentPage][iCurrentLine].bExclude; } } else if (action == "ENABLE_RULE" && currentPageNonEmpty) { bStuffChanged = true; vAutoPickupRules[iCurrentPage][iCurrentLine].bActive = true; } else if (action == "DISABLE_RULE" && currentPageNonEmpty) { bStuffChanged = true; vAutoPickupRules[iCurrentPage][iCurrentLine].bActive = false; } else if (action == "LEFT") { iCurrentCol--; if (iCurrentCol < 1) { iCurrentCol = iTotalCols; } } else if (action == "RIGHT") { iCurrentCol++; if (iCurrentCol > iTotalCols) { iCurrentCol = 1; } } else if (action == "MOVE_RULE_UP" && currentPageNonEmpty) { bStuffChanged = true; if (iCurrentLine < (int)vAutoPickupRules[iCurrentPage].size() - 1) { std::swap(vAutoPickupRules[iCurrentPage][iCurrentLine], vAutoPickupRules[iCurrentPage][iCurrentLine + 1]); iCurrentLine++; iCurrentCol = 1; } } else if (action == "MOVE_RULE_DOWN" && currentPageNonEmpty) { bStuffChanged = true; if (iCurrentLine > 0) { std::swap(vAutoPickupRules[iCurrentPage][iCurrentLine], vAutoPickupRules[iCurrentPage][iCurrentLine - 1]); iCurrentLine--; iCurrentCol = 1; } } else if (action == "TEST_RULE" && currentPageNonEmpty) { test_pattern(iCurrentPage, iCurrentLine); } else if (action == "SWITCH_AUTO_PICKUP_OPTION") { OPTIONS["AUTO_PICKUP"].setNext(); save_options((g->u.name != "")); } } if (bStuffChanged) { if(query_yn(_("Save changes?"))) { save_auto_pickup(false); if (g->u.name != "") { save_auto_pickup(true); } } else { save_reset_changes(true); } } }
void construction_menu() { static bool hide_unconstructable = false; // only display constructions the player can theoretically perform std::vector<std::string> available; std::map<std::string, std::vector<std::string>> cat_available; load_available_constructions( available, cat_available, hide_unconstructable ); if( available.empty() ) { popup( _( "You can not construct anything here." ) ); return; } int w_height = TERMY; if( ( int )available.size() + 2 < w_height ) { w_height = available.size() + 2; } if( w_height < FULL_SCREEN_HEIGHT ) { w_height = FULL_SCREEN_HEIGHT; } const int w_width = std::max( FULL_SCREEN_WIDTH, TERMX * 2 / 3); const int w_y0 = ( TERMY > w_height ) ? ( TERMY - w_height ) / 2 : 0; const int w_x0 = ( TERMX > w_width ) ? ( TERMX - w_width ) / 2 : 0; WINDOW_PTR w_con_ptr {newwin( w_height, w_width, w_y0, w_x0 )}; WINDOW *const w_con = w_con_ptr.get(); const int w_list_width = int( .375 * w_width ); const int w_list_height = w_height - 4; const int w_list_x0 = 1; WINDOW_PTR w_list_ptr {newwin( w_list_height, w_list_width, w_y0 + 3, w_x0 + w_list_x0 )}; WINDOW *const w_list = w_list_ptr.get(); draw_grid( w_con, w_list_width + w_list_x0 ); //tabcount needs to be increased to add more categories int tabcount = 10; std::string construct_cat[] = {_( "All" ), _( "Constructions" ), _( "Furniture" ), _( "Digging and Mining" ), _( "Repairing" ), _( "Reinforcing" ), _( "Decorative" ), _( "Farming and Woodcutting" ), _( "Others" ), _( "Filter" ) }; bool update_info = true; bool update_cat = true; bool isnew = true; int tabindex = 0; int select = 0; int offset = 0; bool exit = false; std::string category_name = ""; std::vector<std::string> constructs; //storage for the color text so it can be scrolled std::vector< std::vector < std::string > > construct_buffers; std::vector<std::string> full_construct_buffer; std::vector<int> construct_buffer_breakpoints; int total_project_breakpoints = 0; int current_construct_breakpoint = 0; bool previous_hide_unconstructable = false; //track the cursor to determine when to refresh the list of construction recipes int previous_tabindex = -1; int previous_select = -1; const inventory &total_inv = g->u.crafting_inventory(); input_context ctxt( "CONSTRUCTION" ); ctxt.register_action( "UP", _( "Move cursor up" ) ); ctxt.register_action( "DOWN", _( "Move cursor down" ) ); ctxt.register_action( "RIGHT", _( "Move tab right" ) ); ctxt.register_action( "LEFT", _( "Move tab left" ) ); ctxt.register_action( "PAGE_UP" ); ctxt.register_action( "PAGE_DOWN" ); ctxt.register_action( "CONFIRM" ); ctxt.register_action( "TOGGLE_UNAVAILABLE_CONSTRUCTIONS" ); ctxt.register_action( "QUIT" ); ctxt.register_action( "HELP_KEYBINDINGS" ); ctxt.register_action( "FILTER" ); std::string filter; int previous_index = 0; do { if( update_cat ) { update_cat = false; switch( tabindex ) { case 0: category_name = "ALL"; break; case 1: category_name = "CONSTRUCT"; break; case 2: category_name = "FURN"; break; case 3: category_name = "DIG"; break; case 4: category_name = "REPAIR"; break; case 5: category_name = "REINFORCE"; break; case 6: category_name = "DECORATE"; break; case 7: category_name = "FARM_WOOD"; break; case 8: category_name = "OTHER"; break; case 9: category_name = "FILTER"; break; } if( category_name == "ALL" ) { constructs = available; previous_index = tabindex; } else if( category_name == "FILTER" ) { constructs.clear(); std::copy_if( available.begin(), available.end(), std::back_inserter( constructs ), [&](const std::string &a){ return lcmatch(a, filter); } ); } else { constructs = cat_available[category_name]; previous_index = tabindex; } if( isnew ){ if( !uistate.last_construction.empty() ){ select = std::distance(constructs.begin(), std::find( constructs.begin(), constructs.end(), uistate.last_construction )); } filter = uistate.construction_filter; } } // Erase existing tab selection & list of constructions mvwhline( w_con, 1, 1, ' ', w_list_width ); werase( w_list ); // Print new tab listing mvwprintz( w_con, 1, 1, c_yellow, "<< %s >>", construct_cat[tabindex].c_str() ); // Determine where in the master list to start printing calcStartPos( offset, select, w_list_height, constructs.size() ); // Print the constructions between offset and max (or how many will fit) for( size_t i = 0; ( int )i < w_list_height && ( i + offset ) < constructs.size(); i++ ) { int current = i + offset; std::string con_name = constructs[current]; bool highlight = ( current == select ); trim_and_print( w_list, i, 0, w_list_width, construction_color( con_name, highlight ), "%s", con_name.c_str() ); } if( update_info ) { update_info = false; // Clear out lines for tools & materials const int pos_x = w_list_width + w_list_x0 + 2; const int available_window_width = w_width - pos_x - 1; for( int i = 1; i < w_height - 1; i++ ) { mvwhline( w_con, i, pos_x, ' ', available_window_width ); } nc_color color_stage = c_white; std::vector<std::string> notes; notes.push_back( string_format( _( "Press %s or %s to tab." ), ctxt.get_desc( "LEFT" ).c_str(), ctxt.get_desc( "RIGHT" ).c_str() ) ); notes.push_back( string_format( _( "Press %s to search." ), ctxt.get_desc( "FILTER" ).c_str() ) ); notes.push_back( string_format( _( "Press %s to toggle unavailable constructions." ), ctxt.get_desc( "TOGGLE_UNAVAILABLE_CONSTRUCTIONS" ).c_str() ) ); notes.push_back( string_format( _( "Press %s to view and edit key-bindings." ), ctxt.get_desc( "HELP_KEYBINDINGS" ).c_str() ) ); //leave room for top and bottom UI text const int available_buffer_height = w_height - 3 - 3 - (int)notes.size(); // print the hotkeys regardless of if there are constructions for( size_t i = 0; i < notes.size(); ++i ) { trim_and_print( w_con, w_height - 1 - (int)notes.size() + (int)i, pos_x, available_window_width, c_white, "%s", notes[i].c_str() ); } if( !constructs.empty() ) { if( select >= (int) constructs.size() ){ select = 0; } std::string current_desc = constructs[select]; // Print construction name trim_and_print( w_con, 1, pos_x, available_window_width, c_white, "%s", current_desc.c_str() ); //only reconstruct the project list when moving away from the current item, or when changing the display mode if( previous_select != select || previous_tabindex != tabindex || previous_hide_unconstructable != hide_unconstructable ) { previous_select = select; previous_tabindex = tabindex; previous_hide_unconstructable = hide_unconstructable; //construct the project list buffer // Print stages and their requirement. std::vector<construction *> options = constructions_by_desc( current_desc ); construct_buffers.clear(); total_project_breakpoints = 0; current_construct_breakpoint = 0; construct_buffer_breakpoints.clear(); full_construct_buffer.clear(); int stage_counter = 0; for( std::vector<construction *>::iterator it = options.begin(); it != options.end(); ++it ) { stage_counter++; construction *current_con = *it; if( hide_unconstructable && !can_construct( *current_con ) ) { continue; } // Update the cached availability of components and tools in the requirement object current_con->requirements->can_make_with_inventory( total_inv ); std::vector<std::string> current_buffer; std::ostringstream current_line; // display result only if more than one step. // Assume single stage constructions should be clear // in their description what their result is. if( current_con->post_terrain != "" && options.size() > 1 ) { //also print out stage number when multiple stages are available current_line << _( "Stage #" ) << stage_counter; current_buffer.push_back( current_line.str() ); current_line.str( "" ); std::string result_string; if( current_con->post_is_furniture ) { result_string = furn_str_id( current_con->post_terrain ).obj().name; } else { result_string = ter_str_id( current_con->post_terrain ).obj().name; } current_line << "<color_" << string_from_color( color_stage ) << ">" << string_format( _( "Result: %s" ), result_string.c_str() ) << "</color>"; std::vector<std::string> folded_result_string = foldstring( current_line.str(), available_window_width ); current_buffer.insert( current_buffer.end(), folded_result_string.begin(), folded_result_string.end() ); } current_line.str( "" ); // display required skill and difficulty int pskill = g->u.get_skill_level( current_con->skill ); int diff = ( current_con->difficulty > 0 ) ? current_con->difficulty : 0; current_line << "<color_" << string_from_color( ( pskill >= diff ? c_white : c_red ) ) << ">" << string_format( _( "Skill Req: %d (%s)" ), diff, current_con->skill.obj().name().c_str() ) << "</color>"; current_buffer.push_back( current_line.str() ); // TODO: Textify pre_flags to provide a bit more information. // Example: First step of dig pit could say something about // requiring diggable ground. current_line.str( "" ); if( current_con->pre_terrain != "" ) { std::string require_string; if( current_con->pre_is_furniture ) { require_string = furn_str_id( current_con->pre_terrain ).obj().name; } else { require_string = ter_str_id( current_con->pre_terrain ).obj().name; } current_line << "<color_" << string_from_color( color_stage ) << ">" << string_format( _( "Requires: %s" ), require_string.c_str() ) << "</color>"; std::vector<std::string> folded_result_string = foldstring( current_line.str(), available_window_width ); current_buffer.insert( current_buffer.end(), folded_result_string.begin(), folded_result_string.end() ); } // get pre-folded versions of the rest of the construction project to be displayed later // get time needed std::vector<std::string> folded_time = current_con->get_folded_time_string( available_window_width ); current_buffer.insert( current_buffer.end(), folded_time.begin(), folded_time.end() ); std::vector<std::string> folded_tools = current_con->requirements->get_folded_tools_list( available_window_width, color_stage, total_inv ); current_buffer.insert( current_buffer.end(), folded_tools.begin(), folded_tools.end() ); std::vector<std::string> folded_components = current_con->requirements->get_folded_components_list( available_window_width, color_stage, total_inv ); current_buffer.insert( current_buffer.end(), folded_components.begin(), folded_components.end() ); construct_buffers.push_back( current_buffer ); } //determine where the printing starts for each project, so it can be scrolled to those points size_t current_buffer_location = 0; for( size_t i = 0; i < construct_buffers.size(); i++ ) { construct_buffer_breakpoints.push_back( static_cast<int>( current_buffer_location ) ); full_construct_buffer.insert( full_construct_buffer.end(), construct_buffers[i].begin(), construct_buffers[i].end() ); //handle text too large for one screen if( construct_buffers[i].size() > static_cast<size_t>( available_buffer_height ) ) { construct_buffer_breakpoints.push_back( static_cast<int>( current_buffer_location + static_cast<size_t>( available_buffer_height ) ) ); } current_buffer_location += construct_buffers[i].size(); if( i < construct_buffers.size() - 1 ) { full_construct_buffer.push_back( std::string( "" ) ); current_buffer_location++; } } total_project_breakpoints = static_cast<int>( construct_buffer_breakpoints.size() ); } if( current_construct_breakpoint > 0 ) { // Print previous stage indicator if breakpoint is past the beginning trim_and_print( w_con, 2, pos_x, available_window_width, c_white, _( "Press %s to show previous stage(s)." ), ctxt.get_desc( "PAGE_UP" ).c_str() ); } if( static_cast<size_t>( construct_buffer_breakpoints[current_construct_breakpoint] + available_buffer_height ) < full_construct_buffer.size() ) { // Print next stage indicator if more breakpoints are remaining after screen height trim_and_print( w_con, w_height - 2 - (int)notes.size(), pos_x, available_window_width, c_white, _( "Press %s to show next stage(s)." ), ctxt.get_desc( "PAGE_DOWN" ).c_str() ); } // Leave room for above/below indicators int ypos = 3; nc_color stored_color = color_stage; for( size_t i = static_cast<size_t>( construct_buffer_breakpoints[current_construct_breakpoint] ); i < full_construct_buffer.size(); i++ ) { //the value of 3 is from leaving room at the top of window if( ypos > available_buffer_height + 3 ) { break; } print_colored_text( w_con, ypos++, ( w_list_width + w_list_x0 + 2 ), stored_color, color_stage, full_construct_buffer[i] ); } } } // Finished updating draw_scrollbar( w_con, select, w_list_height, constructs.size(), 3 ); wrefresh( w_con ); wrefresh( w_list ); const std::string action = ctxt.handle_input(); if( action == "FILTER" ){ filter = string_input_popup( _( "Search" ), 50, filter, "", _( "Filter" ), 100, false ); if( !filter.empty() ){ update_info = true; update_cat = true; tabindex = 9; select = 0; }else if( previous_index !=9 ){ tabindex = previous_index; update_info = true; update_cat = true; select = 0; } uistate.construction_filter = filter; } else if( action == "DOWN" ) { update_info = true; if( select < ( int )constructs.size() - 1 ) { select++; } else { select = 0; } } else if( action == "UP" ) { update_info = true; if( select > 0 ) { select--; } else { select = constructs.size() - 1; } } else if( action == "LEFT" ) { update_info = true; update_cat = true; select = 0; tabindex--; if( tabindex < 0 ) { tabindex = tabcount - 1; } } else if( action == "RIGHT" ) { update_info = true; update_cat = true; select = 0; tabindex = ( tabindex + 1 ) % tabcount; } else if( action == "PAGE_UP" ) { update_info = true; if( current_construct_breakpoint > 0 ) { current_construct_breakpoint--; } if( current_construct_breakpoint < 0 ) { current_construct_breakpoint = 0; } } else if( action == "PAGE_DOWN" ) { update_info = true; if( current_construct_breakpoint < total_project_breakpoints - 1 ) { current_construct_breakpoint++; } if( current_construct_breakpoint >= total_project_breakpoints ) { current_construct_breakpoint = total_project_breakpoints - 1; } } else if( action == "QUIT" ) { exit = true; } else if( action == "HELP_KEYBINDINGS" ) { draw_grid( w_con, w_list_width + w_list_x0 ); } else if( action == "TOGGLE_UNAVAILABLE_CONSTRUCTIONS" ) { update_info = true; update_cat = true; hide_unconstructable = !hide_unconstructable; select = 0; offset = 0; load_available_constructions( available, cat_available, hide_unconstructable ); } else if( action == "CONFIRM" ) { if( constructs.empty() || select >= (int) constructs.size() ){ continue;// Nothing to be done here } if( player_can_build( g->u, total_inv, constructs[select] ) ) { place_construction( constructs[select] ); uistate.last_construction = constructs[select]; exit = true; } else { popup( _( "You can't build that!" ) ); draw_grid( w_con, w_list_width + w_list_x0 ); update_info = true; } } } while( !exit ); w_list_ptr.reset(); w_con_ptr.reset(); g->refresh_all(); }
/* * Generate and refresh output */ void uimenu::show() { if (!started) { setup(); } std::string padspaces = std::string(w_width - 2 - pad_left - pad_right, ' '); const int text_lines = textformatted.size(); for ( int i = 0; i < text_lines; i++ ) { trim_and_print(window, 1 + i, 2, getmaxx(window) - 4, text_color, "%s", textformatted[i].c_str()); } mvwputch(window, text_lines + 1, 0, border_color, LINE_XXXO); for ( int i = 1; i < w_width - 1; ++i) { mvwputch(window, text_lines + 1, i, border_color, LINE_OXOX); } mvwputch(window, text_lines + 1, w_width - 1, border_color, LINE_XOXX); int estart = text_lines + 2; calcStartPos( vshift, fselected, vmax, fentries.size() ); for ( int fei = vshift, si = 0; si < vmax; fei++, si++ ) { if ( fei < (int)fentries.size() ) { int ei = fentries [ fei ]; nc_color co = ( ei == selected ? hilight_color : ( entries[ ei ].enabled ? entries[ ei ].text_color : disabled_color ) ); if ( hilight_full ) { mvwprintz(window, estart + si, pad_left + 1, co , "%s", padspaces.c_str()); } if(entries[ ei ].enabled && entries[ ei ].hotkey >= 33 && entries[ ei ].hotkey < 126 ) { mvwprintz( window, estart + si, pad_left + 2, ( ei == selected ) ? hilight_color : hotkey_color , "%c", entries[ ei ].hotkey ); } if( padspaces.size() > 3 ) { // padspaces's length indicates the maximal width of the entry, it is used above to // activate the highlighting, it is used to override previous text there, but in both // cases printeing starts at pad_left+1, here it starts at pad_left+4, so 3 cells less // to be used. const auto entry = utf8_wrapper( entries[ ei ].txt ); trim_and_print( window, estart + si, pad_left + 4, w_width - 2 - pad_left - pad_right, co, "%s", entry.c_str() ); } if ( !entries[ei].extratxt.txt.empty() ) { mvwprintz( window, estart + si, pad_left + 1 + entries[ ei ].extratxt.left, entries[ ei ].extratxt.color, "%s", entries[ ei ].extratxt.txt.c_str() ); } if ( entries[ei].extratxt.sym != 0 ) { mvwputch ( window, estart + si, pad_left + 1 + entries[ ei ].extratxt.left, entries[ ei ].extratxt.color, entries[ ei ].extratxt.sym ); } if ( callback != NULL && ei == selected ) { callback->select(ei, this); } } else { mvwprintz(window, estart + si, pad_left + 1, c_ltgray , "%s", padspaces.c_str()); } } if ( desc_enabled ) { // draw border mvwputch(window, w_height - desc_lines - 2, 0, border_color, LINE_XXXO); for ( int i = 1; i < w_width - 1; ++i) { mvwputch(window, w_height - desc_lines - 2, i, border_color, LINE_OXOX); } mvwputch(window, w_height - desc_lines - 2, w_width - 1, border_color, LINE_XOXX); // clear previous desc the ugly way for ( int y = desc_lines + 1; y > 1; --y ) { for ( int x = 2; x < w_width - 2; ++x) { mvwputch(window, w_height - y, x, text_color, " "); } } // draw description fold_and_print(window, w_height - desc_lines - 1, 2, w_width - 4, text_color, entries[selected].desc.c_str()); } if ( !filter.empty() ) { mvwprintz( window, w_height - 1, 2, border_color, "< %s >", filter.c_str() ); mvwprintz( window, w_height - 1, 4, text_color, "%s", filter.c_str() ); } apply_scrollbar(); this->refresh(true); }