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.
This commit is contained in:
Knightmare66 2019-06-29 03:33:32 -04:00
parent 5e7cc0a375
commit 890a803e5f
5 changed files with 139 additions and 17 deletions

View file

@ -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

View file

@ -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

View file

@ -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; i<level.fogs; i++)
for (i=0; i<level.fogs; i++)
{
pfog = &gfogs[i];
cFog = &gfogs[i];
gi.dprintf("Fog #%d\n",i+1);
gi.dprintf("Trigger=%s\n",(pfog->Trigger ? "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

View file

@ -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--;

View file

@ -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.