Example #1
0
nh_bool
curses_set_option(const char *name, union nh_optvalue value)
{
    nh_bool game_option = FALSE;
    struct nh_option_desc *option = nhlib_find_option(curses_options, name);

    if (!option) {
        if (game_is_running)
            return nh_set_option(name, value);

        /* If the game is not running, update our local copy of options. */
        if (!nh_options || !(option = nhlib_find_option(nh_options, name))) {
            return FALSE;
        }
        game_option = TRUE;
    }

    if ((int)option->type == OPTTYPE_KEYMAP) {
        return FALSE;
    }

    if (!nhlib_option_value_ok(option, value))
        return FALSE;

    nhlib_copy_option_value(option, value);

    if (game_option)
        return TRUE;

    /* In case the option affects graphics; this is pretty cheap if we don't do
       it every turn */
    mark_mapwin_for_full_refresh();

    if (option->type == OPTTYPE_BOOL) {
        nh_bool *var = nhlib_find_boolopt(boolopt_map, option->name);
        if (!var) {
            curses_impossible("missing boolean option");
            return FALSE;
        }

        *var = value.b;

        if (!strcmp(option->name, "status3")) {
            rebuild_ui();
        } else if (!strcmp(option->name, "darkgray")) {
            set_darkgray();
            draw_map(player.x, player.y);
        } else if (!strcmp(option->name, "mouse")) {
            uncursed_enable_mouse(option->value.b);
        }
    } else if (!strcmp(option->name, "comment")) {
        /* do nothing */
    } else if (!strcmp(option->name, "tileset")) {
        if (settings.tileset)
            free(settings.tileset);
        settings.tileset = malloc(strlen(option->value.s) + 1);
        strcpy(settings.tileset, option->value.s);
        rebuild_ui();
    } else if (!strcmp(option->name, "border")) {
        settings.whichframes = option->value.e;
        rebuild_ui();
    } else if (!strcmp(option->name, "menu_headings")) {
        settings.menu_headings = option->value.e;
    } else if (!strcmp(option->name, "palette")) {
        settings.palette = option->value.e;
        setup_palette();

        if (ui_flags.initialized) {
            /*
             * - We don't want to install a palette as a result of the default
             *   setting of "palette", because some terminals cannot handle a
             *   palette reset, and thus we need to ensure that we've loaded
             *   the user's palette setting before palette initialization.
             *
             * - Besides, clear() will crash with an uninitialized libuncursed.
             *   So we have to delay this anyway.
             */
            clear();
            refresh();
            rebuild_ui();
        }
    } else if (!strcmp(option->name, "animation")) {
        settings.animation = option->value.e;
    } else if (!strcmp(option->name, "sidebar")) {
        settings.sidebar = option->value.e;
        rebuild_ui();
    } 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, "networkmotd")) {
        settings.show_motd = option->value.e;
    } else if (!strcmp(option->name, "menupaging")) {
        settings.menupaging = option->value.e;
    } 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();
    }
    else
        return FALSE;

    return TRUE;
}
Example #2
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;
}
Example #3
0
static void
curses_print_message_core(int turn, const char *msg, nh_bool canblock)
{
    int hsize, vsize, maxlen;
    nh_bool died;

    if (!msghistory)
        alloc_hist_array();

    if (turn != prevturn)
        start_of_turn_curline = last_redraw_curline = curline;

    if (turn < prevturn)        /* going back in time can happen during replay */
        prune_messages(turn);

    if (!*msg)
        return; /* empty message. done. */

    if (action > prevaction) {
        /* re-enable output if it was stopped and start a new line */
        stopprint = FALSE;
        newline();
    }
    prevturn = turn;
    prevaction = action;

    store_message(turn, msg);

    if (stopprint)
        return;

    /* 
     * generally we want to put as many messages on one line as possible to
     * maximize space usage. A new line is begun after each player turn or if
     * more() is called via pause_messages(). "You die" also deserves its own line.
     * 
     * If the message area is only one line high, space for "--More--" must be
     * reserved at the end of the line, otherwise  --More-- is shown on a new line.
     */

    getmaxyx(msgwin, vsize, hsize);

    maxlen = hsize;
    if (maxlen >= COLNO)
        maxlen = COLNO - 1;
    if (vsize == 1)
        maxlen -= 8;    /* for "--More--" */

    died = !strncmp(msg, "You die", 7);
    if (strlen(msglines[curline]) + strlen(msg) + 1 < maxlen && !died) {
        if (msglines[curline][0])
            strcat(msglines[curline], "  ");
        strcat(msglines[curline], msg);
    } else {
        int idx, output_count;
        char **output;

        wrap_text(maxlen, msg, &output_count, &output);

        for (idx = 0; idx < output_count; idx++) {
            if (strlen(msglines[curline]) > 0)
                fresh_message_line(canblock);
            if (stopprint)
                break;  /* may get set in more() */
            strcpy(msglines[curline], output[idx]);
        }

        free_wrap(output);
    }

    draw_msgwin();
}