diff --git a/cl_dll/message.cpp b/cl_dll/message.cpp index 723a6dcf..a9c706ec 100644 --- a/cl_dll/message.cpp +++ b/cl_dll/message.cpp @@ -27,18 +27,22 @@ DECLARE_MESSAGE( m_Message, HudText ) DECLARE_MESSAGE( m_Message, GameTitle ) +// 1 Global client_textmessage_t for custom messages that aren't in the titles.txt +client_textmessage_t g_pCustomMessage; +char *g_pCustomName = "Custom"; +char g_pCustomText[1024]; -int CHudMessage::Init(void) +int CHudMessage::Init( void ) { HOOK_MESSAGE( HudText ); HOOK_MESSAGE( GameTitle ); - gHUD.AddHudElem(this); + gHUD.AddHudElem( this ); Reset(); return 1; -}; +} int CHudMessage::VidInit( void ) { @@ -46,35 +50,33 @@ int CHudMessage::VidInit( void ) m_HUD_title_life = gHUD.GetSpriteIndex( "title_life" ); return 1; -}; - +} void CHudMessage::Reset( void ) { - memset( m_pMessages, 0, sizeof( m_pMessages[0] ) * maxHUDMessages ); - memset( m_startTime, 0, sizeof( m_startTime[0] ) * maxHUDMessages ); - + memset( m_pMessages, 0, sizeof(m_pMessages[0]) * maxHUDMessages ); + memset( m_startTime, 0, sizeof(m_startTime[0]) * maxHUDMessages ); + m_gameTitleTime = 0; m_pGameTitle = NULL; } - float CHudMessage::FadeBlend( float fadein, float fadeout, float hold, float localTime ) { float fadeTime = fadein + hold; float fadeBlend; - if ( localTime < 0 ) + if( localTime < 0 ) return 0; - if ( localTime < fadein ) + if( localTime < fadein ) { - fadeBlend = 1 - ((fadein - localTime) / fadein); + fadeBlend = 1 - ( ( fadein - localTime ) / fadein ); } - else if ( localTime > fadeTime ) + else if( localTime > fadeTime ) { - if ( fadeout > 0 ) - fadeBlend = 1 - ((localTime - fadeTime) / fadeout); + if( fadeout > 0 ) + fadeBlend = 1 - ( ( localTime - fadeTime ) / fadeout ); else fadeBlend = 0; } @@ -85,42 +87,41 @@ float CHudMessage::FadeBlend( float fadein, float fadeout, float hold, float loc } -int CHudMessage::XPosition( float x, int width, int totalWidth ) +int CHudMessage::XPosition( float x, int width, int totalWidth ) { int xPos; - if ( x == -1 ) + if( x == -1 ) { - xPos = (ScreenWidth - width) / 2; + xPos = ( ScreenWidth - width ) / 2; } else { - if ( x < 0 ) - xPos = (1.0 + x) * ScreenWidth - totalWidth; // Alight right + if( x < 0 ) + xPos = ( 1.0 + x ) * ScreenWidth - totalWidth; // Alight right else xPos = x * ScreenWidth; } - if ( xPos + width > ScreenWidth ) + if( xPos + width > ScreenWidth ) xPos = ScreenWidth - width; - else if ( xPos < 0 ) + else if( xPos < 0 ) xPos = 0; return xPos; } - int CHudMessage::YPosition( float y, int height ) { int yPos; - if ( y == -1 ) // Centered? - yPos = (ScreenHeight - height) * 0.5; + if( y == -1 ) // Centered? + yPos = ( ScreenHeight - height ) * 0.5; else { // Alight bottom? if ( y < 0 ) - yPos = (1.0 + y) * ScreenHeight - height; // Alight bottom + yPos = ( 1.0 + y ) * ScreenHeight - height; // Alight bottom else // align top yPos = y * ScreenHeight; } @@ -133,10 +134,9 @@ int CHudMessage::YPosition( float y, int height ) return yPos; } - void CHudMessage::MessageScanNextChar( void ) { - int srcRed, srcGreen, srcBlue, destRed, destGreen, destBlue; + int srcRed, srcGreen, srcBlue, destRed = 0, destGreen = 0, destBlue = 0; int blend; srcRed = m_parms.pMessage->r1; @@ -152,10 +152,9 @@ void CHudMessage::MessageScanNextChar( void ) destRed = destGreen = destBlue = 0; blend = m_parms.fadeBlend; break; - case 2: m_parms.charTime += m_parms.pMessage->fadein; - if ( m_parms.charTime > m_parms.time ) + if( m_parms.charTime > m_parms.time ) { srcRed = srcGreen = srcBlue = 0; blend = 0; // pure source @@ -181,23 +180,22 @@ void CHudMessage::MessageScanNextChar( void ) } break; } - if ( blend > 255 ) + if( blend > 255 ) blend = 255; - else if ( blend < 0 ) + else if( blend < 0 ) blend = 0; - m_parms.r = ((srcRed * (255-blend)) + (destRed * blend)) >> 8; - m_parms.g = ((srcGreen * (255-blend)) + (destGreen * blend)) >> 8; - m_parms.b = ((srcBlue * (255-blend)) + (destBlue * blend)) >> 8; + m_parms.r = ( ( srcRed * ( 255 - blend ) ) + ( destRed * blend ) ) >> 8; + m_parms.g = ( ( srcGreen * (255 - blend ) ) + ( destGreen * blend ) ) >> 8; + m_parms.b = ( ( srcBlue * ( 255 - blend ) ) + ( destBlue * blend ) ) >> 8; - if ( m_parms.pMessage->effect == 1 && m_parms.charTime != 0 ) + if( m_parms.pMessage->effect == 1 && m_parms.charTime != 0 ) { - if ( m_parms.x >= 0 && m_parms.y >= 0 && (m_parms.x + gHUD.m_scrinfo.charWidths[ m_parms.text ]) <= ScreenWidth ) + if( m_parms.x >= 0 && m_parms.y >= 0 && ( m_parms.x + gHUD.m_scrinfo.charWidths[m_parms.text] ) <= ScreenWidth ) TextMessageDrawChar( m_parms.x, m_parms.y, m_parms.text, m_parms.pMessage->r2, m_parms.pMessage->g2, m_parms.pMessage->b2 ); } } - void CHudMessage::MessageScanStart( void ) { switch( m_parms.pMessage->effect ) @@ -208,14 +206,14 @@ void CHudMessage::MessageScanStart( void ) m_parms.fadeTime = m_parms.pMessage->fadein + m_parms.pMessage->holdtime; - if ( m_parms.time < m_parms.pMessage->fadein ) + if( m_parms.time < m_parms.pMessage->fadein ) { - m_parms.fadeBlend = ((m_parms.pMessage->fadein - m_parms.time) * (1.0/m_parms.pMessage->fadein) * 255); + m_parms.fadeBlend = ( ( m_parms.pMessage->fadein - m_parms.time ) * ( 1.0 / m_parms.pMessage->fadein ) * 255 ); } - else if ( m_parms.time > m_parms.fadeTime ) + else if( m_parms.time > m_parms.fadeTime ) { - if ( m_parms.pMessage->fadeout > 0 ) - m_parms.fadeBlend = (((m_parms.time - m_parms.fadeTime) / m_parms.pMessage->fadeout) * 255); + if( m_parms.pMessage->fadeout > 0 ) + m_parms.fadeBlend = ( ( ( m_parms.time - m_parms.fadeTime ) / m_parms.pMessage->fadeout) * 255); else m_parms.fadeBlend = 255; // Pure dest (off) } @@ -223,15 +221,14 @@ void CHudMessage::MessageScanStart( void ) m_parms.fadeBlend = 0; // Pure source (on) m_parms.charTime = 0; - if ( m_parms.pMessage->effect == 1 && (rand()%100) < 10 ) + if( m_parms.pMessage->effect == 1 && ( rand() % 100 ) < 10 ) m_parms.charTime = 1; break; - case 2: m_parms.fadeTime = (m_parms.pMessage->fadein * m_parms.length) + m_parms.pMessage->holdtime; if ( m_parms.time > m_parms.fadeTime && m_parms.pMessage->fadeout > 0 ) - m_parms.fadeBlend = (((m_parms.time - m_parms.fadeTime) / m_parms.pMessage->fadeout) * 255); + m_parms.fadeBlend = ( ( ( m_parms.time - m_parms.fadeTime ) / m_parms.pMessage->fadeout ) * 255 ); else m_parms.fadeBlend = 0; break; @@ -253,12 +250,12 @@ void CHudMessage::MessageDrawScan( client_textmessage_t *pMessage, float time ) length = 0; width = 0; m_parms.totalWidth = 0; - while ( *pText ) + while( *pText ) { - if ( *pText == '\n' ) + if( *pText == '\n' ) { m_parms.lines++; - if ( width > m_parms.totalWidth ) + if( width > m_parms.totalWidth ) m_parms.totalWidth = width; width = 0; } @@ -268,8 +265,7 @@ void CHudMessage::MessageDrawScan( client_textmessage_t *pMessage, float time ) length++; } m_parms.length = length; - m_parms.totalHeight = (m_parms.lines * gHUD.m_scrinfo.iCharHeight); - + m_parms.totalHeight = ( m_parms.lines * gHUD.m_scrinfo.iCharHeight ); m_parms.y = YPosition( pMessage->y, m_parms.totalHeight ); pText = pMessage->pMessage; @@ -278,11 +274,11 @@ void CHudMessage::MessageDrawScan( client_textmessage_t *pMessage, float time ) MessageScanStart(); - for ( i = 0; i < m_parms.lines; i++ ) + for( i = 0; i < m_parms.lines; i++ ) { m_parms.lineLength = 0; m_parms.width = 0; - while ( *pText && *pText != '\n' ) + while( *pText && *pText != '\n' ) { unsigned char c = *pText; line[m_parms.lineLength] = c; @@ -295,13 +291,13 @@ void CHudMessage::MessageDrawScan( client_textmessage_t *pMessage, float time ) m_parms.x = XPosition( pMessage->x, m_parms.width, m_parms.totalWidth ); - for ( j = 0; j < m_parms.lineLength; j++ ) + for( j = 0; j < m_parms.lineLength; j++ ) { m_parms.text = line[j]; - int next = m_parms.x + gHUD.m_scrinfo.charWidths[ m_parms.text ]; + int next = m_parms.x + gHUD.m_scrinfo.charWidths[m_parms.text]; MessageScanNextChar(); - - if ( m_parms.x >= 0 && m_parms.y >= 0 && next <= ScreenWidth ) + + if( m_parms.x >= 0 && m_parms.y >= 0 && next <= ScreenWidth ) TextMessageDrawChar( m_parms.x, m_parms.y, m_parms.text, m_parms.r, m_parms.g, m_parms.b ); m_parms.x = next; } @@ -310,7 +306,6 @@ void CHudMessage::MessageDrawScan( client_textmessage_t *pMessage, float time ) } } - int CHudMessage::Draw( float fTime ) { int i, drawn; @@ -319,53 +314,52 @@ int CHudMessage::Draw( float fTime ) drawn = 0; - if ( m_gameTitleTime > 0 ) + if( m_gameTitleTime > 0 ) { float localTime = gHUD.m_flTime - m_gameTitleTime; float brightness; // Maybe timer isn't set yet - if ( m_gameTitleTime > gHUD.m_flTime ) + if( m_gameTitleTime > gHUD.m_flTime ) m_gameTitleTime = gHUD.m_flTime; - if ( localTime > (m_pGameTitle->fadein + m_pGameTitle->holdtime + m_pGameTitle->fadeout) ) + if( localTime > ( m_pGameTitle->fadein + m_pGameTitle->holdtime + m_pGameTitle->fadeout ) ) m_gameTitleTime = 0; else { brightness = FadeBlend( m_pGameTitle->fadein, m_pGameTitle->fadeout, m_pGameTitle->holdtime, localTime ); - int halfWidth = gHUD.GetSpriteRect(m_HUD_title_half).right - gHUD.GetSpriteRect(m_HUD_title_half).left; - int fullWidth = halfWidth + gHUD.GetSpriteRect(m_HUD_title_life).right - gHUD.GetSpriteRect(m_HUD_title_life).left; - int fullHeight = gHUD.GetSpriteRect(m_HUD_title_half).bottom - gHUD.GetSpriteRect(m_HUD_title_half).top; + int halfWidth = gHUD.GetSpriteRect( m_HUD_title_half ).right - gHUD.GetSpriteRect( m_HUD_title_half ).left; + int fullWidth = halfWidth + gHUD.GetSpriteRect( m_HUD_title_life ).right - gHUD.GetSpriteRect( m_HUD_title_life ).left; + int fullHeight = gHUD.GetSpriteRect( m_HUD_title_half ).bottom - gHUD.GetSpriteRect( m_HUD_title_half ).top; int x = XPosition( m_pGameTitle->x, fullWidth, fullWidth ); int y = YPosition( m_pGameTitle->y, fullHeight ); + SPR_Set( gHUD.GetSprite( m_HUD_title_half ), brightness * m_pGameTitle->r1, brightness * m_pGameTitle->g1, brightness * m_pGameTitle->b1 ); + SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( m_HUD_title_half ) ); - SPR_Set( gHUD.GetSprite(m_HUD_title_half), brightness * m_pGameTitle->r1, brightness * m_pGameTitle->g1, brightness * m_pGameTitle->b1 ); - SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect(m_HUD_title_half) ); - - SPR_Set( gHUD.GetSprite(m_HUD_title_life), brightness * m_pGameTitle->r1, brightness * m_pGameTitle->g1, brightness * m_pGameTitle->b1 ); - SPR_DrawAdditive( 0, x + halfWidth, y, &gHUD.GetSpriteRect(m_HUD_title_life) ); + SPR_Set( gHUD.GetSprite( m_HUD_title_life ), brightness * m_pGameTitle->r1, brightness * m_pGameTitle->g1, brightness * m_pGameTitle->b1 ); + SPR_DrawAdditive( 0, x + halfWidth, y, &gHUD.GetSpriteRect( m_HUD_title_life ) ); drawn = 1; } } // Fixup level transitions - for ( i = 0; i < maxHUDMessages; i++ ) + for( i = 0; i < maxHUDMessages; i++ ) { // Assume m_parms.time contains last time - if ( m_pMessages[i] ) + if( m_pMessages[i] ) { pMessage = m_pMessages[i]; - if ( m_startTime[i] > gHUD.m_flTime ) + if( m_startTime[i] > gHUD.m_flTime ) m_startTime[i] = gHUD.m_flTime + m_parms.time - m_startTime[i] + 0.2; // Server takes 0.2 seconds to spawn, adjust for this } } - for ( i = 0; i < maxHUDMessages; i++ ) + for( i = 0; i < maxHUDMessages; i++ ) { - if ( m_pMessages[i] ) + if( m_pMessages[i] ) { pMessage = m_pMessages[i]; @@ -376,14 +370,14 @@ int CHudMessage::Draw( float fTime ) case 1: endTime = m_startTime[i] + pMessage->fadein + pMessage->fadeout + pMessage->holdtime; break; - + // Fade in is per character in scanning messages case 2: - endTime = m_startTime[i] + (pMessage->fadein * strlen( pMessage->pMessage )) + pMessage->fadeout + pMessage->holdtime; + endTime = m_startTime[i] + ( pMessage->fadein * strlen( pMessage->pMessage ) ) + pMessage->fadeout + pMessage->holdtime; break; } - if ( fTime <= endTime ) + if( fTime <= endTime ) { float messageTime = fTime - m_startTime[i]; @@ -406,29 +400,76 @@ int CHudMessage::Draw( float fTime ) // Remember the time -- to fix up level transitions m_parms.time = gHUD.m_flTime; // Don't call until we get another message - if ( !drawn ) + if( !drawn ) m_iFlags &= ~HUD_ACTIVE; return 1; } - void CHudMessage::MessageAdd( const char *pName, float time ) { - int i; + int i, j; + client_textmessage_t *tempMessage; - for ( i = 0; i < maxHUDMessages; i++ ) + for( i = 0; i < maxHUDMessages; i++ ) { - if ( !m_pMessages[i] ) + if( !m_pMessages[i] ) { - m_pMessages[i] = TextMessageGet( pName ); + // Trim off a leading # if it's there + if( pName[0] == '#' ) + tempMessage = TextMessageGet( pName + 1 ); + else + tempMessage = TextMessageGet( pName ); + // If we couldnt find it in the titles.txt, just create it + if( !tempMessage ) + { + g_pCustomMessage.effect = 2; + g_pCustomMessage.r1 = g_pCustomMessage.g1 = g_pCustomMessage.b1 = g_pCustomMessage.a1 = 100; + g_pCustomMessage.r2 = 240; + g_pCustomMessage.g2 = 110; + g_pCustomMessage.b2 = 0; + g_pCustomMessage.a2 = 0; + g_pCustomMessage.x = -1; // Centered + g_pCustomMessage.y = 0.7; + g_pCustomMessage.fadein = 0.01; + g_pCustomMessage.fadeout = 1.5; + g_pCustomMessage.fxtime = 0.25; + g_pCustomMessage.holdtime = 5; + g_pCustomMessage.pName = g_pCustomName; + strcpy( g_pCustomText, pName ); + g_pCustomMessage.pMessage = g_pCustomText; + + tempMessage = &g_pCustomMessage; + } + + for( j = 0; j < maxHUDMessages; j++ ) + { + if( m_pMessages[j] ) + { + // is this message already in the list + if( !strcmp( tempMessage->pMessage, m_pMessages[j]->pMessage ) ) + { + return; + } + + // get rid of any other messages in same location (only one displays at a time) + if( fabs( tempMessage->y - m_pMessages[j]->y ) < 0.0001 ) + { + if ( fabs( tempMessage->x - m_pMessages[j]->x ) < 0.0001 ) + { + m_pMessages[j] = NULL; + } + } + } + } + + m_pMessages[i] = tempMessage; m_startTime[i] = time; return; } } } - int CHudMessage::MsgFunc_HudText( const char *pszName, int iSize, void *pbuf ) { BEGIN_READ( pbuf, iSize ); @@ -436,43 +477,43 @@ int CHudMessage::MsgFunc_HudText( const char *pszName, int iSize, void *pbuf ) char *pString = READ_STRING(); MessageAdd( pString, gHUD.m_flTime ); + // Remember the time -- to fix up level transitions m_parms.time = gHUD.m_flTime; // Turn on drawing - if ( !(m_iFlags & HUD_ACTIVE) ) + if( !( m_iFlags & HUD_ACTIVE ) ) m_iFlags |= HUD_ACTIVE; return 1; } - int CHudMessage::MsgFunc_GameTitle( const char *pszName, int iSize, void *pbuf ) { m_pGameTitle = TextMessageGet( "GAMETITLE" ); - if ( m_pGameTitle != NULL ) + if( m_pGameTitle != NULL ) { m_gameTitleTime = gHUD.m_flTime; // Turn on drawing - if ( !(m_iFlags & HUD_ACTIVE) ) + if( !( m_iFlags & HUD_ACTIVE ) ) m_iFlags |= HUD_ACTIVE; } return 1; } -void CHudMessage::MessageAdd(client_textmessage_t * newMessage ) +void CHudMessage::MessageAdd( client_textmessage_t * newMessage ) { m_parms.time = gHUD.m_flTime; // Turn on drawing - if ( !(m_iFlags & HUD_ACTIVE) ) + if( !( m_iFlags & HUD_ACTIVE ) ) m_iFlags |= HUD_ACTIVE; - - for ( int i = 0; i < maxHUDMessages; i++ ) + + for( int i = 0; i < maxHUDMessages; i++ ) { - if ( !m_pMessages[i] ) + if( !m_pMessages[i] ) { m_pMessages[i] = newMessage; m_startTime[i] = gHUD.m_flTime;