Skip to content

Commit 8e06da5

Browse files
committed
Add background box capability to game_text
1 parent 6cc2937 commit 8e06da5

6 files changed

Lines changed: 92 additions & 45 deletions

File tree

sp/src/game/client/message.cpp

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -911,59 +911,80 @@ void CHudMessage::MsgFunc_HudMsg(bf_read &msg)
911911
if (msg.GetNumBitsLeft() > 0)
912912
{
913913
int len = msg.ReadByte();
914+
if ( len > 0 )
915+
{
916+
// This is supposed to work around a bug where certain aspect ratios cut off lengthy texts.
917+
//int lineMax = 64 * ((float)ScreenWidth() / 1440.0f);
918+
int lineMax = 160 / engine->GetScreenAspectRatio();
914919

915-
// This is supposed to work around a bug where certain aspect ratios cut off lengthy texts.
916-
//int lineMax = 64 * ((float)ScreenWidth() / 1440.0f);
917-
int lineMax = 100 / engine->GetScreenAspectRatio();
918-
919-
int lineMinBreak = lineMax * 0.9;
920+
int lineMinBreak = lineMax * 0.9;
920921

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

923-
char *curMessage = (char*)pNetMessage->pMessage;
924-
char newMessage[512];
924+
char *curMessage = (char*)pNetMessage->pMessage;
925+
char newMessage[512];
925926

926-
int cur = 0; // Current time on this line
927-
int i = 0; // curMessage
928-
int i2 = 0; // newMessage
929-
for (i = 0; i < len; i++)
930-
{
931-
cur++;
932-
newMessage[i2] = curMessage[i];
933-
934-
// Check if we're past the point in which we should break the line
935-
if (cur >= lineMinBreak)
927+
int cur = 0; // Current time on this line
928+
int i = 0; // curMessage
929+
int i2 = 0; // newMessage
930+
for (i = 0; i < len; i++)
936931
{
937-
// Line break at the next space
938-
if (curMessage[i] == ' ')
939-
{
940-
newMessage[i2] = '\n';
941-
cur = 0;
942-
}
943-
else if (curMessage[i] == '\n')
944-
{
945-
// Already a newline here
946-
cur = 0;
947-
}
948-
else if (cur >= lineMax)
932+
cur++;
933+
newMessage[i2] = curMessage[i];
934+
935+
// Check if we're past the point in which we should break the line
936+
if (cur >= lineMinBreak)
949937
{
950-
// We're at the max and there's no space. Force a newline with a hyphen
951-
newMessage[i2] = '-';
952-
i2++;
953-
newMessage[i2] = '\n';
954-
i2++;
955-
newMessage[i2] = curMessage[i];
956-
cur = 0;
938+
// Line break at the next space
939+
if (curMessage[i] == ' ')
940+
{
941+
newMessage[i2] = '\n';
942+
cur = 0;
943+
}
944+
else if (curMessage[i] == '\n')
945+
{
946+
// Already a newline here
947+
cur = 0;
948+
}
949+
else if (cur >= lineMax)
950+
{
951+
// We're at the max and there's no space. Force a newline with a hyphen
952+
newMessage[i2] = '-';
953+
i2++;
954+
newMessage[i2] = '\n';
955+
i2++;
956+
newMessage[i2] = curMessage[i];
957+
cur = 0;
958+
}
957959
}
960+
961+
i2++;
958962
}
959963

960-
i2++;
961-
}
964+
// Null terminate
965+
newMessage[i2] = '\0';
962966

963-
// Null terminate
964-
newMessage[i2] = '\0';
967+
Q_strncpy( (char*)pNetMessage->pMessage, newMessage, 512 );
968+
}
969+
}
965970

