@@ -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
0 commit comments