Ejemplo n.º 1
0
char curses_query_key(const char *query, int *count)
{
    int width, height, key;
    WINDOW *win;
    int cnt = 0;
    nh_bool hascount = FALSE;
    
    height = 3;
    width = strlen(query) + 4;
    win = newdialog(height, width);
    mvwprintw(win, 1, 2, query);
    wrefresh(win);
    
    key = nh_wgetch(win);
    while ((isdigit(key) || key == KEY_BACKSPACE) && count != NULL) {
	cnt = 10*cnt + (key - '0');
	key = nh_wgetch(win);
	hascount = TRUE;
    }
    
    if (count != NULL) {
	if (!hascount && !cnt)
	    cnt = -1; /* signal to caller that no count was given */
	*count = cnt;
    }
    
    delwin(win);
    redraw_game_windows();
    return key;
}
Ejemplo n.º 2
0
char curses_yn_function(const char *query, const char *resp, char def)
{
    int width, height, key;
    WINDOW *win;
    char prompt[QBUFSZ];
    char *rb, respbuf[QBUFSZ];

    strcpy(respbuf, resp);
    /* any acceptable responses that follow <esc> aren't displayed */
    if ((rb = strchr(respbuf, '\033')) != 0)
	*rb = '\0';
    sprintf(prompt, "%s [%s] ", query, respbuf);
    if (def)
	sprintf(prompt + strlen(prompt), "(%c) ", def);
    
    height = 3;
    width = strlen(prompt) + 5;
    win = newdialog(height, width);
    mvwprintw(win, 1, 2, prompt);
    wrefresh(win);
    
    do {
	key = tolower(nh_wgetch(win));
	
	if (key == '\033') {
	    if (strchr(resp, 'q'))
		key = 'q';
	    else if (strchr(resp, 'n'))
		key = 'n';
	    else
		key = def;
	    break;
	} else if (strchr(quit_chars, key)) {
	    key = def;
	    break;
	}
	
	if (!strchr(resp, key))
	    key = 0;
	
    } while (!key);
    
    delwin(win);
    redraw_game_windows();
    return key;
}
Ejemplo n.º 3
0
static int
curses_msgwin_generic(const char *msg, int (*validator)(int, void *),
                      void *arg, nh_bool cursor_visible,
                      enum keyreq_context context)
{
    int rv;

    /* We don't know whether the window system is inited right now. So ask.
       isendwin() is one of the few uncursed functions that works no matter
       what. */
    if (isendwin()) {
        fprintf(stderr, "%s\n", msg);
        return validator('\x1b', arg);
    }

    /* Don't try to render this on a very small terminal. */
    if (COLS < COLNO || LINES < ROWNO)
        return validator('\x1b', arg);

    int prevcurs = nh_curs_set(cursor_visible);

    struct gamewin *gw = alloc_gamewin(sizeof (struct win_msgwin));
    struct win_msgwin *wmw = (struct win_msgwin *)gw->extra;
    wmw->msg = msg;
    wmw->context = context;
    gw->draw = draw_curses_msgwin;
    gw->resize = resize_curses_msgwin;

    gw->win = 0;
    /* resize_curses_msgwin sets the layout_{width,height}, and because gw->win
       is 0, allocates gw->win. */
    resize_curses_msgwin(gw);
    draw_curses_msgwin(gw);

    rv = -1;
    while (rv == -1)
        rv = validator(nh_wgetch(gw->win, context), arg);

    delete_gamewin(gw);

    nh_curs_set(prevcurs);
    redraw_game_windows();

    return rv;
}
Ejemplo n.º 4
0
int curses_msgwin(const char *msg)
{
    int key, len;
    int width = strlen(msg) + 4;
    int prevcurs = curs_set(0);
    WINDOW *win = newdialog(3, width);
    
    len = strlen(msg);
    while (isspace(msg[len-1]))
	len--;
    
    mvwaddnstr(win, 1, 2, msg, len);
    wrefresh(win);
    key = nh_wgetch(win); /* wait for any key */
    
    delwin(win);
    curs_set(prevcurs);
    redraw_game_windows();
    
    return key;
}
Ejemplo n.º 5
0
static nh_bool option_change_callback(struct nh_option_desc *option)
{
    if (!strcmp(option->name, "classic_status") ||
	!strcmp(option->name, "darkmsg") ||
	!strcmp(option->name, "frame") ||
	!strcmp(option->name, "frame_hp_color") ||
	!strcmp(option->name, "status3") ||
	!strcmp(option->name, "sidebar")) {
	rebuild_ui();
	return TRUE;
    }
    else if (!strcmp(option->name, "showexp") ||
	!strcmp(option->name, "showscore") ||
	!strcmp(option->name, "time")) {
	curses_update_status(NULL);
    }
    else if (!strcmp(option->name, "darkroom") ||
	!strcmp(option->name, "hilite_peaceful") ||
	!strcmp(option->name, "hilite_pet") ||
	!strcmp(option->name, "mapcolors")) {
	draw_map(player.x, player.y);
    }
    else if (!strcmp(option->name, "darkgray")) {
	set_darkgray();
	draw_map(player.x, player.y);
    }
    else if (!strcmp(option->name, "dungeon_name")) {
	settings.dungeon_name = option->value.e;
	rebuild_ui();
    }
    else if (!strcmp(option->name, "menu_headings")) {
	settings.menu_headings = option->value.e;
    }
    else if (!strcmp(option->name, "graphics")) {
	settings.graphics = option->value.e;
	switch_graphics(option->value.e);
	if (ui_flags.ingame) {
	    draw_map(player.x, player.y);
	    redraw_game_windows();
	}
    }
    else if (!strcmp(option->name, "scores_top")) {
	settings.end_top = option->value.i;
    }
    else if (!strcmp(option->name, "scores_around")) {
	settings.end_around = option->value.i;
    }
    else if (!strcmp(option->name, "optstyle")) {
	settings.optstyle = option->value.e;
    }
    else if (!strcmp(option->name, "msgheight")) {
	settings.msgheight = option->value.i;
	rebuild_ui();
    }
    else if (!strcmp(option->name, "msghistory")) {
	settings.msghistory = option->value.i;
	alloc_hist_array();
    }
#if defined(PDCURSES) && defined(WIN32)
    else if (!strcmp(option->name, "win_width")) {
	settings.win_width = option->value.i;
	resize_term(settings.win_height, settings.win_width);
	handle_resize();
    }
    else if (!strcmp(option->name, "win_height")) {
	settings.win_height = option->value.i;
	resize_term(settings.win_height, settings.win_width);
	handle_resize();
    }
#endif
    else if (!strcmp(option->name, "name")) {
	if (option->value.s)
	    strcpy(settings.plname, option->value.s);
	else
	    settings.plname[0] = '\0';
    }
    else
	return FALSE;
    
    return TRUE;
}