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.

984 lines
34 KiB

  1. //========= Copyright � 1996-2001, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "vstdlib/random.h"
  8. #include "dme_controls/dmedageditpanel.h"
  9. #include "dme_controls/dmedagrenderpanel.h"
  10. #include "dme_controls/dmepanel.h"
  11. #include "vgui_controls/Button.h"
  12. #include "vgui_controls/Splitter.h"
  13. #include "vgui_controls/PropertySheet.h"
  14. #include "vgui_controls/PropertyPage.h"
  15. #include "vgui_controls/Label.h"
  16. #include "vgui_controls/ScrollBar.h"
  17. #include "vgui_controls/Slider.h"
  18. #include "vgui_controls/ScrollableEditablePanel.h"
  19. #include "vgui_controls/ListPanel.h"
  20. #include "vgui_controls/Image.h"
  21. #include "vgui_controls/TextImage.h"
  22. #include "vgui/isurface.h"
  23. #include "vgui/ischeme.h"
  24. #include "vgui/iinput.h"
  25. #include "vgui/ivgui.h"
  26. #include "vgui/cursor.h"
  27. #include "movieobjects/dmemakefile.h"
  28. #include "movieobjects/dmemdlmakefile.h"
  29. #include "movieobjects/dmedccmakefile.h"
  30. #include "movieobjects/dmedag.h"
  31. #include "movieobjects/dmeclip.h"
  32. #include "movieobjects/dmeanimationlist.h"
  33. #include "movieobjects/dmecombinationoperator.h"
  34. #include "movieobjects/dmeanimationset.h"
  35. #include "movieobjects/dmeflexrules.h"
  36. #include "tier1/keyvalues.h"
  37. #include "materialsystem/imesh.h"
  38. #include "dme_controls/BaseAnimationSetEditor.h"
  39. #include "dme_controls/BaseAnimationSetEditorController.h"
  40. #include "dme_controls/BaseAnimSetAttributeSliderPanel.h"
  41. //-----------------------------------------------------------------------------
  42. //
  43. // Hook into the dme panel editor system
  44. //
  45. //-----------------------------------------------------------------------------
  46. IMPLEMENT_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeDag, "DmeDagPreview2", "DmeDag Previewer 2", false );
  47. IMPLEMENT_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeSourceSkin, "DmeSourceSkinPreview2", "MDL Skin Previewer 2", false );
  48. IMPLEMENT_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeSourceAnimation, "DmeSourceAnimationPreview2", "MDL Animation Previewer 2", false );
  49. IMPLEMENT_DMEPANEL_FACTORY( CDmeDagEditPanel, DmeDCCMakefile, "DmeMakeFileOutputPreview2", "DCC MakeFile Output Previewer 2", false );
  50. //-----------------------------------------------------------------------------
  51. // Slider panel
  52. //-----------------------------------------------------------------------------
  53. class CDmeAnimationListPanel : public vgui::EditablePanel
  54. {
  55. DECLARE_CLASS_SIMPLE( CDmeAnimationListPanel, vgui::EditablePanel );
  56. public:
  57. // constructor, destructor
  58. CDmeAnimationListPanel( vgui::Panel *pParent, const char *pName );
  59. virtual ~CDmeAnimationListPanel();
  60. void SetAnimationList( CDmeAnimationList *pList );
  61. void RefreshAnimationList();
  62. const char *GetSelectedAnimation() const;
  63. private:
  64. // Called when the selection changes moves
  65. MESSAGE_FUNC( OnItemSelected, "ItemSelected" );
  66. MESSAGE_FUNC( OnItemDeselected, "ItemDeselected" );
  67. vgui::ListPanel *m_pAnimationList;
  68. CDmeHandle< CDmeAnimationList > m_hAnimationList;
  69. };
  70. static int __cdecl AnimationNameSortFunc( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  71. {
  72. const char *string1 = item1.kv->GetString("name");
  73. const char *string2 = item2.kv->GetString("name");
  74. return Q_stricmp( string1, string2 );
  75. }
  76. //-----------------------------------------------------------------------------
  77. // constructor, destructor
  78. //-----------------------------------------------------------------------------
  79. CDmeAnimationListPanel::CDmeAnimationListPanel( vgui::Panel *pParent, const char *pName ) :
  80. BaseClass( pParent, pName )
  81. {
  82. m_pAnimationList = new vgui::ListPanel( this, "AnimationList" );
  83. m_pAnimationList->AddColumnHeader( 0, "name", "name", 100, 0 );
  84. m_pAnimationList->AddActionSignalTarget( this );
  85. m_pAnimationList->SetSortFunc( 0, AnimationNameSortFunc );
  86. m_pAnimationList->SetSortColumn( 0 );
  87. m_pAnimationList->SetEmptyListText("No animations");
  88. m_pAnimationList->SetMultiselectEnabled( false );
  89. LoadControlSettingsAndUserConfig( "resource/dmeanimationlistpanel.res" );
  90. }
  91. CDmeAnimationListPanel::~CDmeAnimationListPanel()
  92. {
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Sets the combination operator
  96. //-----------------------------------------------------------------------------
  97. void CDmeAnimationListPanel::SetAnimationList( CDmeAnimationList *pList )
  98. {
  99. if ( pList != m_hAnimationList.Get() )
  100. {
  101. m_hAnimationList = pList;
  102. RefreshAnimationList();
  103. }
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Builds the list of animations
  107. //-----------------------------------------------------------------------------
  108. void CDmeAnimationListPanel::RefreshAnimationList()
  109. {
  110. m_pAnimationList->RemoveAll();
  111. if ( !m_hAnimationList.Get() )
  112. return;
  113. int nCount = m_hAnimationList->GetAnimationCount();
  114. for ( int i = 0; i < nCount; ++i )
  115. {
  116. CDmeChannelsClip *pAnimation = m_hAnimationList->GetAnimation( i );
  117. KeyValues *pItemKeys = new KeyValues( "node", "name", pAnimation->GetName() );
  118. m_pAnimationList->AddItem( pItemKeys, 0, false, false );
  119. }
  120. m_pAnimationList->SortList();
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Returns the selected animation
  124. //-----------------------------------------------------------------------------
  125. const char *CDmeAnimationListPanel::GetSelectedAnimation() const
  126. {
  127. if ( m_pAnimationList->GetSelectedItemsCount() == 0 )
  128. return "";
  129. int nIndex = m_pAnimationList->GetSelectedItem( 0 );
  130. KeyValues *pItemKeyValues = m_pAnimationList->GetItem( nIndex );
  131. return pItemKeyValues->GetString( "name" );
  132. }
  133. //-----------------------------------------------------------------------------
  134. // Called when an animation is selected or deselected
  135. //-----------------------------------------------------------------------------
  136. void CDmeAnimationListPanel::OnItemSelected( )
  137. {
  138. const char *pAnimationName = GetSelectedAnimation();
  139. PostActionSignal( new KeyValues( "AnimationSelected", "animationName", pAnimationName ) );
  140. }
  141. void CDmeAnimationListPanel::OnItemDeselected( )
  142. {
  143. PostActionSignal( new KeyValues( "AnimationDeselected" ) );
  144. }
  145. class CCombinationOperatorControl : public CBaseAnimationSetControl
  146. {
  147. public:
  148. CCombinationOperatorControl() {}
  149. virtual void ChangeAnimationSetClip( CDmeFilmClip *pFilmClip )
  150. {
  151. RebuildControlList( m_FullControlList, pFilmClip );
  152. CBaseAnimationSetControl::ChangeAnimationSetClip( pFilmClip );
  153. }
  154. virtual void OnControlsAddedOrRemoved()
  155. {
  156. RemoveNullControls( m_FullControlList );
  157. AddMissingControls( m_FullControlList, m_hFilmClip );
  158. CBaseAnimationSetControl::OnControlsAddedOrRemoved();
  159. }
  160. protected:
  161. virtual SelectionInfo_t *FindSelectionInfoForControl( const CDmElement *pControl )
  162. {
  163. return ::FindSelectionInfoForControl( m_FullControlList, pControl );
  164. }
  165. CUtlVector< SelectionInfo_t* > m_FullControlList;
  166. };
  167. class CDmeCombinationOperatorPanel : public CBaseAnimationSetEditor
  168. {
  169. DECLARE_CLASS_SIMPLE( CDmeCombinationOperatorPanel, CBaseAnimationSetEditor );
  170. public:
  171. CDmeCombinationOperatorPanel( vgui::Panel *parent, const char *panelName, CBaseAnimationSetControl *pAnimationSetController );
  172. virtual ~CDmeCombinationOperatorPanel();
  173. virtual void OnTick();
  174. void SetCombinationOperator( CDmeCombinationOperator *pOp );
  175. void RefreshCombinationOperator();
  176. private:
  177. void CreateFakeAnimationSet( );
  178. void DestroyFakeAnimationSet( );
  179. // Adds new controls to the animation set
  180. void AddNewAnimationSetControls();
  181. // Removes a controls from all presets
  182. void RemoveAnimationControlFromPresets( const char *pControlName );
  183. // Removes controls from the animation set that aren't used
  184. void RemoveUnusedAnimationSetControls();
  185. // Modify controls in the presets which have had stereo settings changed
  186. void ModifyExistingAnimationSetControls();
  187. // Modify controls in the presets which have had stereo settings changed
  188. void ModifyExistingAnimationSetPresets( CDmElement *pControlElement );
  189. // Modify controls which have had stereo settings changed
  190. void ModifyExistingAnimationSetControl( CDmElement *pControlElement );
  191. void RefreshAnimationSet();
  192. // Sort control names to match the combination controls
  193. void SortAnimationSetControls();
  194. CDmeHandle< CDmeCombinationOperator > m_hCombinationOperator;
  195. CUtlVector< IDmeOperator * > m_operatorList;
  196. };
  197. //-----------------------------------------------------------------------------
  198. // Constructor/destructor
  199. //-----------------------------------------------------------------------------
  200. CDmeCombinationOperatorPanel::CDmeCombinationOperatorPanel( vgui::Panel *parent, const char *panelName, CBaseAnimationSetControl *pAnimationSetController ) :
  201. BaseClass( parent, panelName, pAnimationSetController )
  202. {
  203. CreateFakeAnimationSet();
  204. vgui::ivgui()->AddTickSignal( GetVPanel(), 0 );
  205. }
  206. CDmeCombinationOperatorPanel::~CDmeCombinationOperatorPanel()
  207. {
  208. DestroyFakeAnimationSet();
  209. }
  210. //-----------------------------------------------------------------------------
  211. // Create, destroy fake animation sets
  212. //-----------------------------------------------------------------------------
  213. void CDmeCombinationOperatorPanel::CreateFakeAnimationSet()
  214. {
  215. CDmeFilmClip *pFilmClip = CreateElement< CDmeFilmClip >( "fakeFilmClip", DMFILEID_INVALID );
  216. CDmeAnimationSet *pAnimSet = CreateElement< CDmeAnimationSet >( "fakeAnimSet", DMFILEID_INVALID );
  217. pAnimSet->SetValue( "gameModel", DMELEMENT_HANDLE_INVALID );
  218. pFilmClip->GetAnimationSets().AddToTail( pAnimSet );
  219. g_pDataModel->DontAutoDelete( pFilmClip->GetHandle() );
  220. ChangeAnimationSetClip( pFilmClip );
  221. }
  222. void CDmeCombinationOperatorPanel::DestroyFakeAnimationSet( )
  223. {
  224. DestroyElement( m_pController->GetAnimationSetClip(), TD_DEEP );
  225. }
  226. //-----------------------------------------------------------------------------
  227. // Sets combination ops + animation sets
  228. //-----------------------------------------------------------------------------
  229. void CDmeCombinationOperatorPanel::SetCombinationOperator( CDmeCombinationOperator *pOp )
  230. {
  231. // The Animation Set Editor Doesn't Handle Passing The Same Animation Set With
  232. // Different Data In It Very Well
  233. DestroyFakeAnimationSet();
  234. CreateFakeAnimationSet();
  235. m_operatorList.RemoveAll();
  236. if ( pOp != m_hCombinationOperator.Get() )
  237. {
  238. m_hCombinationOperator = pOp;
  239. m_operatorList.AddToTail( m_hCombinationOperator );
  240. for ( int i = 0; i < pOp->GetOperationTargetCount(); ++i )
  241. {
  242. CDmeFlexRules *pDmeFlexRules = CastElement< CDmeFlexRules >( pOp->GetOperationTarget( i ) );
  243. if ( !pDmeFlexRules )
  244. continue;
  245. m_operatorList.AddToTail( pDmeFlexRules );
  246. for ( int j = 0; j < pDmeFlexRules->GetRuleCount(); ++j )
  247. {
  248. CDmeFlexRuleBase *pDmeFlexRule = pDmeFlexRules->GetRule( j );
  249. if ( !pDmeFlexRule )
  250. continue;
  251. m_operatorList.AddToTail( pDmeFlexRule );
  252. }
  253. }
  254. RefreshCombinationOperator();
  255. }
  256. }
  257. //-----------------------------------------------------------------------------
  258. // Removes a controls from all presets
  259. //-----------------------------------------------------------------------------
  260. void CDmeCombinationOperatorPanel::RemoveAnimationControlFromPresets( const char *pControlName )
  261. {
  262. // TODO - we should be storing which animationset an item is associated with
  263. CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
  264. CDmeAnimationSet *pAnimationSet = traversal.Next();
  265. Assert( !traversal.IsValid() );
  266. CDmrElementArray< CDmePresetGroup > presetGroupList = pAnimationSet->GetPresetGroups();
  267. int nPresetGroupCount = presetGroupList.Count();
  268. for ( int i = 0; i < nPresetGroupCount; ++i )
  269. {
  270. CDmePresetGroup *pPresetGroup = presetGroupList[ i ];
  271. CDmrElementArray< CDmePreset > presetList = pPresetGroup->GetPresets();
  272. int nPresetCount = presetList.Count();
  273. for ( int j = 0; j < nPresetCount; ++j )
  274. {
  275. CDmePreset *pPreset = presetList[ j ];
  276. CDmrElementArray<> controlValues = pPreset->GetControlValues();
  277. int nControlCount = controlValues.Count();
  278. for ( int k = 0; k < nControlCount; ++k )
  279. {
  280. CDmElement *v = controlValues[ k ];
  281. if ( !Q_stricmp( v->GetName(), pControlName ) )
  282. {
  283. controlValues.FastRemove( k );
  284. break;
  285. }
  286. }
  287. }
  288. }
  289. }
  290. //-----------------------------------------------------------------------------
  291. // Removes controls from the animation set that aren't used
  292. //-----------------------------------------------------------------------------
  293. void CDmeCombinationOperatorPanel::RemoveUnusedAnimationSetControls()
  294. {
  295. // TODO - we should be storing which animationset an item is associated with
  296. CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
  297. CDmeAnimationSet *pAnimationSet = traversal.Next();
  298. Assert( !traversal.IsValid() );
  299. CDmrElementArray< > controls = pAnimationSet->GetControls();
  300. // Remove all controls in the animation set and in presets that don't exist in the combination system
  301. int nAnimSetCount = controls.Count();
  302. for ( int i = nAnimSetCount; --i >= 0; )
  303. {
  304. CDmElement *pControlElement = controls[i];
  305. if ( !pControlElement )
  306. continue;
  307. // Don't do any of this work for transforms
  308. if ( IsTransformControl( pControlElement ) )
  309. continue;
  310. const char *pControlName = pControlElement->GetName();
  311. // Look for a match
  312. if ( FindComboOpControlIndexForAnimSetControl( m_hCombinationOperator, pControlName ) >= 0 )
  313. continue;
  314. // No match, blow the control away.
  315. RemoveAnimationControlFromPresets( pControlName );
  316. pAnimationSet->RemoveControlFromGroups( pControlName );
  317. controls.FastRemove( i );
  318. }
  319. }
  320. //-----------------------------------------------------------------------------
  321. // Modify controls in the presets which have had stereo settings changed
  322. //-----------------------------------------------------------------------------
  323. void CDmeCombinationOperatorPanel::ModifyExistingAnimationSetControl( CDmElement *pControlElement )
  324. {
  325. const char *pControlName = pControlElement->GetName();
  326. // Look for a match
  327. bool bIsMultiControl;
  328. ControlIndex_t nControlIndex = FindComboOpControlIndexForAnimSetControl( m_hCombinationOperator, pControlName, &bIsMultiControl );
  329. Assert( nControlIndex >= 0 );
  330. float flDefaultValue = m_hCombinationOperator->GetControlDefaultValue( nControlIndex );
  331. if ( bIsMultiControl )
  332. {
  333. // multi control can't (currently) be stereo, and so it either exists or it doesn't...
  334. pControlElement->SetValue< float >( "value", m_hCombinationOperator->GetMultiControlLevel( nControlIndex ) );
  335. pControlElement->SetValue( "defaultValue", 0.5f );
  336. }
  337. else
  338. {
  339. bool bIsStereoControl = m_hCombinationOperator->IsStereoControl( nControlIndex );
  340. bool bIsAnimControlStereo = IsStereoControl( pControlElement );
  341. if ( bIsAnimControlStereo != bIsStereoControl )
  342. {
  343. if ( !bIsStereoControl )
  344. {
  345. float flValue = m_hCombinationOperator->GetControlValue( nControlIndex );
  346. pControlElement->SetValue< float >( "value", flValue );
  347. pControlElement->RemoveAttribute( "leftValue" );
  348. pControlElement->RemoveAttribute( "rightValue" );
  349. }
  350. else
  351. {
  352. const Vector2D &value = m_hCombinationOperator->GetStereoControlValue( nControlIndex );
  353. pControlElement->SetValue< float >( "leftValue", value.x );
  354. pControlElement->SetValue< float >( "rightValue", value.y );
  355. pControlElement->RemoveAttribute( "value" );
  356. }
  357. }
  358. pControlElement->SetValue( "defaultValue", flDefaultValue );
  359. }
  360. }
  361. //-----------------------------------------------------------------------------
  362. // Modify controls in the presets which have had stereo settings changed
  363. //-----------------------------------------------------------------------------
  364. void CDmeCombinationOperatorPanel::ModifyExistingAnimationSetPresets( CDmElement *pControlElement )
  365. {
  366. const char *pControlName = pControlElement->GetName();
  367. // TODO - we should be storing which animationset an item is associated with
  368. CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
  369. CDmeAnimationSet *pAnimationSet = traversal.Next();
  370. Assert( !traversal.IsValid() );
  371. const CDmrElementArray< CDmePresetGroup > &presetGroupList = pAnimationSet->GetPresetGroups();
  372. int nPresetGroupCount = presetGroupList.Count();
  373. for ( int g = 0; g < nPresetGroupCount; ++g )
  374. {
  375. CDmePresetGroup *pPresetGroup = presetGroupList[ g ];
  376. const CDmrElementArray< CDmePreset > &presetList = pPresetGroup->GetPresets();
  377. int nPresetCount = presetList.Count();
  378. for ( int i = 0; i < nPresetCount; ++i )
  379. {
  380. CDmePreset *pPreset = presetList[ i ];
  381. Assert( !pPreset->IsAnimated() ); // deal with this after GDC
  382. if ( pPreset->IsAnimated() )
  383. continue;
  384. const CDmrElementArray< CDmElement > &controlValues = pPreset->GetControlValues( );
  385. int nControlCount = controlValues.Count();
  386. for ( int j = 0; j < nControlCount; ++j )
  387. {
  388. CDmElement *v = controlValues[ j ];
  389. if ( Q_stricmp( v->GetName(), pControlName ) )
  390. continue;
  391. bool bIsAnimControlStereo = IsStereoControl( pControlElement );
  392. if ( bIsAnimControlStereo )
  393. {
  394. float flValue = v->GetValue< float >( "value" );
  395. v->RemoveAttribute( "value" );
  396. v->InitValue( "leftValue", flValue );
  397. v->InitValue( "rightValue", flValue );
  398. }
  399. else
  400. {
  401. float flLeftValue = v->GetValue< float >( "leftValue" );
  402. float flRightValue = v->GetValue< float >( "rightValue" );
  403. v->RemoveAttribute( "leftValue" );
  404. v->RemoveAttribute( "rightValue" );
  405. v->InitValue( "value", MAX( flLeftValue, flRightValue ) ); // TODO - should this be max or average?
  406. }
  407. }
  408. }
  409. }
  410. }
  411. //-----------------------------------------------------------------------------
  412. // Modify controls which have had stereo settings changed
  413. //-----------------------------------------------------------------------------
  414. void CDmeCombinationOperatorPanel::ModifyExistingAnimationSetControls()
  415. {
  416. // TODO - we should be storing which animationset an item is associated with
  417. CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
  418. CDmeAnimationSet *pAnimationSet = traversal.Next();
  419. Assert( !traversal.IsValid() );
  420. const CDmrElementArray< CDmElement > &controls = pAnimationSet->GetControls();
  421. // Update the main controls; update defaults and add or remove combo + multi data
  422. int nAnimSetCount = controls.Count();
  423. for ( int i = nAnimSetCount; --i >= 0; )
  424. {
  425. CDmElement *pControlElement = controls[i];
  426. if ( !pControlElement )
  427. continue;
  428. // Don't do any of this work for transforms
  429. if ( IsTransformControl( pControlElement ) )
  430. continue;
  431. ModifyExistingAnimationSetControl( pControlElement );
  432. ModifyExistingAnimationSetPresets( pControlElement );
  433. }
  434. }
  435. //-----------------------------------------------------------------------------
  436. // Adds new controls to the animation set
  437. //-----------------------------------------------------------------------------
  438. void CDmeCombinationOperatorPanel::AddNewAnimationSetControls()
  439. {
  440. if ( !m_hCombinationOperator.Get() )
  441. return;
  442. // TODO - we should be storing which animationset an item is associated with
  443. CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
  444. CDmeAnimationSet *pAnimationSet = traversal.Next();
  445. Assert( !traversal.IsValid() );
  446. CDmaElementArray< > &controls = pAnimationSet->GetControls();
  447. // Remove all controls in the animation set and in presets that don't exist in the combination system
  448. int nFirstControl = controls.Count();
  449. int nCombinationControlCount = m_hCombinationOperator->GetControlCount();
  450. int iCurrentAnimSetControl = 0;
  451. for ( int i = 0; i < nCombinationControlCount; ++i, ++iCurrentAnimSetControl )
  452. {
  453. const char *pControlName = m_hCombinationOperator->GetControlName( i );
  454. if ( !pAnimationSet->FindControl( pControlName ) )
  455. {
  456. bool bIsStereoControl = m_hCombinationOperator->IsStereoControl( i );
  457. float flDefaultValue = m_hCombinationOperator->GetControlDefaultValue( i );
  458. // Add the control to the controls group
  459. CDmElement *pControl = CreateElement< CDmElement >( pControlName, pAnimationSet->GetFileId() );
  460. Assert( pControl );
  461. controls.InsertBefore( iCurrentAnimSetControl, pControl );
  462. if ( bIsStereoControl )
  463. {
  464. const Vector2D &value = m_hCombinationOperator->GetStereoControlValue(i);
  465. pControl->SetValue( "leftValue", value.x );
  466. pControl->SetValue( "rightValue", value.y );
  467. }
  468. else
  469. {
  470. pControl->SetValue( "value", m_hCombinationOperator->GetControlValue(i) );
  471. }
  472. pControl->SetValue( "defaultValue", flDefaultValue );
  473. }
  474. bool bIsMultiControl = m_hCombinationOperator->IsMultiControl( i );
  475. if ( bIsMultiControl )
  476. {
  477. ++iCurrentAnimSetControl;
  478. char pMultiControlName[ 256 ];
  479. V_snprintf( pMultiControlName, sizeof( pMultiControlName ), MULTI_CONTROL_FORMAT_STRING, pControlName );
  480. if ( !pAnimationSet->FindControl( pMultiControlName ) )
  481. {
  482. CDmElement *pMultiControl = CreateElement< CDmElement >( pMultiControlName, pAnimationSet->GetFileId() );
  483. Assert( pMultiControl );
  484. controls.InsertBefore( iCurrentAnimSetControl, pMultiControl );
  485. pMultiControl->SetValue( "value", m_hCombinationOperator->GetMultiControlLevel( i ) );
  486. pMultiControl->SetValue( "defaultValue", 0.5f );
  487. }
  488. }
  489. }
  490. int nLastControl = controls.Count();
  491. if ( nLastControl == nFirstControl )
  492. return;
  493. // Add new controls to the root group
  494. CDmElement *pGroup = pAnimationSet->FindOrAddControlGroup( NULL, "Root" );
  495. // Fill in members
  496. CDmrElementArray<> groups( pGroup, "controls" );
  497. for ( int i = nFirstControl; i < nLastControl; ++i )
  498. {
  499. groups.AddToTail( controls[ i ] );
  500. }
  501. }
  502. //-----------------------------------------------------------------------------
  503. // Sort control names to match the combination controls
  504. //-----------------------------------------------------------------------------
  505. void CDmeCombinationOperatorPanel::SortAnimationSetControls()
  506. {
  507. // TODO - we should be storing which animationset an item is associated with
  508. CAnimSetGroupAnimSetTraversal traversal( m_pController->GetAnimationSetClip() );
  509. CDmeAnimationSet *pAnimSet = traversal.Next();
  510. Assert( !traversal.IsValid() );
  511. // TODO: Figure out why this isn't called on load
  512. pAnimSet->OnElementUnserialized();
  513. CDmaElementArray<> &controls = pAnimSet->GetControls();
  514. int nControlCount = controls.Count();
  515. if ( nControlCount == 0 )
  516. return;
  517. int nCombinationControlCount = m_hCombinationOperator->GetControlCount();
  518. DmElementHandle_t *pElements = (DmElementHandle_t*)_alloca( nControlCount * sizeof(DmElementHandle_t) );
  519. int iCurrentControlIndex = 0;
  520. for ( int i = 0; i < nCombinationControlCount; ++i )
  521. {
  522. const char *pControlName = m_hCombinationOperator->GetControlName( i );
  523. CDmElement *pControl = pAnimSet->FindControl( pControlName );
  524. pElements[iCurrentControlIndex++] = pControl->GetHandle();
  525. if ( m_hCombinationOperator->IsMultiControl( i ) )
  526. {
  527. char pMultiControlName[ 256 ];
  528. V_snprintf( pMultiControlName, sizeof( pMultiControlName ), MULTI_CONTROL_FORMAT_STRING, pControlName );
  529. CDmElement *pMultiControl = pAnimSet->FindControl( pMultiControlName );
  530. pElements[iCurrentControlIndex++] = pMultiControl->GetHandle();
  531. }
  532. }
  533. Assert( nControlCount == iCurrentControlIndex );
  534. controls.SetMultiple( 0, nControlCount, pElements );
  535. }
  536. //-----------------------------------------------------------------------------
  537. // Called when the animation set has to be made to match the combination operator
  538. //-----------------------------------------------------------------------------
  539. void CDmeCombinationOperatorPanel::RefreshAnimationSet()
  540. {
  541. if ( !m_pController->GetAnimationSetClip() )
  542. return;
  543. CDisableUndoScopeGuard sg;
  544. // Remove all controls in the animation set and in presets that don't exist in the combination system
  545. RemoveUnusedAnimationSetControls();
  546. // Modify controls in the presets which have had stereo settings changed
  547. ModifyExistingAnimationSetControls();
  548. // Add all controls not in the animation set but which do exist in the combination system
  549. AddNewAnimationSetControls();
  550. // Sort control names to match the combination controls
  551. SortAnimationSetControls();
  552. }
  553. void CDmeCombinationOperatorPanel::RefreshCombinationOperator()
  554. {
  555. RefreshAnimationSet();
  556. ChangeAnimationSetClip( m_pController->GetAnimationSetClip() );
  557. }
  558. //-----------------------------------------------------------------------------
  559. // Simulate
  560. //-----------------------------------------------------------------------------
  561. void CDmeCombinationOperatorPanel::OnTick()
  562. {
  563. BaseClass::OnTick();
  564. if ( m_hCombinationOperator )
  565. {
  566. {
  567. CDisableUndoScopeGuard sg;
  568. int nCombinationControlCount = m_hCombinationOperator->GetControlCount();
  569. int iCurrentControlIndex = 0;
  570. for ( int i = 0; i < nCombinationControlCount; ++i )
  571. {
  572. AttributeValue_t value;
  573. if ( GetAttributeSlider()->GetSliderValues( &value, iCurrentControlIndex++ ) )
  574. {
  575. if ( m_hCombinationOperator->IsStereoControl( i ) )
  576. {
  577. m_hCombinationOperator->SetControlValue( i, value.m_pValue[ANIM_CONTROL_VALUE_LEFT], value.m_pValue[ANIM_CONTROL_VALUE_RIGHT] );
  578. }
  579. else
  580. {
  581. m_hCombinationOperator->SetControlValue( i, value.m_pValue[ANIM_CONTROL_VALUE] );
  582. }
  583. }
  584. if ( m_hCombinationOperator->IsMultiControl( i ) )
  585. {
  586. AttributeValue_t multiValue;
  587. if ( GetAttributeSlider()->GetSliderValues( &multiValue, iCurrentControlIndex++ ) )
  588. {
  589. m_hCombinationOperator->SetMultiControlLevel( i, multiValue.m_pValue[ANIM_CONTROL_VALUE] );
  590. }
  591. }
  592. }
  593. }
  594. if ( m_operatorList.Count() )
  595. {
  596. CDisableUndoScopeGuard guard;
  597. g_pDmElementFramework->SetOperators( m_operatorList );
  598. g_pDmElementFramework->Operate( true );
  599. }
  600. else
  601. {
  602. // FIXME: Shouldn't this happen at the application level?
  603. // run the machinery - apply, resolve, dependencies, operate, resolve
  604. CUtlVector< IDmeOperator* > operators;
  605. operators.AddToTail( m_hCombinationOperator );
  606. CDisableUndoScopeGuard guard;
  607. g_pDmElementFramework->SetOperators( operators );
  608. g_pDmElementFramework->Operate( true );
  609. }
  610. }
  611. // allow elements and attributes to be edited again
  612. g_pDmElementFramework->BeginEdit();
  613. }
  614. //-----------------------------------------------------------------------------
  615. // Constructor, destructor
  616. //-----------------------------------------------------------------------------
  617. CDmeDagEditPanel::CDmeDagEditPanel( vgui::Panel *pParent, const char *pName ) : BaseClass( pParent, pName )
  618. {
  619. m_pPropertiesSplitter = new vgui::Splitter( this, "PropertiesSplitter", vgui::SPLITTER_MODE_VERTICAL, 1 );
  620. vgui::Panel *pSplitterLeftSide = m_pPropertiesSplitter->GetChild( 0 );
  621. vgui::Panel *pSplitterRightSide = m_pPropertiesSplitter->GetChild( 1 );
  622. m_pDagRenderPanel = new CDmeDagRenderPanel( pSplitterRightSide, "DagRenderPanel" );
  623. m_pEditorSheet = new vgui::PropertySheet( pSplitterLeftSide, "EditorSheet" );
  624. m_pEditorSheet->AddActionSignalTarget( this );
  625. m_pAnimationPage = new vgui::PropertyPage( m_pEditorSheet, "AnimationPage" );
  626. m_pCombinationPage = new vgui::PropertyPage( m_pEditorSheet, "AnimationSetEditor" );
  627. m_pVertexAnimationPage = new vgui::PropertyPage( m_pEditorSheet, "VertexAnimationPage" );
  628. CCombinationOperatorControl *pAnimationSetController = new CCombinationOperatorControl();
  629. m_pCombinationPanel = new CDmeCombinationOperatorPanel( m_pCombinationPage, "AnimationSetEditorPanel", pAnimationSetController );
  630. m_pCombinationPanel->CreateToolsSubPanels();
  631. m_pAnimationListPanel = new CDmeAnimationListPanel( m_pAnimationPage, "AnimationListPanel" );
  632. m_pAnimationListPanel->AddActionSignalTarget( this );
  633. m_pVertexAnimationListPanel = new CDmeAnimationListPanel( m_pVertexAnimationPage, "VertexAnimationListPanel" );
  634. m_pVertexAnimationListPanel->AddActionSignalTarget( this );
  635. m_pCombinationPage->LoadControlSettingsAndUserConfig( "resource/dmedageditpanel_animationseteditorpage.res" );
  636. m_pAnimationPage->LoadControlSettingsAndUserConfig( "resource/dmedageditpanel_animationpage.res" );
  637. m_pVertexAnimationPage->LoadControlSettingsAndUserConfig( "resource/dmedageditpanel_vertexanimationpage.res" );
  638. // Load layout settings; has to happen before pinning occurs in code
  639. LoadControlSettingsAndUserConfig( "resource/dmedageditpanel.res" );
  640. // NOTE: Page adding happens *after* LoadControlSettingsAndUserConfig
  641. // because the layout of the sheet is correct at this point.
  642. m_pEditorSheet->AddPage( m_pAnimationPage, "Animation" );
  643. m_pEditorSheet->AddPage( m_pCombinationPage, "Combination" );
  644. m_pEditorSheet->AddPage( m_pVertexAnimationPage, "Vertex Animation" );
  645. m_pEditorSheet->SetActivePage( m_pCombinationPage );
  646. }
  647. CDmeDagEditPanel::~CDmeDagEditPanel()
  648. {
  649. }
  650. //-----------------------------------------------------------------------------
  651. // Set the scene
  652. //-----------------------------------------------------------------------------
  653. void CDmeDagEditPanel::SetDmeElement( CDmeDag *pScene )
  654. {
  655. m_pDagRenderPanel->SetDmeElement( pScene );
  656. }
  657. //-----------------------------------------------------------------------------
  658. // Sets up the various panels in the dag editor
  659. //-----------------------------------------------------------------------------
  660. void CDmeDagEditPanel::SetMakefileRootElement( CDmElement *pRoot )
  661. {
  662. CDmeAnimationList *pAnimationList = pRoot->GetValueElement< CDmeAnimationList >( "animationList" );
  663. SetAnimationList( pAnimationList );
  664. CDmeAnimationList *pVertexAnimationList = pRoot->GetValueElement< CDmeAnimationList >( "vertexAnimationList" );
  665. SetVertexAnimationList( pVertexAnimationList );
  666. CDmeCombinationOperator *pComboOp = pRoot->GetValueElement< CDmeCombinationOperator >( "combinationOperator" );
  667. SetCombinationOperator( pComboOp );
  668. }
  669. //-----------------------------------------------------------------------------
  670. // Other methods which hook into DmePanel
  671. //-----------------------------------------------------------------------------
  672. void CDmeDagEditPanel::SetDmeElement( CDmeSourceSkin *pSkin )
  673. {
  674. m_pDagRenderPanel->SetDmeElement( pSkin );
  675. // First, try to grab the dependent makefile
  676. CDmeMakefile *pSourceMakefile = pSkin->GetDependentMakefile();
  677. if ( !pSourceMakefile )
  678. return;
  679. // Next, try to grab the output of that makefile
  680. CDmElement *pOutput = pSourceMakefile->GetOutputElement( true );
  681. if ( !pOutput )
  682. return;
  683. SetMakefileRootElement( pOutput );
  684. }
  685. void CDmeDagEditPanel::SetDmeElement( CDmeSourceAnimation *pAnimation )
  686. {
  687. m_pDagRenderPanel->SetDmeElement( pAnimation );
  688. // First, try to grab the dependent makefile
  689. CDmeMakefile *pSourceMakefile = pAnimation->GetDependentMakefile();
  690. if ( !pSourceMakefile )
  691. return;
  692. // Next, try to grab the output of that makefile
  693. CDmElement *pOutput = pSourceMakefile->GetOutputElement( true );
  694. if ( !pOutput )
  695. return;
  696. SetMakefileRootElement( pOutput );
  697. // if ( pAnimationList->FindAnimation( pAnimation->m_SourceAnimationName ) < 0 )
  698. // return;
  699. }
  700. void CDmeDagEditPanel::SetDmeElement( CDmeDCCMakefile *pDCCMakefile )
  701. {
  702. m_pDagRenderPanel->SetDmeElement( pDCCMakefile );
  703. // First, try to grab the dependent makefile
  704. CDmElement *pOutput = pDCCMakefile->GetOutputElement( true );
  705. if ( !pOutput )
  706. return;
  707. SetMakefileRootElement( pOutput );
  708. }
  709. CDmeDag *CDmeDagEditPanel::GetDmeElement()
  710. {
  711. return m_pDagRenderPanel->GetDmeElement();
  712. }
  713. //-----------------------------------------------------------------------------
  714. // paint it!
  715. //-----------------------------------------------------------------------------
  716. void CDmeDagEditPanel::Paint()
  717. {
  718. BaseClass::Paint();
  719. }
  720. //-----------------------------------------------------------------------------
  721. // Sets animation
  722. //-----------------------------------------------------------------------------
  723. void CDmeDagEditPanel::SetAnimationList( CDmeAnimationList *pAnimationList )
  724. {
  725. m_pDagRenderPanel->SetAnimationList( pAnimationList );
  726. m_pDagRenderPanel->SelectAnimation( "" );
  727. m_pAnimationListPanel->SetAnimationList( pAnimationList );
  728. }
  729. void CDmeDagEditPanel::SetVertexAnimationList( CDmeAnimationList *pAnimationList )
  730. {
  731. m_pDagRenderPanel->SetVertexAnimationList( pAnimationList );
  732. m_pDagRenderPanel->SelectVertexAnimation( "" );
  733. m_pVertexAnimationListPanel->SetAnimationList( pAnimationList );
  734. }
  735. void CDmeDagEditPanel::SetCombinationOperator( CDmeCombinationOperator *pComboOp )
  736. {
  737. m_pCombinationPanel->SetCombinationOperator( pComboOp );
  738. }
  739. void CDmeDagEditPanel::RefreshCombinationOperator()
  740. {
  741. m_pCombinationPanel->RefreshCombinationOperator();
  742. }
  743. //-----------------------------------------------------------------------------
  744. // Called when the page changes
  745. //-----------------------------------------------------------------------------
  746. void CDmeDagEditPanel::OnPageChanged( )
  747. {
  748. if ( m_pEditorSheet->GetActivePage() == m_pCombinationPage )
  749. {
  750. m_pDagRenderPanel->SelectAnimation( "" );
  751. m_pDagRenderPanel->SelectVertexAnimation( "" );
  752. return;
  753. }
  754. if ( m_pEditorSheet->GetActivePage() == m_pAnimationPage )
  755. {
  756. m_pDagRenderPanel->SelectAnimation( m_pAnimationListPanel->GetSelectedAnimation() );
  757. m_pDagRenderPanel->SelectVertexAnimation( "" );
  758. return;
  759. }
  760. if ( m_pEditorSheet->GetActivePage() == m_pVertexAnimationPage )
  761. {
  762. m_pDagRenderPanel->SelectAnimation( "" );
  763. m_pDagRenderPanel->SelectVertexAnimation( m_pVertexAnimationListPanel->GetSelectedAnimation() );
  764. return;
  765. }
  766. }
  767. //-----------------------------------------------------------------------------
  768. // Called when new animations are selected
  769. //-----------------------------------------------------------------------------
  770. void CDmeDagEditPanel::OnAnimationSelected( KeyValues *pKeyValues )
  771. {
  772. vgui::Panel *pPanel = (vgui::Panel *)pKeyValues->GetPtr( "panel", NULL );
  773. const char *pAnimationName = pKeyValues->GetString( "animationName", "" );
  774. if ( pPanel == m_pAnimationListPanel )
  775. {
  776. m_pDagRenderPanel->SelectAnimation( pAnimationName );
  777. return;
  778. }
  779. if ( pPanel == m_pVertexAnimationListPanel )
  780. {
  781. m_pDagRenderPanel->SelectVertexAnimation( pAnimationName );
  782. return;
  783. }
  784. }
  785. void CDmeDagEditPanel::OnAnimationDeselected( KeyValues *pKeyValues )
  786. {
  787. vgui::Panel *pPanel = (vgui::Panel *)pKeyValues->GetPtr( "panel", NULL );
  788. if ( pPanel == m_pAnimationListPanel )
  789. {
  790. m_pDagRenderPanel->SelectAnimation( "" );
  791. return;
  792. }
  793. if ( pPanel == m_pVertexAnimationListPanel )
  794. {
  795. m_pDagRenderPanel->SelectVertexAnimation( "" );
  796. return;
  797. }
  798. }