//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======= // // Purpose: // //============================================================================= #include "cbase.h" #include "hud_controlpointicons.h" #include "teamplayroundbased_gamerules.h" #include "IClientMode.h" #include "c_team_objectiveresource.h" #include "c_playerresource.h" #include "c_baseplayer.h" #include "vguimatsurface/IMatSystemSurface.h" #include "hud_macros.h" #include "spectatorgui.h" #include "c_team.h" #include "tf_hud_freezepanel.h" #include "tf_hud_objectivestatus.h" // NOTE: This has to be the last file included! #include "tier0/memdbgon.h" using namespace vgui; //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CControlPointIconPulseable::ApplySchemeSettings( IScheme *pScheme ) { BaseClass::ApplySchemeSettings( pScheme ); if ( !m_pPulseImage ) { m_pPulseImage = scheme()->GetImage( "../sprites/obj_icons/icon_obj_white", true ); } } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CControlPointIconPulseable::OnSizeChanged(int newWide, int newTall) { if ( m_pPulseImage ) { // scaling, force the image size to be our size m_pPulseImage->SetSize(newWide, newTall); } BaseClass::OnSizeChanged(newWide, newTall); } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CControlPointIconPulseable::PaintBackground( void ) { if ( IsInFreezeCam() == true ) return; if ( GetImage() ) { SetAlpha(255); BaseClass::PaintBackground(); } if ( m_flStartCapAnimStart && gpGlobals->curtime > m_flStartCapAnimStart ) { float flElapsedTime = (gpGlobals->curtime - m_flStartCapAnimStart); // Pulse the white over the underlying color float flPulseSpeed = 20; if ( m_bAccelerateOverCapture ) { float flCapPercentage = ObjectiveResource()->GetCPCapPercentage( m_iCPIndex ); flPulseSpeed = RemapValClamped( flCapPercentage, 0, 1, 2, 5 ); } float flPulseMod = fabs(sin( flElapsedTime * flPulseSpeed )); SetAlpha( 255 * flPulseMod ); int wide, tall; GetSize( wide, tall ); // Have to reset these - we're only referencing a material so the // size can be changed by CControlPointIconCapturePulse on a successful cap m_pPulseImage->SetPos( 0, 0 ); m_pPulseImage->SetSize( wide, tall ); m_pPulseImage->Paint(); // Stop if we're only supposed to do this for a short time if ( m_flPulseTime && flElapsedTime >= m_flPulseTime ) { StopPulsing(); } } } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CControlPointIconPulseable::StartPulsing( float flDelay, float flPulseTime, bool bAccelerate ) { m_flStartCapAnimStart = gpGlobals->curtime + flDelay; m_bAccelerateOverCapture = bAccelerate; m_flPulseTime = flPulseTime; } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CControlPointIconPulseable::StopPulsing( void ) { m_flStartCapAnimStart = 0; } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- CControlPointIcon::CControlPointIcon( Panel *parent, const char *pName, int iIndex ) : EditablePanel( parent, "ControlPointIcon" ), CHudElement( pName ) { SetHiddenBits( HIDEHUD_MISCSTATUS ); m_iCPIndex = iIndex; m_pBaseImage = NULL; m_pOverlayImage = NULL; m_pCapImage = NULL; m_pCapHighlightImage = NULL; m_pCapPulseImage = NULL; m_pCapPlayerImage = NULL; m_pCapNumPlayers = NULL; m_bSwipeUp = false; m_flStartCapAnimStart = 0; m_iCapProgressDir = CP_DIR_N; m_iPrevCappers = 0; } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CControlPointIcon::ApplySchemeSettings( IScheme *pScheme ) { BaseClass::ApplySchemeSettings( pScheme ); if ( !m_pCapHighlightImage ) { m_pCapHighlightImage = new CControlPointIconSwoop( this, "CapHighlightImage" ); m_pCapHighlightImage->SetParent( GetClientMode()->GetViewport() ); m_pCapHighlightImage->SetZPos( 10 ); m_pCapHighlightImage->SetShouldScaleImage( true ); } if ( !m_pCapPulseImage ) { m_pCapPulseImage = new CControlPointIconCapturePulse( this, "CapPulse" ); m_pCapPulseImage->SetParent( GetClientMode()->GetViewport() ); m_pCapPulseImage->SetZPos( -1 ); m_pCapPulseImage->SetVisible( false ); m_pCapPulseImage->SetShouldScaleImage( true ); } if ( !m_pBaseImage ) { m_pBaseImage = new CControlPointIconPulseable( this, "BaseImage", m_iCPIndex ); m_pBaseImage->SetShouldScaleImage( true ); } if ( !m_pCapImage ) { m_pCapImage = new CControlPointIconCapArrow( this, this, "CapImage" ); m_pCapImage->SetZPos( 2 ); m_pCapImage->SetVisible( false ); } LoadControlSettings( "resource/UI/ControlPointIcon.res" ); m_pCapPlayerImage = dynamic_cast( FindChildByName("CapPlayerImage") ); m_pCapNumPlayers = dynamic_cast