Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 18 additions & 78 deletions sp/src/game/client/c_point_commentary_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class CHudCommentary : public CHudElement, public vgui::Panel
#ifdef MAPBASE
virtual void PerformLayout();
void ResolveBounds( int width, int height );

virtual void LevelShutdown();
#endif

private:
Expand All @@ -118,10 +116,6 @@ class CHudCommentary : public CHudElement, public vgui::Panel
vgui::Label *m_pFootnoteLabel;
vgui::HFont m_hSmallFont;

// HACKHACK: Needed as a failsafe to prevent desync
int m_iCCDefaultY;
float m_flCCAnimTime;

bool m_bShouldRepositionSubtitles;
#endif

Expand Down Expand Up @@ -909,9 +903,6 @@ CHudCommentary::CHudCommentary( const char *name ) : vgui::Panel( NULL, "HudComm
m_pImage->SetShouldScaleImage( true );

m_pFootnoteLabel = new vgui::Label( this, "HudCommentaryFootnoteLabel", L"Commentary footnote" );

m_iCCDefaultY = 0;
m_flCCAnimTime = 0.0f;
#endif
}

Expand Down Expand Up @@ -955,12 +946,9 @@ void CHudCommentary::Paint()

#ifdef MAPBASE
// Reset close caption element if needed
if (pHudCloseCaption->IsUsingCommentaryDimensions())
if (pHudCloseCaption->IsUsingCustomDimensions( ToHandle() ))
{
// Run this animation command instead of setting the position directly
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( pHudCloseCaption, "YPos", m_iCCDefaultY, 0.0f, 0.4f, vgui::AnimationController::INTERPOLATOR_ACCEL );

pHudCloseCaption->SetUsingCommentaryDimensions( false );
pHudCloseCaption->StopUsingCustomDimensions();
}
#endif
}
Expand All @@ -978,12 +966,9 @@ void CHudCommentary::Paint()

// Reset close caption element if needed
CHudCloseCaption *pHudCloseCaption = (CHudCloseCaption *)GET_HUDELEMENT( CHudCloseCaption );
if (pHudCloseCaption && pHudCloseCaption->IsUsingCommentaryDimensions())
if (pHudCloseCaption && pHudCloseCaption->IsUsingCustomDimensions(ToHandle()))
{
// Run this animation command instead of setting the position directly
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( pHudCloseCaption, "YPos", m_iCCDefaultY, 0.0f, 0.4f, vgui::AnimationController::INTERPOLATOR_ACCEL );

pHudCloseCaption->SetUsingCommentaryDimensions( false );
pHudCloseCaption->StopUsingCustomDimensions();
}
#endif

Expand Down Expand Up @@ -1306,30 +1291,6 @@ void CHudCommentary::ResolveBounds( int width, int height )

SetBounds( xPos, yPos, width, height );
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudCommentary::LevelShutdown( void )
{
if (m_iCCDefaultY != 0)
{
CHudCloseCaption *pHudCloseCaption = (CHudCloseCaption *)GET_HUDELEMENT( CHudCloseCaption );
if (pHudCloseCaption && pHudCloseCaption->IsUsingCommentaryDimensions())
{
int ccX, ccY;
pHudCloseCaption->GetPos( ccX, ccY );

if (m_iCCDefaultY != ccY)
{
DevMsg( "CHudCommentary had to reset misaligned CC element Y (%i) to default Y (%i)\n", ccY, m_iCCDefaultY );
pHudCloseCaption->SetPos( ccX, m_iCCDefaultY );
}

pHudCloseCaption->SetUsingCommentaryDimensions( false );
}
}
}
#endif

//-----------------------------------------------------------------------------
Expand All @@ -1351,9 +1312,6 @@ void CHudCommentary::VidInit( void )
{
SetAlpha(0);
StopCommentary();
#ifdef MAPBASE
m_iCCDefaultY = 0;
#endif
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1677,12 +1635,9 @@ void CHudCommentary::StopCommentary( void )
#ifdef MAPBASE
// Reset close caption element if needed
CHudCloseCaption *pHudCloseCaption = (CHudCloseCaption *)GET_HUDELEMENT( CHudCloseCaption );
if (pHudCloseCaption && pHudCloseCaption->IsUsingCommentaryDimensions())
if (pHudCloseCaption && pHudCloseCaption->IsUsingCustomDimensions(ToHandle()))
{
// Run this animation command instead of setting the position directly
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( pHudCloseCaption, "YPos", m_iCCDefaultY, 0.0f, 0.4f, vgui::AnimationController::INTERPOLATOR_ACCEL );

pHudCloseCaption->SetUsingCommentaryDimensions( false );
pHudCloseCaption->StopUsingCustomDimensions();
}
#endif
}
Expand Down Expand Up @@ -1748,12 +1703,9 @@ void CHudCommentary::FixupCommentaryLabels( const char *pszPrintName, const char
// Reset close caption element if it's still using commentary dimensions
// (fixes problems with switching from node to node)
CHudCloseCaption *pHudCloseCaption = (CHudCloseCaption *)GET_HUDELEMENT( CHudCloseCaption );
if (pHudCloseCaption && pHudCloseCaption->IsUsingCommentaryDimensions())
if (pHudCloseCaption && pHudCloseCaption->IsUsingCustomDimensions(ToHandle()))
{
// Run this animation command instead of setting the position directly
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( pHudCloseCaption, "YPos", m_iCCDefaultY, 0.0f, 0.4f, vgui::AnimationController::INTERPOLATOR_ACCEL );

pHudCloseCaption->SetUsingCommentaryDimensions( false );
pHudCloseCaption->StopUsingCustomDimensions();
}
}

