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.

391 lines
14 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef BASEANIMATIONSETEDITORCONTROLLER_H
  7. #define BASEANIMATIONSETEDITORCONTROLLER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmehandle.h"
  12. #include "movieobjects/animsetattributevalue.h"
  13. #include "dme_controls/dmecontrols_utils.h"
  14. #include "dme_controls/RecordingState.h"
  15. #include "tier1/utlvector.h"
  16. //-----------------------------------------------------------------------------
  17. // Forward declarations
  18. //-----------------------------------------------------------------------------
  19. struct SelectionInfo_t;
  20. class CDmeAnimationSet;
  21. class CDmeAnimationList;
  22. class CDmeChannelsClip;
  23. class CDmeChannel;
  24. class CBaseAnimationSetEditor;
  25. class CAttributeSlider;
  26. class CNotifyAnimationSetControlSelectionChangedScopeGuard;
  27. struct AttributeValue_t;
  28. enum ESelectionMode
  29. {
  30. SELECTION_SET,
  31. SELECTION_ADD,
  32. SELECTION_REMOVE,
  33. SELECTION_TOGGLE,
  34. };
  35. // NOTE - these values were chosen specifically to allow bitwise or (|) to combine selection states together properly
  36. enum SelectionState_t
  37. {
  38. SEL_EMPTY = 0,
  39. SEL_NONE = 1,
  40. SEL_ALL = 2,
  41. SEL_SOME = 3,
  42. };
  43. inline SelectionState_t operator+( SelectionState_t a, SelectionState_t b )
  44. {
  45. return SelectionState_t( int( a ) | int( b ) );
  46. }
  47. inline SelectionState_t operator+=( SelectionState_t &a, SelectionState_t b )
  48. {
  49. return a = a + b;
  50. }
  51. enum TransformComponent_t
  52. {
  53. TRANSFORM_COMPONENT_NONE = 0,
  54. TRANSFORM_COMPONENT_POSITION_X = ( 1 << 0 ),
  55. TRANSFORM_COMPONENT_POSITION_Y = ( 1 << 1 ),
  56. TRANSFORM_COMPONENT_POSITION_Z = ( 1 << 2 ),
  57. TRANSFORM_COMPONENT_ROTATION_X = ( 1 << 3 ),
  58. TRANSFORM_COMPONENT_ROTATION_Y = ( 1 << 4 ),
  59. TRANSFORM_COMPONENT_ROTATION_Z = ( 1 << 5 ),
  60. TRANSFORM_COMPONENT_POSITION = TRANSFORM_COMPONENT_POSITION_X | TRANSFORM_COMPONENT_POSITION_Y | TRANSFORM_COMPONENT_POSITION_Z,
  61. TRANSFORM_COMPONENT_ROTATION = TRANSFORM_COMPONENT_ROTATION_X | TRANSFORM_COMPONENT_ROTATION_Y | TRANSFORM_COMPONENT_ROTATION_Z,
  62. TRANSFORM_COMPONENT_ALL = TRANSFORM_COMPONENT_POSITION | TRANSFORM_COMPONENT_ROTATION
  63. };
  64. DEFINE_ENUM_BITWISE_OPERATORS( TransformComponent_t )
  65. class IOverrideParentChangedListener
  66. {
  67. public:
  68. virtual void OnOverrideParentChanged( CDmeDag *pChildDag ) = 0;
  69. };
  70. class IAnimationSetControlSelectionChangedListener
  71. {
  72. public:
  73. virtual void OnControlSelectionChanged() {}
  74. virtual void OnRebuildControlHierarchy() {}
  75. virtual void ExpandTreeToControl( const CDmElement *pSelection, TransformComponent_t nComponentFlags ) {}
  76. };
  77. struct SelectionInfo_t
  78. {
  79. DECLARE_FIXEDSIZE_ALLOCATOR( SelectionInfo_t );
  80. public:
  81. SelectionInfo_t() : m_nComponentFlags( TRANSFORM_COMPONENT_NONE ) {}
  82. SelectionInfo_t( CDmeAnimationSet *pAnimSet, CDmElement *pControl, TransformComponent_t nComponentFlags = TRANSFORM_COMPONENT_NONE )
  83. : m_hAnimSet( pAnimSet ), m_hControl( pControl ), m_nComponentFlags( nComponentFlags )
  84. {
  85. }
  86. bool IsPositionFullySelected() const
  87. {
  88. return ( ( m_nComponentFlags & TRANSFORM_COMPONENT_POSITION ) == TRANSFORM_COMPONENT_POSITION );
  89. }
  90. bool IsRotationFullySelected() const
  91. {
  92. return ( ( m_nComponentFlags & TRANSFORM_COMPONENT_ROTATION ) == TRANSFORM_COMPONENT_ROTATION );
  93. }
  94. bool AreAnyPositionComponentsSelected()
  95. {
  96. return ( ( m_nComponentFlags & TRANSFORM_COMPONENT_POSITION ) > 0 );
  97. }
  98. bool AreAnyOrientationComponentsSelected()
  99. {
  100. return ( ( m_nComponentFlags & TRANSFORM_COMPONENT_ROTATION ) > 0 );
  101. }
  102. static LogComponents_t ConvertTransformFlagsToLogFlags( TransformComponent_t nTransformFlags, bool bOrientation )
  103. {
  104. LogComponents_t nFlags = LOG_COMPONENTS_NONE;
  105. if ( bOrientation )
  106. {
  107. nFlags |= ( ( nTransformFlags & TRANSFORM_COMPONENT_ROTATION_X ) > 0 ) ? LOG_COMPONENTS_X : LOG_COMPONENTS_NONE;
  108. nFlags |= ( ( nTransformFlags & TRANSFORM_COMPONENT_ROTATION_Y ) > 0 ) ? LOG_COMPONENTS_Y : LOG_COMPONENTS_NONE;
  109. nFlags |= ( ( nTransformFlags & TRANSFORM_COMPONENT_ROTATION_Z ) > 0 ) ? LOG_COMPONENTS_Z : LOG_COMPONENTS_NONE;
  110. }
  111. else
  112. {
  113. nFlags |= ( ( nTransformFlags & TRANSFORM_COMPONENT_POSITION_X ) > 0 ) ? LOG_COMPONENTS_X : LOG_COMPONENTS_NONE;
  114. nFlags |= ( ( nTransformFlags & TRANSFORM_COMPONENT_POSITION_Y ) > 0 ) ? LOG_COMPONENTS_Y : LOG_COMPONENTS_NONE;
  115. nFlags |= ( ( nTransformFlags & TRANSFORM_COMPONENT_POSITION_Z ) > 0 ) ? LOG_COMPONENTS_Z : LOG_COMPONENTS_NONE;
  116. }
  117. return nFlags;
  118. }
  119. static TransformComponent_t ConvertLogFlagsToTransformFlags( LogComponents_t nLogFlags, bool bOrientation )
  120. {
  121. TransformComponent_t nFlags = TRANSFORM_COMPONENT_NONE;
  122. if ( bOrientation )
  123. {
  124. nFlags |= ( ( nLogFlags & LOG_COMPONENTS_X ) > 0 ) ? TRANSFORM_COMPONENT_ROTATION_X : TRANSFORM_COMPONENT_NONE;
  125. nFlags |= ( ( nLogFlags & LOG_COMPONENTS_Y ) > 0 ) ? TRANSFORM_COMPONENT_ROTATION_Y : TRANSFORM_COMPONENT_NONE;
  126. nFlags |= ( ( nLogFlags & LOG_COMPONENTS_Z ) > 0 ) ? TRANSFORM_COMPONENT_ROTATION_Z : TRANSFORM_COMPONENT_NONE;
  127. }
  128. else
  129. {
  130. nFlags |= ( ( nLogFlags & LOG_COMPONENTS_X ) > 0 ) ? TRANSFORM_COMPONENT_POSITION_X : TRANSFORM_COMPONENT_NONE;
  131. nFlags |= ( ( nLogFlags & LOG_COMPONENTS_Y ) > 0 ) ? TRANSFORM_COMPONENT_POSITION_Y : TRANSFORM_COMPONENT_NONE;
  132. nFlags |= ( ( nLogFlags & LOG_COMPONENTS_Z ) > 0 ) ? TRANSFORM_COMPONENT_POSITION_Z : TRANSFORM_COMPONENT_NONE;
  133. }
  134. return nFlags;
  135. }
  136. CDmeHandle< CDmeAnimationSet > m_hAnimSet;
  137. CDmeHandle< CDmElement > m_hControl;
  138. TransformComponent_t m_nComponentFlags;
  139. };
  140. template < class T >
  141. void RebuildControlList( CUtlVector< T* > &controlList, CDmeFilmClip *pFilmClip )
  142. {
  143. int nControls = controlList.Count();
  144. for ( int i = 0; i < nControls; ++i )
  145. {
  146. delete controlList[ i ];
  147. }
  148. controlList.RemoveAll();
  149. CAnimSetGroupAnimSetTraversal traversal( pFilmClip );
  150. while ( CDmeAnimationSet *pAnimSet = traversal.Next() )
  151. {
  152. CDmaElementArray< CDmElement > &controls = pAnimSet->GetControls();
  153. int nControls = controls.Count();
  154. for ( int i = 0; i < nControls; ++i )
  155. {
  156. CDmElement *pControl = controls[ i ];
  157. if ( !pControl )
  158. continue;
  159. controlList.AddToTail( new T( pAnimSet, pControl, TRANSFORM_COMPONENT_NONE ) );
  160. }
  161. }
  162. }
  163. template < class T >
  164. T *FindSelectionInfoForControl( CUtlVector< T* > &controlList, const CDmElement *pControl )
  165. {
  166. if ( !pControl )
  167. return NULL;
  168. int nControls = controlList.Count();
  169. for ( int i = 0; i < nControls; ++i )
  170. {
  171. T *pT = controlList[ i ];
  172. if ( pT->m_hControl.Get() == pControl )
  173. return pT;
  174. }
  175. return NULL;
  176. }
  177. template < class T >
  178. void RemoveNullControls( CUtlVector< T* > &controlList )
  179. {
  180. int nControls = controlList.Count();
  181. for ( int i = nControls-1; i >= 0; --i )
  182. {
  183. if ( controlList[ i ]->m_hControl )
  184. continue; // TODO - are there other conditions that could cause a control to exist, but not want to be part of the full list?
  185. delete controlList[ i ];
  186. controlList.Remove( i );
  187. }
  188. }
  189. template < class T >
  190. void AddMissingControls( CUtlVector< T* > &controlList, CDmeFilmClip *pFilmClip )
  191. {
  192. CAnimSetGroupAnimSetTraversal traversal( pFilmClip );
  193. while ( CDmeAnimationSet *pAnimSet = traversal.Next() )
  194. {
  195. CDmaElementArray< CDmElement > &controls = pAnimSet->GetControls();
  196. int nControls = controls.Count();
  197. for ( int i = 0; i < nControls; ++i )
  198. {
  199. CDmElement *pControl = controls[ i ];
  200. if ( !pControl )
  201. continue;
  202. if ( FindSelectionInfoForControl( controlList, pControl ) )
  203. continue;
  204. controlList.AddToTail( new T( pAnimSet, pControl, TRANSFORM_COMPONENT_NONE ) );
  205. }
  206. }
  207. }
  208. //-----------------------------------------------------------------------------
  209. // Base class for the panel for editing animation sets
  210. //-----------------------------------------------------------------------------
  211. class CBaseAnimationSetControl
  212. {
  213. public:
  214. CBaseAnimationSetControl();
  215. ~CBaseAnimationSetControl();
  216. void SetAnimationSetEditorPanel( CBaseAnimationSetEditor *pEditor ) { m_pEditor = pEditor; }
  217. virtual void ChangeAnimationSetClip( CDmeFilmClip *pFilmClip );
  218. virtual void OnControlsAddedOrRemoved();
  219. virtual RecordingState_t GetRecordingState() const { return AS_PREVIEW; }
  220. CDmeFilmClip *GetAnimationSetClip();
  221. virtual void OnSliderRangeRemapped() {}
  222. void AddOverrideParentChangedListener( IOverrideParentChangedListener *pListener );
  223. void RemoveOverrideParentChangedListener( IOverrideParentChangedListener *pListener );
  224. void AddControlSelectionChangedListener ( IAnimationSetControlSelectionChangedListener *listener );
  225. void RemoveControlSelectionChangedListener( IAnimationSetControlSelectionChangedListener *listener );
  226. void ClearSelection();
  227. SelectionState_t GetSelectionState( CDmeAnimationSet *pAnimSet ) const;
  228. SelectionState_t GetSelectionState( CDmeControlGroup *pControlGroup ) const;
  229. SelectionState_t GetSelectionState( CDmElement *pControl, TransformComponent_t componentFlags = TRANSFORM_COMPONENT_ALL ) const;
  230. void SetRangeSelectionState( bool bInRangeSelection );
  231. void SelectAnimationSet( CDmeAnimationSet *pAnimSet, ESelectionMode selectionMode = SELECTION_ADD );
  232. void SelectControlGroup( CDmeControlGroup *pControlGroup, ESelectionMode selectionMode = SELECTION_ADD );
  233. void SelectControlForDag( const CDmeDag *pDag, ESelectionMode selectionMode = SELECTION_ADD );
  234. bool SelectControl( const CDmElement *pControl, ESelectionMode selectionMode = SELECTION_ADD, TransformComponent_t componentFlags = TRANSFORM_COMPONENT_ALL, bool bExpandTree = false );
  235. void SaveSelection( CUtlVector< SelectionInfo_t > &selection ) const;
  236. void RestoreSelection( const CUtlVector< SelectionInfo_t > &selection );
  237. void DeselectHiddenControls();
  238. CDmElement *GetMostRecentlySelectedControl();
  239. bool IsControlSelected( CDmElement *pControl ) const;
  240. TransformComponent_t GetSelectionComponentFlags( CDmElement *pControl ) const;
  241. virtual void ProceduralPreset_UpdateCrossfade( AttributeDict_t *values, int nPresetType );
  242. void SetWorkCameraParent( CDmeDag *pWorkCameraParent );
  243. CDmeDag *GetWorkCameraParent();
  244. void SetPresetFromControls( const char *pPresetGroupName, const char *pPresetName );
  245. void AddPreset( const char *pPresetGroupName, const char *pPresetName, bool bAnimated );
  246. void UpdatePreviewSliderValues();
  247. void UpdatePreviewSliderTimes();
  248. bool IsPresetFaderBeingDragged() const;
  249. void UpdateDominantSliderStartValues( bool restoreSliderValues );
  250. void GetDominantSliderValues( float &flDomStart, float &flDomValue );
  251. void ApplyPreset( float flScale, AttributeDict_t& values );
  252. bool ApplySliderValues( bool force );
  253. void SetActiveAttributeSlider( CAttributeSlider *pSlider );
  254. CAttributeSlider *GetActiveAttributeSlider() { return m_ActiveAttributeSlider; }
  255. // HACK - these should be removed after creating the CAnimationSetControl,
  256. // and CAnimSetAttributeSliderPanel::ApplySliderValues is moved to there
  257. float GetPreviousPresetAmount() const { return m_flPreviousPresetAmount; }
  258. bool WasPreviouslyHoldingPresetPreviewKey() const { return m_bPreviouslyHoldingPresetPreviewKey; }
  259. bool HasPresetSliderChanged() const { return m_bPresetSliderChanged; }
  260. float GetDominantSliderStartValue( int nSliderIndex, AnimationControlType_t type );
  261. int GetDominantSliderIndex() const { return m_nDominantSlider; }
  262. // Can the control be snapped to
  263. bool IsControlSnapTarget( const CDmElement *pControl ) const;
  264. // Is the control selectable in the viewport
  265. bool IsControlSelectable( const CDmElement *pControl ) const;
  266. // Determine if the specified control is visible
  267. bool IsControlVisible( const CDmElement *pControl ) const;
  268. // Determine if the specified control group is visible
  269. bool IsControlGroupVisible( const CDmeControlGroup *pGroup ) const;
  270. // Return the state indicating if hidden controls are being displayed
  271. bool IsShowingHiddenControls() const { return m_bShowHiddenControls; }
  272. // Set the state indicating if hidden controls are to be displayed
  273. void SetShowHiddenControls( bool showHidden ) { m_bShowHiddenControls = showHidden; }
  274. protected:
  275. void AddPreset( CDmeAnimationSet *pAnimSet, const char *pPresetGroupName, const char *pPresetName, bool bAnimated );
  276. virtual void GetAnimatedPresetTimeParameters( DmeTime_t &tHead, DmeTime_t &tStart, DmeTime_t &tEnd );
  277. // from CBaseAnimSetControlGroupPanel:
  278. void FireOverrideParentChangedListeners( CDmeDag *pChildDag );
  279. virtual void FireControlSelectionChangedListeners();
  280. virtual void FireRebuildControlHierarchyListeners();
  281. template< class T >
  282. void ApplyTransformSliderValue( CAttributeSlider *pSlider, CDmeTransformControl *pControl, bool bUsePreviewValue, bool bForce, bool &valuesChanged, AnimationControlType_t type );
  283. void ApplySliderValueWithDominance( CAttributeSlider *pSlider, int si, float flDomStart, float flDomValue, CDmElement *pControl, bool bUsePreviewValue, bool bForce, bool &valuesChanged, AnimationControlType_t type, const char *pChannelAttrName, const char *pValueAttrName );
  284. virtual SelectionInfo_t *FindSelectionInfoForControl( const CDmElement *pControl ) = 0;
  285. void EnsureCrossfadePresetControlValues( int nCount );
  286. protected:
  287. // from CBaseAnimationSetEditor:
  288. CDmeHandle< CDmeFilmClip > m_hFilmClip;
  289. CBaseAnimationSetEditor *m_pEditor;
  290. // from CBaseAnimSetControlGroupPanel:
  291. CUtlLinkedList< SelectionInfo_t* > m_SelectionHistory;
  292. CDmeHandle< CDmeDag > m_hWorkCameraParent;
  293. CUtlVector< IOverrideParentChangedListener * > m_OverrideParentChangedListeners;
  294. CUtlVector< IAnimationSetControlSelectionChangedListener * > m_ControlSelectionChangedListeners;
  295. // from CBaseAnimSetAttributeSliderPanel:
  296. CUtlString m_PreviousPresetSlider;
  297. float m_flPreviousPresetAmount;
  298. bool m_bPresetPreviouslyDragged : 1;
  299. bool m_bPreviouslyHoldingPresetPreviewKey : 1;
  300. bool m_bPresetSliderChanged : 1;
  301. vgui::DHANDLE< CAttributeSlider > m_ActiveAttributeSlider;
  302. CUtlVector< AttributeValue_t > m_DominantSliderStartValues; // Values of all sliders at start of drag of dominant slider
  303. int m_nDominantSlider;
  304. // Flag indicating if hidden controls are to be displayed
  305. bool m_bShowHiddenControls;
  306. CUtlVector< CDmElement* > m_crossfadePresetControlValues;
  307. friend CBaseAnimationSetEditor;
  308. friend CNotifyAnimationSetControlSelectionChangedScopeGuard;
  309. };
  310. #endif // BASEANIMATIONSETEDITORCONTROLLER_H