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.

131 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Represents an entity in a VMF
  4. //
  5. //=============================================================================
  6. #ifndef DMEVMFENTITY_H
  7. #define DMEVMFENTITY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "toolutils/dmemdlrenderable.h"
  12. #include "datamodel/dmelement.h"
  13. #include "toolframework/itoolentity.h"
  14. #include "materialsystem/MaterialSystemUtil.h"
  15. //-----------------------------------------------------------------------------
  16. // Represents an editable entity; draws its helpers
  17. //-----------------------------------------------------------------------------
  18. class CDmeVMFEntity : public CDmeMdlRenderable<CDmElement>
  19. {
  20. DEFINE_ELEMENT( CDmeVMFEntity, CDmeMdlRenderable<CDmElement> );
  21. public:
  22. // Inherited from CDmElement
  23. virtual void OnAttributeChanged( CDmAttribute *pAttribute );
  24. public:
  25. // Inherited from DmeRenderable
  26. virtual const Vector &GetRenderOrigin( void );
  27. virtual const QAngle &GetRenderAngles( void );
  28. virtual int DrawModel( int flags );
  29. virtual bool IsTransparent( void );
  30. virtual void GetRenderBounds( Vector& mins, Vector& maxs );
  31. public:
  32. int GetEntityId() const;
  33. // Returns the next available entity id
  34. static int GetNextEntityId();
  35. static void SetNextEntityId( int nEntityId );
  36. const char *GetClassName() const;
  37. const char *GetTargetName() const;
  38. bool IsPlaceholder() const;
  39. // Entity Key iteration
  40. CDmAttribute *FirstEntityKey();
  41. CDmAttribute *NextEntityKey( CDmAttribute *pEntityKey );
  42. // Attach/detach from an engine entity with the same editor index
  43. void AttachToEngineEntity( HTOOLHANDLE hToolHandle );
  44. void SetRenderOrigin( const Vector &vecOrigin );
  45. void SetRenderAngles( const QAngle &angles );
  46. void MarkDirty( bool bDirty = true );
  47. bool IsDirty( void ) { return m_bIsDirty; };
  48. void MarkDeleted( bool bDeleted = true );
  49. bool IsDeleted( void ) { return m_bIsDeleted; };
  50. bool CopyFromServer( CBaseEntity *pServerEnt );
  51. bool CopyFromServer( CBaseEntity *pServerEnt, const char *szField );
  52. bool CopyFromServer( CBaseEntity *pServerEnt, const char *szSrcField, const char *szDstField );
  53. bool CopyToServer( void );
  54. bool IsSameOnServer( CBaseEntity *pServerEntity );
  55. bool CreateOnServer( void );
  56. private:
  57. bool IsEntityKey( CDmAttribute *pEntityKey );
  58. // Draws the helper for the entity
  59. void DrawSprite( IMaterial *pMaterial );
  60. void DrawDragHelpers( IMaterial *pMaterial );
  61. void DrawFloorTarget( IMaterial *pMaterial );
  62. CDmaVar<Vector> m_vecLocalOrigin;
  63. // CDmAttributeVar<QAngle> m_vecLocalAngles;
  64. CDmaVar<Vector> m_vecLocalAngles; // something funky with the vmf importer, it asserts when it's a QAngle
  65. CDmaString m_ClassName;
  66. CDmaString m_TargetName;
  67. CDmaVar<bool> m_bIsPlaceholder;
  68. // The entity it's connected to in the engine
  69. HTOOLHANDLE m_hEngineEntity;
  70. CMaterialReference m_Wireframe;
  71. CMaterialReference m_SelectedInfoTarget;
  72. CMaterialReference m_InfoTargetSprite;
  73. // pretty sure this entity is edited
  74. bool m_bIsDirty;
  75. // entity needs to be deleted
  76. CDmaVar<bool> m_bIsDeleted;
  77. // FIXME: This is a hack for info targets
  78. bool m_bInfoTarget;
  79. // Used to store the next unique entity id;
  80. static int s_nNextEntityId;
  81. };
  82. //-----------------------------------------------------------------------------
  83. // Inline methods
  84. //-----------------------------------------------------------------------------
  85. inline const char *CDmeVMFEntity::GetClassName() const
  86. {
  87. return m_ClassName;
  88. }
  89. inline const char *CDmeVMFEntity::GetTargetName() const
  90. {
  91. return m_TargetName;
  92. }
  93. inline bool CDmeVMFEntity::IsPlaceholder() const
  94. {
  95. return m_bIsPlaceholder;
  96. }
  97. #endif // DMEVMFENTITY_H