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.

229 lines
5.6 KiB

  1. //====== Copyright � 1996-2008, 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. class CCustomMaterialOwner;
  13. //-----------------------------------------------------------------------------
  14. // Resource file data used in posing the model inside of the model panel.
  15. //-----------------------------------------------------------------------------
  16. struct BMPResAnimData_t
  17. {
  18. const char *m_pszName;
  19. const char *m_pszSequence;
  20. const char *m_pszActivity;
  21. KeyValues *m_pPoseParameters;
  22. bool m_bDefault;
  23. BMPResAnimData_t()
  24. {
  25. m_pszName = NULL;
  26. m_pszSequence = NULL;
  27. m_pszActivity = NULL;
  28. m_pPoseParameters = NULL;
  29. m_bDefault = false;
  30. }
  31. ~BMPResAnimData_t()
  32. {
  33. if ( m_pszName && m_pszName[0] )
  34. {
  35. delete [] m_pszName;
  36. m_pszName = NULL;
  37. }
  38. if ( m_pszSequence && m_pszSequence[0] )
  39. {
  40. delete [] m_pszSequence;
  41. m_pszSequence = NULL;
  42. }
  43. if ( m_pszActivity && m_pszActivity[0] )
  44. {
  45. delete [] m_pszActivity;
  46. m_pszActivity = NULL;
  47. }
  48. if ( m_pPoseParameters )
  49. {
  50. m_pPoseParameters->deleteThis();
  51. m_pPoseParameters = NULL;
  52. }
  53. }
  54. };
  55. struct BMPResAttachData_t
  56. {
  57. const char *m_pszModelName;
  58. int m_nSkin;
  59. BMPResAttachData_t()
  60. {
  61. m_pszModelName = NULL;
  62. m_nSkin = 0;
  63. }
  64. ~BMPResAttachData_t()
  65. {
  66. if ( m_pszModelName && m_pszModelName[0] )
  67. {
  68. delete [] m_pszModelName;
  69. m_pszModelName = NULL;
  70. }
  71. }
  72. };
  73. struct BMPResData_t
  74. {
  75. float m_flFOV;
  76. const char *m_pszModelName;
  77. const char *m_pszModelName_HWM;
  78. const char *m_pszVCD;
  79. QAngle m_angModelPoseRot;
  80. Vector m_vecOriginOffset;
  81. Vector m_vecFramedOriginOffset;
  82. Vector2D m_vecViewportOffset;
  83. int m_nSkin;
  84. bool m_bUseSpotlight;
  85. const char *m_pszModelCameraAttachment;
  86. CUtlVector<BMPResAnimData_t> m_aAnimations;
  87. CUtlVector<BMPResAttachData_t> m_aAttachModels;
  88. BMPResData_t()
  89. {
  90. m_flFOV = 0.0f;
  91. m_pszModelName = NULL;
  92. m_pszModelName_HWM = NULL;
  93. m_pszVCD = NULL;
  94. m_angModelPoseRot.Init();
  95. m_vecOriginOffset.Init();
  96. m_vecFramedOriginOffset.Init();
  97. m_vecViewportOffset.Init();
  98. m_nSkin = 0;
  99. m_bUseSpotlight = false;
  100. m_pszModelCameraAttachment = NULL;
  101. }
  102. ~BMPResData_t()
  103. {
  104. if ( m_pszModelCameraAttachment && m_pszModelCameraAttachment[0] )
  105. {
  106. delete [] m_pszModelCameraAttachment;
  107. m_pszModelCameraAttachment = NULL;
  108. }
  109. if ( m_pszModelName && m_pszModelName[0] )
  110. {
  111. delete [] m_pszModelName;
  112. m_pszModelName = NULL;
  113. }
  114. if ( m_pszModelName_HWM && m_pszModelName_HWM[0] )
  115. {
  116. delete [] m_pszModelName_HWM;
  117. m_pszModelName_HWM = NULL;
  118. }
  119. if ( m_pszVCD && m_pszVCD[0] )
  120. {
  121. delete [] m_pszVCD;
  122. m_pszVCD = NULL;
  123. }
  124. m_aAnimations.Purge();
  125. m_aAttachModels.Purge();
  126. }
  127. };
  128. //-----------------------------------------------------------------------------
  129. // Base Model Panel
  130. //
  131. // ...vgui::Panel |--> vgui
  132. // +->vgui::EditablePanel |
  133. // +->PotterWheelPanel |--> matsys_controls
  134. // +->MDLPanel |
  135. // +->BaseModelPanel |--> game_controls, client.dll
  136. //
  137. //-----------------------------------------------------------------------------
  138. class CBaseModelPanel : public CMDLPanel
  139. {
  140. DECLARE_CLASS_SIMPLE( CBaseModelPanel, CMDLPanel );
  141. public:
  142. // Constructor, Destructor.
  143. CBaseModelPanel( vgui::Panel *pParent, const char *pName );
  144. virtual ~CBaseModelPanel();
  145. // Overridden mdlpanel.h
  146. virtual void SetMDL( MDLHandle_t handle, CCustomMaterialOwner* pCustomMaterialOwner = NULL, void *pProxyData = NULL );
  147. virtual void SetMDL( const char *pMDLName, CCustomMaterialOwner* pCustomMaterialOwner = NULL, void *pProxyData = NULL );
  148. void SetMdlSkinIndex( int nNewSkinIndex );
  149. // Overridden methods of vgui::Panel
  150. virtual void ApplySettings( KeyValues *inResourceData );
  151. virtual void PerformLayout();
  152. // Animaiton.
  153. int FindDefaultAnim( void );
  154. int FindAnimByName( const char *pszName );
  155. void SetModelAnim( int iAnim, bool bUseSequencePlaybackFPS );
  156. void SetModelAnim( const char *pszName, bool bUseSequencePlaybackFPS );
  157. void ClearModelAnimFollowLoop();
  158. void AddModelAnimFollowLoop( const char *pszName, bool bUseSequencePlaybackFPS );
  159. // Manipulation.
  160. virtual void OnKeyCodePressed ( vgui::KeyCode code );
  161. virtual void OnKeyCodeReleased( vgui::KeyCode code );
  162. virtual void OnMousePressed ( vgui::MouseCode code );
  163. virtual void OnMouseReleased( vgui::MouseCode code );
  164. virtual void OnCursorMoved( int x, int y );
  165. virtual void OnMouseWheeled( int delta );
  166. studiohdr_t* GetStudioHdr( void ) { return m_RootMDL.m_MDL.GetStudioHdr(); }
  167. void SetBody( unsigned int nBody ) { m_RootMDL.m_MDL.m_nBody = nBody; }
  168. void RotateYaw( float flDelta );
  169. void SetStartFramed( bool bStartFramed ) { m_bStartFramed = bStartFramed; }
  170. void LookAtBounds( const Vector &vecBoundsMin, const Vector &vecBoundsMax );
  171. private:
  172. // Resource file data.
  173. void ParseModelResInfo( KeyValues *inResourceData );
  174. void ParseModelAnimInfo( KeyValues *inResourceData );
  175. void ParseModelAttachInfo( KeyValues *inResourceData );
  176. void SetupModelDefaults( void );
  177. void SetupModelAnimDefaults( void );
  178. int FindSequenceFromActivity( CStudioHdr *pStudioHdr, const char *pszActivity );
  179. protected:
  180. BMPResData_t m_BMPResData; // Base model panel data set in the .res file.
  181. QAngle m_angPlayer;
  182. Vector m_vecPlayerPos;
  183. bool m_bForcePos;
  184. bool m_bMousePressed;
  185. bool m_bAllowRotation;
  186. // VGUI script accessible variables.
  187. CPanelAnimationVar( bool, m_bStartFramed, "start_framed", "0" );
  188. CPanelAnimationVar( bool, m_bDisableManipulation, "disable_manipulation", "0" );
  189. };
  190. #endif // BASEMODEL_PANEL_H