Esempio n. 1
0
/**
 * Display data in table, each cell contains one entry from the
 * data vector. Allows vertical scrolling if the data does not fit.
 * Data is displayed using fold_and_print_from, which allows coloring!
 * @param columns Number of columns, can be 1. Make sure each entry
 * of the data vector fits into one cell.
 * @param title The title text, displayed on top.
 * @param w The window to draw this in, the whole widow is used.
 */
void display_table(WINDOW *w, const std::string &title, int columns,
                   const std::vector<std::string> &data)
{
    const int width = getmaxx(w) - 2; // -2 for border
    const int rows = getmaxy(w) - 2 - 1; // -2 for border, -1 for title
    const int col_width = width / columns;
    int offset = 0;

    const int title_length = utf8_width(title.c_str());
    while(true) {
        werase(w);
        draw_border(w);
        mvwprintz(w, 1, (width - title_length) / 2, c_white, "%s", title.c_str());
        for(int i = 0; i < rows * columns; i++) {
            if(i + offset * columns >= data.size()) {
                break;
            }
            const int x = 2 + (i % columns) * col_width;
            const int y = (i / columns) + 2;
            fold_and_print_from(w, y, x, col_width, 0, c_white, data[i + offset * columns]);
        }
        draw_scrollbar(w, offset, rows, data.size() / 3, 2, 0);
        wrefresh(w);
        int ch = getch();
        if (ch == KEY_DOWN && ((offset + 1) * columns) < data.size()) {
            offset++;
        } else if(ch == KEY_UP && offset > 0) {
            offset--;
        } else if(ch == ' ' || ch == '\n' || ch == KEY_ESCAPE) {
            break;
        }
    }
}
Esempio n. 2
0
int fold_and_print_from(WINDOW *w, int begin_y, int begin_x, int width, int begin_line,
                        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_from(w, begin_y, begin_x, width, begin_line, base_color, text);
}
Esempio n. 3
0
void game::extended_description( const tripoint &p )
{
    const int left = 0;
    const int right = TERMX;
    const int top = 3;
    const int bottom = TERMY;
    const int width = right - left;
    const int height = bottom - top;
    catacurses::window w_head = catacurses::newwin( top, TERMX, 0, 0 );
    catacurses::window w_main = catacurses::newwin( height, width, top, left );
    // @todo: De-hardcode
    std::string header_message = _( "\
c to describe creatures, f to describe furniture, t to describe terrain, Esc/Enter to close." );
    mvwprintz( w_head, 0, 0, c_white, header_message.c_str() );

    // Set up line drawings
    for( int i = 0; i < TERMX; i++ ) {
        mvwputch( w_head, top - 1, i, c_white, LINE_OXOX );
    }

    wrefresh( w_head );
    // Default to critter (if any), furniture (if any), then terrain.
    description_target cur_target = description_target::terrain;
    if( seen_critter( *this, p ) != nullptr ) {
        cur_target = description_target::creature;
    } else if( g->m.has_furn( p ) ) {
        cur_target = description_target::furniture;
    }
    int ch = 'c';
    do {
        std::string desc;
        // Allow looking at invisible tiles - player may want to examine hallucinations etc.
        switch( cur_target ) {
            case description_target::creature: {
                const Creature *critter = seen_critter( *this, p );
                if( critter != nullptr ) {
                    desc = critter->extended_description();
                } else {
                    desc = _( "You do not see any creature here." );
                }
            }
            break;
            case description_target::furniture:
                if( !u.sees( p ) || !m.has_furn( p ) ) {
                    desc = _( "You do not see any furniture here." );
                } else {
                    const furn_id fid = m.furn( p );
                    desc = fid.obj().extended_description();
                }
                break;
            case description_target::terrain:
                if( !u.sees( p ) ) {
                    desc = _( "You can't see the terrain here." );
                } else {
                    const ter_id tid = m.ter( p );
                    desc = tid.obj().extended_description();
                }
                break;
        }

        std::string signage = m.get_signage( p );
        if( !signage.empty() ) {
            desc += u.has_trait( trait_ILLITERATE ) ? string_format( _( "\nSign: ???" ) ) : string_format(
                        _( "\nSign: %s" ), signage.c_str() );
        }

        werase( w_main );
        fold_and_print_from( w_main, 0, 0, width, 0, c_light_gray, desc );
        wrefresh( w_main );
        // TODO: use input context
        ch = inp_mngr.get_input_event().get_first_input();
        switch( ch ) {
            case 'c':
                cur_target = description_target::creature;
                break;
            case 'f':
                cur_target = description_target::furniture;
                break;
            case 't':
                cur_target = description_target::terrain;
                break;
        }

    } while( ch != KEY_ESCAPE && ch != '\n' );
}