diff --git a/Source/hu_lib.c b/Source/hu_lib.c index 6a0acd9e..4777d4ec 100644 --- a/Source/hu_lib.c +++ b/Source/hu_lib.c @@ -155,8 +155,13 @@ void HUlib_drawTextLine(hu_textline_t *l, boolean drawcursor) else if (c == '\x1b') //jff 2/17/98 escape code for color change { //jff 3/26/98 changed to actual escape char - if (++i < l->len && l->l[i] >= '0' && l->l[i] <= '9') - l->cr = colrngs[l->l[i]-'0']; + if (++i < l->len) + { + if (l->l[i] >= '0' && l->l[i] <= '9') + l->cr = colrngs[l->l[i]-'0']; + else if (l->l[i] == '0'-1) // [FG] reset to original color + l->cr = oc; + } } else if (c != ' ' && c >= l->sc && c <= 127) diff --git a/Source/hu_stuff.c b/Source/hu_stuff.c index fe4d2898..9c7db843 100644 --- a/Source/hu_stuff.c +++ b/Source/hu_stuff.c @@ -39,6 +39,7 @@ #include "r_draw.h" #include "m_input.h" #include "p_map.h" // crosshair (linetarget) +#include "m_misc2.h" #include "m_swap.h" // global heads up display controls @@ -203,6 +204,7 @@ static boolean secret_on; static int secret_counter; boolean message_centered; +boolean message_colorized; extern int showMessages; static boolean headsupactive = false; @@ -310,6 +312,79 @@ static boolean VANILLAMAP(int e, int m) return (e > 0 && e <= 4 && m > 0 && m <= 9); } +struct { + char **str; + const int cr; + const char *col; +} static const colorize_strings[] = { + // [Woof!] colorize keycard and skull key messages + {&s_GOTBLUECARD, CR_BLUE, " blue "}, + {&s_GOTBLUESKUL, CR_BLUE, " blue "}, + {&s_GOTREDCARD, CR_RED, " red "}, + {&s_GOTREDSKULL, CR_RED, " red "}, + {&s_GOTYELWCARD, CR_GOLD, " yellow "}, + {&s_GOTYELWSKUL, CR_GOLD, " yellow "}, + {&s_PD_BLUEC, CR_BLUE, " blue "}, + {&s_PD_BLUEK, CR_BLUE, " blue "}, + {&s_PD_BLUEO, CR_BLUE, " blue "}, + {&s_PD_BLUES, CR_BLUE, " blue "}, + {&s_PD_REDC, CR_RED, " red "}, + {&s_PD_REDK, CR_RED, " red "}, + {&s_PD_REDO, CR_RED, " red "}, + {&s_PD_REDS, CR_RED, " red "}, + {&s_PD_YELLOWC, CR_GOLD, " yellow "}, + {&s_PD_YELLOWK, CR_GOLD, " yellow "}, + {&s_PD_YELLOWO, CR_GOLD, " yellow "}, + {&s_PD_YELLOWS, CR_GOLD, " yellow "}, + + // [Woof!] colorize multi-player messages + {&s_HUSTR_PLRGREEN, CR_GREEN, "Green: "}, + {&s_HUSTR_PLRINDIGO, CR_GRAY, "Indigo: "}, + {&s_HUSTR_PLRBROWN, CR_BROWN, "Brown: "}, + {&s_HUSTR_PLRRED, CR_RED, "Red: "}, +}; + +static char* PrepareColor(const char *str, const char *col) +{ + char *str_replace, col_replace[16]; + + M_snprintf(col_replace, sizeof(col_replace), + "\x1b%c%s\x1b%c", '0'-1, col, '0'-1); + str_replace = M_StringReplace(str, col, col_replace); + + return str_replace; +} + +static void UpdateColor(char *str, int cr) +{ + int i; + int len = strlen(str); + + if (!message_colorized) + { + cr = -1; + } + + for (i = 0; i < len; ++i) + { + if (str[i] == '\x1b' && i + 1 < len) + { + str[i + 1] = '0'+cr; + break; + } + } +} + +void HU_ResetMessageColors(void) +{ + int i; + + for (i = 0; i < arrlen(colorize_strings); i++) + { + UpdateColor(*colorize_strings[i].str, colorize_strings[i].cr); + } +} + // // HU_Init() // @@ -435,6 +510,14 @@ void HU_Init(void) crosshair_nam[i] = NULL; } } + + // [Woof!] prepare player messages for colorization + for (i = 0; i < arrlen(colorize_strings); i++) + { + *colorize_strings[i].str = PrepareColor(*colorize_strings[i].str, colorize_strings[i].col); + } + + HU_ResetMessageColors(); } // diff --git a/Source/hu_stuff.h b/Source/hu_stuff.h index 5c993966..b89cfa53 100644 --- a/Source/hu_stuff.h +++ b/Source/hu_stuff.h @@ -62,6 +62,8 @@ void HU_Erase(void); boolean HU_DemoProgressBar(boolean force); +void HU_ResetMessageColors(void); + // killough 5/2/98: moved from m_misc.c: //jff 2/16/98 hud supported automap colors added @@ -85,6 +87,7 @@ extern int hud_secret_message; // "A secret is revealed!" message extern int map_player_coords, map_level_stats, map_level_time; // [FG] level stats and level time widgets extern int hud_timests; // Time/STS above status bar extern boolean message_centered; // center messages +extern boolean message_colorized; // colorize player messages extern int defdemotics, deftotaldemotics; diff --git a/Source/m_menu.c b/Source/m_menu.c index 383e4f31..be224078 100644 --- a/Source/m_menu.c +++ b/Source/m_menu.c @@ -4138,6 +4138,7 @@ enum { mess_secret, mess_stub1, mess_centered, + mess_colorized, mess_color_play, mess_timer, mess_color_chat, @@ -4171,6 +4172,9 @@ setup_menu_t mess_settings1[] = // Messages screen {"Center Messages", S_YESNO, m_null, M_X, M_Y + mess_centered*M_SPC, {"message_centered"}}, + {"Colorize Player Messages", S_YESNO, m_null, M_X, + M_Y + mess_colorized*M_SPC, {"message_colorized"}, 0, HU_ResetMessageColors}, + {"Message Color During Play", S_CRITEM, m_null, M_X, M_Y + mess_color_play*M_SPC, {"hudcolor_mesg"}, 0, NULL, hudcolor_str}, diff --git a/Source/m_misc.c b/Source/m_misc.c index 35184962..15b796cf 100644 --- a/Source/m_misc.c +++ b/Source/m_misc.c @@ -1783,6 +1783,13 @@ default_t defaults[] = { "number of message lines" }, + { + "message_colorized", + (config_t *) &message_colorized, NULL, + {0}, {0,1}, number, ss_mess, wad_no, + "1 to colorize player messages" + }, + { // killough 11/98 "message_centered", (config_t *) &message_centered, NULL,