diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/cstrike/vgui_viewc4panel.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/client/cstrike/vgui_viewc4panel.cpp')
| -rw-r--r-- | game/client/cstrike/vgui_viewc4panel.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/game/client/cstrike/vgui_viewc4panel.cpp b/game/client/cstrike/vgui_viewc4panel.cpp new file mode 100644 index 0000000..e5c7b04 --- /dev/null +++ b/game/client/cstrike/vgui_viewc4panel.cpp @@ -0,0 +1,117 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#include "cbase.h" +#include "c_vguiscreen.h" +#include "vgui_controls/Label.h" +#include <vgui/IVGui.h> +#include "weapon_c4.h" +#include "ienginevgui.h" + +using namespace vgui; + +//----------------------------------------------------------------------------- +// Control screen +//----------------------------------------------------------------------------- +class CViewC4Panel : public CVGuiScreenPanel +{ + DECLARE_CLASS( CViewC4Panel, CVGuiScreenPanel ); + +public: + CViewC4Panel( vgui::Panel *parent, const char *panelName ); + ~CViewC4Panel(); + virtual bool Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData ); + virtual void OnTick(); + + C_BaseCombatWeapon *GetOwningWeapon(); + + virtual void ApplySchemeSettings( IScheme *pScheme ); + +private: + vgui::Label *m_pTimeLabel; +}; + + +DECLARE_VGUI_SCREEN_FACTORY( CViewC4Panel, "c4_view_panel" ); + +//----------------------------------------------------------------------------- +// Constructor: +//----------------------------------------------------------------------------- +CViewC4Panel::CViewC4Panel( vgui::Panel *parent, const char *panelName ) + : BaseClass( parent, "CViewC4Panel", vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/C4Panel.res", "ClientScheme" ) ) +{ + SetSize( 10, 10 ); // Quiet "parent not sized yet" spew + m_pTimeLabel = new vgui::Label( this, "TimerLabel", "" ); +} + +CViewC4Panel::~CViewC4Panel() +{ +} + +void CViewC4Panel::ApplySchemeSettings( IScheme *pScheme ) +{ + if( pScheme ) + { + m_pTimeLabel->SetFgColor( pScheme->GetColor( "C4Panel_Armed", GetFgColor() ) ); + } +} + +//----------------------------------------------------------------------------- +// Initialization +//----------------------------------------------------------------------------- +bool CViewC4Panel::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData ) +{ + // Make sure we get ticked... + vgui::ivgui()->AddTickSignal( GetVPanel() ); + + if (!BaseClass::Init(pKeyValues, pInitData)) + return false; + + return true; +} + +C_BaseCombatWeapon *CViewC4Panel::GetOwningWeapon() +{ + C_BaseEntity *pScreenEnt = GetEntity(); + if (!pScreenEnt) + return NULL; + + C_BaseEntity *pOwner = pScreenEnt->GetOwnerEntity(); + if (!pOwner) + return NULL; + + C_BaseViewModel *pViewModel = dynamic_cast< C_BaseViewModel * >( pOwner ); + if ( !pViewModel ) + return NULL; + + return pViewModel->GetOwningWeapon(); +} + + +//----------------------------------------------------------------------------- +// Update the screen with the latest string from the view model +//----------------------------------------------------------------------------- +void CViewC4Panel::OnTick() +{ + BaseClass::OnTick(); + + SetVisible( true ); + + C_BaseEntity *pEnt = GetOwningWeapon(); + + C_C4 *pViewC4 = dynamic_cast<C_C4*>( pEnt ); + + if( pViewC4 ) + { + char *display = pViewC4->GetScreenText(); + + if( display ) + { + m_pTimeLabel->SetText( display ); + } + } +}
\ No newline at end of file |