Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

360 lines
9.2 KiB

//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include <stdarg.h>
#include "vguicenterprint.h"
#include "ivrenderview.h"
#include "vgui/IVGui.h"
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "vgui_controls/Label.h"
#include "vgui_controls/Controls.h"
#include "vgui/ISurface.h"
#include "vgui/IScheme.h"
#include "vgui/IPanel.h"
#if defined ( CSTRIKE15 )
#include "Scaleform/HUD/sfhudinfopanel.h"
#endif // CSTRIKE15
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// [jason] Forward the message to the Scaleform info panel
#if defined ( CSTRIKE15 )
#define FORWARD_PRIORITY_MSG( x ) \
{ \
CHudElement *pElement = GetHud().FindElement( "SFHudInfoPanel" ); \
if ( pElement ) \
{ \
((SFHudInfoPanel *)pElement)->SetPriorityText( x ); \
} \
}
#endif // CSTRIKE15
#ifdef TF_CLIENT_DLL
static ConVar scr_centertime( "scr_centertime", "5" );
#else
static ConVar scr_centertime( "scr_centertime", "4" );
#endif
//-----------------------------------------------------------------------------
// Purpose: Implements Center String printing
//-----------------------------------------------------------------------------
class CCenterStringLabel : public vgui::Label
{
DECLARE_CLASS_SIMPLE( CCenterStringLabel, vgui::Label );
public:
explicit CCenterStringLabel( vgui::VPANEL parent );
virtual ~CCenterStringLabel( void );
// vgui::Panel
virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
virtual void OnTick( void );
virtual bool ShouldDraw( void );
// CVGuiCenterPrint
virtual void SetTextColor( int r, int g, int b, int a );
virtual void Print( char *text );
virtual void Print( wchar_t *text );
virtual void ColorPrint( int r, int g, int b, int a, char *text );
virtual void ColorPrint( int r, int g, int b, int a, wchar_t *text );
virtual void Clear( void );
protected:
MESSAGE_FUNC_INT_INT( OnScreenSizeChanged, "OnScreenSizeChanged", oldwide, oldtall );
private:
void ComputeSize( void );
vgui::HFont m_hFont;
float m_flCentertimeOff;
};
//-----------------------------------------------------------------------------
// Purpose:
// Input : *parent -
//-----------------------------------------------------------------------------
CCenterStringLabel::CCenterStringLabel( vgui::VPANEL parent ) :
BaseClass( NULL, "CCenterStringLabel", " " )
{
SetParent( parent );
ComputeSize();
SetVisible( false );
SetCursor( 0 );
SetKeyBoardInputEnabled( false );
SetMouseInputEnabled( false );
SetContentAlignment( vgui::Label::a_center );
SetScheme( "ClientScheme" );
m_hFont = 0;
SetFgColor( Color( 255, 255, 255, 255 ) );
SetPaintBackgroundEnabled( false );
m_flCentertimeOff = 0.0;
vgui::ivgui()->AddTickSignal( GetVPanel(), 100 );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CCenterStringLabel::~CCenterStringLabel( void )
{
}
//-----------------------------------------------------------------------------
// Purpose: Updates panel to handle the new screen size
//-----------------------------------------------------------------------------
void CCenterStringLabel::OnScreenSizeChanged(int iOldWide, int iOldTall)
{
BaseClass::OnScreenSizeChanged(iOldWide, iOldTall);
ComputeSize();
}
//-----------------------------------------------------------------------------
// Purpose: Computes panel's desired size and position
//-----------------------------------------------------------------------------
void CCenterStringLabel::ComputeSize( void )
{
int w, h;
if ( GetVParent() )
{
vgui::ipanel()->GetSize( GetVParent(), w, h );
int iHeight = (int)(h * 0.3);
SetSize( w, iHeight );
SetPos( 0, ( h * 0.35 ) - ( iHeight / 2 ) );
}
}
void CCenterStringLabel::ApplySchemeSettings(vgui::IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
// Use a large font
m_hFont = pScheme->GetFont( "Default" );
Assert( m_hFont );
SetFont( m_hFont );
ComputeSize();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : r -
// g -
// b -
// a -
//-----------------------------------------------------------------------------
void CCenterStringLabel::SetTextColor( int r, int g, int b, int a )
{
SetFgColor( Color( r, g, b, a ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCenterStringLabel::Print( char *text )
{
SetText( text );
m_flCentertimeOff = scr_centertime.GetFloat() + gpGlobals->curtime;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCenterStringLabel::Print( wchar_t *text )
{
SetText( text );
m_flCentertimeOff = scr_centertime.GetFloat() + gpGlobals->curtime;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCenterStringLabel::ColorPrint( int r, int g, int b, int a, char *text )
{
SetTextColor( r, g, b, a );
Print( text );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCenterStringLabel::ColorPrint( int r, int g, int b, int a, wchar_t *text )
{
SetTextColor( r, g, b, a );
Print( text );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCenterStringLabel::Clear( void )
{
m_flCentertimeOff = 0;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CCenterStringLabel::OnTick( void )
{
bool bVisible = ShouldDraw();
if ( IsVisible() != bVisible )
{
SetVisible( bVisible );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : Returns true on success, false on failure.
// FIXME, this has dependencies on the engine that should go away
//-----------------------------------------------------------------------------
bool CCenterStringLabel::ShouldDraw( void )
{
// [jason] This element only exists to forward center print messages to the Scaleform InfoPanel
#if defined ( CSTRIKE15 )
return false;
#endif
if ( engine->IsDrawingLoadingImage() )
{
return false;
}
if ( m_flCentertimeOff <= gpGlobals->curtime )
{
// not time to turn off the message yet
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output :
//-----------------------------------------------------------------------------
CCenterPrint::CCenterPrint( void )
{
vguiCenterString = NULL;
}
void CCenterPrint::SetTextColor( int r, int g, int b, int a )
{
if ( vguiCenterString )
{
vguiCenterString->SetTextColor( r, g, b, a );
}
}
void CCenterPrint::Print( char *text )
{
// [jason] Forward the message to the Scaleform info panel
#if defined ( CSTRIKE15 )
FORWARD_PRIORITY_MSG( text );
return;
#endif
if ( vguiCenterString )
{
vguiCenterString->ColorPrint( 255, 255, 255, 255, text );
}
}
void CCenterPrint::Print( wchar_t *text )
{
// [jason] Forward the message to the Scaleform info panel
#if defined ( CSTRIKE15 )
FORWARD_PRIORITY_MSG( text );
return;
#endif
if ( vguiCenterString )
{
vguiCenterString->ColorPrint( 255, 255, 255, 255, text );
}
}
void CCenterPrint::ColorPrint( int r, int g, int b, int a, char *text )
{
// [jason] Forward the message to the Scaleform info panel
#if defined ( CSTRIKE15 )
FORWARD_PRIORITY_MSG( text );
return;
#endif
if ( vguiCenterString )
{
vguiCenterString->ColorPrint( r, g, b, a, text );
}
}
void CCenterPrint::ColorPrint( int r, int g, int b, int a, wchar_t *text )
{
// [jason] Forward the message to the Scaleform info panel
#if defined ( CSTRIKE15 )
FORWARD_PRIORITY_MSG( text );
return;
#endif
if ( vguiCenterString )
{
vguiCenterString->ColorPrint( r, g, b, a, text );
}
}
void CCenterPrint::Clear( void )
{
// [jason] Forward the message to the Scaleform info panel
#if defined ( CSTRIKE15 )
FORWARD_PRIORITY_MSG( static_cast<wchar_t*>(NULL) );
return;
#endif
if ( vguiCenterString )
{
vguiCenterString->Clear();
}
}
void CCenterPrint::Create( vgui::VPANEL parent )
{
if ( vguiCenterString )
{
Destroy();
}
vguiCenterString = new CCenterStringLabel( parent );
}
void CCenterPrint::Destroy( void )
{
if ( vguiCenterString )
{
vguiCenterString->SetParent( (vgui::Panel *)NULL );
delete vguiCenterString;
vguiCenterString = NULL;
}
}
static CCenterPrint g_CenterString[ MAX_SPLITSCREEN_PLAYERS ];
CCenterPrint *GetCenterPrint()
{
ASSERT_LOCAL_PLAYER_RESOLVABLE();
return &g_CenterString[ GET_ACTIVE_SPLITSCREEN_SLOT() ];
}