Team Fortress 2 Source Code as on 22/4/2020
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.

116 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "c_vguiscreen.h"
  10. #include "vgui_controls/Label.h"
  11. #include <vgui/IVGui.h>
  12. #include "weapon_c4.h"
  13. #include "ienginevgui.h"
  14. using namespace vgui;
  15. //-----------------------------------------------------------------------------
  16. // Control screen
  17. //-----------------------------------------------------------------------------
  18. class CViewC4Panel : public CVGuiScreenPanel
  19. {
  20. DECLARE_CLASS( CViewC4Panel, CVGuiScreenPanel );
  21. public:
  22. CViewC4Panel( vgui::Panel *parent, const char *panelName );
  23. ~CViewC4Panel();
  24. virtual bool Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData );
  25. virtual void OnTick();
  26. C_BaseCombatWeapon *GetOwningWeapon();
  27. virtual void ApplySchemeSettings( IScheme *pScheme );
  28. private:
  29. vgui::Label *m_pTimeLabel;
  30. };
  31. DECLARE_VGUI_SCREEN_FACTORY( CViewC4Panel, "c4_view_panel" );
  32. //-----------------------------------------------------------------------------
  33. // Constructor:
  34. //-----------------------------------------------------------------------------
  35. CViewC4Panel::CViewC4Panel( vgui::Panel *parent, const char *panelName )
  36. : BaseClass( parent, "CViewC4Panel", vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/C4Panel.res", "ClientScheme" ) )
  37. {
  38. SetSize( 10, 10 ); // Quiet "parent not sized yet" spew
  39. m_pTimeLabel = new vgui::Label( this, "TimerLabel", "" );
  40. }
  41. CViewC4Panel::~CViewC4Panel()
  42. {
  43. }
  44. void CViewC4Panel::ApplySchemeSettings( IScheme *pScheme )
  45. {
  46. if( pScheme )
  47. {
  48. m_pTimeLabel->SetFgColor( pScheme->GetColor( "C4Panel_Armed", GetFgColor() ) );
  49. }
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Initialization
  53. //-----------------------------------------------------------------------------
  54. bool CViewC4Panel::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData )
  55. {
  56. // Make sure we get ticked...
  57. vgui::ivgui()->AddTickSignal( GetVPanel() );
  58. if (!BaseClass::Init(pKeyValues, pInitData))
  59. return false;
  60. return true;
  61. }
  62. C_BaseCombatWeapon *CViewC4Panel::GetOwningWeapon()
  63. {
  64. C_BaseEntity *pScreenEnt = GetEntity();
  65. if (!pScreenEnt)
  66. return NULL;
  67. C_BaseEntity *pOwner = pScreenEnt->GetOwnerEntity();
  68. if (!pOwner)
  69. return NULL;
  70. C_BaseViewModel *pViewModel = dynamic_cast< C_BaseViewModel * >( pOwner );
  71. if ( !pViewModel )
  72. return NULL;
  73. return pViewModel->GetOwningWeapon();
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Update the screen with the latest string from the view model
  77. //-----------------------------------------------------------------------------
  78. void CViewC4Panel::OnTick()
  79. {
  80. BaseClass::OnTick();
  81. SetVisible( true );
  82. C_BaseEntity *pEnt = GetOwningWeapon();
  83. C_C4 *pViewC4 = dynamic_cast<C_C4*>( pEnt );
  84. if( pViewC4 )
  85. {
  86. char *display = pViewC4->GetScreenText();
  87. if( display )
  88. {
  89. m_pTimeLabel->SetText( display );
  90. }
  91. }
  92. }