Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 63 additions & 42 deletions sp/src/game/client/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,59 +911,80 @@ void CHudMessage::MsgFunc_HudMsg(bf_read &msg)
if (msg.GetNumBitsLeft() > 0)
{
int len = msg.ReadByte();
if ( len > 0 )
{
// This is supposed to work around a bug where certain aspect ratios cut off lengthy texts.
//int lineMax = 64 * ((float)ScreenWidth() / 1440.0f);
int lineMax = 160 / engine->GetScreenAspectRatio();

// This is supposed to work around a bug where certain aspect ratios cut off lengthy texts.
//int lineMax = 64 * ((float)ScreenWidth() / 1440.0f);
int lineMax = 100 / engine->GetScreenAspectRatio();

int lineMinBreak = lineMax * 0.9;
int lineMinBreak = lineMax * 0.9;

CGMsg( 2, CON_GROUP_CHOREO, "Line max is %i from an aspect ratio of %.3f (strlen %i)\n", lineMax, engine->GetScreenAspectRatio(), len );
CGMsg( 2, CON_GROUP_CHOREO, "Line max is %i from an aspect ratio of %.3f (strlen %i)\n", lineMax, engine->GetScreenAspectRatio(), len );

char *curMessage = (char*)pNetMessage->pMessage;
char newMessage[512];
char *curMessage = (char*)pNetMessage->pMessage;
char newMessage[512];

int cur = 0; // Current time on this line
int i = 0; // curMessage
int i2 = 0; // newMessage
for (i = 0; i < len; i++)
{
cur++;
newMessage[i2] = curMessage[i];

// Check if we're past the point in which we should break the line
if (cur >= lineMinBreak)
int cur = 0; // Current time on this line
int i = 0; // curMessage
int i2 = 0; // newMessage
for (i = 0; i < len; i++)
{
// Line break at the next space
if (curMessage[i] == ' ')
{
newMessage[i2] = '\n';
cur = 0;
}
else if (curMessage[i] == '\n')
{
// Already a newline here
cur = 0;
}
else if (cur >= lineMax)
cur++;
newMessage[i2] = curMessage[i];

// Check if we're past the point in which we should break the line
if (cur >= lineMinBreak)
{
// We're at the max and there's no space. Force a newline with a hyphen
newMessage[i2] = '-';
i2++;
newMessage[i2] = '\n';
i2++;
newMessage[i2] = curMessage[i];
cur = 0;
// Line break at the next space
if (curMessage[i] == ' ')
{
newMessage[i2] = '\n';
cur = 0;
}
else if (curMessage[i] == '\n')
{
// Already a newline here
cur = 0;
}
else if (cur >= lineMax)
{
// We're at the max and there's no space. Force a newline with a hyphen
newMessage[i2] = '-';
i2++;
newMessage[i2] = '\n';
i2++;
newMessage[i2] = curMessage[i];
cur = 0;
}
}

i2++;
}

i2++;
}
// Null terminate
newMessage[i2] = '\0';

// Null terminate
newMessage[i2] = '\0';
Q_strncpy( (char*)pNetMessage->pMessage, newMessage, 512 );
}
}

Q_strncpy( (char*)pNetMessage->pMessage, newMessage, 512 );
//
// Mapbase adds new data entries for the background box.
// These are not transmitted if no background box is defined, and some existing instances of this user message may not have this,
// so we have to make sure we have any bits left first.
//
if (msg.GetNumBitsLeft() > 0)
{
pNetMessage->bRoundedRectBackdropBox = true;
pNetMessage->flBoxSize = msg.ReadFloat();
pNetMessage->boxcolor[0] = msg.ReadByte();
pNetMessage->boxcolor[1] = msg.ReadByte();
pNetMessage->boxcolor[2] = msg.ReadByte();
pNetMessage->boxcolor[3] = msg.ReadByte();
}
else
{
pNetMessage->bRoundedRectBackdropBox = false;
}
#endif

Expand Down
7 changes: 7 additions & 0 deletions sp/src/game/server/ai_speech_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,13 @@ bool CAI_Expresser::SpeakDispatchResponse( AIConcept_t concept, AI_Response *res
WRITE_STRING( response );
WRITE_STRING( "" ); // No custom font
WRITE_BYTE ( responseLen );

// Background box
WRITE_FLOAT( 0.4f );
WRITE_BYTE( 31 );
WRITE_BYTE( 31 );
WRITE_BYTE( 31 );
WRITE_BYTE( 127 );
MessageEnd();

spoke = true;
Expand Down
7 changes: 7 additions & 0 deletions sp/src/game/server/baseflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,13 @@ bool CBaseFlex::StartSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CCh
WRITE_STRING( event->GetParameters2() );
WRITE_STRING( "" ); // No custom font
WRITE_BYTE ( Q_strlen( event->GetParameters2() ) );

// Background box
WRITE_FLOAT( 0.4f );
WRITE_BYTE( 31 );
WRITE_BYTE( 31 );
WRITE_BYTE( 31 );
WRITE_BYTE( 127 );
MessageEnd();
}
return true;
Expand Down
3 changes: 3 additions & 0 deletions sp/src/game/server/maprules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ BEGIN_DATADESC( CGameText )
DEFINE_KEYFIELD( m_textParms.fxTime, FIELD_FLOAT, "fxtime" ),

#ifdef MAPBASE
DEFINE_KEYFIELD( m_textParms.boxSize, FIELD_FLOAT, "boxsize" ),
DEFINE_KEYFIELD( m_textParms.boxColor, FIELD_COLOR32, "boxcolor" ),

DEFINE_KEYFIELD( m_strFont, FIELD_STRING, "font" ),
DEFINE_KEYFIELD( m_bAutobreak, FIELD_BOOLEAN, "autobreak" ),
#endif
Expand Down
11 changes: 8 additions & 3 deletions sp/src/game/server/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,9 +1116,14 @@ void UTIL_HudMessage( CBasePlayer *pToPlayer, const hudtextparms_t &textparms, c
WRITE_STRING( pMessage );
#ifdef MAPBASE
WRITE_STRING( pszFont );
if (bAutobreak)
{
WRITE_BYTE ( Q_strlen( pMessage ) );
WRITE_BYTE ( bAutobreak ? Q_strlen( pMessage ) : 0 );
if ( textparms.boxSize > 0.0f )
{
WRITE_FLOAT( textparms.boxSize );
WRITE_BYTE( textparms.boxColor.r );
WRITE_BYTE( textparms.boxColor.g );
WRITE_BYTE( textparms.boxColor.b );
WRITE_BYTE( textparms.boxColor.a );
}
#endif
MessageEnd();
Expand Down
4 changes: 4 additions & 0 deletions sp/src/game/server/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ typedef struct hudtextparms_s
float holdTime;
float fxTime;
int channel;
#ifdef MAPBASE
float boxSize = 0.0f;
color32 boxColor;
#endif
} hudtextparms_t;


Expand Down