Ejemplo n.º 1
0
static void
draw_bar(int barlen, int val_cur, int val_max, nh_bool ishp)
{
    char str[ui_flags.mapwidth];
    int fill_len = 0, bl, colorattr, invcolorattr, color;

    bl = barlen - 2;
    if (val_max > 0 && val_cur > 0)
        fill_len = bl * val_cur / val_max;

    /*
     * Rules:  HP     Pw
     *    max  white  white
     *   >2/3  green  cyan
     *   >1/3  yellow blue
     *   >1/7  red    magenta
     *  <=1/7  br.red br.magenta
     *
     * Note: we can't draw a brightly colored background, but the dim color
     * gets substituted
     */
    if (val_cur == val_max)
        color = CLR_GRAY;
    else if (val_cur * 3 > val_max * 2)
        color = ishp ? CLR_GREEN : CLR_CYAN;
    else if (val_cur * 3 > val_max * 1)
        color = ishp ? CLR_BROWN : CLR_BLUE;
    else
        color = ishp ? CLR_RED : CLR_MAGENTA;
    if (val_cur * 7 <= val_max || color == CLR_BROWN)
        color |= 8;                                     /* bold color */
    colorattr = curses_color_attr(color, 0);        /* color on black */
    /* For the 'bar' portion, we use a 'color & 7'-colored background, and
       the foreground is either black or bolded background (depending on
       whether the foreground equals the background or not). */
    invcolorattr = curses_color_attr(color, color & 7);

    sprintf(str, "%*d / %-*d", (bl - 3) / 2, val_cur, (bl - 2) / 2, val_max);

    if (statuswin) {
        wattron(statuswin, colorattr);
        wprintw(statuswin, ishp ? "HP:" : "Pw:");
        wattroff(statuswin, colorattr);
        waddch(statuswin, '[');
        wattron(statuswin, invcolorattr);
        wprintw(statuswin, "%.*s", fill_len, str);
        wattroff(statuswin, invcolorattr);
        wattron(statuswin, colorattr);
        wprintw(statuswin, "%s", &str[fill_len]);
        wattroff(statuswin, colorattr);
        waddch(statuswin, ']');
    }
}
Ejemplo n.º 2
0
void
draw_msgwin(void)
{
    int i, pos;

    werase(msgwin);

    for (i = getmaxy(msgwin) - 1; i >= 0; i--) {
        pos = curline - getmaxy(msgwin) + 1 + i;
        if (pos < 0)
            pos += MAX_MSGLINES;
        if (pos == start_of_turn_curline)
            wattron(msgwin, curses_color_attr(COLOR_BLACK, 0));

        wmove(msgwin, i, 0);
        waddstr(msgwin, msglines[pos]);
        /* Only clear the remainder of the line if the cursor did not wrap. */
        if (getcurx(msgwin))
            wclrtoeol(msgwin);
    }
    wattroff(msgwin, curses_color_attr(COLOR_BLACK, 0));
    wnoutrefresh(msgwin);
}
Ejemplo n.º 3
0
static attr_t
get_trouble_color(const char *stat)
{
    attr_t res = curses_color_attr(CLR_GRAY, 0);
    const struct statcolor *clr;
    for (clr = default_colors; clr->txt; clr++) {
        if (stat && !strcmp(clr->txt, stat)) {
#ifdef STATUS_COLORS
            /* Check if we have a color enabled with statuscolors */
            if (!iflags.use_status_colors)
                return curses_color_attr(CLR_GRAY, 0); /* no color configured */

            struct color_option stat_color;

            stat_color = text_color_of(clr->txt, text_colors);
            if (stat_color.color == NO_COLOR && !stat_color.attr_bits)
                return curses_color_attr(CLR_GRAY, 0);

            if (stat_color.color != NO_COLOR)
                res = curses_color_attr(stat_color.color, 0);

            res = curses_color_attr(stat_color.color, 0);
            int count;
            for (count = 0; (1 << count) <= stat_color.attr_bits; count++) {
                if (count != ATR_NONE &&
                    (stat_color.attr_bits & (1 << count)))
                    res |= curses_convert_attr(count);
            }

            return res;
#else
            return curses_color_attr(clr->color, 0);
#endif
        }
    }

    return res;
}
Ejemplo n.º 4
0
static void
draw_status(struct nh_player_info *pi, nh_bool threeline)
{
    char buf[ui_flags.mapwidth];
    int i, j, k;

    if (!statuswin)
        return;

    if (ui_flags.statusheight < 2) {
        werase(statuswin);
        return;
    }

    /* penultimate line */
    wmove(statuswin, (threeline ? 1 : 0), 0);
    draw_bar(15, pi->hp, pi->hpmax, TRUE);
    wprintw(statuswin, " Def:%d %s:%d", 10 - pi->ac,
            pi->monnum == pi->cur_monnum ? "Xp" : "HD", pi->level);
    if (threeline && pi->monnum == pi->cur_monnum) {
        /* keep this synced with newuexp in exper.c */
        long newuexp = 10L * (1L << pi->level);

        if (pi->level >= 10)
            newuexp = 10000L * (1L << (pi->level - 10));
        if (pi->level >= 20)
            newuexp = 10000000L * ((long)(pi->level - 19));
        wprintw(statuswin, "(%ld)", newuexp - pi->xp);
    }
    wprintw(statuswin, " %s", pi->level_desc);
    wclrtoeol(statuswin);

    /* last line */
    wmove(statuswin, (threeline ? 2 : 1), 0);
    draw_bar(15, pi->en, pi->enmax, FALSE);
    wprintw(statuswin, " %c%ld S:%ld T:%ld", pi->coinsym, pi->gold, pi->score,
            pi->moves);
    if (getcurx(statuswin) > 0)
        wclrtoeol(statuswin);

    /* status */
    int mainframe_color = CLR_GRAY;
    j = getmaxx(statuswin) + 1;
    for (i = 0; i < pi->nr_items; i++) {
        int color = CLR_WHITE, colorattr;

        j -= strlen(pi->statusitems[i]) + 1;
        for (k = 0; statuscolors[k].name; k++) {
            if (!strcmp(pi->statusitems[i], statuscolors[k].name)) {
                color = statuscolors[k].color;
                if (statuscolors[k].framecolor != -1)
                    mainframe_color = statuscolors[k].framecolor;
                break;
            }
        }
        colorattr = curses_color_attr(color, 0);
        wmove(statuswin, (threeline ? 2 : 1), j);
        wattron(statuswin, colorattr);
        wprintw(statuswin, "%s", pi->statusitems[i]);
        wattroff(statuswin, colorattr);
    }

    /* frame color */
    if (pi->hp * 7 <= pi->hpmax)
        mainframe_color = CLR_ORANGE;
    else if (pi->hp * 3 <= pi->hpmax)
        mainframe_color = CLR_RED;

    if (ui_flags.current_followmode != FM_PLAY)
        mainframe_color = CLR_BLACK;     /* a hint that we can't write */

    /* We change the frame color via palette manipulation, because it's awkward
       to correctly redraw otherwise. However, we don't want to do color
       mapping logic here. So we copy an existing palette entry. */
    uncursed_color fgcode, bgcode;
    pair_content(PAIR_NUMBER(curses_color_attr(mainframe_color, 0)),
                 &fgcode, &bgcode);
    init_pair(MAINFRAME_PAIR, fgcode, bgcode);

    /* name */
    if (threeline) {
        sprintf(buf, "%.12s the %s %s", pi->plname,
                (pi->align == A_CHAOTIC) ? "Chaotic" :
                (pi->align == A_NEUTRAL) ? "Neutral" :
                "Lawful", pi->rank);
        wmove(statuswin, 0, 0);
    } else {
        sprintf(buf, "%.12s, %s", pi->plname, pi->rank);
        wmove(statuswin, 0, getmaxx(statuswin) - strlen(buf));
    }
    wprintw(statuswin, "%s", buf);
    if (getcurx(statuswin) > 0)
        wclrtoeol(statuswin);

    /* abilities (in threeline mode) "In:18 Wi:18 Ch:18" = 17 chars */
    if (threeline) {
        wmove(statuswin, 0, getmaxx(statuswin) - (pi->st == 18 ? 20 : 17));
        wprintw(statuswin, "Dx:%-2d Co:%-2d St:%-2d", pi->dx, pi->co, pi->st);
        if (pi->st == 18 && pi->st_extra == 100)
            wprintw(statuswin, "/**");
        else if (pi->st == 18)
            wprintw(statuswin, "/%02d", pi->st_extra);
        wmove(statuswin, 1, getmaxx(statuswin) - (pi->st == 18 ? 20 : 17));
        wprintw(statuswin, "In:%-2d Wi:%-2d Ch:%-2d", pi->in, pi->wi, pi->ch);
    }
}