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.

87 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=============================================================================
  4. #include "cbase.h"
  5. #include "proxyentity.h"
  6. #include "materialsystem/imaterial.h"
  7. #include "materialsystem/imaterialvar.h"
  8. #include "c_team.h"
  9. #include "tf_shareddefs.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //=============================================================================
  13. //
  14. // Team Material Proxy
  15. //
  16. // Handles changing team color (skins).
  17. //
  18. class CTeamMaterialProxy : public CEntityMaterialProxy
  19. {
  20. public:
  21. CTeamMaterialProxy();
  22. virtual ~CTeamMaterialProxy();
  23. virtual bool Init( IMaterial *pMaterial, KeyValues* pKeyValues );
  24. virtual void OnBind( C_BaseEntity *pEnt );
  25. virtual IMaterial *GetMaterial();
  26. private:
  27. IMaterialVar* m_FrameVar;
  28. };
  29. //-----------------------------------------------------------------------------
  30. // Purpose: Constructor.
  31. //-----------------------------------------------------------------------------
  32. CTeamMaterialProxy::CTeamMaterialProxy()
  33. {
  34. m_FrameVar = 0;
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Destructor.
  38. //-----------------------------------------------------------------------------
  39. CTeamMaterialProxy::~CTeamMaterialProxy()
  40. {
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose: Initialization.
  44. //-----------------------------------------------------------------------------
  45. bool CTeamMaterialProxy::Init( IMaterial *pMaterial, KeyValues* pKeyValues )
  46. {
  47. bool foundVar;
  48. m_FrameVar = pMaterial->FindVar( "$frame", &foundVar, false );
  49. if( !foundVar )
  50. {
  51. m_FrameVar = 0;
  52. }
  53. return true;
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Set the appropriate texture (in the animated texture).
  57. //-----------------------------------------------------------------------------
  58. void CTeamMaterialProxy::OnBind( C_BaseEntity *pEnt )
  59. {
  60. if( !m_FrameVar )
  61. return;
  62. int team = pEnt->GetRenderTeamNumber();
  63. team -= 2;
  64. // Use that as an animated frame number
  65. m_FrameVar->SetIntValue( team );
  66. }
  67. IMaterial *CTeamMaterialProxy::GetMaterial()
  68. {
  69. if ( !m_FrameVar )
  70. return NULL;
  71. return m_FrameVar->GetOwningMaterial();
  72. }
  73. EXPOSE_INTERFACE( CTeamMaterialProxy, IMaterialProxy, "TeamTexture" IMATERIAL_PROXY_INTERFACE_VERSION );