Skip to content

Commit 323f9fc

Browse files
authored
Merge pull request #230 from Petercov/mapbase-feature/caption-fixes
Caption Fixes
2 parents 68ea86e + b5deefa commit 323f9fc

File tree

1 file changed

+85
-7
lines changed

1 file changed

+85
-7
lines changed

sp/src/game/client/hud_closecaption.cpp

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,9 +1496,23 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
14961496

14971497
if ( m_Items.Count() > 0 )
14981498
{
1499+
#ifndef MAPBASE
14991500
// Get the remaining life span of the last item
1500-
CCloseCaptionItem *final = m_Items[ m_Items.Count() - 1 ];
1501+
CCloseCaptionItem* final = m_Items[m_Items.Count() - 1];
15011502
float prevlife = final->GetTimeToLive();
1503+
#else
1504+
float prevlife = 0.f;
1505+
// Get the remaining life span of the last displayed item
1506+
for (int i = m_Items.Count() - 1; i >= 0; i--)
1507+
{
1508+
if (m_Items[i]->GetPreDisplayTime() > cc_predisplay_time.GetFloat())
1509+
continue;
1510+
1511+
prevlife = m_Items[i]->GetTimeToLive();
1512+
break;
1513+
}
1514+
#endif // !MAPBASE
1515+
15021516

15031517
if ( prevlife > lifespan )
15041518
{
@@ -1532,7 +1546,31 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
15321546
if ( wcslen( phrase ) > 0 )
15331547
{
15341548
CCloseCaptionItem *item = new CCloseCaptionItem( phrase, lifespan, addedlife, delay, valid, fromplayer );
1535-
m_Items.AddToTail( item );
1549+
#ifdef MAPBASE
1550+
if (m_Items.Count())
1551+
{
1552+
// Add it where it will appear
1553+
for (int i = m_Items.Count() - 1; i >= 0; i--)
1554+
{
1555+
if (m_Items[i]->GetPreDisplayTime() > delay + cc_predisplay_time.GetFloat())
1556+
{
1557+
if (i == 0)
1558+
{
1559+
m_Items.AddToHead(item);
1560+
break;
1561+
}
1562+
else
1563+
continue;
1564+
}
1565+
1566+
m_Items.InsertAfter(i, item);
1567+
break;
1568+
}
1569+
}
1570+
else
1571+
#endif // MAPBASE
1572+
m_Items.AddToTail(item);
1573+
15361574
if ( StreamHasCommand( phrase, L"sfx" ) )
15371575
{
15381576
// SFX show up instantly.
@@ -1541,6 +1579,9 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
15411579

15421580
if ( GetFloatCommandValue( phrase, L"len", override_duration ) )
15431581
{
1582+
#ifdef MAPBASE
1583+
override_duration += cc_linger_time.GetFloat();
1584+
#endif // MAPBASE
15441585
item->SetTimeToLive( override_duration );
15451586
}
15461587
}
@@ -1569,7 +1610,30 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
15691610
if ( wcslen( phrase ) > 0 )
15701611
{
15711612
CCloseCaptionItem *item = new CCloseCaptionItem( phrase, lifespan, addedlife, delay, valid, fromplayer );
1572-
m_Items.AddToTail( item );
1613+
#ifdef MAPBASE
1614+
if (m_Items.Count())
1615+
{
1616+
// Add it where it will appear
1617+
for (int i = m_Items.Count() - 1; i >= 0; i--)
1618+
{
1619+
if (m_Items[i]->GetPreDisplayTime() > delay + cc_predisplay_time.GetFloat())
1620+
{
1621+
if (i == 0)
1622+
{
1623+
m_Items.AddToHead(item);
1624+
break;
1625+
}
1626+
else
1627+
continue;
1628+
}
1629+
1630+
m_Items.InsertAfter(i, item);
1631+
break;
1632+
}
1633+
}
1634+
else
1635+
#endif // MAPBASE
1636+
m_Items.AddToTail(item);
15731637

15741638
if ( StreamHasCommand( phrase, L"sfx" ) )
15751639
{
@@ -1579,6 +1643,10 @@ void CHudCloseCaption::Process( const wchar_t *stream, float duration, const cha
15791643

15801644
if ( GetFloatCommandValue( phrase, L"len", override_duration ) )
15811645
{
1646+
#ifdef MAPBASE
1647+
override_duration += cc_linger_time.GetFloat();
1648+
#endif // MAPBASE
1649+
15821650
item->SetTimeToLive( override_duration );
15831651
item->SetInitialLifeSpan( override_duration );
15841652
}
@@ -2614,8 +2682,14 @@ void CHudCloseCaption::InitCaptionDictionary( const char *dbfile )
26142682

26152683
g_AsyncCaptionResourceManager.Clear();
26162684

2685+
#ifdef MAPBASE
2686+
int iBufferSize = filesystem->GetSearchPath("GAME", true, nullptr, 0);
2687+
char* searchPaths = (char*)stackalloc(iBufferSize);
2688+
filesystem->GetSearchPath("GAME", true, searchPaths, iBufferSize);
2689+
#else
26172690
char searchPaths[4096];
26182691
filesystem->GetSearchPath( "GAME", true, searchPaths, sizeof( searchPaths ) );
2692+
#endif
26192693

26202694
for ( char *path = strtok( searchPaths, ";" ); path; path = strtok( NULL, ";" ) )
26212695
{
@@ -2626,8 +2700,13 @@ void CHudCloseCaption::InitCaptionDictionary( const char *dbfile )
26262700
}
26272701

26282702
char fullpath[MAX_PATH];
2629-
Q_snprintf( fullpath, sizeof( fullpath ), "%s%s", path, dbfile );
2630-
Q_FixSlashes( fullpath );
2703+
#ifndef MAPBASE
2704+
Q_snprintf(fullpath, sizeof(fullpath), "%s%s", path, dbfile);
2705+
Q_FixSlashes(fullpath);
2706+
#else
2707+
V_ComposeFileName(path, dbfile, fullpath, sizeof(fullpath));
2708+
#endif // !MAPBASE
2709+
26312710

26322711
if ( IsX360() )
26332712
{
@@ -2692,8 +2771,7 @@ void CHudCloseCaption::AddAdditionalCaptionDictionary( const char *dbfile, CUtlV
26922771
}
26932772

26942773
char fullpath[MAX_PATH];
2695-
Q_snprintf( fullpath, sizeof( fullpath ), "%s%s", path, dbfile );
2696-
Q_FixSlashes( fullpath );
2774+
V_ComposeFileName(path, dbfile, fullpath, sizeof(fullpath));
26972775

26982776
if ( IsX360() )
26992777
{

0 commit comments

Comments
 (0)