コード例 #1
0
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;
}
コード例 #2
0
ファイル: output.cpp プロジェクト: Devanon/Cataclysm-DDA
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);
}
コード例 #3
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
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;
}
コード例 #4
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
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);
}
コード例 #5
0
ファイル: output.cpp プロジェクト: Devanon/Cataclysm-DDA
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);
}
コード例 #6
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
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);
}
コード例 #7
0
ファイル: cursesport.cpp プロジェクト: mbojan/Cataclysm-DDA
//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);
}
コード例 #8
0
ファイル: ui.cpp プロジェクト: Caleneledh/Cataclysm-DDA
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));
}
コード例 #9
0
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);
}
コード例 #10
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
// 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);
}
コード例 #11
0
ファイル: debug.cpp プロジェクト: 2birdie/Cataclysm-DDA
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();
}
コード例 #12
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
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);
}
コード例 #13
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
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);
}
コード例 #14
0
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);
}
コード例 #15
0
ファイル: cursesport.cpp プロジェクト: mbojan/Cataclysm-DDA
//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);
}
コード例 #16
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
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());
}
コード例 #17
0
ファイル: cursesport.cpp プロジェクト: mbojan/Cataclysm-DDA
//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);
}
コード例 #18
0
ファイル: cursesport.cpp プロジェクト: mbojan/Cataclysm-DDA
//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);
}
コード例 #19
0
ファイル: debug.cpp プロジェクト: Aenye/Cataclysm-DDA
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();
}
コード例 #20
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
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);
}
コード例 #21
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
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());
}
コード例 #22
0
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);
}
コード例 #23
0
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);
}
コード例 #24
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
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;
}
コード例 #25
0
ファイル: ui.cpp プロジェクト: Euphe/Cataclysm-DDA
void uimenu::settext(const char *format, ...) {
   va_list ap;
   va_start(ap, format);
   text = vstring_format(format, ap);
   va_end(ap);
}
コード例 #26
0
ファイル: messages.cpp プロジェクト: Catacstone/Cataclysm-DDA
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);
}
コード例 #27
0
ファイル: output.cpp プロジェクト: ramza500/Cataclysm-DDA
std::string vstring_format(const std::string &pattern, va_list argptr)
{
    return vstring_format(pattern.c_str(), argptr);
}
コード例 #28
0
ファイル: output.cpp プロジェクト: Devanon/Cataclysm-DDA
// 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);
}
コード例 #29
0
ファイル: messages.cpp プロジェクト: Catacstone/Cataclysm-DDA
void Messages::vadd_msg(const char *msg, va_list ap)
{
    player_messages.impl_->add_msg_string(vstring_format(msg, ap));
}