Expand All @@ -1767,41 +1719,29 @@ void CHudCommentary::RepositionAndFollowCloseCaption( int yOffset )

// Place underneath the close caption element
CHudCloseCaption *pHudCloseCaption = (CHudCloseCaption *)GET_HUDELEMENT( CHudCloseCaption );
if (pHudCloseCaption /*&& !pHudCloseCaption->IsUsingCommentaryDimensions()*/)
if (pHudCloseCaption /*&& !pHudCloseCaption->IsUsingCustomDimensions()*/)
{
int ccX, ccY;
pHudCloseCaption->GetPos( ccX, ccY );

// Save the default position in case we need to do a hard reset
// (this usually happens when players begin commentary before the CC element's return animation command is finished)
if (m_iCCDefaultY == 0)
{
m_iCCDefaultY = ccY;
}
int ccDefX, ccDefY;
pHudCloseCaption->GetDefaultPos( ccDefX, ccDefY );

if (!pHudCloseCaption->IsUsingCommentaryDimensions())
if (!pHudCloseCaption->IsUsingCustomDimensions( ToHandle() ))
{
if (m_iCCDefaultY != ccY /*&& !pHudCloseCaption->IsUsingCommentaryDimensions()*/)
if (ccDefY != ccY /*&& !pHudCloseCaption->IsUsingCustomDimensions()*/)
{
DevMsg( "CHudCommentary had to reset misaligned CC element Y (%i) to default Y (%i)\n", ccY, m_iCCDefaultY );
ccY = m_iCCDefaultY;
ccY = ccDefY;
}

ccY -= m_iTypeAudioT;

// Run this animation command instead of setting the position directly
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( pHudCloseCaption, "YPos", ccY - yOffset, 0.0f, 0.2f, vgui::AnimationController::INTERPOLATOR_DEACCEL );
//pHudCloseCaption->SetPos( ccX, ccY );
m_flCCAnimTime = gpGlobals->curtime + 0.2f;

pHudCloseCaption->SetUsingCommentaryDimensions( true );
pHudCloseCaption->StartUsingCustomDimensions( ToHandle(), -1, ccY - yOffset );
}
else if (gpGlobals->curtime > m_flCCAnimTime && ccY != m_iCCDefaultY - m_iTypeAudioT - yOffset)
else if (!pHudCloseCaption->IsMovingToCustomDimensions() && ccY != ccDefY - m_iTypeAudioT - yOffset)
{
DevMsg( "CHudCommentary had to correct misaligned CC element offset (%i != %i)\n", m_iCCDefaultY - ccY, yOffset );

g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( pHudCloseCaption, "YPos", m_iCCDefaultY - m_iTypeAudioT - yOffset, 0.0f, 0.2f, vgui::AnimationController::INTERPOLATOR_DEACCEL );
m_flCCAnimTime = gpGlobals->curtime + 0.2f;
DevMsg( "CHudCommentary had to correct misaligned CC element offset (%i != %i)\n", ccDefY - ccY, yOffset );
pHudCloseCaption->StartUsingCustomDimensions( ToHandle(), -1, ccDefY - m_iTypeAudioT - yOffset );
}

SetPos( ccX, ccY + pHudCloseCaption->GetTall() + commentary_audio_element_below_cc_margin.GetInt() );
Expand Down
88 changes: 88 additions & 0 deletions sp/src/game/client/hud_closecaption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "filesystem.h"
#include "datacache/idatacache.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#ifdef MAPBASE
#include <vgui_controls/AnimationController.h>
#endif

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down Expand Up @@ -839,6 +842,12 @@ CHudCloseCaption::CHudCloseCaption( const char *pElementName )
m_bLocked = false;
m_bVisibleDueToDirect = false;

#ifdef MAPBASE
m_hCustomDimensionsOwner = vgui::INVALID_PANEL;
m_flCustomDimensionsAnimTime = 0.0f;
m_nDefaultX = m_nDefaultY = 0;
#endif

SetPaintBorderEnabled( false );
SetPaintBackgroundEnabled( false );

Expand Down Expand Up @@ -890,6 +899,17 @@ void CHudCloseCaption::LevelInit( void )

// Wipe any stale pending work items...
ClearAsyncWork();

#ifdef MAPBASE
if ( IsUsingCustomDimensions() )
{
// Reset position immediately
SetPos( m_nDefaultX, m_nDefaultY );
m_hCustomDimensionsOwner = vgui::INVALID_PANEL;
}

m_nDefaultX = m_nDefaultY = 0;
#endif
}

