std::string cata::string_formatter::raw_string_format( const char *const pattern, ... ) { va_list ap; va_start( ap, pattern ); std::string result = vstring_format( pattern, ap ); va_end( ap ); return result; }
void full_screen_popup(const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); popup(text, PF_FULLSCREEN); }
std::string string_format(const std::string &pattern, ...) { va_list ap; va_start(ap, pattern); const std::string result = vstring_format(pattern.c_str(), ap); va_end(ap); return result; }
char popup_getkey(const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); return popup(text, PF_GET_KEY); }
void popup_nowait(const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); popup(text, PF_NO_WAIT); }
void popup_top(const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); popup(text, PF_ON_TOP); }
//Prints a formatted string to the main window at the current cursor int printw(const char *fmt, ...) { va_list args; va_start(args, fmt); const std::string printbuf = vstring_format(fmt, args); va_end(args); return printstring(mainwin, printbuf); }
void uimenu::addentry(int r, bool e, int k, const char *format, ...) { va_list ap; va_start(ap, format); const std::string text = vstring_format(format, ap); va_end(ap); entries.push_back(uimenu_entry(r, e, k, text)); }
void monster::add_msg_if_npc(game_message_type type, const char *msg, ...) const { va_list ap; va_start(ap, msg); std::string processed_npc_string = vstring_format(msg, ap); processed_npc_string = replace_with_npc_name(processed_npc_string, disp_name()); add_msg(type, processed_npc_string.c_str()); va_end(ap); }
// returns number of printed lines int fold_and_print(WINDOW *w, int begin_y, int begin_x, int width, nc_color base_color, const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); return fold_and_print(w, begin_y, begin_x, width, base_color, text); }
void realDebugmsg( const char *filename, const char *line, const char *funcname, const char *mes, ... ) { assert( filename != nullptr ); assert( line != nullptr ); assert( funcname != nullptr ); va_list ap; va_start( ap, mes ); const std::string text = vstring_format( mes, ap ); va_end( ap ); if( debug_fatal ) { throw std::runtime_error( string_format( "%s:%s [%s] %s", filename, line, funcname, text.c_str() ) ); } DebugLog( D_ERROR, D_MAIN ) << filename << ":" << line << " [" << funcname << "] " << text; std::string msg_key( filename ); msg_key += line; if( ignored_messages.count( msg_key ) > 0 ) { return; } if( stdscr == nullptr ) { std::cerr << text.c_str() << std::endl; abort(); } fold_and_print( stdscr, 0, 0, getmaxx( stdscr ), c_ltred, "\n \n" // Looks nicer with some space " DEBUG : %s\n \n" " FUNCTION : %s\n" " FILE : %s\n" " LINE : %s\n \n" " Press <color_white>spacebar</color> to continue the game...\n" " Press <color_white>I</color> (or <color_white>i</color>) to also ignore this particular message in the future...", text.c_str(), funcname, filename, line ); for( bool stop = false; !stop; ) { switch( getch() ) { case 'i': case 'I': ignored_messages.insert( msg_key ); // Falling through case ' ': stop = true; break; } } werase( stdscr ); refresh(); }
void printz(nc_color FG, const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); attron(FG); printw("%s", text.c_str()); attroff(FG); }
void wprintz(WINDOW *w, nc_color FG, const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); wattron(w, FG); wprintw(w, "%s", text.c_str()); wattroff(w, FG); }
void monster::add_msg_player_or_npc(game_message_type type, const char *, const char* npc_str, ...) const { va_list ap; va_start(ap, npc_str); if (g->u.sees(*this)) { std::string processed_npc_string = vstring_format(npc_str, ap); processed_npc_string = replace_with_npc_name(processed_npc_string, disp_name()); add_msg(type, processed_npc_string.c_str()); } va_end(ap); }
//Prints a formatted string to the main window, moves the cursor int mvprintw(int y, int x, const char *fmt, ...) { va_list args; va_start(args, fmt); const std::string printbuf = vstring_format(fmt, args); va_end(args); if (move(y, x) == 0) { return 0; } return printstring(mainwin, printbuf); }
int query_int(const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); std::string raw_input = string_input_popup(text); //Note that atoi returns 0 for anything it doesn't like. return atoi(raw_input.c_str()); }
//Prints a formatted string to a window at the current cursor, base function int wprintw(WINDOW *win, const char *fmt, ...) { if( win == nullptr ) { return 1; } va_list args; va_start(args, fmt); const std::string printbuf = vstring_format(fmt, args); va_end(args); return printstring(win, printbuf); }
//Prints a formatted string to a window, moves the cursor int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...) { if( win == nullptr ) { return 1; } va_list args; va_start(args, fmt); const std::string printbuf = vstring_format(fmt, args); va_end(args); if (wmove(win, y, x) == 0) { return 0; } return printstring(win, printbuf); }
void realDebugmsg( const char *filename, const char *line, const char *mes, ... ) { va_list ap; va_start( ap, mes ); const std::string text = vstring_format( mes, ap ); va_end( ap ); DebugLog( D_ERROR, D_MAIN ) << filename << ":" << line << " " << text; fold_and_print( stdscr, 0, 0, getmaxx( stdscr ), c_ltred, "DEBUG: %s\n Press spacebar...", text.c_str() ); while( getch() != ' ' ) { // wait for spacebar } werase( stdscr ); refresh(); }
void realDebugmsg(const char *filename, const char *line, const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); fold_and_print(stdscr, 0, 0, getmaxx(stdscr), c_red, "DEBUG: %s\n Press spacebar...", text.c_str()); std::ofstream fout; fout.open("debug.log", std::ios_base::app | std::ios_base::out); fout << filename << "[" << line << "]: " << text << "\n"; fout.close(); while (getch() != ' ') { // wait for spacebar } werase(stdscr); }
void center_print(WINDOW *w, int y, nc_color FG, const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); int window_width = getmaxx(w); int string_width = utf8_width(text.c_str()); int x; if (string_width >= window_width) { x = 0; } else { x = (window_width - string_width) / 2; } mvwprintz(w, y, x, FG, "%s", text.c_str()); }
void monster::add_msg_if_npc(game_message_type type, const char *msg, ...) { va_list ap; va_start(ap, msg); std::string processed_npc_string = vstring_format(msg, ap); // These strings contain the substring <npcname>, // if present replace it with the actual monster name. size_t offset = processed_npc_string.find("<npcname>"); if (offset != std::string::npos) { processed_npc_string.replace(offset, 9, disp_name()); if (offset == 0 && !processed_npc_string.empty()) { capitalize_letter(processed_npc_string, 0); } } add_msg(type, processed_npc_string.c_str()); va_end(ap); }
void monster::add_msg_player_or_npc(const char *, const char* npc_str, ...) { va_list ap; va_start(ap, npc_str); if (g->u_see(this)) { std::string processed_npc_string = vstring_format(npc_str, ap); // These strings contain the substring <npcname>, // if present replace it with the actual monster name. size_t offset = processed_npc_string.find("<npcname>"); if (offset != std::string::npos) { processed_npc_string.replace(offset, 9, disp_name()); if (offset == 0 && !processed_npc_string.empty()) { capitalize_letter(processed_npc_string, 0); } } add_msg(processed_npc_string.c_str()); } va_end(ap); }
bool query_yn(const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); bool force_uc = OPTIONS["FORCE_CAPITAL_YN"]; std::string query; if (force_uc) { query = string_format(_("%s (Y/N - Case Sensitive)"), text.c_str()); } else { query = string_format(_("%s (y/n)"), text.c_str()); } int win_width = utf8_width(query.c_str()) + 2; win_width = (win_width < FULL_SCREEN_WIDTH - 2 ? win_width : FULL_SCREEN_WIDTH - 2); std::vector<std::string> textformatted; textformatted = foldstring(query, win_width); WINDOW *w = newwin(textformatted.size() + 2, win_width, (TERMY - 3) / 2, (TERMX > win_width) ? (TERMX - win_width) / 2 : 0); fold_and_print(w, 1, 1, win_width, c_ltred, query); draw_border(w); wrefresh(w); char ch; do { ch = getch(); } while (ch != '\n' && ch != ' ' && ch != KEY_ESCAPE && ch != 'Y' && ch != 'N' && (force_uc || (ch != 'y' && ch != 'n'))); werase(w); wrefresh(w); delwin(w); refresh(); if (ch == 'Y' || ch == 'y') { return true; } return false; }
void uimenu::settext(const char *format, ...) { va_list ap; va_start(ap, format); text = vstring_format(format, ap); va_end(ap); }
void Messages::vadd_msg(game_message_type type, const char *msg, va_list ap) { player_messages.impl_->add_msg_string(vstring_format(msg, ap), type); }
std::string vstring_format(const std::string &pattern, va_list argptr) { return vstring_format(pattern.c_str(), argptr); }
// yn to make an immediate selection // esc to cancel, returns false // enter or space to accept, any other key to toggle bool query_yn(const char *mes, ...) { va_list ap; va_start(ap, mes); const std::string text = vstring_format(mes, ap); va_end(ap); bool force_uc = OPTIONS["FORCE_CAPITAL_YN"]; // localizes the selectors, requires translation to use lower case std::string selectors = _("yn"); if (selectors.length()<2) { selectors = "yn"; } std::string ucselectors = selectors; capitalize_letter(ucselectors, 0); capitalize_letter(ucselectors, 1); std::string ucwarning = ""; std::string *dispkeys = &selectors; if (force_uc) { ucwarning = _("Case Sensitive"); ucwarning = " (" + ucwarning +")"; dispkeys = &ucselectors; } // figures the length of the combined texts // width needed for text +2 for the border. + (/) 4 for the symbols and a space int win_width = utf8_width(text.c_str()) + utf8_width(selectors.c_str()) + utf8_width(ucwarning.c_str()) + 2 + 4; win_width = (win_width < FULL_SCREEN_WIDTH - 2 ? win_width : FULL_SCREEN_WIDTH - 2); WINDOW *w = NULL; std::vector<std::string> textformatted; std::string query; std::string color_on = "<color_white>"; std::string color_off = "</color>"; char ch ='?'; bool result = true; bool gotkey = false; while (ch != '\n' && ch != ' ' && ch != KEY_ESCAPE) { gotkey= (force_uc && ((ch == ucselectors[0]) || (ch == ucselectors[1]))) || (!force_uc && ((ch == selectors[0]) || (ch == selectors[1]))); if (gotkey) { result = (!force_uc && (ch == selectors[0])) || (force_uc && (ch == ucselectors[0])); break; // could move break past render to flash final choice once. } else if ((!force_uc && (ch != ucselectors[0]) && (ch != ucselectors[1])) || (force_uc && ((ch != selectors[0]) && (ch != selectors[1])))) { result = !result; } if (result) { query = " (" + color_on + dispkeys->substr(0,1) + color_off + "/" + dispkeys->substr(1,1) + ")"; } else { query = " (" + dispkeys->substr(0,1) + "/" + color_on + dispkeys->substr(1,1) + color_off + ")"; } if (force_uc) { query += ucwarning; } if (!w) { textformatted = foldstring(text + query, win_width); w = newwin(textformatted.size() + 2, win_width, (TERMY - 3) / 2, (TERMX > win_width) ? (TERMX - win_width) / 2 : 0); draw_border(w); } fold_and_print(w, 1, 1, win_width, c_ltred, text + query); wrefresh(w); ch = getch(); }; werase(w); wrefresh(w); delwin(w); refresh(); return ((ch != KEY_ESCAPE) && result); }
void Messages::vadd_msg(const char *msg, va_list ap) { player_messages.impl_->add_msg_string(vstring_format(msg, ap)); }