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 game::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; //mapLines[61] = true; //mapLines[68] = 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; tmpx += shortcut_print(w_auto_pickup_header, 0, tmpx, c_white, c_ltgreen, _("<T>est"))+2; 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; tmpx += shortcut_print(w_auto_pickup_header, 1, tmpx, c_white, c_ltgreen, _("<Tab>-Switch Page"))+2; 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")); //mvwprintz(w_auto_pickup_header, 3, 55, c_white, "Volume"); //mvwprintz(w_auto_pickup_header, 3, 62, c_white, "Weight"); 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; locx = shortcut_print(w_auto_pickup_header, 2, locx, c_white, (iCurrentPage == 2) ? hilite(c_white) : c_white, _("[<Character>]"))+1; /* mvwprintz(w_auto_pickup_header, 2, 12 + 21, c_white, "["); wprintz(w_auto_pickup_header, (iCurrentPage == 3) ? hilite(c_white) : c_white, "Options"); wprintz(w_auto_pickup_header, c_white, "]"); */ 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 = 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); }
void main_menu::world_tab() { while( sel1 == 3 && ( layer == 2 || layer == 3 ) ) { print_menu( w_open, 3, iMenuOffsetX, iMenuOffsetY, true ); if( layer == 3 ) { // World Menu // Show options for Destroy, Reset worlds. // Reset and Destroy ask for world to modify. // Reset empties world of everything but options, then makes new world within it. // Destroy asks for confirmation, then destroys everything in world and then removes world folder. int xoffset = 40 + iMenuOffsetX + extra_w / 2; int yoffset = iMenuOffsetY - 2 - sel2; const auto all_worldnames = world_generator->all_worldnames(); mvwprintz( w_open, yoffset, xoffset - 15, h_white, all_worldnames[sel2 - 1].c_str() ); for( size_t i = 0; i < vWorldSubItems.size(); ++i ) { nc_color text_color; nc_color key_color; if( sel3 == static_cast<int>( i ) ) { text_color = h_white; key_color = h_white; } else { text_color = c_ltgray; key_color = c_white; } wmove( w_open, yoffset - i, xoffset ); wprintz( w_open, c_ltgray, "[" ); shortcut_print( w_open, text_color, key_color, vWorldSubItems[i] ); wprintz( w_open, c_ltgray, "]" ); } wrefresh( w_open ); refresh(); std::string action = ctxt.handle_input(); std::string sInput = ctxt.get_raw_input().text; for( size_t i = 0; i < vWorldSubItems.size(); ++i ) { for( auto hotkey : vWorldHotkeys[i] ) { if( sInput == hotkey ) { sel3 = i; action = "CONFIRM"; } } } if( action == "DOWN" ) { if( sel3 > 0 ) { --sel3; } else { sel3 = vWorldSubItems.size() - 1; } on_move(); } else if( action == "UP" ) { if( sel3 < static_cast<int>( vWorldSubItems.size() ) - 1 ) { ++sel3; } else { sel3 = 0; } on_move(); } else if( action == "LEFT" || action == "QUIT" ) { layer = 2; } if( action == "RIGHT" || action == "CONFIRM" ) { if( sel3 == 2 ) { // Active World Mods WORLDPTR world = world_generator->get_world( all_worldnames[sel2 - 1] ); world_generator->show_active_world_mods( world->active_mod_order ); } else { bool query_yes = false; bool do_delete = false; if( sel3 == 0 ) { // Delete World if( query_yn( _( "Delete the world and all saves?" ) ) ) { query_yes = true; do_delete = true; } } else if( sel3 == 1 ) { // Reset World if( query_yn( _( "Remove all saves and regenerate world?" ) ) ) { query_yes = true; do_delete = false; } } if( query_yes ) { layer = 2; // Go to world submenu, not list of worlds world_generator->delete_world( all_worldnames[sel2 - 1], do_delete ); savegames.clear(); MAPBUFFER.reset(); overmap_buffer.clear(); if( do_delete ) { sel2 = 0; // reset to create world selection } } } } } else if( layer == 2 ) { // Show world names if( MAP_SHARING::isSharing() && !MAP_SHARING::isWorldmenu() && !MAP_SHARING::isAdmin() ) { layer = 1; popup( _( "Only the admin can change worlds." ) ); continue; } mvwprintz( w_open, iMenuOffsetY - 2, 25 + iMenuOffsetX + extra_w / 2, ( sel2 == 0 ? h_white : c_white ), _( "Create World" ) ); int i = 1; const auto all_worldnames = world_generator->all_worldnames(); for( auto it = all_worldnames.begin(); it != all_worldnames.end(); ++it, i++ ) { int savegames_count = world_generator->get_world( *it )->world_saves.size(); int line = iMenuOffsetY - 2 - i; nc_color color1, color2; if( *it == "TUTORIAL" || *it == "DEFENSE" ) { color1 = c_ltcyan; color2 = h_ltcyan; } else { color1 = c_white; color2 = h_white; } mvwprintz( w_open, line, 25 + iMenuOffsetX + extra_w / 2, ( sel2 == i ? color2 : color1 ), "%s (%d)", ( *it ).c_str(), savegames_count ); } wrefresh( w_open ); refresh(); std::string action = ctxt.handle_input(); if( action == "DOWN" ) { if( sel2 > 0 ) { --sel2; } else { sel2 = all_worldnames.size(); } } else if( action == "UP" ) { if( sel2 < ( int )all_worldnames.size() ) { ++sel2; } else { sel2 = 0; } } else if( action == "LEFT" || action == "QUIT" ) { layer = 1; } if( action == "RIGHT" || action == "CONFIRM" ) { if( sel2 == 0 ) { world_generator->make_new_world(); } else { layer = 3; sel3 = 0; } } } } // end while layer == ... }
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); } } }
int draw_item_info(WINDOW *win, const std::string sItemName, std::vector<iteminfo> &vItemDisplay, std::vector<iteminfo> &vItemCompare, const int selected, const bool without_getch, const bool without_border) { int line_num = 1; if (sItemName != "") { mvwprintz(win, line_num, (without_border) ? 0 : 2, c_white, "%s", sItemName.c_str()); line_num = 3; } int iStartX = 0; bool bStartNewLine = true; int selected_ret = '\n'; std::string spaces(getmaxx(win), ' '); for (int i = 0; i < vItemDisplay.size(); i++) { if (vItemDisplay[i].sType == "MENU") { if (vItemDisplay[i].sFmt == "iOffsetY") { line_num += int(vItemDisplay[i].dValue); } else if (vItemDisplay[i].sFmt == "iOffsetX") { iStartX = int(vItemDisplay[i].dValue); } else { nc_color nameColor = c_ltgreen; //pre-existing behavior, so make it the default //patched to allow variable "name" coloring, e.g. for item examining nc_color bgColor = c_white; //yes the name makes no sense if (vItemDisplay[i].dValue >= 0) { if (vItemDisplay[i].dValue < .1 && vItemDisplay[i].dValue > -.1) { nameColor = c_ltgray; } else { nameColor = c_ltred; } } if ( i == selected && vItemDisplay[i].sName != "" ) { bgColor = h_white; selected_ret = (int)vItemDisplay[i].sName.c_str()[0]; // fixme: sanity check(?) } mvwprintz(win, line_num, 0, bgColor, "%s", spaces.c_str() ); shortcut_print(win, line_num, iStartX, bgColor, nameColor, vItemDisplay[i].sFmt); line_num++; } } else if (vItemDisplay[i].sType == "DESCRIPTION") { line_num++; if (vItemDisplay[i].bDrawName) { line_num += fold_and_print(win, line_num, (without_border) ? 1 : 2, getmaxx(win) - 4, c_white, vItemDisplay[i].sName); } } else { if (bStartNewLine) { if (vItemDisplay[i].bDrawName) { mvwprintz(win, line_num, (without_border) ? 1 : 2, c_white, "%s", (vItemDisplay[i].sName).c_str()); } bStartNewLine = false; } else { if (vItemDisplay[i].bDrawName) { wprintz(win, c_white, "%s", vItemDisplay[i].sName.c_str()); } } std::string sPlus = vItemDisplay[i].sPlus; std::string sFmt = vItemDisplay[i].sFmt; std::string sNum = " "; std::string sPost = ""; //A bit tricky, find %d and split the string size_t pos = sFmt.find("<num>"); if(pos != std::string::npos) { wprintz(win, c_white, "%s", sFmt.substr(0, pos).c_str()); sPost = sFmt.substr(pos + 5); } else { wprintz(win, c_white, "%s", sFmt.c_str()); } if (vItemDisplay[i].sValue != "-999") { nc_color thisColor = c_white; for (int k = 0; k < vItemCompare.size(); k++) { if (vItemCompare[k].sValue != "-999") { if (vItemDisplay[i].sName == vItemCompare[k].sName) { if (vItemDisplay[i].dValue > vItemCompare[k].dValue - .1 && vItemDisplay[i].dValue < vItemCompare[k].dValue + .1) { thisColor = c_white; } else if (vItemDisplay[i].dValue > vItemCompare[k].dValue) { if (vItemDisplay[i].bLowerIsBetter) { thisColor = c_ltred; } else { thisColor = c_ltgreen; } } else if (vItemDisplay[i].dValue < vItemCompare[k].dValue) { if (vItemDisplay[i].bLowerIsBetter) { thisColor = c_ltgreen; } else { thisColor = c_ltred; } } break; } } } if (vItemDisplay[i].is_int == true) { wprintz(win, thisColor, "%s%.0f", sPlus.c_str(), vItemDisplay[i].dValue); } else { wprintz(win, thisColor, "%s%.1f", sPlus.c_str(), vItemDisplay[i].dValue); } } wprintz(win, c_white, "%s", sPost.c_str()); if (vItemDisplay[i].bNewLine) { line_num++; bStartNewLine = true; } } } if (!without_border) { draw_border(win); wrefresh(win); } int ch = (int)' '; if (!without_getch) { ch = (int)getch(); if ( selected > 0 && ( ch == '\n' || ch == KEY_RIGHT ) && selected_ret != 0 ) { ch = selected_ret; } else if ( selected == KEY_LEFT ) { ch = (int)' '; } delwin(win); } return ch; }
//note that passing in iteminfo instances with sType == "MENU" or "DESCRIPTION" does special things //if sType == "MENU", sFmt == "iOffsetY" or "iOffsetX" also do special things //otherwise if sType == "MENU", dValue can be used to control color //all this should probably be cleaned up at some point, rather than using a function for things it wasn't meant for // well frack, half the game uses it so: optional (int)selected argument causes entry highlight, and enter to return entry's key. Also it now returns int int compare_split_screen_popup(int iLeft, int iWidth, int iHeight, std::string sItemName, std::vector<iteminfo> vItemDisplay, std::vector<iteminfo> vItemCompare, int selected) { WINDOW* w = newwin(iHeight, iWidth, VIEW_OFFSET_Y, iLeft + VIEW_OFFSET_X); mvwprintz(w, 1, 2, c_white, sItemName.c_str()); int line_num = 3; int iStartX = 0; bool bStartNewLine = true; int selected_ret='\n'; std::string spaces(iWidth-2, ' '); for (int i = 0; i < vItemDisplay.size(); i++) { if (vItemDisplay[i].sType == "MENU") { if (vItemDisplay[i].sFmt == "iOffsetY") { line_num += int(vItemDisplay[i].dValue); } else if (vItemDisplay[i].sFmt == "iOffsetX") { iStartX = int(vItemDisplay[i].dValue); } else { nc_color nameColor = c_ltgreen; //pre-existing behavior, so make it the default //patched to allow variable "name" coloring, e.g. for item examining nc_color bgColor = c_white; //yes the name makes no sense if (vItemDisplay[i].dValue >= 0) { if (vItemDisplay[i].dValue < .1 && vItemDisplay[i].dValue > -.1){ nameColor = c_ltgray; } else { nameColor = c_ltred; } } if ( i == selected && vItemDisplay[i].sName != "" ) { bgColor = h_white; selected_ret=(int)vItemDisplay[i].sName.c_str()[0]; // fixme: sanity check(?) } mvwprintz(w, line_num, 1, bgColor, "%s", spaces.c_str() ); shortcut_print(w, line_num, iStartX, bgColor, nameColor, vItemDisplay[i].sFmt.c_str()); line_num++; } } else if (vItemDisplay[i].sType == "DESCRIPTION") { std::string sText = word_rewrap(vItemDisplay[i].sName, iWidth-4); std::stringstream ss(sText); std::string l; while (std::getline(ss, l, '\n')) { line_num++; mvwprintz(w, line_num, 2, c_white, l.c_str()); } } else { if (bStartNewLine) { mvwprintz(w, line_num, 2, c_white, "%s", (vItemDisplay[i].sName).c_str()); bStartNewLine = false; } else { wprintz(w, c_white, "%s", (vItemDisplay[i].sName).c_str()); } std::string sPlus = vItemDisplay[i].sPlus; std::string sFmt = vItemDisplay[i].sFmt; std::string sNum = " "; std::string sPost = ""; //A bit tricky, find %d and split the string size_t pos = sFmt.find("<num>"); if(pos != std::string::npos) { wprintz(w, c_white, sFmt.substr(0, pos).c_str()); sPost = sFmt.substr(pos+5); } else { wprintz(w, c_white, sFmt.c_str()); } if (vItemDisplay[i].sValue != "-999") { nc_color thisColor = c_white; for (int k = 0; k < vItemCompare.size(); k++) { if (vItemCompare[k].sValue != "-999") { if (vItemDisplay[i].sName == vItemCompare[k].sName) { if (vItemDisplay[i].dValue > vItemCompare[k].dValue - .1 && vItemDisplay[i].dValue < vItemCompare[k].dValue + .1) { thisColor = c_white; } else if (vItemDisplay[i].dValue > vItemCompare[k].dValue) { if (vItemDisplay[i].bLowerIsBetter) { thisColor = c_ltred; } else { thisColor = c_ltgreen; } } else if (vItemDisplay[i].dValue < vItemCompare[k].dValue) { if (vItemDisplay[i].bLowerIsBetter) { thisColor = c_ltgreen; } else { thisColor = c_ltred; } } break; } } } if (vItemDisplay[i].is_int == true) { wprintz(w, thisColor, "%s%.0f", sPlus.c_str(), vItemDisplay[i].dValue); } else { wprintz(w, thisColor, "%s%.1f", sPlus.c_str(), vItemDisplay[i].dValue); } } wprintz(w, c_white, sPost.c_str()); if (vItemDisplay[i].bNewLine) { line_num++; bStartNewLine = true; } } } wborder(w, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); int ch = (int)' '; wrefresh(w); if (iLeft > 0) { ch = (int)getch(); if ( selected > 0 && ( ch == '\n' || ch == KEY_RIGHT ) && selected_ret != 0 ) { ch=selected_ret; } else if ( selected == KEY_LEFT ) { ch=(int)' '; } //werase(w); //wrefresh(w); delwin(w); //refresh(); } return ch; }
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(); catacurses::window w_help = catacurses::newwin( ( FULL_SCREEN_HEIGHT / 2 ) - 2, FULL_SCREEN_WIDTH * 3 / 4, 7 + offset_y + ( FULL_SCREEN_HEIGHT / 2 ) / 2, offset_x + 19 / 2 ); catacurses::window w_border = catacurses::newwin( FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, offset_y, offset_x ); catacurses::window w_header = catacurses::newwin( header_height, FULL_SCREEN_WIDTH - 2, 1 + offset_y, 1 + offset_x ); catacurses::window w = catacurses::newwin( content_height, FULL_SCREEN_WIDTH - 2, header_height + 1 + offset_y, 1 + offset_x ); draw_border( w_border, BORDER_COLOR, custom_name_in ); mvwputch( w_border, 3, 0, c_light_gray, LINE_XXXO ); // |- mvwputch( w_border, 3, 79, c_light_gray, LINE_XOXX ); // -| for( auto &column : column_pos ) { mvwputch( w_border, FULL_SCREEN_HEIGHT - 1, column.second + 1, c_light_gray, 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_light_green, hotkey ) + 2; } tmpx = 0; tmpx += shortcut_print( w_header, 1, tmpx, c_white, c_light_green, _( "<+-> Move up/down" ) ) + 2; tmpx += shortcut_print( w_header, 1, tmpx, c_white, c_light_green, _( "<Enter>-Edit" ) ) + 2; shortcut_print( w_header, 1, tmpx, c_white, c_light_green, _( "<Tab>-Switch Page" ) ); for( int i = 0; i < 78; i++ ) { mvwputch( w_header, 2, i, c_light_gray, LINE_OXOX ); // Draw line under header } for( auto &pos : column_pos ) { mvwputch( w_header, 2, pos.second, c_light_gray, LINE_OXXX ); mvwputch( w_header, 3, pos.second, c_light_gray, 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_light_green : c_light_red ), c_white, ( ( get_option<bool>( "SAFEMODE" ) ) ? _( "True" ) : _( "False" ) ) ); locx += shortcut_print( w_header, 1, locx, c_white, c_light_green, " " ); locx += shortcut_print( w_header, 1, locx, c_white, c_light_green, _( "<S>witch" ) ); shortcut_print( w_header, 1, locx, c_white, c_light_green, " " ); 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_light_gray, 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 < static_cast<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_light_gray; 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, const std::string & text_in ) { mvwprintz( w, i - start_pos, column_pos[column_in] + 2, ( line == i && column == column_in ) ? hilite( line_color ) : line_color, text_in ); }; 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 ) : "---" ); 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 >= static_cast<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 > static_cast<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 view distance)" ) ) .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 < static_cast<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; } }