static ConVar cc_minvisibleitems( "cc_minvisibleitems", "1", 0, "Minimum number of caption items to show." );
Expand Down Expand Up @@ -3160,3 +3180,71 @@ void CHudCloseCaption::FindSound( char const *pchANSI )
delete[] block;
}
}

#ifdef MAPBASE
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudCloseCaption::GetDefaultPos( int &x, int &y )
{
GetPos( x, y );

if ( m_nDefaultX != 0 )
x = m_nDefaultX;

if ( m_nDefaultY != 0 )
y = m_nDefaultY;
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudCloseCaption::StartUsingCustomDimensions( vgui::HPanel hOwner, int nNewX, int nNewY, float flAnimTime )
{
int x, y;
GetPos( x, y );

if ( m_hCustomDimensionsOwner == vgui::INVALID_PANEL && m_nDefaultY == 0 )
{
m_nDefaultX = x;
m_nDefaultY = y;
}

// Run animation commands instead of setting the position directly
if ( x != nNewX && nNewX != -1 )
{
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( this, "XPos", nNewX, 0.0f, flAnimTime, vgui::AnimationController::INTERPOLATOR_DEACCEL );
}

if ( y != nNewY && nNewY != -1 )
{
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( this, "YPos", nNewY, 0.0f, flAnimTime, vgui::AnimationController::INTERPOLATOR_DEACCEL );
}

m_hCustomDimensionsOwner = hOwner;
m_flCustomDimensionsAnimTime = gpGlobals->curtime + flAnimTime;
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudCloseCaption::StopUsingCustomDimensions( float flAnimTime )
{
int x, y;
GetPos( x, y );

// Run animation commands instead of setting the position directly
if ( x != m_nDefaultX )
{
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( this, "XPos", m_nDefaultX, 0.0f, flAnimTime, vgui::AnimationController::INTERPOLATOR_SIMPLESPLINE );
}

if ( y != m_nDefaultY )
{
g_pClientMode->GetViewportAnimationController()->RunAnimationCommand( this, "YPos", m_nDefaultY, 0.0f, flAnimTime, vgui::AnimationController::INTERPOLATOR_SIMPLESPLINE );
}

m_hCustomDimensionsOwner = vgui::INVALID_PANEL;
m_flCustomDimensionsAnimTime = gpGlobals->curtime + flAnimTime;
}
#endif
15 changes: 12 additions & 3 deletions sp/src/game/client/hud_closecaption.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,15 @@ class CHudCloseCaption : public CHudElement, public vgui::Panel
void FindSound( char const *pchANSI );

#ifdef MAPBASE
inline bool IsUsingCommentaryDimensions() const { return m_bUsingCommentaryDimensions; }
inline void SetUsingCommentaryDimensions( bool bToggle ) { m_bUsingCommentaryDimensions = bToggle; }
// Other HUD elements may need to take the caption element's place
inline bool IsUsingCustomDimensions() const { return m_hCustomDimensionsOwner != vgui::INVALID_PANEL; }
inline bool IsUsingCustomDimensions( vgui::HPanel hOwner ) const { return m_hCustomDimensionsOwner == hOwner; }
inline bool IsMovingToCustomDimensions() const { return m_flCustomDimensionsAnimTime > gpGlobals->curtime; }
inline float GetBackgroundAlpha() const { return m_flBackgroundAlpha; }

void GetDefaultPos( int &x, int &y );
void StartUsingCustomDimensions( vgui::HPanel hOwner, int nNewX, int nNewY, float flAnimTime = 0.2f );
void StopUsingCustomDimensions( float flAnimTime = 0.4f );
#endif

public:
Expand Down Expand Up @@ -224,7 +231,9 @@ class CHudCloseCaption : public CHudElement, public vgui::Panel
CUtlSymbol m_CurrentLanguage;

#ifdef MAPBASE
bool m_bUsingCommentaryDimensions;
vgui::HPanel m_hCustomDimensionsOwner;
float m_flCustomDimensionsAnimTime;
int m_nDefaultX, m_nDefaultY;
#endif
};

Expand Down
Loading