From 890a803e5fa717300903089834e10ed0ae151e40 Mon Sep 17 00:00:00 2001 From: Knightmare66 Date: Sat, 29 Jun 2019 03:33:32 -0400 Subject: [PATCH] Fixed text color and formatting disappearing after word wrap in console. Added format code tracking to cl_console.c->Con_Print() to properly handle word wraps with text colors and bold/shadow/italic formatting. Removed console ormask for player chat in CL_ParseServerMessage(), as the color formatting codes make it redundant. --- client/cl_console.c | 133 ++++++++++++++++++++++++++++++++++++++--- client/cl_parse.c | 2 +- game/g_fog.c | 17 +++--- game/g_phys.c | 2 +- kmquake2_changelog.txt | 2 + 5 files changed, 139 insertions(+), 17 deletions(-) diff --git a/client/cl_console.c b/client/cl_console.c index 1acf26d..c9e7f67 100644 --- a/client/cl_console.c +++ b/client/cl_console.c @@ -355,19 +355,120 @@ void Con_Init (void) } +/* +=============== +Con_StringSetParams +=============== +*/ +qboolean Con_StringSetParams (char modifier, char *colorCode, qboolean *bold, qboolean *shadow, qboolean *italic, qboolean *alt) +{ + // sanity check + if (!colorCode || !bold || !shadow || !italic || !alt) + return false; + + switch (modifier) + { + case 'R': + case 'r': + *colorCode = 0; + *bold = *shadow = *italic = *alt = false; + return true; + case 'B': + case 'b': + if (*bold) + *bold = false; + else + *bold = true; + return true; + case 'S': + case 's': + if (*shadow) + *shadow = false; + else + *shadow = true; + return true; + case 'I': + case 'i': + if (*italic) + *italic = false; + else + *italic = true; + return true; + case COLOR_RED: + case COLOR_GREEN: + case COLOR_YELLOW: + case COLOR_BLUE: + case COLOR_CYAN: + case COLOR_MAGENTA: + case COLOR_WHITE: + case COLOR_BLACK: + case COLOR_ORANGE: + case COLOR_GRAY: + *colorCode = modifier; + return true; + case 'A': // alt text color + case 'a': + *alt = true; + return true; + } + + return false; +} + + /* =============== Con_Linefeed =============== */ -void Con_Linefeed (void) +void Con_Linefeed (char colorCode, qboolean bold, qboolean shadow, qboolean italic, qboolean alt) { + int y; + con.x = 0; if (con.display == con.current) con.display++; con.current++; memset (&con.text[(con.current%con.totallines)*con.linewidth] , ' ', con.linewidth); + + // add any wrapped formatting + y = con.current % con.totallines; + if (colorCode != 0) + { + con.text[y*con.linewidth+con.x] = '^'; + con.x++; + con.text[y*con.linewidth+con.x] = colorCode; + con.x++; + } + if (bold) + { + con.text[y*con.linewidth+con.x] = '^'; + con.x++; + con.text[y*con.linewidth+con.x] = 'b'; + con.x++; + } + if (shadow) + { + con.text[y*con.linewidth+con.x] = '^'; + con.x++; + con.text[y*con.linewidth+con.x] = 's'; + con.x++; + } + if (italic) + { + con.text[y*con.linewidth+con.x] = '^'; + con.x++; + con.text[y*con.linewidth+con.x] = 'i'; + con.x++; + } + if (alt) + { + con.text[y*con.linewidth+con.x] = '^'; + con.x++; + con.text[y*con.linewidth+con.x] = 'a'; + con.x++; + } } /* @@ -381,10 +482,12 @@ If no console is visible, the text will appear at the top of the game window */ void Con_Print (char *txt) { - int y; - int c, l; + int y, c, l; //, i; static int cr; - int mask; + int mask; + // vars for format wrapping + char modifier, colorCode = 0; + qboolean nextCharModifierCheck = false, bold = false, shadow = false, italic = false, alt = false; if (!con.initialized) return; @@ -406,8 +509,9 @@ void Con_Print (char *txt) break; // word wrap - if (l != con.linewidth && (con.x + l > con.linewidth) ) + if (l != con.linewidth && (con.x + l > con.linewidth) ) { con.x = 0; + } txt++; @@ -416,25 +520,40 @@ void Con_Print (char *txt) con.current--; cr = false; } - if (!con.x) { - Con_Linefeed (); + Con_Linefeed (colorCode, bold, shadow, italic, alt); // mark time for transparent overlay if (con.current >= 0) con.times[con.current % NUM_CON_TIMES] = cls.realtime; } + // track formatting codes for word wrap + modifier = (c & ~128); + if (nextCharModifierCheck) // last char was a ^ + { + Con_StringSetParams (modifier, &colorCode, &bold, &shadow, &italic, &alt); + nextCharModifierCheck = false; + } + else { + // set var to check modifier if char is ^ + nextCharModifierCheck = (modifier == '^') ? true : false; + } + switch (c) { case '\n': con.x = 0; + colorCode = 0; + bold = shadow = italic = alt = false; break; case '\r': con.x = 0; cr = 1; + colorCode = 0; + bold = shadow = italic = alt = false; break; default: // display character and advance diff --git a/client/cl_parse.c b/client/cl_parse.c index 84864ce..624df6f 100644 --- a/client/cl_parse.c +++ b/client/cl_parse.c @@ -911,7 +911,7 @@ void CL_ParseServerMessage (void) if (i == PRINT_CHAT) { S_StartLocalSound ("misc/talk.wav"); - con.ormask = 128; + // con.ormask = 128; // Knightmare- made redundant by color code Com_Printf (S_COLOR_ALT"%s", MSG_ReadString (&net_message)); // Knightmare- add green flag } else diff --git a/game/g_fog.c b/game/g_fog.c index c8f96e7..9be3822 100644 --- a/game/g_fog.c +++ b/game/g_fog.c @@ -325,21 +325,22 @@ void Cmd_Fog_f (edict_t *ent) Fog_ConsoleFog(); } } - else if(Q_stricmp (cmd, "Fog_List") == 0 ) + else if (Q_stricmp (cmd, "Fog_List") == 0 ) { - int i; + int i; + fog_t *cFog; gi.dprintf("level.fogs=%d\n",level.fogs); gi.dprintf("level.trigger_fogs=%d\n",level.trigger_fogs); - for(i=0; iTrigger ? "true" : "false")); + gi.dprintf("Trigger=%s\n",(cFog->Trigger ? "true" : "false")); gi.dprintf("Model=%d, Near=%g, Far=%g, Density=%g\n", - pfog->Model, pfog->Near, pfog->Far, pfog->Density); - gi.dprintf("Color=%g,%g,%g\n",pfog->Color[0],pfog->Color[1],pfog->Color[2]); - gi.dprintf("Targetname=%s\n",(pfog->ent ? pfog->ent->targetname : "no ent")); + cFog->Model, cFog->Near, cFog->Far, cFog->Density); + gi.dprintf("Color=%g,%g,%g\n",cFog->Color[0],cFog->Color[1],cFog->Color[2]); + gi.dprintf("Targetname=%s\n",(cFog->ent ? cFog->ent->targetname : "no ent")); } } else diff --git a/game/g_phys.c b/game/g_phys.c index 48d431f..9395a47 100644 --- a/game/g_phys.c +++ b/game/g_phys.c @@ -1228,7 +1228,7 @@ qboolean SV_Push (edict_t *pusher, vec3_t move, vec3_t amove) pushed_p--; continue; } - if (check->svflags & SVF_GIB) //Knightmare- gibs don't block + if (check->svflags & SVF_GIB) // Knightmare- gibs don't block { G_FreeEdict(check); pushed_p--; diff --git a/kmquake2_changelog.txt b/kmquake2_changelog.txt index 0c71c66..922404f 100644 --- a/kmquake2_changelog.txt +++ b/kmquake2_changelog.txt @@ -35,6 +35,8 @@ Changes as of v0.20 update 8: - Fixed alignment issue with colored text on help computer and centerprints. +- Fixed text color and formatting disappearing after word wrap in console. + - Fixed oversized 404 message from aborting all HTTP downloads. - Fixed HTTP download of the first pak in a filelist from aborting other paks.