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.

253 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef BASEMODEL_PANEL_H
  7. #define BASEMODEL_PANEL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "matsys_controls/mdlpanel.h"
  12. //-----------------------------------------------------------------------------
  13. // Resource file data used in posing the model inside of the model panel.
  14. //-----------------------------------------------------------------------------
  15. struct BMPResAnimData_t
  16. {
  17. const char *m_pszName;
  18. const char *m_pszSequence;
  19. const char *m_pszActivity;
  20. KeyValues *m_pPoseParameters;
  21. bool m_bDefault;
  22. BMPResAnimData_t()
  23. {
  24. m_pszName = NULL;
  25. m_pszSequence = NULL;
  26. m_pszActivity = NULL;
  27. m_pPoseParameters = NULL;
  28. m_bDefault = false;
  29. }
  30. ~BMPResAnimData_t()
  31. {
  32. if ( m_pszName && m_pszName[0] )
  33. {
  34. delete [] m_pszName;
  35. m_pszName = NULL;
  36. }
  37. if ( m_pszSequence && m_pszSequence[0] )
  38. {
  39. delete [] m_pszSequence;
  40. m_pszSequence = NULL;
  41. }
  42. if ( m_pszActivity && m_pszActivity[0] )
  43. {
  44. delete [] m_pszActivity;
  45. m_pszActivity = NULL;
  46. }
  47. if ( m_pPoseParameters )
  48. {
  49. m_pPoseParameters->deleteThis();
  50. m_pPoseParameters = NULL;
  51. }
  52. }
  53. };
  54. struct BMPResAttachData_t
  55. {
  56. const char *m_pszModelName;
  57. int m_nSkin;
  58. BMPResAttachData_t()
  59. {
  60. m_pszModelName = NULL;
  61. m_nSkin = 0;
  62. }
  63. ~BMPResAttachData_t()
  64. {
  65. if ( m_pszModelName && m_pszModelName[0] )
  66. {
  67. delete [] m_pszModelName;
  68. m_pszModelName = NULL;
  69. }
  70. }
  71. };
  72. struct BMPResData_t
  73. {
  74. float m_flFOV;
  75. const char *m_pszModelName;
  76. const char *m_pszModelName_HWM;
  77. const char *m_pszVCD;
  78. QAngle m_angModelPoseRot;
  79. Vector m_vecOriginOffset;
  80. Vector m_vecFramedOriginOffset;
  81. Vector2D m_vecViewportOffset;
  82. int m_nSkin;
  83. bool m_bUseSpotlight;
  84. CUtlVector<BMPResAnimData_t> m_aAnimations;
  85. CUtlVector<BMPResAttachData_t> m_aAttachModels;
  86. BMPResData_t()
  87. {
  88. m_flFOV = 0.0f;
  89. m_pszModelName = NULL;
  90. m_pszModelName_HWM = NULL;
  91. m_pszVCD = NULL;
  92. m_angModelPoseRot.Init();
  93. m_vecOriginOffset.Init();
  94. m_vecFramedOriginOffset.Init();
  95. m_vecViewportOffset.Init();
  96. m_nSkin = 0;
  97. m_bUseSpotlight = false;
  98. }
  99. ~BMPResData_t()
  100. {
  101. if ( m_pszModelName && m_pszModelName[0] )
  102. {
  103. delete [] m_pszModelName;
  104. m_pszModelName = NULL;
  105. }
  106. if ( m_pszModelName_HWM && m_pszModelName_HWM[0] )
  107. {
  108. delete [] m_pszModelName_HWM;
  109. m_pszModelName_HWM = NULL;
  110. }
  111. if ( m_pszVCD && m_pszVCD[0] )
  112. {
  113. delete [] m_pszVCD;
  114. m_pszVCD = NULL;
  115. }
  116. m_aAnimations.Purge();
  117. m_aAttachModels.Purge();
  118. }
  119. };
  120. //-----------------------------------------------------------------------------
  121. // Base Model Panel
  122. //
  123. // ...vgui::Panel |--> vgui
  124. // +->vgui::EditablePanel |
  125. // +->PotterWheelPanel |--> matsys_controls
  126. // +->MDLPanel |
  127. // +->BaseModelPanel |--> game_controls, client.dll
  128. //
  129. //-----------------------------------------------------------------------------
  130. class CBaseModelPanel : public CMDLPanel
  131. {
  132. DECLARE_CLASS_SIMPLE( CBaseModelPanel, CMDLPanel );
  133. public:
  134. // Constructor, Destructor.
  135. CBaseModelPanel( vgui::Panel *pParent, const char *pName );
  136. virtual ~CBaseModelPanel();
  137. // Overridden mdlpanel.h
  138. virtual void SetMDL( MDLHandle_t handle, void *pProxyData = NULL );
  139. virtual void SetMDL( const char *pMDLName, void *pProxyData = NULL );
  140. virtual void SetModelAnglesAndPosition( const QAngle &angRot, const Vector &vecPos );
  141. // Overridden methods of vgui::Panel
  142. virtual void ApplySettings( KeyValues *inResourceData );
  143. virtual void PerformLayout();
  144. virtual void OnTick() OVERRIDE;
  145. // Animation.
  146. int FindDefaultAnim( void );
  147. int FindAnimByName( const char *pszName );
  148. void SetModelAnim( int iAnim );
  149. // Manipulation.
  150. virtual void OnKeyCodePressed ( vgui::KeyCode code );
  151. virtual void OnKeyCodeReleased( vgui::KeyCode code );
  152. virtual void OnMousePressed ( vgui::MouseCode code );
  153. virtual void OnMouseReleased( vgui::MouseCode code );
  154. virtual void OnCursorMoved( int x, int y );
  155. virtual void OnMouseWheeled( int delta );
  156. studiohdr_t* GetStudioHdr( void ) { return m_RootMDL.m_MDL.GetStudioHdr(); }
  157. void SetBody( unsigned int nBody ) { m_RootMDL.m_MDL.m_nBody = nBody; }
  158. void RotateYaw( float flDelta );
  159. void RotatePitch( float flDelta );
  160. Vector GetPlayerPos() const;
  161. QAngle GetPlayerAngles() const;
  162. void PlaySequence( const char *pszSequenceName );
  163. void LookAtBounds( const Vector &vecBoundsMin, const Vector &vecBoundsMax );
  164. // Set to true if external code has set a specific camera position that shouldn't be clobbered by layout
  165. void SetForcedCameraPosition( bool bForcedCameraPosition ) { m_bForcedCameraPosition = bForcedCameraPosition; }
  166. int FindSequenceFromActivity( CStudioHdr *pStudioHdr, const char *pszActivity );
  167. protected:
  168. // Resource file data.
  169. void ParseModelResInfo( KeyValues *inResourceData );
  170. void ParseModelAnimInfo( KeyValues *inResourceData );
  171. void ParseModelAttachInfo( KeyValues *inResourceData );
  172. void SetupModelDefaults( void );
  173. void SetupModelAnimDefaults( void );
  174. public:
  175. BMPResData_t m_BMPResData; // Base model panel data set in the .res file.
  176. QAngle m_angPlayer;
  177. Vector m_vecPlayerPos;
  178. protected:
  179. bool m_bForcePos;
  180. bool m_bMousePressed;
  181. bool m_bAllowRotation;
  182. bool m_bAllowPitch;
  183. bool m_bAllowFullManipulation;
  184. bool m_bApplyManipulators;
  185. bool m_bForcedCameraPosition;
  186. int m_nActiveSequence;
  187. float m_flActiveSequenceDuration;
  188. // VGUI script accessible variables.
  189. CPanelAnimationVar( bool, m_bStartFramed, "start_framed", "0" );
  190. CPanelAnimationVar( bool, m_bDisableManipulation, "disable_manipulation", "0" );
  191. CPanelAnimationVar( bool, m_bUseParticle, "use_particle", "0" );
  192. CPanelAnimationVar( float, m_flMaxPitch, "max_pitch", "90" );
  193. struct particle_data_t
  194. {
  195. ~particle_data_t();
  196. void UpdateControlPoints( CStudioHdr *pStudioHdr, matrix3x4_t *pWorldMatrix, const CUtlVector< int >& vecAttachments, int iDefaultBone = 0, const Vector& vecParticleOffset = vec3_origin );
  197. bool m_bIsUpdateToDate;
  198. CParticleCollection *m_pParticleSystem;
  199. };
  200. CUtlVector< particle_data_t* > m_particleList;
  201. particle_data_t *CreateParticleData( const char *pszParticleName );
  202. bool SafeDeleteParticleData( particle_data_t **pData );
  203. virtual void PrePaint3D( IMatRenderContext *pRenderContext ) OVERRIDE;
  204. virtual void PostPaint3D( IMatRenderContext *pRenderContext ) OVERRIDE;
  205. };
  206. #endif // BASEMODEL_PANEL_H