Fixed delayed closed captions

This commit is contained in:
Peter Covington 2023-02-19 19:26:55 -05:00
parent e672c3521c
commit b5deefa088

View File

@ -1496,9 +1496,23 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
if ( m_Items.Count() > 0 )
{
#ifndef MAPBASE
// Get the remaining life span of the last item
CCloseCaptionItem *final = m_Items[ m_Items.Count() - 1 ];
CCloseCaptionItem* final = m_Items[m_Items.Count() - 1];
float prevlife = final->GetTimeToLive();
#else
float prevlife = 0.f;
// Get the remaining life span of the last displayed item
for (int i = m_Items.Count() - 1; i >= 0; i--)
{
if (m_Items[i]->GetPreDisplayTime() > cc_predisplay_time.GetFloat())
continue;
prevlife = m_Items[i]->GetTimeToLive();
break;
}
#endif // !MAPBASE
if ( prevlife > lifespan )
{
@ -1532,7 +1546,31 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
if ( wcslen( phrase ) > 0 )
{
CCloseCaptionItem *item = new CCloseCaptionItem( phrase, lifespan, addedlife, delay, valid, fromplayer );
m_Items.AddToTail( item );
#ifdef MAPBASE
if (m_Items.Count())
{
// Add it where it will appear
for (int i = m_Items.Count() - 1; i >= 0; i--)
{
if (m_Items[i]->GetPreDisplayTime() > delay + cc_predisplay_time.GetFloat())
{
if (i == 0)
{
m_Items.AddToHead(item);
break;
}
else
continue;
}
m_Items.InsertAfter(i, item);
break;
}
}
else
#endif // MAPBASE
m_Items.AddToTail(item);
if ( StreamHasCommand( phrase, L"sfx" ) )
{
// SFX show up instantly.
@ -1541,6 +1579,9 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
if ( GetFloatCommandValue( phrase, L"len", override_duration ) )
{
#ifdef MAPBASE
override_duration += cc_linger_time.GetFloat();
#endif // MAPBASE
item->SetTimeToLive( override_duration );
}
}
@ -1569,7 +1610,30 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
if ( wcslen( phrase ) > 0 )
{
CCloseCaptionItem *item = new CCloseCaptionItem( phrase, lifespan, addedlife, delay, valid, fromplayer );
m_Items.AddToTail( item );
#ifdef MAPBASE
if (m_Items.Count())
{
// Add it where it will appear
for (int i = m_Items.Count() - 1; i >= 0; i--)
{
if (m_Items[i]->GetPreDisplayTime() > delay + cc_predisplay_time.GetFloat())
{
if (i == 0)
{
m_Items.AddToHead(item);
break;
}
else
continue;
}
m_Items.InsertAfter(i, item);
break;
}
}
else
#endif // MAPBASE
m_Items.AddToTail(item);
if ( StreamHasCommand( phrase, L"sfx" ) )
{
@ -1579,6 +1643,10 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
if ( GetFloatCommandValue( phrase, L"len", override_duration ) )
{
#ifdef MAPBASE
override_duration += cc_linger_time.GetFloat();
#endif // MAPBASE
item->SetTimeToLive( override_duration );
item->SetInitialLifeSpan( override_duration );
}