Skip to content

Commit

Permalink
Statuscolors 1.2 patch - https://bilious.alt.org/?142
Browse files Browse the repository at this point in the history
There's a minor quirk with this - graphics display is set as 'plain' regardless of what the player has set in their RC configuration file. Via options, you can set what you want (DEC/IBMgraphics) to 'false', then back to 'true' to correct it, but it does not persist between saves. Will fix.
  • Loading branch information
k21971 committed Dec 21, 2018
1 parent 5f0b520 commit 6350580
Show file tree
Hide file tree
Showing 7 changed files with 438 additions and 35 deletions.
19 changes: 19 additions & 0 deletions include/color.h
Expand Up @@ -58,6 +58,25 @@
#define DRAGON_SILVER CLR_BRIGHT_CYAN
#define HI_ZAP CLR_BRIGHT_BLUE

#ifdef STATUS_COLORS
struct color_option {
int color;
int attr_bits;
};

struct percent_color_option {
int percentage;
struct color_option color_option;
const struct percent_color_option *next;
};

struct text_color_option {
const char *text;
struct color_option color_option;
const struct text_color_option *next;
};
#endif

#ifdef MENU_COLOR
struct menucoloring {
#ifdef USE_REGEX_MATCH
Expand Down
2 changes: 2 additions & 0 deletions include/config.h
Expand Up @@ -510,6 +510,8 @@ typedef unsigned char uchar;
Can be left undefined for not writing extrainfo. */
#define EXTRAINFO_FN "/dgldir/extrainfo-sl008/%n.extrainfo"

#define STATUS_COLORS

/* End of Section 5 */

#include "global.h" /* Define everything else according to choices above */
Expand Down
3 changes: 3 additions & 0 deletions include/flag.h
Expand Up @@ -201,6 +201,9 @@ struct instance_flags {
char prevmsg_window; /* type of old message window to use */
boolean extmenu; /* extended commands use menu interface */
#endif
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
boolean use_status_colors; /* use color in status line; only if wc_color */
#endif
#ifdef MENU_COLOR
boolean use_menu_color; /* use color in menus; only if wc_color */
#endif
Expand Down
211 changes: 186 additions & 25 deletions src/botl.c
Expand Up @@ -57,6 +57,106 @@ STATIC_DCL void FDECL(set_botl_warn, (int));
#define MAXCO (COLNO+20)
#endif

#if defined(STATUS_COLORS) && defined(TEXTCOLOR)

extern const struct percent_color_option *hp_colors;
extern const struct percent_color_option *pw_colors;
extern const struct text_color_option *text_colors;

struct color_option
text_color_of(text, color_options)
const char *text;
const struct text_color_option *color_options;
{
if (color_options == NULL) {
struct color_option result = {NO_COLOR, 0};
return result;
}
if (strstri(color_options->text, text)
|| strstri(text, color_options->text))
return color_options->color_option;
return text_color_of(text, color_options->next);
}

struct color_option
percentage_color_of(value, max, color_options)
int value, max;
const struct percent_color_option *color_options;
{
if (color_options == NULL) {
struct color_option result = {NO_COLOR, 0};
return result;
}
if (100 * value <= color_options->percentage * max)
return color_options->color_option;
return percentage_color_of(value, max, color_options->next);
}

void
start_color_option(color_option)
struct color_option color_option;
{
int i;
if (color_option.color != NO_COLOR)
term_start_color(color_option.color);
for (i = 0; (1 << i) <= color_option.attr_bits; ++i)
if (i != ATR_NONE && color_option.attr_bits & (1 << i))
term_start_attr(i);
}

void
end_color_option(color_option)
struct color_option color_option;
{
int i;
if (color_option.color != NO_COLOR)
term_end_color(color_option.color);
for (i = 0; (1 << i) <= color_option.attr_bits; ++i)
if (i != ATR_NONE && color_option.attr_bits & (1 << i))
term_end_attr(i);
}

void
apply_color_option(color_option, newbot2)
struct color_option color_option;
const char *newbot2;
{
if (!iflags.use_status_colors) return;
curs(WIN_STATUS, 1, 1);
start_color_option(color_option);
putstr(WIN_STATUS, 0, newbot2);
end_color_option(color_option);
}

void
add_colored_text(text, newbot2)
const char *text;
char *newbot2;
{
char *nb;
struct color_option color_option;

if (*text == '\0') return;

if (!iflags.use_status_colors) {
Sprintf(nb = eos(newbot2), " %s", text);
return;
}

Strcat(nb = eos(newbot2), " ");
curs(WIN_STATUS, 1, 1);
putstr(WIN_STATUS, 0, newbot2);

Strcat(nb = eos(nb), text);
curs(WIN_STATUS, 1, 1);
color_option = text_color_of(text, text_colors);
start_color_option(color_option);
putstr(WIN_STATUS, 0, newbot2);
end_color_option(color_option);
}

#endif

#ifndef OVLB
STATIC_DCL int mrank_sz;
#else /* OVLB */
Expand Down Expand Up @@ -265,7 +365,7 @@ bot1()
j = (nb + 2) - newbot1; /* aka strlen(newbot1) but less computation */
if((i - j) > 0)
Sprintf(nb = eos(nb),"%*s", i-j, " "); /* pad with spaces */

Sprintf(nb = eos(nb), "St:%s ", botl_strength());
Sprintf(nb = eos(nb),
"Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
Expand Down Expand Up @@ -353,6 +453,11 @@ bot2()
int w;
#endif

#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
struct color_option color_option;
int save_botlx = flags.botlx;
#endif

hp = Upolyd ? u.mh : u.uhp;
hpmax = Upolyd ? u.mhmax : u.uhpmax;

Expand All @@ -362,21 +467,39 @@ bot2()
else
newbot2[0] = '\0';
if (bot2_abbrev < 1)
Sprintf(nb = eos(newbot2), "%c:%-2ld ",
oc_syms[COIN_CLASS],
Sprintf(nb = eos(newbot2), "%c:%-2ld ", oc_syms[COIN_CLASS],
#ifndef GOLDOBJ
u.ugold
#else
money_cnt(invent)
#endif
);
else
nb = newbot2;
Sprintf(nb = eos(nb), "HP:%d(%d) Pw:%d(%d) AC:%-2d",
hp, hpmax, u.uen, u.uenmax, u.uac);
);

#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
Strcat(nb = eos(newbot2), " HP:");
curs(WIN_STATUS, 1, 1);
putstr(WIN_STATUS, 0, newbot2);
flags.botlx = 0;

Sprintf(nb = eos(nb), "%d(%d)", hp, hpmax);
apply_color_option(percentage_color_of(hp, hpmax, hp_colors), newbot2);
#else
Sprintf(nb = eos(nb), " HP:%d(%d)", hp, hpmax);
#endif
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
Strcat(nb = eos(nb), " Pw:");
curs(WIN_STATUS, 1, 1);
putstr(WIN_STATUS, 0, newbot2);

Sprintf(nb = eos(nb), "%d(%d)", u.uen, u.uenmax);
apply_color_option(percentage_color_of(u.uen, u.uenmax, pw_colors), newbot2);
#else
Sprintf(nb = eos(nb), " Pw:%d(%d)", u.uen, u.uenmax);
#endif
Sprintf(nb = eos(nb), " AC:%-2d", u.uac);

if (Upolyd)
Sprintf(nb = eos(nb), " HD:%d", ((u.ulycn == u.umonnum) ?
Sprintf(nb = eos(nb), " HD:%d", ((u.ulycn == u.umonnum) ?
u.ulevel : mons[u.umonnum].mlevel));
#ifdef EXP_ON_BOTL
else if(flags.showexp && bot2_abbrev < 3)
Expand All @@ -402,25 +525,21 @@ bot2()
Sprintf(nb = eos(nb), "!");
}
#endif

#ifdef REALTIME_ON_BOTL
if(iflags.showrealtime) {
time_t currenttime = get_realtime();
Sprintf(nb = eos(nb), " %ld:%2.2ld", currenttime / 3600,
Sprintf(nb = eos(nb), " %ld:%2.2ld", currenttime / 3600,
(currenttime % 3600) / 60);
}
#endif

if (bot2_abbrev >= 2) {
if (hu_abbrev_stat[u.uhs][0]!='\0') {
Sprintf(nb = eos(nb), " ");
Strcat(newbot2, hu_abbrev_stat[u.uhs]);
}
}
else if(strcmp(hu_stat[u.uhs], " ")) {
Sprintf(nb = eos(nb), " ");
Strcat(newbot2, hu_stat[u.uhs]);
}

/* WAC further Up
#ifdef SCORE_ON_BOTL
Expand All @@ -429,31 +548,76 @@ bot2()
u.ugold, botl_score());
#endif
*/

else if(strcmp(hu_stat[u.uhs], " "))
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
add_colored_text(hu_stat[u.uhs], newbot2);
#else
Sprintf(nb = eos(nb), " %s", hu_stat[u.uhs]);
#endif

/* KMH -- changed to Lev */
if (Levitation) Sprintf(nb = eos(nb), " Lev");
if(Levitation) Sprintf(nb = eos(nb), " Lev");
if(Confusion)
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
add_colored_text("Conf", newbot2);
#else
Sprintf(nb = eos(nb), bot2_abbrev >= 2 ? " Cnf" : " Conf");
#endif
if(Sick) {
if (u.usick_type & SICK_VOMITABLE)
Sprintf(nb = eos(nb),
bot2_abbrev >= 2 ? " FPs" : " FoodPois");
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
add_colored_text("FoodPois", newbot2);
#else
Sprintf(nb = eos(nb), bot2_abbrev >= 2 ? " FPs" : " FoodPois");
#endif
if (u.usick_type & SICK_NONVOMITABLE)
Sprintf(nb = eos(nb), " Ill");
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
add_colored_text("Ill", newbot2);
#else
Strcat(nb = eos(nb), " Ill");
#endif
}

if(Blind)
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
add_colored_text("Blind", newbot2);
#else
Sprintf(nb = eos(nb), bot2_abbrev >= 2 ? " Bnd" : " Blind");
#endif
if(Stunned)
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
add_colored_text("Stun", newbot2);
#else
Sprintf(nb = eos(nb), bot2_abbrev >= 2 ? " Stn" : " Stun");
#endif
if(Hallucination)
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
add_colored_text("Hallu", newbot2);
#else
Sprintf(nb = eos(nb), bot2_abbrev >= 2 ? " Hal" : " Hallu");
#endif
if(Slimed)
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
add_colored_text("Slime", newbot2);
if(u.ustuck && !u.uswallow && !sticks(youmonst.data))
add_colored_text(" Held", newbot2);
#else
Sprintf(nb = eos(nb), bot2_abbrev >= 2 ? " Slm" : " Slime");
#endif
if(u.ustuck && !u.uswallow && !sticks(youmonst.data))
Sprintf(nb = eos(nb), " Held");
if(cap > UNENCUMBERED)
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
add_colored_text(enc_stat[cap], newbot2);
#else
Sprintf(nb = eos(nb), " %s",
bot2_abbrev >= 2 ? enc_abbrev_stat[cap] : enc_stat[cap]);
#endif
curs(WIN_STATUS, 1, 1);
putstr(WIN_STATUS, 0, newbot2);
flags.botlx = save_botlx;

#ifdef DUMP_LOG
}
STATIC_OVL void
Expand All @@ -462,9 +626,6 @@ bot2()
char newbot2[MAXCO];
bot2str(newbot2);
#endif
curs(WIN_STATUS, 1, 1);

putstr(WIN_STATUS, 0, newbot2);
return;
}

Expand All @@ -489,10 +650,10 @@ int len;
*bp1++ = *bp0;
k++;
} while(*bp0++ && k < (len - 49));

cbuf[k] = '.';
bp1++;

bp0 = index(str, ':') - 3;
do {
*bp1++ = *bp0;
Expand Down
4 changes: 4 additions & 0 deletions src/files.c
Expand Up @@ -2019,6 +2019,10 @@ char *tmp_levels;
} else if (match_varname(buf, "GRAPHICS", 4)) {
len = get_uchars(fp, buf, bufp, translate, FALSE,
MAXPCHARS, "GRAPHICS");
#if defined(STATUS_COLORS) && defined(TEXTCOLOR)
} else if (match_varname(buf, "STATUSCOLOR", 11)) {
(void) parse_status_color_options(bufp);
#endif
assign_graphics(translate, len, MAXPCHARS, 0);
} else if (match_varname(buf, "DUNGEON", 4)) {
len = get_uchars(fp, buf, bufp, translate, FALSE,
Expand Down

0 comments on commit 6350580

Please sign in to comment.