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.

238 lines
5.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BASEMODELPANEL_H
  8. #define BASEMODELPANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/IScheme.h>
  13. #include <vgui_controls/ImagePanel.h>
  14. #include <vgui_controls/EditablePanel.h>
  15. #include "GameEventListener.h"
  16. #include "KeyValues.h"
  17. class C_SceneEntity;
  18. class CModelPanelModel : public C_BaseFlex
  19. {
  20. public:
  21. CModelPanelModel(){}
  22. DECLARE_CLASS( CModelPanelModel, C_BaseFlex );
  23. virtual bool IsMenuModel() const{ return true; }
  24. };
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. //-----------------------------------------------------------------------------
  28. class CModelPanelModelAnimation
  29. {
  30. public:
  31. CModelPanelModelAnimation()
  32. {
  33. m_pszName = NULL;
  34. m_pszSequence = NULL;
  35. m_pszActivity = NULL;
  36. m_pPoseParameters = NULL;
  37. m_bDefault = false;
  38. }
  39. ~CModelPanelModelAnimation()
  40. {
  41. if ( m_pszName && m_pszName[0] )
  42. {
  43. delete [] m_pszName;
  44. m_pszName = NULL;
  45. }
  46. if ( m_pszSequence && m_pszSequence[0] )
  47. {
  48. delete [] m_pszSequence;
  49. m_pszSequence = NULL;
  50. }
  51. if ( m_pszActivity && m_pszActivity[0] )
  52. {
  53. delete [] m_pszActivity;
  54. m_pszActivity = NULL;
  55. }
  56. if ( m_pPoseParameters )
  57. {
  58. m_pPoseParameters->deleteThis();
  59. m_pPoseParameters = NULL;
  60. }
  61. }
  62. public:
  63. const char *m_pszName;
  64. const char *m_pszSequence;
  65. const char *m_pszActivity;
  66. KeyValues *m_pPoseParameters;
  67. bool m_bDefault;
  68. };
  69. //-----------------------------------------------------------------------------
  70. // Purpose:
  71. //-----------------------------------------------------------------------------
  72. class CModelPanelAttachedModelInfo
  73. {
  74. public:
  75. CModelPanelAttachedModelInfo()
  76. {
  77. m_pszModelName = NULL;
  78. m_nSkin = 0;
  79. }
  80. ~CModelPanelAttachedModelInfo()
  81. {
  82. if ( m_pszModelName && m_pszModelName[0] )
  83. {
  84. delete [] m_pszModelName;
  85. m_pszModelName = NULL;
  86. }
  87. }
  88. public:
  89. const char *m_pszModelName;
  90. int m_nSkin;
  91. };
  92. //-----------------------------------------------------------------------------
  93. // Purpose:
  94. //-----------------------------------------------------------------------------
  95. class CModelPanelModelInfo
  96. {
  97. public:
  98. CModelPanelModelInfo()
  99. : m_mapBodygroupValues( DefLessFunc( int ) )
  100. {
  101. m_pszModelName = NULL;
  102. m_pszModelName_HWM = NULL;
  103. m_nSkin = -1;
  104. m_vecAbsAngles.Init();
  105. m_vecOriginOffset.Init();
  106. m_vecFramedOriginOffset.Init();
  107. m_bUseSpotlight = false;
  108. }
  109. ~CModelPanelModelInfo()
  110. {
  111. if ( m_pszModelName && m_pszModelName[0] )
  112. {
  113. delete [] m_pszModelName;
  114. m_pszModelName = NULL;
  115. }
  116. if ( m_pszModelName_HWM && m_pszModelName_HWM[0] )
  117. {
  118. delete [] m_pszModelName_HWM;
  119. m_pszModelName_HWM = NULL;
  120. }
  121. if ( m_pszVCD && m_pszVCD[0] )
  122. {
  123. delete [] m_pszVCD;
  124. m_pszVCD = NULL;
  125. }
  126. m_Animations.PurgeAndDeleteElements();
  127. m_AttachedModelsInfo.PurgeAndDeleteElements();
  128. }
  129. public:
  130. const char *m_pszModelName;
  131. const char *m_pszModelName_HWM;
  132. int m_nSkin;
  133. const char *m_pszVCD;
  134. Vector m_vecAbsAngles;
  135. Vector m_vecOriginOffset;
  136. Vector2D m_vecViewportOffset;
  137. Vector m_vecFramedOriginOffset;
  138. bool m_bUseSpotlight;
  139. CUtlMap< int, int > m_mapBodygroupValues;
  140. CUtlVector<CModelPanelModelAnimation*> m_Animations;
  141. CUtlVector<CModelPanelAttachedModelInfo*> m_AttachedModelsInfo;
  142. };
  143. //-----------------------------------------------------------------------------
  144. // Purpose:
  145. //-----------------------------------------------------------------------------
  146. class CModelPanel : public vgui::EditablePanel, public CGameEventListener
  147. {
  148. public:
  149. DECLARE_CLASS_SIMPLE( CModelPanel, vgui::EditablePanel );
  150. CModelPanel( vgui::Panel *parent, const char *name );
  151. virtual ~CModelPanel();
  152. virtual void Paint();
  153. virtual void ApplySettings( KeyValues *inResourceData );
  154. virtual void OnCommand( const char *command ) OVERRIDE;
  155. virtual void DeleteVCDData( void );
  156. virtual void DeleteModelData( void );
  157. virtual void SetFOV( int nFOV ){ m_nFOV = nFOV; }
  158. virtual void SetPanelDirty( void ){ m_bPanelDirty = true; }
  159. virtual bool SetSequence( const char *pszSequence );
  160. virtual void SetSkin( int nSkin );
  161. void SetBodyGroup( const char* pszBodyGroupName, int nGroup );
  162. MESSAGE_FUNC_PARAMS( OnAddAnimation, "AddAnimation", data );
  163. MESSAGE_FUNC_PARAMS( OnSetAnimation, "SetAnimation", data );
  164. void SetDefaultAnimation( const char *pszName );
  165. void SwapModel( const char *pszName, const char *pszAttached = NULL );
  166. virtual void ParseModelInfo( KeyValues *inResourceData );
  167. void ClearAttachedModelInfos( void );
  168. void CalculateFrameDistance( void );
  169. void ZoomToFrameDistance( void );
  170. void UpdateModel();
  171. public: // IGameEventListener:
  172. virtual void FireGameEvent( IGameEvent * event );
  173. protected:
  174. virtual void SetupModel( void );
  175. virtual void SetupVCD( void );
  176. virtual const char *GetModelName( void );
  177. private:
  178. void InitCubeMaps();
  179. int FindAnimByName( const char *pszName );
  180. void CalculateFrameDistanceInternal( const model_t *pModel );
  181. public:
  182. int m_nFOV;
  183. float m_flFrameDistance;
  184. bool m_bStartFramed;
  185. CModelPanelModelInfo *m_pModelInfo;
  186. CHandle<CModelPanelModel> m_hModel;
  187. CUtlVector<CHandle<C_BaseAnimating> > m_AttachedModels;
  188. CHandle<C_SceneEntity> m_hScene;
  189. private:
  190. bool m_bPanelDirty;
  191. int m_iDefaultAnimation;
  192. bool m_bAllowOffscreen;
  193. CTextureReference m_DefaultEnvCubemap;
  194. CTextureReference m_DefaultHDREnvCubemap;
  195. };
  196. #endif // BASEMODELPANEL_H