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.

2332 lines
76 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "dme_controls/dmepresetgroupeditorpanel.h"
  8. #include "dme_controls/dmecontrols_utils.h"
  9. #include "movieobjects/dmeanimationset.h"
  10. #include "vgui_controls/ListPanel.h"
  11. #include "vgui_controls/PropertySheet.h"
  12. #include "vgui_controls/PropertyPage.h"
  13. #include "vgui_controls/Button.h"
  14. #include "vgui_controls/Menu.h"
  15. #include "vgui_controls/Splitter.h"
  16. #include "vgui_controls/MessageBox.h"
  17. #include "vgui_controls/ComboBox.h"
  18. #include "vgui_controls/InputDialog.h"
  19. #include "vgui_controls/TextEntry.h"
  20. #include "vgui/MouseCode.h"
  21. #include "vgui/IInput.h"
  22. #include "vgui/ISurface.h"
  23. #include "tier1/KeyValues.h"
  24. #include "tier1/utldict.h"
  25. #include "dme_controls/presetpicker.h"
  26. #include "vgui_controls/FileOpenDialog.h"
  27. #include "tier2/fileutils.h"
  28. #include "tier1/utlbuffer.h"
  29. #include "dme_controls/inotifyui.h"
  30. #include "../game/shared/iscenetokenprocessor.h"
  31. #include "movieobjects/dmx_to_vcd.h"
  32. #include "studio.h"
  33. #include "phonemeconverter.h"
  34. // Forward declaration
  35. class CDmePresetGroupEditorPanel;
  36. //-----------------------------------------------------------------------------
  37. // Utility scope guards
  38. //-----------------------------------------------------------------------------
  39. DEFINE_SOURCE_UNDO_SCOPE_GUARD( PresetGroup, NOTIFY_SOURCE_PRESET_GROUP_EDITOR );
  40. DEFINE_SOURCE_NOTIFY_SCOPE_GUARD( PresetGroup, NOTIFY_SOURCE_PRESET_GROUP_EDITOR );
  41. #define PRESET_FILE_FORMAT "preset"
  42. //-----------------------------------------------------------------------------
  43. //
  44. //-----------------------------------------------------------------------------
  45. //-----------------------------------------------------------------------------
  46. //
  47. // CDmePresetRemapPanel
  48. //
  49. // Implementation below because of scoping issues
  50. //
  51. //-----------------------------------------------------------------------------
  52. class CDmePresetRemapPanel : public vgui::Frame
  53. {
  54. DECLARE_CLASS_SIMPLE( CDmePresetRemapPanel, vgui::Frame );
  55. public:
  56. CDmePresetRemapPanel( vgui::Panel *pParent, const char *pTitle );
  57. ~CDmePresetRemapPanel();
  58. // Shows the modal dialog
  59. void DoModal( CDmeAnimationSet *pAnimationSet, CDmePresetGroup *pDestGroup );
  60. // Inherited from Frame
  61. virtual void OnCommand( const char *pCommand );
  62. virtual void OnKeyCodeTyped( KeyCode code );
  63. private:
  64. MESSAGE_FUNC( OnTextChanged, "TextChanged" );
  65. MESSAGE_FUNC( OnSelectPreset, "SelectPreset" );
  66. MESSAGE_FUNC( OnRemovePreset, "RemovePreset" );
  67. MESSAGE_FUNC_PARAMS( OnPresetPicked, "PresetPicked", params );
  68. MESSAGE_FUNC_PARAMS( OnOpenContextMenu, "OpenContextMenu", kv );
  69. // Refreshes the list of presets
  70. void RefreshPresetList( );
  71. // Applies changes to the preset remap
  72. void ApplyChangesToPresetRemap();
  73. // Cleans up the context menu
  74. void CleanupContextMenu();
  75. vgui::ListPanel *m_pPresetRemapList;
  76. vgui::ComboBox *m_pSourcePresetGroup;
  77. CDmeHandle< CDmePresetGroup > m_hSourceGroup;
  78. CDmeHandle< CDmePresetGroup > m_hDestGroup;
  79. vgui::DHANDLE< vgui::Menu > m_hContextMenu;
  80. };
  81. //-----------------------------------------------------------------------------
  82. // Constructor
  83. //-----------------------------------------------------------------------------
  84. static int __cdecl DestPresetNameSortFunc( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  85. {
  86. const char *string1 = item1.kv->GetString( "dest" );
  87. const char *string2 = item2.kv->GetString( "dest" );
  88. return Q_stricmp( string1, string2 );
  89. }
  90. static int __cdecl SrcPresetNameSortFunc( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  91. {
  92. const char *string1 = item1.kv->GetString( "src" );
  93. const char *string2 = item2.kv->GetString( "src" );
  94. return Q_stricmp( string1, string2 );
  95. }
  96. CDmePresetRemapPanel::CDmePresetRemapPanel( vgui::Panel *pParent, const char *pTitle ) :
  97. BaseClass( pParent, "DmePresetRemapPanel" )
  98. {
  99. m_pSourcePresetGroup = new vgui::ComboBox( this, "SourcePresetGroup", 8, true );
  100. SetDeleteSelfOnClose( true );
  101. m_pPresetRemapList = new vgui::ListPanel( this, "PresetRemapList" );
  102. m_pPresetRemapList->AddColumnHeader( 0, "dest", "Dest Preset", 100, 0 );
  103. m_pPresetRemapList->AddColumnHeader( 1, "src", "Source Preset", 100, 0 );
  104. m_pPresetRemapList->SetSelectIndividualCells( false );
  105. m_pPresetRemapList->SetMultiselectEnabled( true );
  106. m_pPresetRemapList->SetEmptyListText( "No presets" );
  107. m_pPresetRemapList->AddActionSignalTarget( this );
  108. m_pPresetRemapList->SetSortFunc( 0, DestPresetNameSortFunc );
  109. m_pPresetRemapList->SetSortFunc( 1, SrcPresetNameSortFunc );
  110. m_pPresetRemapList->SetSortColumn( 0 );
  111. SetBlockDragChaining( true );
  112. LoadControlSettingsAndUserConfig( "resource/presetremappanel.res" );
  113. SetTitle( pTitle, false );
  114. }
  115. CDmePresetRemapPanel::~CDmePresetRemapPanel()
  116. {
  117. CleanupContextMenu();
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Cleans up the context menu
  121. //-----------------------------------------------------------------------------
  122. void CDmePresetRemapPanel::CleanupContextMenu()
  123. {
  124. if ( m_hContextMenu.Get() )
  125. {
  126. m_hContextMenu->MarkForDeletion();
  127. m_hContextMenu = NULL;
  128. }
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Refreshes the list of presets
  132. //-----------------------------------------------------------------------------
  133. void CDmePresetRemapPanel::RefreshPresetList( )
  134. {
  135. m_pPresetRemapList->RemoveAll();
  136. CDmaElementArray< CDmePreset > *pPresetList = m_hDestGroup.Get() ? &m_hDestGroup->GetPresets() : NULL;
  137. if ( !pPresetList )
  138. return;
  139. int nCount = pPresetList->Count();
  140. if ( nCount == 0 )
  141. return;
  142. CDmePresetRemap *pRemap = m_hDestGroup->GetPresetRemap();
  143. bool bUseRemap = ( pRemap && m_hSourceGroup.Get() && !Q_stricmp( pRemap->m_SourcePresetGroup, m_hSourceGroup->GetName() ) );
  144. for ( int i = 0; i < nCount; ++i )
  145. {
  146. CDmePreset *pPreset = pPresetList->Get(i);
  147. const char *pName = pPreset->GetName();
  148. if ( !pName || !pName[0] )
  149. {
  150. pName = "<no name>";
  151. }
  152. KeyValues *kv = new KeyValues( "node" );
  153. kv->SetString( "dest", pName );
  154. SetElementKeyValue( kv, "destPreset", pPreset );
  155. if ( bUseRemap )
  156. {
  157. const char *pSource = pRemap->FindSourcePreset( pName );
  158. CDmePreset *pSrcPreset = pSource ? m_hSourceGroup->FindPreset( pSource ) : NULL;
  159. kv->SetString( "src", pSrcPreset ? pSrcPreset->GetName() : "" );
  160. SetElementKeyValue( kv, "srcPreset", pSrcPreset );
  161. }
  162. else
  163. {
  164. kv->SetString( "src", "" );
  165. SetElementKeyValue( kv, "srcPreset", NULL );
  166. }
  167. m_pPresetRemapList->AddItem( kv, 0, false, false );
  168. }
  169. m_pPresetRemapList->SortList();
  170. }
  171. //-----------------------------------------------------------------------------
  172. // Called by the preset picker when a preset is picked
  173. //-----------------------------------------------------------------------------
  174. void CDmePresetRemapPanel::OnPresetPicked( KeyValues *pParams )
  175. {
  176. int nSelectedItemCount = m_pPresetRemapList->GetSelectedItemsCount();
  177. if ( nSelectedItemCount != 1 )
  178. return;
  179. CDmePreset *pPreset = GetElementKeyValue< CDmePreset >( pParams, "preset" );
  180. int nItemID = m_pPresetRemapList->GetSelectedItem( 0 );
  181. KeyValues *kv = m_pPresetRemapList->GetItem( nItemID );
  182. kv->SetString( "src", pPreset ? pPreset->GetName() : "" );
  183. SetElementKeyValue( kv, "srcPreset", pPreset );
  184. m_pPresetRemapList->ApplyItemChanges( nItemID );
  185. }
  186. //-----------------------------------------------------------------------------
  187. // Called when double-clicking on a list entry
  188. //-----------------------------------------------------------------------------
  189. void CDmePresetRemapPanel::OnKeyCodeTyped( KeyCode code )
  190. {
  191. if ( code == KEY_ENTER )
  192. {
  193. OnSelectPreset();
  194. return;
  195. }
  196. if ( code == KEY_DELETE || code == KEY_BACKSPACE )
  197. {
  198. OnRemovePreset();
  199. return;
  200. }
  201. BaseClass::OnKeyCodeTyped( code );
  202. }
  203. //-----------------------------------------------------------------------------
  204. // Called by the context menu
  205. //-----------------------------------------------------------------------------
  206. void CDmePresetRemapPanel::OnSelectPreset()
  207. {
  208. int nSelectedItemCount = m_pPresetRemapList->GetSelectedItemsCount();
  209. if ( nSelectedItemCount != 1 )
  210. return;
  211. CPresetPickerFrame *pPresetPicker = new CPresetPickerFrame( this, "Select Source Preset", false );
  212. pPresetPicker->AddActionSignalTarget( this );
  213. pPresetPicker->DoModal( m_hSourceGroup, false, NULL );
  214. }
  215. void CDmePresetRemapPanel::OnRemovePreset()
  216. {
  217. int nSelectedItemCount = m_pPresetRemapList->GetSelectedItemsCount();
  218. if ( nSelectedItemCount != 1 )
  219. return;
  220. int nItemID = m_pPresetRemapList->GetSelectedItem( 0 );
  221. KeyValues *kv = m_pPresetRemapList->GetItem( nItemID );
  222. kv->SetString( "src", "" );
  223. SetElementKeyValue( kv, "srcPreset", NULL );
  224. m_pPresetRemapList->ApplyItemChanges( nItemID );
  225. }
  226. //-----------------------------------------------------------------------------
  227. // Called to open a context-sensitive menu for a particular menu item
  228. //-----------------------------------------------------------------------------
  229. void CDmePresetRemapPanel::OnOpenContextMenu( KeyValues *kv )
  230. {
  231. CleanupContextMenu();
  232. int nSelectedItemCount = m_pPresetRemapList->GetSelectedItemsCount();
  233. if ( nSelectedItemCount != 1 )
  234. return;
  235. m_hContextMenu = new vgui::Menu( this, "ActionMenu" );
  236. m_hContextMenu->AddMenuItem( "#DmePresetRemapPanel_SelectPreset", new KeyValues( "SelectPreset" ), this );
  237. m_hContextMenu->AddMenuItem( "#DmePresetRemapPanel_RemovePreset", new KeyValues( "RemovePreset" ), this );
  238. vgui::Menu::PlaceContextMenu( this, m_hContextMenu.Get() );
  239. }
  240. //-----------------------------------------------------------------------------
  241. // Called when the dest combo list changes
  242. //-----------------------------------------------------------------------------
  243. void CDmePresetRemapPanel::OnTextChanged()
  244. {
  245. KeyValues *pCurrentGroup = m_pSourcePresetGroup->GetActiveItemUserData();
  246. m_hSourceGroup = pCurrentGroup ? GetElementKeyValue<CDmePresetGroup>( pCurrentGroup, "presetGroup" ) : NULL;
  247. RefreshPresetList();
  248. }
  249. void CDmePresetRemapPanel::DoModal( CDmeAnimationSet *pAnimationSet, CDmePresetGroup *pDestGroup )
  250. {
  251. m_hDestGroup = pDestGroup;
  252. m_pSourcePresetGroup->DeleteAllItems();
  253. bool bSelected = false;
  254. CDmePresetRemap* pRemap = m_hDestGroup->GetPresetRemap();
  255. // Populate the combo box with preset group names
  256. const CDmaElementArray< CDmePresetGroup > &presetGroupList = pAnimationSet->GetPresetGroups();
  257. int nCount = presetGroupList.Count();
  258. for ( int i = 0; i < nCount; ++i )
  259. {
  260. CDmePresetGroup *pPresetGroup = presetGroupList[i];
  261. if ( pPresetGroup == m_hDestGroup.Get() )
  262. continue;
  263. KeyValues *kv = new KeyValues( "entry" );
  264. SetElementKeyValue( kv, "presetGroup", pPresetGroup );
  265. int nItemID = m_pSourcePresetGroup->AddItem( pPresetGroup->GetName(), kv );
  266. if ( !bSelected || ( pRemap && !Q_stricmp( pRemap->m_SourcePresetGroup, pPresetGroup->GetName() ) ) )
  267. {
  268. m_pSourcePresetGroup->ActivateItem( nItemID );
  269. bSelected = true;
  270. }
  271. }
  272. BaseClass::DoModal( );
  273. m_pSourcePresetGroup->RequestFocus();
  274. }
  275. //-----------------------------------------------------------------------------
  276. // Applies changes to the preset remap
  277. //-----------------------------------------------------------------------------
  278. void CDmePresetRemapPanel::ApplyChangesToPresetRemap()
  279. {
  280. int nTextLength = m_pSourcePresetGroup->GetTextLength() + 1;
  281. char* pSourceName = (char*)_alloca( nTextLength * sizeof(char) );
  282. m_pSourcePresetGroup->GetText( pSourceName, nTextLength );
  283. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Change Preset Remap" );
  284. CDmePresetRemap *pPresetRemap = m_hDestGroup->GetOrAddPresetRemap();
  285. pPresetRemap->m_SourcePresetGroup = pSourceName;
  286. pPresetRemap->RemoveAll();
  287. for ( int nItemID = m_pPresetRemapList->FirstItem();
  288. nItemID != m_pPresetRemapList->InvalidItemID();
  289. nItemID = m_pPresetRemapList->NextItem( nItemID ) )
  290. {
  291. KeyValues* pKeyValues = m_pPresetRemapList->GetItem( nItemID );
  292. CDmePreset *pSrcPreset = GetElementKeyValue< CDmePreset >( pKeyValues, "srcPreset" );
  293. CDmePreset *pDestPreset = GetElementKeyValue< CDmePreset >( pKeyValues, "destPreset" );
  294. if ( pSrcPreset && pDestPreset )
  295. {
  296. pPresetRemap->AddRemap( pSrcPreset->GetName(), pDestPreset->GetName() );
  297. }
  298. }
  299. }
  300. //-----------------------------------------------------------------------------
  301. // command handler
  302. //-----------------------------------------------------------------------------
  303. void CDmePresetRemapPanel::OnCommand( const char *command )
  304. {
  305. if ( !Q_stricmp( command, "Ok") )
  306. {
  307. ApplyChangesToPresetRemap();
  308. CloseModal();
  309. return;
  310. }
  311. if ( !Q_stricmp( command, "Cancel") )
  312. {
  313. CloseModal();
  314. return;
  315. }
  316. BaseClass::OnCommand( command );
  317. }
  318. //-----------------------------------------------------------------------------
  319. //
  320. // CDmePresetGroupListPanel
  321. //
  322. // Implementation below because of scoping issues
  323. //
  324. //-----------------------------------------------------------------------------
  325. class CDmePresetGroupListPanel : public vgui::ListPanel
  326. {
  327. DECLARE_CLASS_SIMPLE( CDmePresetGroupListPanel, vgui::ListPanel );
  328. public:
  329. // constructor, destructor
  330. CDmePresetGroupListPanel( vgui::Panel *pParent, const char *pName, CDmePresetGroupEditorPanel *pComboPanel );
  331. virtual void OnCreateDragData( KeyValues *msg );
  332. virtual bool IsDroppable( CUtlVector< KeyValues * >& msgList );
  333. virtual void OnPanelDropped( CUtlVector< KeyValues * >& msgList );
  334. virtual void OnKeyCodeTyped( vgui::KeyCode code );
  335. virtual void OnMouseDoublePressed( vgui::MouseCode code );
  336. virtual void OnDroppablePanelPaint( CUtlVector< KeyValues * >& msglist, CUtlVector< Panel * >& dragPanels );
  337. private:
  338. CDmePresetGroupEditorPanel *m_pPresetGroupPanel;
  339. };
  340. //-----------------------------------------------------------------------------
  341. //
  342. // CDmePresetListPanel
  343. //
  344. // Implementation below because of scoping issues
  345. //
  346. //-----------------------------------------------------------------------------
  347. class CDmePresetListPanel : public vgui::ListPanel
  348. {
  349. DECLARE_CLASS_SIMPLE( CDmePresetListPanel, vgui::ListPanel );
  350. public:
  351. // constructor, destructor
  352. CDmePresetListPanel( vgui::Panel *pParent, const char *pName, CDmePresetGroupEditorPanel *pComboPanel );
  353. virtual void OnKeyCodeTyped( vgui::KeyCode code );
  354. virtual void OnCreateDragData( KeyValues *msg );
  355. virtual bool IsDroppable( CUtlVector< KeyValues * >& msgList );
  356. virtual void OnPanelDropped( CUtlVector< KeyValues * >& msgList );
  357. virtual void OnDroppablePanelPaint( CUtlVector< KeyValues * >& msglist, CUtlVector< Panel * >& dragPanels );
  358. private:
  359. CDmePresetGroupEditorPanel *m_pPresetGroupPanel;
  360. };
  361. //-----------------------------------------------------------------------------
  362. // Sort functions for list panel
  363. //-----------------------------------------------------------------------------
  364. static int __cdecl IndexSortFunc( vgui::ListPanel *pPanel, const vgui::ListPanelItem &item1, const vgui::ListPanelItem &item2 )
  365. {
  366. int nIndex1 = item1.kv->GetInt("index");
  367. int nIndex2 = item2.kv->GetInt("index");
  368. return nIndex1 - nIndex2;
  369. }
  370. //-----------------------------------------------------------------------------
  371. // constructor, destructor
  372. //-----------------------------------------------------------------------------
  373. CDmePresetGroupEditorPanel::CDmePresetGroupEditorPanel( vgui::Panel *pParent, const char *pName ) :
  374. BaseClass( pParent, pName )
  375. {
  376. m_pSplitter = new vgui::Splitter( this, "PresetGroupSplitter", vgui::SPLITTER_MODE_VERTICAL, 1 );
  377. vgui::Panel *pSplitterLeftSide = m_pSplitter->GetChild( 0 );
  378. vgui::Panel *pSplitterRightSide = m_pSplitter->GetChild( 1 );
  379. m_pPresetGroupList = new CDmePresetGroupListPanel( pSplitterLeftSide, "PresetGroupList", this );
  380. m_pPresetGroupList->AddColumnHeader( 0, "name", "Preset Group Name", 150, 0 );
  381. m_pPresetGroupList->AddColumnHeader( 1, "visible", "Visible", 70, 0 );
  382. m_pPresetGroupList->AddColumnHeader( 2, "shared", "Shared", 52, 0 );
  383. m_pPresetGroupList->AddColumnHeader( 3, "readonly", "Read Only", 52, 0 );
  384. m_pPresetGroupList->SetSelectIndividualCells( false );
  385. m_pPresetGroupList->SetMultiselectEnabled( false );
  386. m_pPresetGroupList->SetEmptyListText( "No preset groups" );
  387. m_pPresetGroupList->AddActionSignalTarget( this );
  388. m_pPresetGroupList->SetSortFunc( 0, IndexSortFunc );
  389. m_pPresetGroupList->SetSortFunc( 1, NULL );
  390. m_pPresetGroupList->SetColumnSortable( 1, false );
  391. m_pPresetGroupList->SetSortFunc( 2, NULL );
  392. m_pPresetGroupList->SetColumnSortable( 2, false );
  393. m_pPresetGroupList->SetSortFunc( 3, NULL );
  394. m_pPresetGroupList->SetColumnSortable( 3, false );
  395. m_pPresetGroupList->SetDropEnabled( true );
  396. m_pPresetGroupList->SetSortColumn( 0 );
  397. m_pPresetGroupList->SetDragEnabled( true );
  398. m_pPresetGroupList->SetDropEnabled( true );
  399. m_pPresetGroupList->SetIgnoreDoubleClick( true );
  400. m_pPresetList = new CDmePresetListPanel( pSplitterRightSide, "PresetList", this );
  401. m_pPresetList->AddColumnHeader( 0, "name", "Preset Name", 150, 0 );
  402. m_pPresetList->SetSelectIndividualCells( false );
  403. m_pPresetList->SetEmptyListText( "No presets" );
  404. m_pPresetList->AddActionSignalTarget( this );
  405. m_pPresetList->SetSortFunc( 0, IndexSortFunc );
  406. m_pPresetList->SetSortColumn( 0 );
  407. m_pPresetList->SetDragEnabled( true );
  408. m_pPresetList->SetDropEnabled( true );
  409. m_pPresetList->SetIgnoreDoubleClick( true );
  410. LoadControlSettingsAndUserConfig( "resource/dmepresetgroupeditorpanel.res" );
  411. m_hFileOpenStateMachine = new vgui::FileOpenStateMachine( this, this );
  412. m_hFileOpenStateMachine->AddActionSignalTarget( this );
  413. }
  414. CDmePresetGroupEditorPanel::~CDmePresetGroupEditorPanel()
  415. {
  416. CleanupContextMenu();
  417. SaveUserConfig();
  418. }
  419. //-----------------------------------------------------------------------------
  420. // Cleans up the context menu
  421. //-----------------------------------------------------------------------------
  422. void CDmePresetGroupEditorPanel::CleanupContextMenu()
  423. {
  424. if ( m_hContextMenu.Get() )
  425. {
  426. m_hContextMenu->MarkForDeletion();
  427. m_hContextMenu = NULL;
  428. }
  429. }
  430. //-----------------------------------------------------------------------------
  431. // Sets the combination operator
  432. //-----------------------------------------------------------------------------
  433. void CDmePresetGroupEditorPanel::SetAnimationSet( CDmeAnimationSet *pAnimationSet )
  434. {
  435. m_hAnimationSet = pAnimationSet;
  436. RefreshAnimationSet();
  437. }
  438. CDmeAnimationSet* CDmePresetGroupEditorPanel::GetAnimationSet()
  439. {
  440. return m_hAnimationSet;
  441. }
  442. //-----------------------------------------------------------------------------
  443. // Builds the preset group list for the animation set
  444. //-----------------------------------------------------------------------------
  445. void CDmePresetGroupEditorPanel::RefreshAnimationSet()
  446. {
  447. CDmePresetGroup *pSelectedPresetGroup = GetSelectedPresetGroup();
  448. m_pPresetGroupList->RemoveAll();
  449. if ( !m_hAnimationSet.Get() )
  450. return;
  451. const CDmaElementArray< CDmePresetGroup > &presetGroupList = m_hAnimationSet->GetPresetGroups();
  452. int nCount = presetGroupList.Count();
  453. for ( int i = 0; i < nCount; ++i )
  454. {
  455. CDmePresetGroup *pPresetGroup = presetGroupList[i];
  456. Assert( pPresetGroup );
  457. if ( !pPresetGroup )
  458. continue;
  459. bool bIsVisible = pPresetGroup->m_bIsVisible;
  460. KeyValues *kv = new KeyValues( "node", "name", pPresetGroup->GetName() );
  461. kv->SetString( "visible", bIsVisible ? "Yes" : "No" );
  462. kv->SetString( "shared", pPresetGroup->IsShared() ? "Yes" : "No" );
  463. kv->SetString( "readonly", pPresetGroup->m_bIsReadOnly ? "Yes" : "No" );
  464. SetElementKeyValue( kv, "presetGroup", pPresetGroup );
  465. kv->SetColor( "cellcolor", pPresetGroup->m_bIsReadOnly ? Color( 255, 0, 0, 255 ) : Color( 255, 255, 255, 255 ) );
  466. kv->SetInt( "index", i );
  467. int nItemID = m_pPresetGroupList->AddItem( kv, 0, false, false );
  468. if ( pSelectedPresetGroup == pPresetGroup )
  469. {
  470. m_pPresetGroupList->AddSelectedItem( nItemID );
  471. }
  472. }
  473. m_pPresetGroupList->SortList();
  474. RefreshPresetNames();
  475. }
  476. //-----------------------------------------------------------------------------
  477. // Tells any class that cares that the data in this thing has changed
  478. //-----------------------------------------------------------------------------
  479. void CDmePresetGroupEditorPanel::NotifyDataChanged()
  480. {
  481. PostActionSignal( new KeyValues( "PresetsChanged" ) );
  482. }
  483. //-----------------------------------------------------------------------------
  484. // Refreshes the list of presets in the selected preset group
  485. //-----------------------------------------------------------------------------
  486. void CDmePresetGroupEditorPanel::RefreshPresetNames()
  487. {
  488. CDmePreset *pSelectedPreset = GetSelectedPreset();
  489. m_pPresetList->RemoveAll();
  490. if ( !m_hAnimationSet.Get() )
  491. return;
  492. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  493. if ( !pPresetGroup )
  494. return;
  495. const CDmaElementArray< CDmePreset > &presetList = pPresetGroup->GetPresets();
  496. int nCount = presetList.Count( );
  497. for ( int i = 0; i < nCount; ++i )
  498. {
  499. CDmePreset *pPreset = presetList[i];
  500. KeyValues *kv = new KeyValues( "node", "name", pPreset->GetName() );
  501. SetElementKeyValue( kv, "preset", pPreset );
  502. kv->SetInt( "index", i );
  503. int nItemID = m_pPresetList->AddItem( kv, 0, false, false );
  504. if ( pSelectedPreset == pPreset )
  505. {
  506. m_pPresetList->AddSelectedItem( nItemID );
  507. }
  508. }
  509. m_pPresetList->SortList();
  510. }
  511. //-----------------------------------------------------------------------------
  512. // Called to open a context-sensitive menu for a particular menu item
  513. //-----------------------------------------------------------------------------
  514. CDmePreset* CDmePresetGroupEditorPanel::GetSelectedPreset()
  515. {
  516. if ( !m_hAnimationSet.Get() )
  517. return NULL;
  518. int nSelectedPresetCount = m_pPresetList->GetSelectedItemsCount();
  519. if ( nSelectedPresetCount != 1 )
  520. return NULL;
  521. int nItemID = m_pPresetList->GetSelectedItem( 0 );
  522. KeyValues *pKeyValues = m_pPresetList->GetItem( nItemID );
  523. CDmePreset *pPreset = GetElementKeyValue< CDmePreset >( pKeyValues, "preset" );
  524. return pPreset;
  525. }
  526. //-----------------------------------------------------------------------------
  527. // Selects a particular preset
  528. //-----------------------------------------------------------------------------
  529. void CDmePresetGroupEditorPanel::SetSelectedPreset( CDmePreset* pPreset )
  530. {
  531. m_pPresetList->ClearSelectedItems();
  532. for ( int nItemID = m_pPresetList->FirstItem();
  533. nItemID != m_pPresetList->InvalidItemID();
  534. nItemID = m_pPresetList->NextItem( nItemID ) )
  535. {
  536. KeyValues* pKeyValues = m_pPresetList->GetItem( nItemID );
  537. CDmePreset *pItemPreset = GetElementKeyValue< CDmePreset >( pKeyValues, "preset" );
  538. if ( pItemPreset == pPreset )
  539. {
  540. m_pPresetList->AddSelectedItem( nItemID );
  541. }
  542. }
  543. }
  544. //-----------------------------------------------------------------------------
  545. // Called to open a context-sensitive menu for a particular menu item
  546. //-----------------------------------------------------------------------------
  547. CDmePresetGroup* CDmePresetGroupEditorPanel::GetSelectedPresetGroup()
  548. {
  549. if ( !m_hAnimationSet.Get() )
  550. return NULL;
  551. int nSelectedItemCount = m_pPresetGroupList->GetSelectedItemsCount();
  552. if ( nSelectedItemCount != 1 )
  553. return NULL;
  554. int nItemID = m_pPresetGroupList->GetSelectedItem( 0 );
  555. KeyValues *pKeyValues = m_pPresetGroupList->GetItem( nItemID );
  556. CDmePresetGroup *pPresetGroup = GetElementKeyValue<CDmePresetGroup>( pKeyValues, "presetGroup" );
  557. return pPresetGroup;
  558. }
  559. //-----------------------------------------------------------------------------
  560. // Selects a particular preset group
  561. //-----------------------------------------------------------------------------
  562. void CDmePresetGroupEditorPanel::SetSelectedPresetGroup( CDmePresetGroup* pPresetGroup )
  563. {
  564. m_pPresetGroupList->ClearSelectedItems();
  565. for ( int nItemID = m_pPresetGroupList->FirstItem();
  566. nItemID != m_pPresetGroupList->InvalidItemID();
  567. nItemID = m_pPresetGroupList->NextItem( nItemID ) )
  568. {
  569. KeyValues* pKeyValues = m_pPresetGroupList->GetItem( nItemID );
  570. CDmePresetGroup *pItemPresetGroup = GetElementKeyValue< CDmePresetGroup >( pKeyValues, "presetGroup" );
  571. if ( pItemPresetGroup == pPresetGroup )
  572. {
  573. m_pPresetGroupList->AddSelectedItem( nItemID );
  574. }
  575. }
  576. }
  577. //-----------------------------------------------------------------------------
  578. // If it finds a duplicate preset name, reports an error message and returns it found one
  579. //-----------------------------------------------------------------------------
  580. bool CDmePresetGroupEditorPanel::HasDuplicatePresetName( const char *pPresetName, CDmePreset *pIgnorePreset )
  581. {
  582. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  583. if ( !pPresetGroup )
  584. return false;
  585. CDmePreset *pMatch = pPresetGroup->FindPreset( pPresetName );
  586. if ( pMatch && pMatch != pIgnorePreset )
  587. {
  588. vgui::MessageBox *pError = new vgui::MessageBox( "#DmePresetGroupEditor_DuplicatePresetNameTitle", "#DmePresetGroupEditor_DuplicatePresetNameText", this );
  589. pError->DoModal();
  590. return true;
  591. }
  592. return false;
  593. }
  594. //-----------------------------------------------------------------------------
  595. // Called by OnInputCompleted after we get a new group name
  596. //-----------------------------------------------------------------------------
  597. void CDmePresetGroupEditorPanel::PerformAddPreset( const char *pNewPresetName )
  598. {
  599. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  600. if ( !pPresetGroup )
  601. return;
  602. if ( HasDuplicatePresetName( pNewPresetName ) )
  603. return;
  604. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Add Preset" );
  605. CDmePreset *pPreset = pPresetGroup->FindOrAddPreset( pNewPresetName );
  606. sg.Release();
  607. RefreshPresetNames();
  608. SetSelectedPreset( pPreset );
  609. NotifyDataChanged();
  610. KeyValues *pKeyValues = new KeyValues( "AddNewPreset" );
  611. SetElementKeyValue( pKeyValues, "preset", pPreset );
  612. PostActionSignal( pKeyValues );
  613. }
  614. //-----------------------------------------------------------------------------
  615. // Called by OnInputCompleted after we get a new group name
  616. //-----------------------------------------------------------------------------
  617. void CDmePresetGroupEditorPanel::PerformRenamePreset( const char *pNewPresetName )
  618. {
  619. CDmePreset *pPreset = GetSelectedPreset();
  620. if ( !pPreset )
  621. return;
  622. if ( HasDuplicatePresetName( pNewPresetName, pPreset ) )
  623. return;
  624. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Rename Preset" );
  625. pPreset->SetName( pNewPresetName );
  626. sg.Release();
  627. RefreshPresetNames();
  628. NotifyDataChanged();
  629. }
  630. //-----------------------------------------------------------------------------
  631. // Add a preset
  632. //-----------------------------------------------------------------------------
  633. void CDmePresetGroupEditorPanel::OnAddPreset()
  634. {
  635. vgui::InputDialog *pInput = new vgui::InputDialog( this, "Add Preset", "Enter name of new preset" );
  636. pInput->SetMultiline( false );
  637. pInput->DoModal( new KeyValues( "OnAddPreset" ) );
  638. }
  639. //-----------------------------------------------------------------------------
  640. // Rename a preset
  641. //-----------------------------------------------------------------------------
  642. void CDmePresetGroupEditorPanel::OnRenamePreset()
  643. {
  644. CDmePreset *pPreset = GetSelectedPreset();
  645. if ( !pPreset )
  646. return;
  647. vgui::InputDialog *pInput = new vgui::InputDialog( this, "Rename Preset", "Enter new name of preset" );
  648. pInput->SetMultiline( false );
  649. pInput->DoModal( new KeyValues( "OnRenamePreset" ) );
  650. }
  651. //-----------------------------------------------------------------------------
  652. // Remove a preset
  653. //-----------------------------------------------------------------------------
  654. void CDmePresetGroupEditorPanel::OnRemovePreset()
  655. {
  656. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  657. if ( !pPresetGroup )
  658. return;
  659. CDmePreset *pPreset = GetSelectedPreset();
  660. if ( !pPreset )
  661. return;
  662. int nItemID = m_pPresetList->GetSelectedItem( 0 );
  663. int nCurrentRow = m_pPresetList->GetItemCurrentRow( nItemID );
  664. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Remove Preset" );
  665. pPresetGroup->RemovePreset( pPreset );
  666. sg.Release();
  667. RefreshPresetNames();
  668. if ( nCurrentRow >= m_pPresetList->GetItemCount() )
  669. {
  670. --nCurrentRow;
  671. }
  672. if ( nCurrentRow >= 0 )
  673. {
  674. nItemID = m_pPresetList->GetItemIDFromRow( nCurrentRow );
  675. m_pPresetList->ClearSelectedItems();
  676. m_pPresetList->AddSelectedItem( nItemID );
  677. }
  678. NotifyDataChanged();
  679. }
  680. //-----------------------------------------------------------------------------
  681. // Called to open a context-sensitive menu for a particular menu item
  682. //-----------------------------------------------------------------------------
  683. void CDmePresetGroupEditorPanel::OnMovePresetUp()
  684. {
  685. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  686. CDmePreset *pPreset = GetSelectedPreset();
  687. if ( !pPresetGroup || !pPreset )
  688. return;
  689. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Reorder Presets" );
  690. pPresetGroup->MovePresetUp( pPreset );
  691. sg.Release();
  692. RefreshPresetNames();
  693. SetSelectedPreset( pPreset );
  694. NotifyDataChanged();
  695. }
  696. //-----------------------------------------------------------------------------
  697. // Called to open a context-sensitive menu for a particular menu item
  698. //-----------------------------------------------------------------------------
  699. void CDmePresetGroupEditorPanel::OnMovePresetDown()
  700. {
  701. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  702. CDmePreset *pPreset = GetSelectedPreset();
  703. if ( !pPresetGroup || !pPreset )
  704. return;
  705. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Reorder Presets" );
  706. pPresetGroup->MovePresetDown( pPreset );
  707. sg.Release();
  708. RefreshPresetNames();
  709. SetSelectedPreset( pPreset );
  710. NotifyDataChanged();
  711. }
  712. //-----------------------------------------------------------------------------
  713. // Drag/drop reordering of presets
  714. //-----------------------------------------------------------------------------
  715. void CDmePresetGroupEditorPanel::MovePresetInFrontOf( CDmePreset *pDragPreset, CDmePreset *pDropPreset )
  716. {
  717. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  718. if ( !pPresetGroup )
  719. return;
  720. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Reorder Presets" );
  721. pPresetGroup->MovePresetInFrontOf( pDragPreset, pDropPreset );
  722. sg.Release();
  723. RefreshPresetNames();
  724. SetSelectedPreset( pDragPreset );
  725. NotifyDataChanged();
  726. }
  727. //-----------------------------------------------------------------------------
  728. // Fileopen state machine
  729. //-----------------------------------------------------------------------------
  730. void CDmePresetGroupEditorPanel::OnFileStateMachineFinished( KeyValues *pParams )
  731. {
  732. KeyValues *pContextKeyValues = pParams->GetFirstTrueSubKey();
  733. if ( Q_stricmp( pContextKeyValues->GetName(), "ImportPresets" ) )
  734. return;
  735. CDmElement *pRoot = GetElementKeyValue<CDmElement>( pContextKeyValues, "presets" );
  736. if ( !pRoot )
  737. return;
  738. if ( pParams->GetInt( "completionState", 0 ) != 0 )
  739. {
  740. CPresetPickerFrame *pPresetPicker = new CPresetPickerFrame( this, "Select Preset(s) to Import" );
  741. pPresetPicker->AddActionSignalTarget( this );
  742. KeyValues *pContextKeyValuesImport = new KeyValues( "ImportPicked" );
  743. SetElementKeyValue( pContextKeyValuesImport, "presets", pRoot );
  744. pPresetPicker->DoModal( pRoot, true, pContextKeyValuesImport );
  745. }
  746. else
  747. {
  748. // Clean up the read-in file
  749. CDisableUndoScopeGuard sg;
  750. g_pDataModel->RemoveFileId( pRoot->GetFileId() );
  751. }
  752. }
  753. //-----------------------------------------------------------------------------
  754. // Finds a control index
  755. //-----------------------------------------------------------------------------
  756. struct ExportedControl_t
  757. {
  758. CUtlString m_Name;
  759. bool m_bIsStereo;
  760. bool m_bIsMulti;
  761. int m_nFirstIndex;
  762. };
  763. static int FindExportedControlIndex( const char *pControlName, CUtlVector< ExportedControl_t > &uniqueControls )
  764. {
  765. int nCount = uniqueControls.Count();
  766. for ( int i = 0; i < nCount; ++i )
  767. {
  768. if ( !Q_stricmp( pControlName, uniqueControls[i].m_Name ) )
  769. return i;
  770. }
  771. return -1;
  772. }
  773. //-----------------------------------------------------------------------------
  774. // Builds a unique list of controls found in the presets
  775. //-----------------------------------------------------------------------------
  776. static int BuildExportedControlList( CDmeAnimationSet *pAnimationSet, CDmePresetGroup *pPresetGroup, CUtlVector< ExportedControl_t > &uniqueControls )
  777. {
  778. int nGlobalIndex = 0;
  779. const CDmrElementArray< CDmePreset > &presets = pPresetGroup->GetPresets();
  780. int nPresetCount = presets.Count();
  781. for ( int iPreset = 0; iPreset < nPresetCount; ++iPreset )
  782. {
  783. CDmePreset *pPreset = presets[iPreset];
  784. const CDmrElementArray< CDmElement > &controls = pPreset->GetControlValues();
  785. int nControlCount = controls.Count();
  786. for ( int i = 0; i < nControlCount; ++i )
  787. {
  788. const char *pControlName = controls[i]->GetName();
  789. int nIndex = FindExportedControlIndex( pControlName, uniqueControls );
  790. if ( nIndex >= 0 )
  791. continue;
  792. CDmAttribute *pValueAttribute = controls[i]->GetAttribute( "value" );
  793. if ( !pValueAttribute || pValueAttribute->GetType() != AT_FLOAT )
  794. continue;
  795. CDmElement *pControl = pAnimationSet->FindControl( pControlName );
  796. if ( !pControl )
  797. continue;
  798. int j = uniqueControls.AddToTail();
  799. ExportedControl_t &control = uniqueControls[j];
  800. control.m_Name = pControlName;
  801. control.m_bIsStereo = pControl->GetValue<bool>( "combo" );
  802. control.m_bIsMulti = pControl->GetValue<bool>( "multi" );
  803. control.m_nFirstIndex = nGlobalIndex;
  804. nGlobalIndex += 1 + control.m_bIsStereo + control.m_bIsMulti;
  805. }
  806. }
  807. return nGlobalIndex;
  808. }
  809. //-----------------------------------------------------------------------------
  810. // Fileopen state machine
  811. //-----------------------------------------------------------------------------
  812. void CDmePresetGroupEditorPanel::SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues )
  813. {
  814. if ( bOpenFile )
  815. {
  816. pDialog->SetTitle( "Import Preset File", true );
  817. }
  818. else
  819. {
  820. pDialog->SetTitle( "Export Preset File", true );
  821. }
  822. char pPresetPath[MAX_PATH];
  823. if ( !Q_stricmp( pFileFormat, PRESET_FILE_FORMAT ) )
  824. {
  825. GetModSubdirectory( "models", pPresetPath, sizeof(pPresetPath) );
  826. pDialog->SetStartDirectoryContext( "preset_importexport", pPresetPath );
  827. pDialog->AddFilter( "*.*", "All Files (*.*)", false );
  828. pDialog->AddFilter( "*.pre", "Preset File (*.pre)", true, PRESET_FILE_FORMAT );
  829. }
  830. else if ( !Q_stricmp( pFileFormat, "vfe" ) )
  831. {
  832. GetModSubdirectory( "expressions", pPresetPath, sizeof(pPresetPath) );
  833. pDialog->SetStartDirectoryContext( "preset_exportvfe", pPresetPath );
  834. pDialog->AddFilter( "*.*", "All Files (*.*)", false );
  835. pDialog->AddFilter( "*.vfe", "Expression File (*.vfe)", true, "vfe" );
  836. }
  837. else if ( !Q_stricmp( pFileFormat, "txt" ) )
  838. {
  839. GetModSubdirectory( "expressions", pPresetPath, sizeof(pPresetPath) );
  840. pDialog->SetStartDirectoryContext( "preset_exportvfe", pPresetPath );
  841. pDialog->AddFilter( "*.*", "All Files (*.*)", false );
  842. pDialog->AddFilter( "*.txt", "Faceposer Expression File (*.txt)", true, "txt" );
  843. }
  844. }
  845. bool CDmePresetGroupEditorPanel::OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
  846. {
  847. CDmElement *pRoot;
  848. CDisableUndoScopeGuard sgRestore;
  849. DmFileId_t fileId = g_pDataModel->RestoreFromFile( pFileName, NULL, pFileFormat, &pRoot, CR_FORCE_COPY );
  850. sgRestore.Release();
  851. if ( fileId == DMFILEID_INVALID )
  852. return false;
  853. // When importing an entire group, we can do it all right here
  854. if ( !Q_stricmp( pContextKeyValues->GetName(), "ImportPresetGroup" ) )
  855. {
  856. CDmePresetGroup *pPresetGroup = CastElement< CDmePresetGroup >( pRoot );
  857. if ( !pPresetGroup )
  858. return false;
  859. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Import Preset Group" );
  860. pPresetGroup->SetFileId( m_hAnimationSet->GetFileId(), TD_DEEP );
  861. m_hAnimationSet->GetPresetGroups( ).AddToTail( pPresetGroup );
  862. sg.Release();
  863. // Warn if we import a remap which doesn't exist
  864. CDmePresetRemap *pPresetRemap = pPresetGroup->GetPresetRemap();
  865. if ( pPresetRemap )
  866. {
  867. if ( m_hAnimationSet->FindPresetGroup( pPresetRemap->m_SourcePresetGroup ) == NULL )
  868. {
  869. char pBuf[512];
  870. Q_snprintf( pBuf, sizeof(pBuf),
  871. "Import contains a remap which refers to an unknown preset group \"%s\"!\n",
  872. pPresetRemap->m_SourcePresetGroup.Get() );
  873. vgui::MessageBox *pError = new vgui::MessageBox( "Bad source remap name!", pBuf, this );
  874. pError->DoModal();
  875. }
  876. }
  877. RefreshAnimationSet();
  878. NotifyDataChanged();
  879. return true;
  880. }
  881. CDmAttribute* pPresets = pRoot->GetAttribute( "presets", AT_ELEMENT_ARRAY );
  882. if ( !pPresets )
  883. return false;
  884. SetElementKeyValue( pContextKeyValues, "presets", pRoot );
  885. return true;
  886. }
  887. bool CDmePresetGroupEditorPanel::OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
  888. {
  889. // Used when exporting an entire preset group
  890. if ( !Q_stricmp( pContextKeyValues->GetName(), "ExportPresetGroup" ) )
  891. {
  892. CDmePresetGroup *pPresetGroup = GetElementKeyValue<CDmePresetGroup>( pContextKeyValues, "presetGroup" );
  893. if ( !pPresetGroup )
  894. return false;
  895. bool bOk = g_pDataModel->SaveToFile( pFileName, NULL, g_pDataModel->GetDefaultEncoding( pFileFormat ), pFileFormat, pPresetGroup );
  896. return bOk;
  897. }
  898. // Used when exporting an entire preset group
  899. if ( !Q_stricmp( pContextKeyValues->GetName(), "ExportPresetGroupToVFE" ) )
  900. {
  901. CDmePresetGroup *pPresetGroup = GetElementKeyValue<CDmePresetGroup>( pContextKeyValues, "presetGroup" );
  902. if ( !pPresetGroup )
  903. return false;
  904. bool bOk = pPresetGroup->ExportToVFE( pFileName, m_hAnimationSet );
  905. return bOk;
  906. }
  907. // Used when exporting an entire preset group
  908. if ( !Q_stricmp( pContextKeyValues->GetName(), "ExportPresetGroupToTXT" ) )
  909. {
  910. CDmePresetGroup *pPresetGroup = GetElementKeyValue<CDmePresetGroup>( pContextKeyValues, "presetGroup" );
  911. if ( !pPresetGroup )
  912. return false;
  913. bool bOk = pPresetGroup->ExportToTXT( pFileName, m_hAnimationSet );
  914. return bOk;
  915. }
  916. // Used when exporting a subset of a preset group
  917. int nCount = pContextKeyValues->GetInt( "count" );
  918. if ( nCount == 0 )
  919. return true;
  920. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  921. const char *pPresetGroupName = pPresetGroup ? pPresetGroup->GetName() : "root";
  922. CDisableUndoScopeGuard sg;
  923. CDmePresetGroup *pRoot = CreateElement< CDmePresetGroup >( pPresetGroupName, DMFILEID_INVALID );
  924. CDmaElementArray< CDmePreset >& presets = pRoot->GetPresets( );
  925. // Build list of selected presets
  926. for ( int i = 0; i < nCount; ++i )
  927. {
  928. char pBuf[32];
  929. Q_snprintf( pBuf, sizeof(pBuf), "%d", i );
  930. CDmePreset *pPreset = GetElementKeyValue<CDmePreset>( pContextKeyValues, pBuf );
  931. presets.AddToTail( pPreset );
  932. }
  933. bool bOk = g_pDataModel->SaveToFile( pFileName, NULL, g_pDataModel->GetDefaultEncoding( pFileFormat ), pFileFormat, pRoot );
  934. g_pDataModel->DestroyElement( pRoot->GetHandle() );
  935. return bOk;
  936. }
  937. //-----------------------------------------------------------------------------
  938. // Called when preset picking is cancelled
  939. //-----------------------------------------------------------------------------
  940. void CDmePresetGroupEditorPanel::OnPresetPickCancelled( KeyValues *pParams )
  941. {
  942. KeyValues *pContextKeyValues = pParams->FindKey( "ImportPicked" );
  943. if ( pContextKeyValues )
  944. {
  945. // Clean up the read-in file
  946. CDisableUndoScopeGuard sg;
  947. CDmElement *pRoot = GetElementKeyValue<CDmElement>( pContextKeyValues, "presets" );
  948. g_pDataModel->RemoveFileId( pRoot->GetFileId() );
  949. return;
  950. }
  951. }
  952. //-----------------------------------------------------------------------------
  953. // Actually imports the presets from a file
  954. //-----------------------------------------------------------------------------
  955. void CDmePresetGroupEditorPanel::ImportPresets( const CUtlVector< CDmePreset * >& presets )
  956. {
  957. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  958. if ( !pPresetGroup )
  959. return;
  960. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Import Presets" );
  961. int nPresetCount = presets.Count();
  962. for ( int i = 0; i < nPresetCount; ++i )
  963. {
  964. CDmePreset *pPreset = pPresetGroup->FindOrAddPreset( presets[i]->GetName() );
  965. const CDmaElementArray< CDmElement > &srcValues = presets[i]->GetControlValues( );
  966. CDmaElementArray< CDmElement > &values = pPreset->GetControlValues( );
  967. values.RemoveAll();
  968. int nValueCount = srcValues.Count();
  969. for ( int j = 0; j < nValueCount; ++j )
  970. {
  971. CDmElement *pSrcControlValue = srcValues[j];
  972. CDmElement *pControlValue = pSrcControlValue->Copy( );
  973. pControlValue->SetFileId( pPresetGroup->GetFileId(), TD_DEEP );
  974. values.AddToTail( pControlValue );
  975. }
  976. }
  977. RefreshAnimationSet();
  978. NotifyDataChanged();
  979. }
  980. //-----------------------------------------------------------------------------
  981. // The 'export presets' context menu option
  982. //-----------------------------------------------------------------------------
  983. void CDmePresetGroupEditorPanel::OnPresetPicked( KeyValues *pParams )
  984. {
  985. CUtlVector< CDmePreset * > presets;
  986. int nCount = pParams->GetInt( "count" );
  987. if ( nCount == 0 )
  988. return;
  989. // Build list of selected presets
  990. for ( int i = 0; i < nCount; ++i )
  991. {
  992. char pBuf[32];
  993. Q_snprintf( pBuf, sizeof(pBuf), "%d", i );
  994. CDmePreset *pPreset = GetElementKeyValue<CDmePreset>( pParams, pBuf );
  995. presets.AddToTail( pPreset );
  996. }
  997. if ( pParams->FindKey( "ExportPicked" ) )
  998. {
  999. KeyValues *pContextKeyValues = new KeyValues( "ExportPresets" );
  1000. pContextKeyValues->SetInt( "count", nCount );
  1001. for ( int i = 0; i < nCount; ++i )
  1002. {
  1003. char pBuf[32];
  1004. Q_snprintf( pBuf, sizeof(pBuf), "%d", i );
  1005. SetElementKeyValue( pContextKeyValues, pBuf, presets[i] );
  1006. }
  1007. m_hFileOpenStateMachine->SaveFile( pContextKeyValues, NULL, PRESET_FILE_FORMAT, vgui::FOSM_SHOW_PERFORCE_DIALOGS );
  1008. return;
  1009. }
  1010. KeyValues *pContextKeyValues = pParams->FindKey( "ImportPicked" );
  1011. if ( pContextKeyValues )
  1012. {
  1013. ImportPresets( presets );
  1014. // Clean up the read-in file
  1015. {
  1016. CDisableUndoScopeGuard sg;
  1017. CDmElement *pRoot = GetElementKeyValue<CDmElement>( pContextKeyValues, "presets" );
  1018. g_pDataModel->RemoveFileId( pRoot->GetFileId() );
  1019. return;
  1020. }
  1021. }
  1022. }
  1023. //-----------------------------------------------------------------------------
  1024. // The 'export presets' context menu option
  1025. //-----------------------------------------------------------------------------
  1026. void CDmePresetGroupEditorPanel::OnExportPresets()
  1027. {
  1028. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1029. if ( !pPresetGroup )
  1030. return;
  1031. CPresetPickerFrame *pPresetPicker = new CPresetPickerFrame( this, "Select Preset(s) to Export" );
  1032. pPresetPicker->AddActionSignalTarget( this );
  1033. pPresetPicker->DoModal( pPresetGroup, true, new KeyValues( "ExportPicked" ) );
  1034. }
  1035. //-----------------------------------------------------------------------------
  1036. // The 'import presets' context menu option
  1037. //-----------------------------------------------------------------------------
  1038. void CDmePresetGroupEditorPanel::OnImportPresets()
  1039. {
  1040. KeyValues *pContextKeyValues = new KeyValues( "ImportPresets" );
  1041. m_hFileOpenStateMachine->OpenFile( PRESET_FILE_FORMAT, pContextKeyValues );
  1042. }
  1043. //-----------------------------------------------------------------------------
  1044. // The 'export preset groups to VFE' context menu option
  1045. //-----------------------------------------------------------------------------
  1046. void CDmePresetGroupEditorPanel::OnExportPresetGroupToVFE()
  1047. {
  1048. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1049. if ( !pPresetGroup )
  1050. return;
  1051. KeyValues *pContextKeyValues = new KeyValues( "ExportPresetGroupToVFE" );
  1052. SetElementKeyValue( pContextKeyValues, "presetGroup", pPresetGroup );
  1053. m_hFileOpenStateMachine->SaveFile( pContextKeyValues, NULL, "vfe", vgui::FOSM_SHOW_PERFORCE_DIALOGS );
  1054. }
  1055. //-----------------------------------------------------------------------------
  1056. // The 'export preset groups to TXT' context menu option
  1057. //-----------------------------------------------------------------------------
  1058. void CDmePresetGroupEditorPanel::OnExportPresetGroupToTXT()
  1059. {
  1060. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1061. if ( !pPresetGroup )
  1062. return;
  1063. KeyValues *pContextKeyValues = new KeyValues( "ExportPresetGroupToTXT" );
  1064. SetElementKeyValue( pContextKeyValues, "presetGroup", pPresetGroup );
  1065. m_hFileOpenStateMachine->SaveFile( pContextKeyValues, NULL, "txt", vgui::FOSM_SHOW_PERFORCE_DIALOGS );
  1066. }
  1067. //-----------------------------------------------------------------------------
  1068. // The 'export preset groups' context menu option
  1069. //-----------------------------------------------------------------------------
  1070. void CDmePresetGroupEditorPanel::OnExportPresetGroups()
  1071. {
  1072. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1073. if ( !pPresetGroup )
  1074. return;
  1075. KeyValues *pContextKeyValues = new KeyValues( "ExportPresetGroup" );
  1076. SetElementKeyValue( pContextKeyValues, "presetGroup", pPresetGroup );
  1077. m_hFileOpenStateMachine->SaveFile( pContextKeyValues, NULL, PRESET_FILE_FORMAT, vgui::FOSM_SHOW_PERFORCE_DIALOGS );
  1078. }
  1079. //-----------------------------------------------------------------------------
  1080. // The 'import preset groups' context menu option
  1081. //-----------------------------------------------------------------------------
  1082. void CDmePresetGroupEditorPanel::OnImportPresetGroups()
  1083. {
  1084. KeyValues *pContextKeyValues = new KeyValues( "ImportPresetGroup" );
  1085. m_hFileOpenStateMachine->OpenFile( PRESET_FILE_FORMAT, pContextKeyValues );
  1086. }
  1087. //-----------------------------------------------------------------------------
  1088. // Preset remap editor
  1089. //-----------------------------------------------------------------------------
  1090. void CDmePresetGroupEditorPanel::OnRemoveDefaultControls()
  1091. {
  1092. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1093. if ( !pPresetGroup )
  1094. return;
  1095. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Remove Default Controls" );
  1096. CDmrElementArray< CDmePreset > presets = pPresetGroup->GetPresets();
  1097. int nPresetCount = presets.Count();
  1098. for ( int i = 0; i < nPresetCount; ++i )
  1099. {
  1100. CDmePreset *pPreset = presets[i];
  1101. CDmrElementArray< CDmElement > controls = pPreset->GetControlValues();
  1102. int nControlCount = controls.Count();
  1103. for ( int j = nControlCount; --j >= 0; )
  1104. {
  1105. CDmElement *pControlValue = controls[j];
  1106. CDmElement *pControl = m_hAnimationSet->FindControl( pControlValue->GetName() );
  1107. if ( !pControl )
  1108. {
  1109. controls.Remove( j );
  1110. continue;
  1111. }
  1112. bool bIsDefault = true;
  1113. if ( pControl->GetValue<float>( "defaultValue" ) != pControlValue->GetValue<float>( "value" ) )
  1114. {
  1115. bIsDefault = false;
  1116. }
  1117. bool bIsStereo = pControl->GetValue<bool>( "combo" );
  1118. if ( bIsStereo )
  1119. {
  1120. if ( pControl->GetValue<float>( "defaultBalance" ) != pControlValue->GetValue<float>( "balance" ) )
  1121. {
  1122. bIsDefault = false;
  1123. }
  1124. }
  1125. bool bIsMulti = pControl->GetValue<bool>( "multi" );
  1126. if ( bIsMulti )
  1127. {
  1128. if ( pControl->GetValue<float>( "defaultMultilevel" ) != pControlValue->GetValue<float>( "multilevel" ) )
  1129. {
  1130. bIsDefault = false;
  1131. }
  1132. }
  1133. if ( bIsDefault )
  1134. {
  1135. controls.Remove( j );
  1136. }
  1137. }
  1138. }
  1139. }
  1140. //-----------------------------------------------------------------------------
  1141. // Preset remap editor
  1142. //-----------------------------------------------------------------------------
  1143. void CDmePresetGroupEditorPanel::OnEditPresetRemapping()
  1144. {
  1145. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1146. if ( !pPresetGroup )
  1147. return;
  1148. CDmePresetRemapPanel *pPresetRemapPanel = new CDmePresetRemapPanel( this, "Manage Preset Remapping" );
  1149. pPresetRemapPanel->DoModal( m_hAnimationSet, pPresetGroup );
  1150. }
  1151. //-----------------------------------------------------------------------------
  1152. // Perform preset remap
  1153. //-----------------------------------------------------------------------------
  1154. void CDmePresetGroupEditorPanel::OnRemapPresets()
  1155. {
  1156. CDmePresetGroup *pDestPresetGroup = GetSelectedPresetGroup();
  1157. if ( !pDestPresetGroup || pDestPresetGroup->m_bIsReadOnly )
  1158. return;
  1159. CDmePresetRemap *pPresetRemap = pDestPresetGroup->GetPresetRemap();
  1160. if ( !pPresetRemap )
  1161. return;
  1162. CDmePresetGroup *pSourcePresetGroup = m_hAnimationSet->FindPresetGroup( pPresetRemap->m_SourcePresetGroup );
  1163. if ( !pSourcePresetGroup )
  1164. {
  1165. char pBuf[512];
  1166. Q_snprintf( pBuf, sizeof(pBuf), "Unable to find preset group name %s in animation set %s!\n",
  1167. pPresetRemap->m_SourcePresetGroup.Get(), m_hAnimationSet->GetName() );
  1168. vgui::MessageBox *pError = new vgui::MessageBox( "Bad source remap name!", pBuf, this );
  1169. pError->DoModal();
  1170. return;
  1171. }
  1172. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Remap Presets" );
  1173. int nCount = pPresetRemap->GetRemapCount();
  1174. for ( int i = 0; i < nCount; ++i )
  1175. {
  1176. const char *pSourceName = pPresetRemap->GetRemapSource( i );
  1177. CDmePreset *pSourcePreset = pSourcePresetGroup->FindPreset( pSourceName );
  1178. const char *pDestName = pPresetRemap->GetRemapDest( i );
  1179. CDmePreset *pDestPreset = pDestPresetGroup->FindPreset( pDestName );
  1180. if ( !pSourcePreset || !pDestPreset )
  1181. continue;
  1182. pDestPreset->CopyControlValuesFrom( pSourcePreset );
  1183. }
  1184. sg.Release();
  1185. NotifyDataChanged();
  1186. }
  1187. //-----------------------------------------------------------------------------
  1188. // Called to open a context-sensitive menu for a particular preset
  1189. //-----------------------------------------------------------------------------
  1190. void CDmePresetGroupEditorPanel::OnOpenPresetContextMenu( )
  1191. {
  1192. if ( !m_hAnimationSet.Get() )
  1193. return;
  1194. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1195. if ( !pPresetGroup )
  1196. return;
  1197. CDmePreset *pPreset = GetSelectedPreset();
  1198. m_hContextMenu = new vgui::Menu( this, "ActionMenu" );
  1199. // Can only export from read-only groups
  1200. if ( pPresetGroup->m_bIsReadOnly )
  1201. {
  1202. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_ExportPresets", new KeyValues( "ExportPresets" ), this );
  1203. vgui::Menu::PlaceContextMenu( this, m_hContextMenu.Get() );
  1204. return;
  1205. }
  1206. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_AddPreset", new KeyValues( "AddPreset" ), this );
  1207. if ( pPreset )
  1208. {
  1209. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_RenamePreset", new KeyValues( "RenamePreset" ), this );
  1210. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_RemovePreset", new KeyValues( "RemovePreset" ), this );
  1211. m_hContextMenu->AddSeparator();
  1212. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_MoveUp", new KeyValues( "MovePresetUp" ), this );
  1213. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_MoveDown", new KeyValues( "MovePresetDown" ), this );
  1214. }
  1215. m_hContextMenu->AddSeparator();
  1216. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_ImportPresets", new KeyValues( "ImportPresets" ), this );
  1217. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_ExportPresets", new KeyValues( "ExportPresets" ), this );
  1218. vgui::Menu::PlaceContextMenu( this, m_hContextMenu.Get() );
  1219. }
  1220. //-----------------------------------------------------------------------------
  1221. // Called to open a context-sensitive menu for a particular menu item
  1222. //-----------------------------------------------------------------------------
  1223. void CDmePresetGroupEditorPanel::OnOpenContextMenu( KeyValues *kv )
  1224. {
  1225. CleanupContextMenu();
  1226. if ( !m_hAnimationSet.Get() )
  1227. return;
  1228. Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
  1229. if ( pPanel == m_pPresetList )
  1230. {
  1231. OnOpenPresetContextMenu();
  1232. return;
  1233. }
  1234. if ( pPanel != m_pPresetGroupList )
  1235. return;
  1236. m_hContextMenu = new vgui::Menu( this, "ActionMenu" );
  1237. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_AddGroup", new KeyValues( "AddGroup" ), this );
  1238. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_AddPhonemeGroup", new KeyValues( "AddPhonemeGroup" ), this );
  1239. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1240. if ( pPresetGroup )
  1241. {
  1242. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_RenameGroup", new KeyValues( "RenameGroup" ), this );
  1243. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_RemoveGroup", new KeyValues( "RemoveGroup" ), this );
  1244. m_hContextMenu->AddSeparator();
  1245. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_ToggleVisibility", new KeyValues( "ToggleGroupVisibility" ), this );
  1246. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_ToggleSharing", new KeyValues( "ToggleGroupSharing" ), this );
  1247. m_hContextMenu->AddSeparator();
  1248. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_MoveUp", new KeyValues( "MoveGroupUp" ), this );
  1249. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_MoveDown", new KeyValues( "MoveGroupDown" ), this );
  1250. CDmePresetRemap *pPresetRemap = pPresetGroup->GetPresetRemap();
  1251. bool bUseSeparator = !pPresetGroup->m_bIsReadOnly || pPresetRemap;
  1252. if ( bUseSeparator )
  1253. {
  1254. m_hContextMenu->AddSeparator();
  1255. }
  1256. if ( !pPresetGroup->m_bIsReadOnly )
  1257. {
  1258. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_RemoveDefaultControls", new KeyValues( "RemoveDefaultControls" ), this );
  1259. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_EditPresetRemapping", new KeyValues( "EditPresetRemapping" ), this );
  1260. }
  1261. if ( pPresetRemap )
  1262. {
  1263. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_RemapPresets", new KeyValues( "RemapPresets" ), this );
  1264. }
  1265. }
  1266. m_hContextMenu->AddSeparator();
  1267. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_ImportPresets", new KeyValues( "ImportPresetGroups" ), this );
  1268. if ( pPresetGroup )
  1269. {
  1270. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_ExportPresets", new KeyValues( "ExportPresetGroups" ), this );
  1271. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_ExportPresetsToFaceposer", new KeyValues( "ExportPresetGroupsToTXT" ), this );
  1272. m_hContextMenu->AddMenuItem( "#DmePresetGroupEditor_ExportPresetsToExpression", new KeyValues( "ExportPresetGroupsToVFE" ), this );
  1273. }
  1274. vgui::Menu::PlaceContextMenu( this, m_hContextMenu.Get() );
  1275. }
  1276. //-----------------------------------------------------------------------------
  1277. // Called when a list panel's selection changes
  1278. //-----------------------------------------------------------------------------
  1279. void CDmePresetGroupEditorPanel::OnItemSelected( KeyValues *kv )
  1280. {
  1281. Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
  1282. if ( pPanel == m_pPresetGroupList )
  1283. {
  1284. RefreshPresetNames();
  1285. return;
  1286. }
  1287. }
  1288. //-----------------------------------------------------------------------------
  1289. // Called when a list panel's selection changes
  1290. //-----------------------------------------------------------------------------
  1291. void CDmePresetGroupEditorPanel::OnItemDeselected( KeyValues *kv )
  1292. {
  1293. Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
  1294. if ( pPanel == m_pPresetGroupList )
  1295. {
  1296. RefreshPresetNames();
  1297. return;
  1298. }
  1299. }
  1300. //-----------------------------------------------------------------------------
  1301. // If it finds a duplicate control name, reports an error message and returns it found one
  1302. //-----------------------------------------------------------------------------
  1303. bool CDmePresetGroupEditorPanel::HasDuplicateGroupName( const char *pGroupName, CDmePresetGroup *pIgnorePreset )
  1304. {
  1305. if ( !m_hAnimationSet )
  1306. return false;
  1307. CDmePresetGroup *pMatch = m_hAnimationSet->FindPresetGroup( pGroupName );
  1308. if ( pMatch && pMatch != pIgnorePreset )
  1309. {
  1310. vgui::MessageBox *pError = new vgui::MessageBox( "#DmePresetGroupEditor_DuplicateNameTitle", "#DmePresetGroupEditor_DuplicateNameText", this );
  1311. pError->DoModal();
  1312. return true;
  1313. }
  1314. return false;
  1315. }
  1316. //-----------------------------------------------------------------------------
  1317. // Called by OnInputCompleted after we get a new group name
  1318. //-----------------------------------------------------------------------------
  1319. void CDmePresetGroupEditorPanel::PerformAddGroup( const char *pNewGroupName )
  1320. {
  1321. if ( !m_hAnimationSet )
  1322. return;
  1323. if ( HasDuplicateGroupName( pNewGroupName ) )
  1324. return;
  1325. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Add Preset Group" );
  1326. CDmePresetGroup *pPresetGroup = m_hAnimationSet->FindOrAddPresetGroup( pNewGroupName );
  1327. sg.Release();
  1328. RefreshAnimationSet();
  1329. SetSelectedPresetGroup( pPresetGroup );
  1330. NotifyDataChanged();
  1331. }
  1332. //-----------------------------------------------------------------------------
  1333. // Called by OnInputCompleted after we get a new group name
  1334. //-----------------------------------------------------------------------------
  1335. void CDmePresetGroupEditorPanel::PerformAddPhonemeGroup( const char *pNewGroupName )
  1336. {
  1337. if ( !m_hAnimationSet )
  1338. return;
  1339. if ( HasDuplicateGroupName( pNewGroupName ) )
  1340. return;
  1341. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Add Phoneme Preset Group" );
  1342. CDmePresetGroup *pPresetGroup = m_hAnimationSet->FindOrAddPresetGroup( pNewGroupName );
  1343. int nPhonemeCount = NumPhonemes();
  1344. for ( int i = 0; i < nPhonemeCount; ++i )
  1345. {
  1346. if ( !IsStandardPhoneme( i ) )
  1347. continue;
  1348. char pTempBuf[256];
  1349. const char *pPhonemeName = NameForPhonemeByIndex( i );
  1350. if ( !Q_stricmp( pPhonemeName, "<sil>" ) )
  1351. {
  1352. pPhonemeName = "silence";
  1353. }
  1354. Q_snprintf( pTempBuf, sizeof(pTempBuf), "p_%s", pPhonemeName );
  1355. pPresetGroup->FindOrAddPreset( pTempBuf );
  1356. }
  1357. sg.Release();
  1358. RefreshAnimationSet();
  1359. SetSelectedPresetGroup( pPresetGroup );
  1360. NotifyDataChanged();
  1361. }
  1362. //-----------------------------------------------------------------------------
  1363. // Called by OnInputCompleted after we get a new group name
  1364. //-----------------------------------------------------------------------------
  1365. void CDmePresetGroupEditorPanel::PerformRenameGroup( const char *pNewGroupName )
  1366. {
  1367. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1368. if ( !pPresetGroup )
  1369. return;
  1370. if ( HasDuplicateGroupName( pNewGroupName, pPresetGroup ) )
  1371. return;
  1372. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Rename Preset Group" );
  1373. pPresetGroup->SetName( pNewGroupName );
  1374. sg.Release();
  1375. RefreshAnimationSet();
  1376. NotifyDataChanged();
  1377. }
  1378. //-----------------------------------------------------------------------------
  1379. // Called by OnGroupControls after we get a new group name
  1380. //-----------------------------------------------------------------------------
  1381. void CDmePresetGroupEditorPanel::OnInputCompleted( KeyValues *pKeyValues )
  1382. {
  1383. const char *pName = pKeyValues->GetString( "text", NULL );
  1384. if ( !pName || !pName[0] )
  1385. return;
  1386. if ( pKeyValues->FindKey( "OnAddGroup" ) )
  1387. {
  1388. PerformAddGroup( pName );
  1389. return;
  1390. }
  1391. if ( pKeyValues->FindKey( "OnAddPhonemeGroup" ) )
  1392. {
  1393. PerformAddPhonemeGroup( pName );
  1394. return;
  1395. }
  1396. if ( pKeyValues->FindKey( "OnRenameGroup" ) )
  1397. {
  1398. PerformRenameGroup( pName );
  1399. return;
  1400. }
  1401. if ( pKeyValues->FindKey( "OnAddPreset" ) )
  1402. {
  1403. PerformAddPreset( pName );
  1404. return;
  1405. }
  1406. if ( pKeyValues->FindKey( "OnRenamePreset" ) )
  1407. {
  1408. PerformRenamePreset( pName );
  1409. return;
  1410. }
  1411. }
  1412. //-----------------------------------------------------------------------------
  1413. // Toggle group visibility
  1414. //-----------------------------------------------------------------------------
  1415. void CDmePresetGroupEditorPanel::ToggleGroupVisibility( CDmePresetGroup *pPresetGroup )
  1416. {
  1417. if ( pPresetGroup )
  1418. {
  1419. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Toggle Preset Group Visibility" );
  1420. pPresetGroup->m_bIsVisible = !pPresetGroup->m_bIsVisible;
  1421. }
  1422. RefreshAnimationSet();
  1423. NotifyDataChanged();
  1424. }
  1425. //-----------------------------------------------------------------------------
  1426. // Ungroup controls from each other
  1427. //-----------------------------------------------------------------------------
  1428. void CDmePresetGroupEditorPanel::OnToggleGroupVisibility( )
  1429. {
  1430. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1431. ToggleGroupVisibility( pPresetGroup );
  1432. }
  1433. //-----------------------------------------------------------------------------
  1434. // Ungroup controls from each other
  1435. //-----------------------------------------------------------------------------
  1436. void CDmePresetGroupEditorPanel::OnToggleGroupSharing( )
  1437. {
  1438. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1439. if ( pPresetGroup )
  1440. {
  1441. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Toggle Preset Group Sharing" );
  1442. pPresetGroup->SetShared( !pPresetGroup->IsShared() );
  1443. }
  1444. RefreshAnimationSet();
  1445. }
  1446. //-----------------------------------------------------------------------------
  1447. // Add a preset group
  1448. //-----------------------------------------------------------------------------
  1449. void CDmePresetGroupEditorPanel::OnAddGroup()
  1450. {
  1451. vgui::InputDialog *pInput = new vgui::InputDialog( this, "Add Preset Group", "Enter name of new preset group" );
  1452. pInput->SetMultiline( false );
  1453. pInput->DoModal( new KeyValues( "OnAddGroup" ) );
  1454. }
  1455. //-----------------------------------------------------------------------------
  1456. // Add a preset group
  1457. //-----------------------------------------------------------------------------
  1458. void CDmePresetGroupEditorPanel::OnAddPhonemeGroup()
  1459. {
  1460. vgui::InputDialog *pInput = new vgui::InputDialog( this, "Add Phoneme Preset Group", "Enter name of new preset group", "phoneme" );
  1461. pInput->SetMultiline( false );
  1462. pInput->DoModal( new KeyValues( "OnAddPhonemeGroup" ) );
  1463. }
  1464. //-----------------------------------------------------------------------------
  1465. // Rename a preset group
  1466. //-----------------------------------------------------------------------------
  1467. void CDmePresetGroupEditorPanel::OnRenameGroup()
  1468. {
  1469. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1470. if ( !pPresetGroup )
  1471. return;
  1472. vgui::InputDialog *pInput = new vgui::InputDialog( this, "Rename Preset Group", "Enter new name of preset group" );
  1473. pInput->SetMultiline( false );
  1474. pInput->DoModal( new KeyValues( "OnRenameGroup" ) );
  1475. }
  1476. //-----------------------------------------------------------------------------
  1477. // Remove a preset group
  1478. //-----------------------------------------------------------------------------
  1479. void CDmePresetGroupEditorPanel::OnRemoveGroup()
  1480. {
  1481. if ( !m_hAnimationSet.Get() )
  1482. return;
  1483. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1484. if ( !pPresetGroup )
  1485. return;
  1486. if ( !Q_stricmp( pPresetGroup->GetName(), "procedural" ) )
  1487. {
  1488. vgui::MessageBox *pError = new vgui::MessageBox( "#DmePresetGroupEditor_CannotRemovePresetGroupTitle", "#DmePresetGroupEditor_CannotRemovePresetGroupText", this );
  1489. pError->DoModal();
  1490. return;
  1491. }
  1492. int nItemID = m_pPresetGroupList->GetSelectedItem( 0 );
  1493. int nCurrentRow = m_pPresetGroupList->GetItemCurrentRow( nItemID );
  1494. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Remove Preset Group" );
  1495. m_hAnimationSet->RemovePresetGroup( pPresetGroup );
  1496. sg.Release();
  1497. RefreshAnimationSet();
  1498. if ( nCurrentRow >= m_pPresetGroupList->GetItemCount() )
  1499. {
  1500. --nCurrentRow;
  1501. }
  1502. if ( nCurrentRow >= 0 )
  1503. {
  1504. nItemID = m_pPresetGroupList->GetItemIDFromRow( nCurrentRow );
  1505. m_pPresetGroupList->ClearSelectedItems();
  1506. m_pPresetGroupList->AddSelectedItem( nItemID );
  1507. }
  1508. NotifyDataChanged();
  1509. }
  1510. //-----------------------------------------------------------------------------
  1511. // Called to open a context-sensitive menu for a particular menu item
  1512. //-----------------------------------------------------------------------------
  1513. void CDmePresetGroupEditorPanel::OnMoveGroupUp()
  1514. {
  1515. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1516. if ( !pPresetGroup || !m_hAnimationSet.Get() )
  1517. return;
  1518. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Reorder Preset Groups" );
  1519. m_hAnimationSet->MovePresetGroupUp( pPresetGroup );
  1520. sg.Release();
  1521. RefreshAnimationSet();
  1522. SetSelectedPresetGroup( pPresetGroup );
  1523. NotifyDataChanged();
  1524. }
  1525. //-----------------------------------------------------------------------------
  1526. // Called to open a context-sensitive menu for a particular menu item
  1527. //-----------------------------------------------------------------------------
  1528. void CDmePresetGroupEditorPanel::OnMoveGroupDown()
  1529. {
  1530. CDmePresetGroup *pPresetGroup = GetSelectedPresetGroup();
  1531. if ( !pPresetGroup || !m_hAnimationSet.Get() )
  1532. return;
  1533. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Reorder Preset Groups" );
  1534. m_hAnimationSet->MovePresetGroupDown( pPresetGroup );
  1535. sg.Release();
  1536. RefreshAnimationSet();
  1537. SetSelectedPresetGroup( pPresetGroup );
  1538. NotifyDataChanged();
  1539. }
  1540. //-----------------------------------------------------------------------------
  1541. // Drag/drop reordering of preset groups
  1542. //-----------------------------------------------------------------------------
  1543. void CDmePresetGroupEditorPanel::MovePresetGroupInFrontOf( CDmePresetGroup *pDragGroup, CDmePresetGroup *pDropGroup )
  1544. {
  1545. if ( !m_hAnimationSet.Get() )
  1546. return;
  1547. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Reorder Preset Groups" );
  1548. m_hAnimationSet->MovePresetGroupInFrontOf( pDragGroup, pDropGroup );
  1549. sg.Release();
  1550. RefreshAnimationSet();
  1551. SetSelectedPresetGroup( pDragGroup );
  1552. NotifyDataChanged();
  1553. }
  1554. //-----------------------------------------------------------------------------
  1555. // Drag/drop preset moving
  1556. //-----------------------------------------------------------------------------
  1557. void CDmePresetGroupEditorPanel::MovePresetIntoGroup( CDmePreset *pPreset, CDmePresetGroup *pGroup )
  1558. {
  1559. if ( !m_hAnimationSet.Get() || !pPreset || !pGroup )
  1560. return;
  1561. CPresetGroupUndoScopeGuard sg( NOTIFY_SETDIRTYFLAG, "Change Preset Group" );
  1562. m_hAnimationSet->RemovePreset( pPreset );
  1563. pGroup->GetPresets().AddToTail( pPreset );
  1564. sg.Release();
  1565. RefreshPresetNames();
  1566. NotifyDataChanged();
  1567. }
  1568. //-----------------------------------------------------------------------------
  1569. //
  1570. //
  1571. // CDmePresetGroupListPanel
  1572. //
  1573. // Declaration above because of scoping issues
  1574. //
  1575. //
  1576. //-----------------------------------------------------------------------------
  1577. //-----------------------------------------------------------------------------
  1578. // Constructor, destructor
  1579. //-----------------------------------------------------------------------------
  1580. CDmePresetGroupListPanel::CDmePresetGroupListPanel( vgui::Panel *pParent, const char *pName, CDmePresetGroupEditorPanel *pComboPanel ) :
  1581. BaseClass( pParent, pName ), m_pPresetGroupPanel( pComboPanel )
  1582. {
  1583. }
  1584. //-----------------------------------------------------------------------------
  1585. // Handle keypresses
  1586. //-----------------------------------------------------------------------------
  1587. void CDmePresetGroupListPanel::OnMouseDoublePressed( vgui::MouseCode code )
  1588. {
  1589. if ( code == MOUSE_LEFT )
  1590. {
  1591. int x, y, row, column;
  1592. vgui::input()->GetCursorPos( x, y );
  1593. GetCellAtPos( x, y, row, column );
  1594. int itemId = GetItemIDFromRow( row );
  1595. KeyValues *pKeyValues = GetItem( itemId );
  1596. CDmePresetGroup *pPresetGroup = GetElementKeyValue< CDmePresetGroup >( pKeyValues, "presetGroup" );
  1597. m_pPresetGroupPanel->ToggleGroupVisibility( pPresetGroup );
  1598. return;
  1599. }
  1600. BaseClass::OnMouseDoublePressed( code );
  1601. }
  1602. //-----------------------------------------------------------------------------
  1603. // Handle keypresses
  1604. //-----------------------------------------------------------------------------
  1605. void CDmePresetGroupListPanel::OnKeyCodeTyped( vgui::KeyCode code )
  1606. {
  1607. if ( code == KEY_DELETE || code == KEY_BACKSPACE )
  1608. {
  1609. m_pPresetGroupPanel->OnRemoveGroup();
  1610. return;
  1611. }
  1612. if ( vgui::input()->IsKeyDown( KEY_LSHIFT ) || vgui::input()->IsKeyDown( KEY_RSHIFT ) )
  1613. {
  1614. if ( code == KEY_UP )
  1615. {
  1616. m_pPresetGroupPanel->OnMoveGroupUp();
  1617. return;
  1618. }
  1619. if ( code == KEY_DOWN )
  1620. {
  1621. m_pPresetGroupPanel->OnMoveGroupDown();
  1622. return;
  1623. }
  1624. }
  1625. vgui::ListPanel::OnKeyCodeTyped( code );
  1626. }
  1627. //-----------------------------------------------------------------------------
  1628. // Called when a list panel's selection changes
  1629. //-----------------------------------------------------------------------------
  1630. void CDmePresetGroupListPanel::OnCreateDragData( KeyValues *msg )
  1631. {
  1632. CDmePresetGroup *pPresetGroup = m_pPresetGroupPanel->GetSelectedPresetGroup();
  1633. if ( !pPresetGroup )
  1634. return;
  1635. SetElementKeyValue( msg, "presetGroup", pPresetGroup );
  1636. msg->SetInt( "selfDroppable", 1 );
  1637. }
  1638. //-----------------------------------------------------------------------------
  1639. // Called when a list panel's selection changes
  1640. //-----------------------------------------------------------------------------
  1641. bool CDmePresetGroupListPanel::IsDroppable( CUtlVector< KeyValues * >& msgList )
  1642. {
  1643. if ( msgList.Count() > 0 )
  1644. {
  1645. KeyValues *pData( msgList[ 0 ] );
  1646. if ( m_pPresetGroupPanel )
  1647. {
  1648. CDmePresetGroup *pPresetGroup = GetElementKeyValue< CDmePresetGroup >( pData, "presetGroup" );
  1649. if ( pPresetGroup )
  1650. return true;
  1651. CDmePreset *pPreset = GetElementKeyValue< CDmePreset >( pData, "preset" );
  1652. if ( pPreset )
  1653. {
  1654. // Can't drop presets onto read-only preset groups
  1655. int x, y, row, column;
  1656. vgui::input()->GetCursorPos( x, y );
  1657. GetCellAtPos( x, y, row, column );
  1658. KeyValues *pKeyValues = GetItem( row );
  1659. CDmePresetGroup *pDropGroup = pKeyValues ? GetElementKeyValue<CDmePresetGroup>( pKeyValues, "presetGroup" ) : NULL;
  1660. if ( pDropGroup && !pDropGroup->m_bIsReadOnly )
  1661. return true;
  1662. }
  1663. }
  1664. }
  1665. return false;
  1666. }
  1667. //-----------------------------------------------------------------------------
  1668. // Called when a list panel's selection changes
  1669. //-----------------------------------------------------------------------------
  1670. void CDmePresetGroupListPanel::OnPanelDropped( CUtlVector< KeyValues * >& msgList )
  1671. {
  1672. if ( msgList.Count() == 0 )
  1673. return;
  1674. KeyValues *pData = msgList[ 0 ];
  1675. if ( !m_pPresetGroupPanel )
  1676. return;
  1677. // Discover the cell the panel is over
  1678. int x, y, row, column;
  1679. vgui::input()->GetCursorPos( x, y );
  1680. GetCellAtPos( x, y, row, column );
  1681. KeyValues *pKeyValues = GetItem( row );
  1682. CDmePresetGroup *pDragGroup = GetElementKeyValue<CDmePresetGroup>( pData, "presetGroup" );
  1683. if ( pDragGroup )
  1684. {
  1685. CDmePresetGroup *pDropGroup = pKeyValues ? GetElementKeyValue<CDmePresetGroup>( pKeyValues, "presetGroup" ) : NULL;
  1686. m_pPresetGroupPanel->MovePresetGroupInFrontOf( pDragGroup, pDropGroup );
  1687. return;
  1688. }
  1689. CDmePreset *pDragPreset = GetElementKeyValue<CDmePreset>( pData, "preset" );
  1690. if ( pDragPreset )
  1691. {
  1692. CDmePresetGroup *pDropGroup = pKeyValues ? GetElementKeyValue<CDmePresetGroup>( pKeyValues, "presetGroup" ) : NULL;
  1693. if ( pDropGroup )
  1694. {
  1695. m_pPresetGroupPanel->MovePresetIntoGroup( pDragPreset, pDropGroup );
  1696. }
  1697. return;
  1698. }
  1699. }
  1700. //-----------------------------------------------------------------------------
  1701. // Mouse is now over a droppable panel
  1702. //-----------------------------------------------------------------------------
  1703. void CDmePresetGroupListPanel::OnDroppablePanelPaint( CUtlVector< KeyValues * >& msglist, CUtlVector< Panel * >& dragPanels )
  1704. {
  1705. // Discover the cell the panel is over
  1706. int x, y, w, h, row, column;
  1707. vgui::input()->GetCursorPos( x, y );
  1708. GetCellAtPos( x, y, row, column );
  1709. GetCellBounds( row, 0, x, y, w, h );
  1710. int x2, y2, w2, h2;
  1711. GetCellBounds( row, 3, x2, y2, w2, h2 );
  1712. w = x2 + w2 - x;
  1713. LocalToScreen( x, y );
  1714. surface()->DrawSetColor( GetDropFrameColor() );
  1715. // Draw insertion point
  1716. surface()->DrawFilledRect( x, y, x + w, y + 2 );
  1717. surface()->DrawFilledRect( x, y + h - 2, x + w, y + h );
  1718. surface()->DrawFilledRect( x, y, x + 2, y + h );
  1719. surface()->DrawFilledRect( x + w - 2, y, x + w, y + h );
  1720. }
  1721. //-----------------------------------------------------------------------------
  1722. //
  1723. //
  1724. // CDmePresetListPanel
  1725. //
  1726. // Declaration above because of scoping issues
  1727. //
  1728. //
  1729. //-----------------------------------------------------------------------------
  1730. //-----------------------------------------------------------------------------
  1731. // Constructor, destructor
  1732. //-----------------------------------------------------------------------------
  1733. CDmePresetListPanel::CDmePresetListPanel( vgui::Panel *pParent, const char *pName, CDmePresetGroupEditorPanel *pComboPanel ) :
  1734. BaseClass( pParent, pName ), m_pPresetGroupPanel( pComboPanel )
  1735. {
  1736. }
  1737. void CDmePresetListPanel::OnKeyCodeTyped( vgui::KeyCode code )
  1738. {
  1739. CDmePresetGroup *pPresetGroup = m_pPresetGroupPanel->GetSelectedPresetGroup();
  1740. if ( pPresetGroup && !pPresetGroup->m_bIsReadOnly )
  1741. {
  1742. if ( code == KEY_DELETE || code == KEY_BACKSPACE )
  1743. {
  1744. m_pPresetGroupPanel->OnRemovePreset();
  1745. return;
  1746. }
  1747. // Not sure how to handle 'edit' mode... the relevant stuff is private
  1748. if ( vgui::input()->IsKeyDown( KEY_LSHIFT ) || vgui::input()->IsKeyDown( KEY_RSHIFT ) )
  1749. {
  1750. if ( code == KEY_UP )
  1751. {
  1752. m_pPresetGroupPanel->OnMovePresetUp();
  1753. return;
  1754. }
  1755. if ( code == KEY_DOWN )
  1756. {
  1757. m_pPresetGroupPanel->OnMovePresetDown();
  1758. return;
  1759. }
  1760. }
  1761. }
  1762. vgui::ListPanel::OnKeyCodeTyped( code );
  1763. }
  1764. //-----------------------------------------------------------------------------
  1765. // Called when a list panel's selection changes
  1766. //-----------------------------------------------------------------------------
  1767. void CDmePresetListPanel::OnCreateDragData( KeyValues *msg )
  1768. {
  1769. CDmePresetGroup *pPresetGroup = m_pPresetGroupPanel->GetSelectedPresetGroup();
  1770. if ( pPresetGroup->m_bIsReadOnly )
  1771. return;
  1772. CDmePreset *pPreset = m_pPresetGroupPanel->GetSelectedPreset();
  1773. if ( !pPreset )
  1774. return;
  1775. SetElementKeyValue( msg, "preset", pPreset );
  1776. msg->SetInt( "selfDroppable", 1 );
  1777. }
  1778. //-----------------------------------------------------------------------------
  1779. // Called when a list panel's selection changes
  1780. //-----------------------------------------------------------------------------
  1781. bool CDmePresetListPanel::IsDroppable( CUtlVector< KeyValues * >& msgList )
  1782. {
  1783. if ( msgList.Count() > 0 )
  1784. {
  1785. KeyValues *pData( msgList[ 0 ] );
  1786. if ( pData->GetPtr( "panel", NULL ) == this && m_pPresetGroupPanel )
  1787. {
  1788. CDmePreset *pPreset = GetElementKeyValue< CDmePreset >( pData, "preset" );
  1789. if ( pPreset )
  1790. return true;
  1791. }
  1792. }
  1793. return false;
  1794. }
  1795. //-----------------------------------------------------------------------------
  1796. // Called when a list panel's selection changes
  1797. //-----------------------------------------------------------------------------
  1798. void CDmePresetListPanel::OnPanelDropped( CUtlVector< KeyValues * >& msgList )
  1799. {
  1800. if ( msgList.Count() == 0 )
  1801. return;
  1802. KeyValues *pData = msgList[ 0 ];
  1803. if ( pData->GetPtr( "panel", NULL ) != this || !m_pPresetGroupPanel )
  1804. return;
  1805. // Discover the cell the panel is over
  1806. int x, y, row, column;
  1807. vgui::input()->GetCursorPos( x, y );
  1808. GetCellAtPos( x, y, row, column );
  1809. KeyValues *pKeyValues = GetItem( row );
  1810. CDmePreset *pDragPreset = GetElementKeyValue<CDmePreset>( pData, "preset" );
  1811. if ( pDragPreset )
  1812. {
  1813. CDmePreset *pDropPreset = pKeyValues ? GetElementKeyValue<CDmePreset>( pKeyValues, "preset" ) : NULL;
  1814. m_pPresetGroupPanel->MovePresetInFrontOf( pDragPreset, pDropPreset );
  1815. return;
  1816. }
  1817. }
  1818. //-----------------------------------------------------------------------------
  1819. // Mouse is now over a droppable panel
  1820. //-----------------------------------------------------------------------------
  1821. void CDmePresetListPanel::OnDroppablePanelPaint( CUtlVector< KeyValues * >& msglist, CUtlVector< Panel * >& dragPanels )
  1822. {
  1823. // Discover the cell the panel is over
  1824. int x, y, w, h, row, column;
  1825. vgui::input()->GetCursorPos( x, y );
  1826. GetCellAtPos( x, y, row, column );
  1827. GetCellBounds( row, column, x, y, w, h );
  1828. LocalToScreen( x, y );
  1829. surface()->DrawSetColor( GetDropFrameColor() );
  1830. // Draw insertion point
  1831. surface()->DrawFilledRect( x, y, x + w, y + 2 );
  1832. surface()->DrawFilledRect( x, y + h - 2, x + w, y + h );
  1833. surface()->DrawFilledRect( x, y, x + 2, y + h );
  1834. surface()->DrawFilledRect( x + w - 2, y, x + w, y + h );
  1835. }
  1836. //-----------------------------------------------------------------------------
  1837. //
  1838. // Purpose: Combination system editor frame
  1839. //
  1840. //-----------------------------------------------------------------------------
  1841. CDmePresetGroupEditorFrame::CDmePresetGroupEditorFrame( vgui::Panel *pParent, const char *pTitle ) :
  1842. BaseClass( pParent, "DmePresetGroupEditorFrame" )
  1843. {
  1844. SetDeleteSelfOnClose( true );
  1845. m_pEditor = new CDmePresetGroupEditorPanel( this, "DmePresetGroupEditorPanel" );
  1846. m_pEditor->AddActionSignalTarget( this );
  1847. m_pOkButton = new vgui::Button( this, "OkButton", "#VGui_OK", this, "Ok" );
  1848. SetBlockDragChaining( true );
  1849. LoadControlSettingsAndUserConfig( "resource/dmepresetgroupeditorframe.res" );
  1850. SetTitle( pTitle, false );
  1851. g_pDataModel->InstallNotificationCallback( this );
  1852. }
  1853. CDmePresetGroupEditorFrame::~CDmePresetGroupEditorFrame()
  1854. {
  1855. g_pDataModel->RemoveNotificationCallback( this );
  1856. }
  1857. //-----------------------------------------------------------------------------
  1858. // Sets the current scene + animation list
  1859. //-----------------------------------------------------------------------------
  1860. void CDmePresetGroupEditorFrame::SetAnimationSet( CDmeAnimationSet *pComboSystem )
  1861. {
  1862. m_pEditor->SetAnimationSet( pComboSystem );
  1863. }
  1864. //-----------------------------------------------------------------------------
  1865. // On command
  1866. //-----------------------------------------------------------------------------
  1867. void CDmePresetGroupEditorFrame::OnCommand( const char *pCommand )
  1868. {
  1869. if ( !Q_stricmp( pCommand, "Ok" ) )
  1870. {
  1871. CloseModal();
  1872. return;
  1873. }
  1874. BaseClass::OnCommand( pCommand );
  1875. }
  1876. //-----------------------------------------------------------------------------
  1877. // Inherited from IDmNotify
  1878. //-----------------------------------------------------------------------------
  1879. void CDmePresetGroupEditorFrame::NotifyDataChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
  1880. {
  1881. if ( !IsVisible() )
  1882. return;
  1883. if ( nNotifySource == NOTIFY_SOURCE_PRESET_GROUP_EDITOR )
  1884. return;
  1885. m_pEditor->RefreshAnimationSet();
  1886. }
  1887. //-----------------------------------------------------------------------------
  1888. // Chains notification messages from the contained panel to external clients
  1889. //-----------------------------------------------------------------------------
  1890. void CDmePresetGroupEditorFrame::OnPresetsChanged()
  1891. {
  1892. PostActionSignal( new KeyValues( "PresetsChanged" ) );
  1893. }
  1894. void CDmePresetGroupEditorFrame::OnAddNewPreset( KeyValues *pKeyValues )
  1895. {
  1896. PostActionSignal( pKeyValues->MakeCopy() );
  1897. }
  1898. //-----------------------------------------------------------------------------
  1899. // Various command handlers related to the Edit menu
  1900. //-----------------------------------------------------------------------------
  1901. void CDmePresetGroupEditorFrame::OnUndo()
  1902. {
  1903. if ( g_pDataModel->CanUndo() )
  1904. {
  1905. CDisableUndoScopeGuard guard;
  1906. g_pDataModel->Undo();
  1907. }
  1908. }
  1909. void CDmePresetGroupEditorFrame::OnRedo()
  1910. {
  1911. if ( g_pDataModel->CanRedo() )
  1912. {
  1913. CDisableUndoScopeGuard guard;
  1914. g_pDataModel->Redo();
  1915. }
  1916. }