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.

59 lines
1.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "functionproxy.h"
  9. #include "toolframework_client.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. // forward declarations
  13. void ToolFramework_RecordMaterialParams( IMaterial *pMaterial );
  14. //-----------------------------------------------------------------------------
  15. // Returns the player health (from 0 to 1)
  16. //-----------------------------------------------------------------------------
  17. class CProxyHealth : public CResultProxy
  18. {
  19. public:
  20. bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  21. void OnBind( void *pC_BaseEntity );
  22. private:
  23. CFloatInput m_Factor;
  24. };
  25. bool CProxyHealth::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  26. {
  27. if (!CResultProxy::Init( pMaterial, pKeyValues ))
  28. return false;
  29. if (!m_Factor.Init( pMaterial, pKeyValues, "scale", 1 ))
  30. return false;
  31. return true;
  32. }
  33. void CProxyHealth::OnBind( void *pC_BaseEntity )
  34. {
  35. if (!pC_BaseEntity)
  36. return;
  37. C_BaseEntity *pEntity = BindArgToEntity( pC_BaseEntity );
  38. Assert( m_pResult );
  39. SetFloatResult( pEntity->HealthFraction() * m_Factor.GetFloat() );
  40. if ( ToolsEnabled() )
  41. {
  42. ToolFramework_RecordMaterialParams( GetMaterial() );
  43. }
  44. }
  45. EXPOSE_INTERFACE( CProxyHealth, IMaterialProxy, "Health" IMATERIAL_PROXY_INTERFACE_VERSION );