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.

132 lines
3.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "materialsystem/imesh.h"
  9. #include "toolframework_client.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. // -------------------------------------------------------------------------------- //
  13. // An entity used to access overlays (and change their texture)
  14. // -------------------------------------------------------------------------------- //
  15. class C_InfoOverlayAccessor : public C_BaseEntity
  16. {
  17. public:
  18. DECLARE_CLASS( C_InfoOverlayAccessor, C_BaseEntity );
  19. DECLARE_CLIENTCLASS();
  20. C_InfoOverlayAccessor();
  21. virtual void OnDataChanged( DataUpdateType_t updateType );
  22. virtual void GetToolRecordingState( KeyValues *msg );
  23. void RestoreToToolRecordedState( KeyValues *pKV );
  24. void DestroyToolRecording( void );
  25. private:
  26. int m_iOverlayID;
  27. };
  28. // Expose it to the engine.
  29. IMPLEMENT_CLIENTCLASS(C_InfoOverlayAccessor, DT_InfoOverlayAccessor, CInfoOverlayAccessor);
  30. BEGIN_RECV_TABLE_NOBASE(C_InfoOverlayAccessor, DT_InfoOverlayAccessor)
  31. RecvPropInt(RECVINFO(m_iTextureFrameIndex)),
  32. RecvPropInt(RECVINFO(m_iOverlayID)),
  33. END_RECV_TABLE()
  34. // -------------------------------------------------------------------------------- //
  35. // Functions.
  36. // -------------------------------------------------------------------------------- //
  37. C_InfoOverlayAccessor::C_InfoOverlayAccessor()
  38. {
  39. }
  40. void C_InfoOverlayAccessor::OnDataChanged( DataUpdateType_t updateType )
  41. {
  42. if ( updateType == DATA_UPDATE_CREATED )
  43. {
  44. // Update overlay's bind proxy
  45. engine->SetOverlayBindProxy( m_iOverlayID, GetClientRenderable() );
  46. }
  47. }
  48. void C_InfoOverlayAccessor::GetToolRecordingState( KeyValues *msg )
  49. {
  50. BaseClass::GetToolRecordingState( msg );
  51. KeyValues *pKV = CIFM_EntityKeyValuesHandler_AutoRegister::FindOrCreateNonConformantKeyValues( msg );
  52. pKV->SetString( CIFM_EntityKeyValuesHandler_AutoRegister::GetHandlerIDKeyString(), "C_InfoOverlayAccessor" );
  53. pKV->SetInt( "entIndex", index );
  54. pKV->SetInt( "overlayID", m_iOverlayID );
  55. pKV->SetInt( "textureFrame", GetTextureFrameIndex() );
  56. //mark entity as visible so we'll get playback (even though we're invisible, the overlay we talk to isn't)
  57. {
  58. BaseEntityRecordingState_t dummyState;
  59. BaseEntityRecordingState_t *pState = (BaseEntityRecordingState_t *)msg->GetPtr( "baseentity", &dummyState );
  60. pState->m_bVisible = true;
  61. }
  62. }
  63. void C_InfoOverlayAccessor::RestoreToToolRecordedState( KeyValues *pKV )
  64. {
  65. m_iOverlayID = pKV->GetInt( "overlayID" );
  66. SetTextureFrameIndex( pKV->GetInt( "textureFrame" ) );
  67. engine->SetOverlayBindProxy( m_iOverlayID, GetClientRenderable() );
  68. }
  69. void C_InfoOverlayAccessor::DestroyToolRecording( void )
  70. {
  71. engine->SetOverlayBindProxy( m_iOverlayID, NULL );
  72. }
  73. class C_InfoOverlayAccessor_NonConformantDataHandler : public CIFM_EntityKeyValuesHandler_RecreateEntities
  74. {
  75. public:
  76. C_InfoOverlayAccessor_NonConformantDataHandler( void )
  77. : CIFM_EntityKeyValuesHandler_RecreateEntities( "C_InfoOverlayAccessor" )
  78. { }
  79. virtual void *CreateInstance( void )
  80. {
  81. return new C_InfoOverlayAccessor;
  82. }
  83. virtual void DestroyInstance( void *pEntity )
  84. {
  85. C_InfoOverlayAccessor *pCastEntity = (C_InfoOverlayAccessor *)pEntity;
  86. //clienttools->RemoveClientRenderable( pCastEntity );
  87. pCastEntity->DestroyToolRecording();
  88. delete pCastEntity;
  89. }
  90. virtual void HandleInstance( void *pEntity, KeyValues *pKeyValues )
  91. {
  92. C_InfoOverlayAccessor *pCastEntity = (C_InfoOverlayAccessor *)pEntity;
  93. pCastEntity->RestoreToToolRecordedState( pKeyValues );
  94. //if( pCastEntity->RenderHandle() == INVALID_CLIENT_RENDER_HANDLE )
  95. //{
  96. // clienttools->AddClientRenderable( pCastEntity, false, RENDERABLE_IS_TRANSLUCENT );
  97. //}
  98. //clienttools->MarkClientRenderableDirty( pCastEntity );
  99. }
  100. };
  101. static C_InfoOverlayAccessor_NonConformantDataHandler s_InfoOverlayAccessorEntityIFMHandler;