The engine does not tell the game code about reset color codes
The engine does not tell the game code about reset color codes, it replaces them with white color codes first:
From src/common/Color.h:
enum {
ESCAPE = '^',
NULL_COLOR = '*',
}; // enum
const Color Black = { 0.00, 0.00, 0.00, 1.00 };
const Color Red = { 1.00, 0.00, 0.00, 1.00 };
const Color Green = { 0.00, 1.00, 0.00, 1.00 };
const Color Blue = { 0.00, 0.00, 1.00, 1.00 };
const Color Yellow = { 1.00, 1.00, 0.00, 1.00 };
const Color Orange = { 1.00, 0.50, 0.00, 1.00 };
const Color Magenta = { 1.00, 0.00, 1.00, 1.00 };
const Color Cyan = { 0.00, 1.00, 1.00, 1.00 };
const Color White = { 1.00, 1.00, 1.00, 1.00 };
const Color LtGrey = { 0.75, 0.75, 0.75, 1.00 };
const Color MdGrey = { 0.50, 0.50, 0.50, 1.00 };
const Color LtOrange = { 0.50, 0.25, 0.00, 1.00 };
explicit Parser(const char* input, const Color& default_color = White)
: input(input), default_color(default_color)
{}
From src/common/Color.cpp:
else if ( input[1] == Constants::NULL_COLOR )
{
return value_type( input, input+2, parent->DefaultColor() );
}
Color DefaultColor() const
{
return default_color;
}
We may want to add a special Color::Token::TokenType::NULL_COLOR alongside Color::Token::TokenType::COLOR and Color::Constants::ESCAPE.
The Unvanquished game code currently workarounds the lack of specific token type by testing if the color has zeroed alpha channel, I don't know how this is set:
else if ( token.Type() == Color::Token::TokenType::COLOR )
{
if ( span && spanHasContent )
{
out.append( "</span>" );
span = false;
spanHasContent = false;
}
if ( token.Color().Alpha() != 0 )
{
char rgb[32];
Color::Color32Bit color32 = token.Color();
Com_sprintf( rgb, sizeof( rgb ), "<span style='color: #%02X%02X%02X;'>",
(int) color32.Red(),
(int) color32.Green(),
(int) color32.Blue() );
[…]
The default color can be specified in the Color::Parser constructor. The alpha trick is only needed if you have a special use case where you want to behave differently from a regular color when the color was defaulted.