966-
Q_strncpy( (char*)pNetMessage->pMessage, newMessage, 512 );
971+
//
972+
// Mapbase adds new data entries for the background box.
973+
// These are not transmitted if no background box is defined, and some existing instances of this user message may not have this,
974+
// so we have to make sure we have any bits left first.
975+
//
976+
if (msg.GetNumBitsLeft() > 0)
977+
{
978+
pNetMessage->bRoundedRectBackdropBox = true;
979+
pNetMessage->flBoxSize = msg.ReadFloat();
980+
pNetMessage->boxcolor[0] = msg.ReadByte();
981+
pNetMessage->boxcolor[1] = msg.ReadByte();
982+
pNetMessage->boxcolor[2] = msg.ReadByte();
983+
pNetMessage->boxcolor[3] = msg.ReadByte();
984+
}
985+
else
986+
{
987+
pNetMessage->bRoundedRectBackdropBox = false;
967988
}
968989
#endif
969990

sp/src/game/server/ai_speech_new.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,13 @@ bool CAI_Expresser::SpeakDispatchResponse( AIConcept_t concept, AI_Response *res
948948
WRITE_STRING( response );
949949
WRITE_STRING( "" ); // No custom font
950950
WRITE_BYTE ( responseLen );
951+
952+
// Background box
953+
WRITE_FLOAT( 0.4f );
954+
WRITE_BYTE( 31 );
955+
WRITE_BYTE( 31 );
956+
WRITE_BYTE( 31 );
957+
WRITE_BYTE( 127 );
951958
MessageEnd();
952959

953960
spoke = true;

sp/src/game/server/baseflex.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,13 @@ bool CBaseFlex::StartSceneEvent( CSceneEventInfo *info, CChoreoScene *scene, CCh
842842
WRITE_STRING( event->GetParameters2() );
843843
WRITE_STRING( "" ); // No custom font
844844
WRITE_BYTE ( Q_strlen( event->GetParameters2() ) );
845+
846+
// Background box
847+
WRITE_FLOAT( 0.4f );
848+
WRITE_BYTE( 31 );
849+
WRITE_BYTE( 31 );
850+
WRITE_BYTE( 31 );
851+
WRITE_BYTE( 127 );
845852
MessageEnd();
846853
}
847854
return true;

sp/src/game/server/maprules.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ BEGIN_DATADESC( CGameText )
336336
DEFINE_KEYFIELD( m_textParms.fxTime, FIELD_FLOAT, "fxtime" ),
337337

338338
#ifdef MAPBASE
339+
DEFINE_KEYFIELD( m_textParms.boxSize, FIELD_FLOAT, "boxsize" ),
340+
DEFINE_KEYFIELD( m_textParms.boxColor, FIELD_COLOR32, "boxcolor" ),
341+
339342
DEFINE_KEYFIELD( m_strFont, FIELD_STRING, "font" ),
340343
DEFINE_KEYFIELD( m_bAutobreak, FIELD_BOOLEAN, "autobreak" ),
341344
#endif

sp/src/game/server/util.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,14 @@ void UTIL_HudMessage( CBasePlayer *pToPlayer, const hudtextparms_t &textparms, c
11161116
WRITE_STRING( pMessage );
11171117
#ifdef MAPBASE
11181118
WRITE_STRING( pszFont );
1119-
if (bAutobreak)
1120-
{
1121-
WRITE_BYTE ( Q_strlen( pMessage ) );
1119+
WRITE_BYTE ( bAutobreak ? Q_strlen( pMessage ) : 0 );
1120+
if ( textparms.boxSize > 0.0f )
1121+
{
1122+
WRITE_FLOAT( textparms.boxSize );
1123+
WRITE_BYTE( textparms.boxColor.r );
1124+
WRITE_BYTE( textparms.boxColor.g );
1125+
WRITE_BYTE( textparms.boxColor.b );
1126+
WRITE_BYTE( textparms.boxColor.a );
11221127
}
11231128
#endif
11241129
MessageEnd();

sp/src/game/server/util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ typedef struct hudtextparms_s
504504
float holdTime;
505505
float fxTime;
506506
int channel;
507+
#ifdef MAPBASE
508+
float boxSize = 0.0f;
509+
color32 boxColor;
510+
#endif
507511
} hudtextparms_t;
508512

509513

0 commit comments

Comments
 (0)