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.

1336 lines
37 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Act busy tool; main UI smarts class
  4. //
  5. //=============================================================================
  6. #include "toolutils/basetoolsystem.h"
  7. #include "toolutils/toolmenubar.h"
  8. #include "toolutils/toolswitchmenubutton.h"
  9. #include "toolutils/toolfilemenubutton.h"
  10. #include "toolutils/tooleditmenubutton.h"
  11. #include "toolutils/toolmenubutton.h"
  12. #include "vgui_controls/Menu.h"
  13. #include "tier1/KeyValues.h"
  14. #include "toolutils/enginetools_int.h"
  15. #include "toolframework/ienginetool.h"
  16. #include "vgui/IInput.h"
  17. #include "vgui/KeyCode.h"
  18. #include "vgui_controls/FileOpenDialog.h"
  19. #include "filesystem.h"
  20. #include "vmtdoc.h"
  21. #include "vgui/ilocalize.h"
  22. #include "dme_controls/elementpropertiestree.h"
  23. #include "matsys_controls/vmtpanel.h"
  24. #include "vmttool.h"
  25. #include "movieobjects/dmeeditortypedictionary.h"
  26. #include "dme_controls/attributestringchoicepanel.h"
  27. #include "matsys_controls/mdlsequencepicker.h"
  28. #include "istudiorender.h"
  29. #include "materialsystem/imaterialsystem.h"
  30. #include "VGuiMatSurface/IMatSystemSurface.h"
  31. #include "toolutils/toolwindowfactory.h"
  32. #include "toolutils/basepropertiescontainer.h"
  33. #include "toolutils/savewindowpositions.h"
  34. #include "tier3/tier3.h"
  35. #include "tier2/fileutils.h"
  36. #include "vgui/ivgui.h"
  37. using namespace vgui;
  38. //-----------------------------------------------------------------------------
  39. // Singleton interfaces
  40. //-----------------------------------------------------------------------------
  41. CDmeEditorTypeDictionary *g_pEditorTypeDict;
  42. //-----------------------------------------------------------------------------
  43. // Methods needed by scenedatabase. They have to live here instead of toolutils
  44. // because this is a DLL but toolutils is only a static library
  45. //-----------------------------------------------------------------------------
  46. char const *GetVGuiControlsModuleName()
  47. {
  48. return "VMTTool";
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Connect, disconnect
  52. //-----------------------------------------------------------------------------
  53. bool ConnectTools( CreateInterfaceFn factory )
  54. {
  55. return (g_pMDLCache != NULL) && (studiorender != NULL) && (materials != NULL) && (g_pMatSystemSurface != NULL);
  56. }
  57. void DisconnectTools( )
  58. {
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Implementation of the act busy tool
  62. //-----------------------------------------------------------------------------
  63. class CVMTTool : public CBaseToolSystem, public IFileMenuCallbacks, public IVMTDocCallback
  64. {
  65. DECLARE_CLASS_SIMPLE( CVMTTool, CBaseToolSystem );
  66. public:
  67. CVMTTool();
  68. // Inherited from IToolSystem
  69. virtual char const *GetToolName() { return "Material Editor"; }
  70. virtual const char *GetBindingsContextFile() { return "cfg/VMTTool.kb"; }
  71. virtual bool Init();
  72. virtual void Shutdown();
  73. virtual bool CanQuit( );
  74. virtual void PostMessage( HTOOLHANDLE hEntity, KeyValues *message );
  75. // Inherited from IFileMenuCallbacks
  76. virtual int GetFileMenuItemsEnabled( );
  77. virtual void AddRecentFilesToMenu( vgui::Menu *menu );
  78. virtual bool GetPerforceFileName( char *pFileName, int nMaxLen );
  79. virtual vgui::Panel* GetRootPanel() { return this; }
  80. // Inherited from IVMTDocCallback
  81. virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
  82. virtual void AddShaderParameter( const char *pParam, const char *pWidget, const char *pTextType );
  83. virtual void RemoveShaderParameter( const char *pParam );
  84. virtual void AddFlagParameter( const char *pParam );
  85. virtual void AddToolParameter( const char *pParam, const char *pWidget, const char *pTextType );
  86. virtual void RemoveAllFlagParameters();
  87. virtual void RemoveAllToolParameters();
  88. // Inherited from CBaseToolSystem
  89. virtual vgui::HScheme GetToolScheme();
  90. virtual vgui::Menu *CreateActionMenu( vgui::Panel *pParent );
  91. virtual void OnCommand( const char *cmd );
  92. virtual const char *GetRegistryName() { return "VMT"; }
  93. virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
  94. virtual void OnToolActivate();
  95. virtual void OnToolDeactivate();
  96. virtual CVMTDoc *GetDocument();
  97. virtual CBasePropertiesContainer *GetProperties();
  98. virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues );
  99. virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  100. virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  101. virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues );
  102. public:
  103. // Commands related to the file menu
  104. MESSAGE_FUNC( OnNew, "OnNew" );
  105. MESSAGE_FUNC( OnOpen, "OnOpen" );
  106. MESSAGE_FUNC( OnSave, "OnSave" );
  107. MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
  108. MESSAGE_FUNC( OnClose, "OnClose" );
  109. MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
  110. MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
  111. MESSAGE_FUNC( OnExit, "OnExit" );
  112. void PerformNew();
  113. void OpenFileFromHistory( int slot, const char *pCommand );
  114. void OpenSpecificFile( const char *pFileName );
  115. // Commands related to the edit menu
  116. KEYBINDING_FUNC( undo, KEY_Z, vgui::MODIFIER_CONTROL, OnUndo, "#undo_help", 0 );
  117. KEYBINDING_FUNC( redo, KEY_Z, vgui::MODIFIER_CONTROL | vgui::MODIFIER_SHIFT, OnRedo, "#redo_help", 0 );
  118. void OnDescribeUndo();
  119. // Methods related to the view menu
  120. MESSAGE_FUNC( OnToggleProperties, "OnToggleProperties" );
  121. MESSAGE_FUNC( OnToggleVMTPreview, "OnToggleVMTPreview" );
  122. MESSAGE_FUNC( OnShowFlags, "OnShowFlags" );
  123. MESSAGE_FUNC( OnShowToolParams, "OnShowToolParams" );
  124. MESSAGE_FUNC( OnDefaultLayout, "OnDefaultLayout" );
  125. // Methods related to the material menu
  126. MESSAGE_FUNC( OnSetParamsToDefault, "OnSetParamsToDefault" );
  127. // Returns the VMT preview window
  128. CVMTPanel *GetVMTPreview();
  129. // Which parameters are visible?
  130. bool IsFlagParamsVisible() const;
  131. bool IsToolParamsVisible() const;
  132. private:
  133. // Flags for HideStandardFields
  134. enum EditorTypeStandardFields_t
  135. {
  136. EDITOR_FIELD_NAME = 0x1,
  137. EDITOR_FIELD_TYPE = 0x2,
  138. EDITOR_FIELD_ID = 0x4,
  139. EDITOR_FIELD_EDITORTYPE = 0x8,
  140. };
  141. void HideStandardFields( CDmeEditorType *pEditorType, int nFieldFlags );
  142. // Creates a new document
  143. void NewDocument( );
  144. // Loads up a new document
  145. bool LoadDocument( char const *pDocName );
  146. // Updates the menu bar based on the current file
  147. void UpdateMenuBar( );
  148. // Shows element properties
  149. void ShowElementProperties( );
  150. // Create custom editors
  151. void InitEditorDict();
  152. void CreateTools( CVMTDoc *doc );
  153. void InitTools();
  154. void DestroyTools();
  155. void ToggleToolWindow( Panel *tool, char const *toolName );
  156. void ShowToolWindow( Panel *tool, char const *toolName, bool visible );
  157. void DestroyToolContainers();
  158. virtual char const *GetLogoTextureName();
  159. private:
  160. // All editable data
  161. CVMTDoc *m_pDoc;
  162. // The menu bar
  163. CToolFileMenuBar *m_pMenuBar;
  164. // Element properties for editing material
  165. vgui::DHANDLE< CBasePropertiesContainer > m_hProperties;
  166. // The sequence picker!
  167. vgui::DHANDLE< CVMTPanel > m_hVMTPreview;
  168. // The VMT editor type
  169. CDmeEditorType *m_pVMTType;
  170. // Separate undo context for the act busy tool
  171. CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
  172. // List of tool + flag parameters
  173. CUtlVector<CUtlString> m_ToolParams;
  174. CUtlVector<CUtlString> m_FlagParams;
  175. bool m_bToolParamsVisible;
  176. bool m_bFlagParamsVisible;
  177. CUtlVector< DmElementHandle_t > m_toolElements;
  178. };
  179. //-----------------------------------------------------------------------------
  180. // Singleton
  181. //-----------------------------------------------------------------------------
  182. CVMTTool *g_pVMTTool = NULL;
  183. void CreateTools()
  184. {
  185. g_pVMTTool = new CVMTTool();
  186. }
  187. //-----------------------------------------------------------------------------
  188. // Constructor
  189. //-----------------------------------------------------------------------------
  190. CVMTTool::CVMTTool()
  191. {
  192. m_pVMTType = NULL;
  193. m_pMenuBar = NULL;
  194. m_pDoc = NULL;
  195. }
  196. //-----------------------------------------------------------------------------
  197. // Init, shutdown
  198. //-----------------------------------------------------------------------------
  199. bool CVMTTool::Init()
  200. {
  201. m_bToolParamsVisible = false;
  202. m_bFlagParamsVisible = true;
  203. m_pDoc = NULL;
  204. m_RecentFiles.LoadFromRegistry( GetRegistryName() );
  205. // NOTE: This has to happen before BaseClass::Init
  206. g_pVGuiLocalize->AddFile( "resource/toolvmt_%language%.txt" );
  207. if ( !BaseClass::Init() )
  208. return false;
  209. InitEditorDict();
  210. return true;
  211. }
  212. void CVMTTool::Shutdown()
  213. {
  214. m_RecentFiles.SaveToRegistry( GetRegistryName() );
  215. {
  216. CDisableUndoScopeGuard sg;
  217. int nElements = m_toolElements.Count();
  218. for ( int i = 0; i < nElements; ++i )
  219. {
  220. g_pDataModel->DestroyElement( m_toolElements[ i ] );
  221. }
  222. }
  223. BaseClass::Shutdown();
  224. }
  225. //-----------------------------------------------------------------------------
  226. // Tool activation/deactivation
  227. //-----------------------------------------------------------------------------
  228. void CVMTTool::OnToolActivate()
  229. {
  230. BaseClass::OnToolActivate();
  231. }
  232. void CVMTTool::OnToolDeactivate()
  233. {
  234. BaseClass::OnToolDeactivate();
  235. }
  236. //-----------------------------------------------------------------------------
  237. // Hides standard fields
  238. //-----------------------------------------------------------------------------
  239. void CVMTTool::HideStandardFields( CDmeEditorType *pEditorType, int nFieldFlags )
  240. {
  241. CDmeEditorAttributeInfo *pInfo;
  242. if ( nFieldFlags & EDITOR_FIELD_NAME )
  243. {
  244. pInfo = CreateElement< CDmeEditorAttributeInfo >( "name info", pEditorType->GetFileId() );
  245. pEditorType->AddAttributeInfo( "name", pInfo );
  246. pInfo->m_bIsVisible = false;
  247. m_toolElements.AddToTail( pInfo->GetHandle() );
  248. }
  249. if ( nFieldFlags & EDITOR_FIELD_TYPE )
  250. {
  251. pInfo = CreateElement< CDmeEditorAttributeInfo >( "type info", pEditorType->GetFileId() );
  252. pInfo->m_bIsVisible = false;
  253. pEditorType->AddAttributeInfo( "type", pInfo );
  254. m_toolElements.AddToTail( pInfo->GetHandle() );
  255. }
  256. if ( nFieldFlags & EDITOR_FIELD_ID )
  257. {
  258. pInfo = CreateElement< CDmeEditorAttributeInfo >( "id info", pEditorType->GetFileId() );
  259. pInfo->m_bIsVisible = false;
  260. pEditorType->AddAttributeInfo( "id", pInfo );
  261. m_toolElements.AddToTail( pInfo->GetHandle() );
  262. }
  263. if ( nFieldFlags & EDITOR_FIELD_EDITORTYPE )
  264. {
  265. pInfo = CreateElement< CDmeEditorAttributeInfo >( "editor type info", pEditorType->GetFileId() );
  266. pInfo->m_bIsVisible = false;
  267. pEditorType->AddAttributeInfo( "editorType", pInfo );
  268. m_toolElements.AddToTail( pInfo->GetHandle() );
  269. }
  270. }
  271. //-----------------------------------------------------------------------------
  272. // Update the editor dict based on the current material parameters
  273. //-----------------------------------------------------------------------------
  274. void CVMTTool::AddShaderParameter( const char *pParam, const char *pWidget, const char *pTextType )
  275. {
  276. // anims only accept activity names
  277. CDmeEditorAttributeInfo *pInfo = CreateElement< CDmeEditorAttributeInfo >( "shader param info", m_pVMTType->GetFileId() );
  278. m_pVMTType->AddAttributeInfo( pParam, pInfo );
  279. pInfo->m_Widget = pWidget;
  280. if ( pTextType )
  281. {
  282. pInfo->SetValue( "texttype", pTextType );
  283. }
  284. m_toolElements.AddToTail( pInfo->GetHandle() );
  285. }
  286. //-----------------------------------------------------------------------------
  287. // Update the editor dict based on the current material parameters
  288. //-----------------------------------------------------------------------------
  289. void CVMTTool::RemoveShaderParameter( const char *pParam )
  290. {
  291. m_pVMTType->RemoveAttributeInfo( pParam );
  292. }
  293. //-----------------------------------------------------------------------------
  294. // Which parameters are visible?
  295. //-----------------------------------------------------------------------------
  296. inline bool CVMTTool::IsFlagParamsVisible() const
  297. {
  298. return m_bFlagParamsVisible;
  299. }
  300. inline bool CVMTTool::IsToolParamsVisible() const
  301. {
  302. return m_bToolParamsVisible;
  303. }
  304. //-----------------------------------------------------------------------------
  305. // Adds flags, tool parameters
  306. //-----------------------------------------------------------------------------
  307. void CVMTTool::AddFlagParameter( const char *pParam )
  308. {
  309. Assert( m_pVMTType->GetAttributeInfo( pParam ) == NULL );
  310. int i = m_FlagParams.AddToTail( );
  311. m_FlagParams[i] = pParam;
  312. CDmeEditorAttributeInfo *pInfo = CreateElement< CDmeEditorAttributeInfo >( "flag param info", m_pVMTType->GetFileId() );
  313. m_pVMTType->AddAttributeInfo( pParam, pInfo );
  314. pInfo->m_bIsVisible = m_bFlagParamsVisible;
  315. pInfo->m_Widget = NULL;
  316. m_toolElements.AddToTail( pInfo->GetHandle() );
  317. }
  318. void CVMTTool::AddToolParameter( const char *pParam, const char *pWidget, const char *pTextType )
  319. {
  320. Assert( m_pVMTType->GetAttributeInfo( pParam ) == NULL );
  321. int i = m_ToolParams.AddToTail( );
  322. m_ToolParams[i] = pParam;
  323. CDmeEditorAttributeInfo *pInfo = CreateElement< CDmeEditorAttributeInfo >( "tool param info", m_pVMTType->GetFileId() );
  324. m_pVMTType->AddAttributeInfo( pParam, pInfo );
  325. pInfo->m_bIsVisible = m_bToolParamsVisible;
  326. pInfo->m_Widget = pWidget;
  327. if ( pTextType )
  328. {
  329. pInfo->SetValue( "texttype", pTextType );
  330. }
  331. m_toolElements.AddToTail( pInfo->GetHandle() );
  332. }
  333. void CVMTTool::RemoveAllFlagParameters()
  334. {
  335. int nCount = m_FlagParams.Count();
  336. for ( int i = 0; i < nCount; ++i )
  337. {
  338. RemoveShaderParameter( m_FlagParams[i] );
  339. }
  340. m_FlagParams.RemoveAll();
  341. }
  342. void CVMTTool::RemoveAllToolParameters()
  343. {
  344. int nCount = m_ToolParams.Count();
  345. for ( int i = 0; i < nCount; ++i )
  346. {
  347. RemoveShaderParameter( m_ToolParams[i] );
  348. }
  349. m_ToolParams.RemoveAll();
  350. }
  351. //-----------------------------------------------------------------------------
  352. // Create custom editors
  353. //-----------------------------------------------------------------------------
  354. void CVMTTool::InitEditorDict()
  355. {
  356. CDmeEditorAttributeInfo *pInfo;
  357. // FIXME: This eventually will move to an .fgd-like file.
  358. g_pEditorTypeDict = CreateElement< CDmeEditorTypeDictionary >( "DmeEditorTypeDictionary", DMFILEID_INVALID );
  359. m_toolElements.AddToTail( g_pEditorTypeDict->GetHandle() );
  360. m_pVMTType = CreateElement< CDmeEditorType >( "vmt", DMFILEID_INVALID );
  361. HideStandardFields( m_pVMTType, EDITOR_FIELD_NAME | EDITOR_FIELD_TYPE | EDITOR_FIELD_ID | EDITOR_FIELD_EDITORTYPE );
  362. g_pEditorTypeDict->AddEditorType( m_pVMTType );
  363. m_toolElements.AddToTail( m_pVMTType->GetHandle() );
  364. // Create a picker for the shader name
  365. pInfo = CreateElement< CDmeEditorAttributeInfo >( "shader name info", DMFILEID_INVALID );
  366. m_pVMTType->AddAttributeInfo( "shader", pInfo );
  367. pInfo->m_Widget = "shaderpicker";
  368. pInfo->SetValue( "texttype", "shaderName" );
  369. m_toolElements.AddToTail( pInfo->GetHandle() );
  370. }
  371. //-----------------------------------------------------------------------------
  372. //
  373. // The Material menu
  374. //
  375. //-----------------------------------------------------------------------------
  376. class CVMTMaterialMenuButton : public CToolMenuButton
  377. {
  378. DECLARE_CLASS_SIMPLE( CVMTMaterialMenuButton, CToolMenuButton );
  379. public:
  380. CVMTMaterialMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget );
  381. virtual void OnShowMenu(vgui::Menu *menu);
  382. };
  383. CVMTMaterialMenuButton::CVMTMaterialMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget )
  384. : BaseClass( parent, panelName, text, pActionSignalTarget )
  385. {
  386. AddMenuItem( "default", "#VMTSetToDefault", new KeyValues( "OnSetParamsToDefault" ), pActionSignalTarget );
  387. SetMenu(m_pMenu);
  388. }
  389. void CVMTMaterialMenuButton::OnShowMenu(vgui::Menu *menu)
  390. {
  391. BaseClass::OnShowMenu( menu );
  392. // Update the menu
  393. int id;
  394. CVMTDoc *pDoc = g_pVMTTool->GetDocument();
  395. if ( pDoc )
  396. {
  397. id = m_Items.Find( "default" );
  398. m_pMenu->SetItemEnabled( id, true );
  399. }
  400. else
  401. {
  402. id = m_Items.Find( "default" );
  403. m_pMenu->SetItemEnabled( id, false );
  404. }
  405. }
  406. //-----------------------------------------------------------------------------
  407. //
  408. // The View menu
  409. //
  410. //-----------------------------------------------------------------------------
  411. class CVMTViewMenuButton : public CToolMenuButton
  412. {
  413. DECLARE_CLASS_SIMPLE( CVMTViewMenuButton, CToolMenuButton );
  414. public:
  415. CVMTViewMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget );
  416. virtual void OnShowMenu(vgui::Menu *menu);
  417. };
  418. CVMTViewMenuButton::CVMTViewMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget )
  419. : BaseClass( parent, panelName, text, pActionSignalTarget )
  420. {
  421. AddCheckableMenuItem( "properties", "#VMTProperties", new KeyValues( "OnToggleProperties" ), pActionSignalTarget );
  422. AddCheckableMenuItem( "preview", "#VMTPreview", new KeyValues( "OnToggleVMTPreview" ), pActionSignalTarget );
  423. AddSeparator();
  424. AddCheckableMenuItem( "showflagparams", "#VMTShowFlags", new KeyValues( "OnShowFlags" ), pActionSignalTarget );
  425. AddCheckableMenuItem( "showtoolparams", "#VMTShowToolParams", new KeyValues( "OnShowToolParams" ), pActionSignalTarget );
  426. AddSeparator();
  427. AddMenuItem( "defaultlayout", "#VMTViewDefault", new KeyValues( "OnDefaultLayout" ), pActionSignalTarget );
  428. SetMenu(m_pMenu);
  429. }
  430. void CVMTViewMenuButton::OnShowMenu(vgui::Menu *menu)
  431. {
  432. BaseClass::OnShowMenu( menu );
  433. // Update the menu
  434. int id;
  435. CVMTDoc *pDoc = g_pVMTTool->GetDocument();
  436. if ( pDoc )
  437. {
  438. id = m_Items.Find( "properties" );
  439. m_pMenu->SetItemEnabled( id, true );
  440. Panel *p;
  441. p = g_pVMTTool->GetProperties();
  442. Assert( p );
  443. m_pMenu->SetMenuItemChecked( id, ( p && p->GetParent() ) ? true : false );
  444. id = m_Items.Find( "preview" );
  445. m_pMenu->SetItemEnabled( id, true );
  446. p = g_pVMTTool->GetVMTPreview();
  447. Assert( p );
  448. m_pMenu->SetMenuItemChecked( id, ( p && p->GetParent() ) ? true : false );
  449. id = m_Items.Find( "showflagparams" );
  450. m_pMenu->SetItemEnabled( id, true );
  451. m_pMenu->SetMenuItemChecked( id, g_pVMTTool->IsFlagParamsVisible() );
  452. id = m_Items.Find( "showtoolparams" );
  453. m_pMenu->SetItemEnabled( id, true );
  454. m_pMenu->SetMenuItemChecked( id, g_pVMTTool->IsToolParamsVisible() );
  455. }
  456. else
  457. {
  458. id = m_Items.Find( "properties" );
  459. m_pMenu->SetItemEnabled( id, false );
  460. id = m_Items.Find( "preview" );
  461. m_pMenu->SetItemEnabled( id, false );
  462. id = m_Items.Find( "showflagparams" );
  463. m_pMenu->SetItemEnabled( id, false );
  464. id = m_Items.Find( "showtoolparams" );
  465. m_pMenu->SetItemEnabled( id, false );
  466. }
  467. }
  468. //-----------------------------------------------------------------------------
  469. // Initializes the menu bar
  470. //-----------------------------------------------------------------------------
  471. vgui::MenuBar *CVMTTool::CreateMenuBar( CBaseToolSystem *pParent )
  472. {
  473. m_pMenuBar = new CToolFileMenuBar( pParent, "VMTMenuBar" );
  474. // Sets info in the menu bar
  475. char title[ 64 ];
  476. ComputeMenuBarTitle( title, sizeof( title ) );
  477. m_pMenuBar->SetInfo( title );
  478. m_pMenuBar->SetToolName( GetToolName() );
  479. UpdateMenuBar();
  480. // Add menu buttons
  481. CToolMenuButton *pFileButton = CreateToolFileMenuButton( m_pMenuBar, "File", "&File", GetActionTarget(), this );
  482. CToolMenuButton *pEditButton = CreateToolEditMenuButton( m_pMenuBar, "Edit", "&Edit", GetActionTarget() );
  483. CToolMenuButton *pMaterialButton = new CVMTMaterialMenuButton( m_pMenuBar, "Material", "&Material", GetActionTarget() );
  484. CToolMenuButton *pSwitchButton = CreateToolSwitchMenuButton( m_pMenuBar, "Switcher", "&Tools", GetActionTarget() );
  485. CVMTViewMenuButton *pViewButton = new CVMTViewMenuButton( m_pMenuBar, "View", "&View", GetActionTarget() );
  486. m_pMenuBar->AddButton( pFileButton );
  487. m_pMenuBar->AddButton( pEditButton );
  488. m_pMenuBar->AddButton( pMaterialButton );
  489. m_pMenuBar->AddButton( pViewButton );
  490. m_pMenuBar->AddButton( pSwitchButton );
  491. return m_pMenuBar;
  492. }
  493. //-----------------------------------------------------------------------------
  494. // Updates the menu bar based on the current file
  495. //-----------------------------------------------------------------------------
  496. void CVMTTool::UpdateMenuBar( )
  497. {
  498. if ( !m_pDoc )
  499. {
  500. m_pMenuBar->SetFileName( "#VMTNoFile" );
  501. return;
  502. }
  503. if ( m_pDoc->IsDirty() )
  504. {
  505. char sz[ 512 ];
  506. Q_snprintf( sz, sizeof( sz ), "* %s", m_pDoc->GetFileName() );
  507. m_pMenuBar->SetFileName( sz );
  508. }
  509. else
  510. {
  511. m_pMenuBar->SetFileName( m_pDoc->GetFileName() );
  512. }
  513. }
  514. //-----------------------------------------------------------------------------
  515. // Inherited from IFileMenuCallbacks
  516. //-----------------------------------------------------------------------------
  517. int CVMTTool::GetFileMenuItemsEnabled( )
  518. {
  519. int nFlags;
  520. if ( !m_pDoc )
  521. {
  522. nFlags = FILE_NEW | FILE_OPEN | FILE_RECENT | FILE_CLEAR_RECENT | FILE_EXIT;
  523. }
  524. else
  525. {
  526. nFlags = FILE_ALL;
  527. }
  528. if ( m_RecentFiles.IsEmpty() )
  529. {
  530. nFlags &= ~(FILE_RECENT | FILE_CLEAR_RECENT);
  531. }
  532. return nFlags;
  533. }
  534. void CVMTTool::AddRecentFilesToMenu( vgui::Menu *pMenu )
  535. {
  536. m_RecentFiles.AddToMenu( pMenu, GetActionTarget(), "OnRecent" );
  537. }
  538. //-----------------------------------------------------------------------------
  539. // Returns the file name for perforce
  540. //-----------------------------------------------------------------------------
  541. bool CVMTTool::GetPerforceFileName( char *pFileName, int nMaxLen )
  542. {
  543. if ( !m_pDoc )
  544. return false;
  545. Q_strncpy( pFileName, m_pDoc->GetFileName(), nMaxLen );
  546. return true;
  547. }
  548. //-----------------------------------------------------------------------------
  549. // Derived classes can implement this to get a new scheme to be applied to this tool
  550. //-----------------------------------------------------------------------------
  551. vgui::HScheme CVMTTool::GetToolScheme()
  552. {
  553. return vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "BoxRocket" );
  554. }
  555. //-----------------------------------------------------------------------------
  556. // Creates the action menu
  557. //-----------------------------------------------------------------------------
  558. vgui::Menu *CVMTTool::CreateActionMenu( vgui::Panel *pParent )
  559. {
  560. vgui::Menu *pActionMenu = new Menu( pParent, "ActionMenu" );
  561. pActionMenu->AddMenuItem( "#ToolHide", new KeyValues( "Command", "command", "HideActionMenu" ), GetActionTarget() );
  562. return pActionMenu;
  563. }
  564. //-----------------------------------------------------------------------------
  565. // Purpose:
  566. // Input : -
  567. //-----------------------------------------------------------------------------
  568. void CVMTTool::OnExit()
  569. {
  570. // Throw up a "save" dialog?
  571. enginetools->Command( "quit\n" );
  572. }
  573. //-----------------------------------------------------------------------------
  574. // Handle commands from the action menu and other menus
  575. //-----------------------------------------------------------------------------
  576. void CVMTTool::OnCommand( const char *cmd )
  577. {
  578. if ( !V_stricmp( cmd, "HideActionMenu" ) )
  579. {
  580. if ( GetActionMenu() )
  581. {
  582. GetActionMenu()->SetVisible( false );
  583. }
  584. }
  585. else if ( !V_stricmp( cmd, "OnUndo" ) )
  586. {
  587. OnUndo();
  588. }
  589. else if ( !V_stricmp( cmd, "OnRedo" ) )
  590. {
  591. OnRedo();
  592. }
  593. else if ( !V_stricmp( cmd, "OnDescribeUndo" ) )
  594. {
  595. OnDescribeUndo();
  596. }
  597. else if ( const char *pSuffix = StringAfterPrefix( cmd, "OnRecent" ) )
  598. {
  599. int idx = Q_atoi( pSuffix );
  600. g_pVMTTool->OpenFileFromHistory( idx, cmd );
  601. }
  602. else if ( const char *pSuffix = StringAfterPrefix( cmd, "OnTool" ) )
  603. {
  604. int idx = Q_atoi( pSuffix );
  605. enginetools->SwitchToTool( idx );
  606. }
  607. else
  608. {
  609. BaseClass::OnCommand( cmd );
  610. }
  611. }
  612. //-----------------------------------------------------------------------------
  613. // Messages from the engine
  614. //-----------------------------------------------------------------------------
  615. void CVMTTool::PostMessage( HTOOLHANDLE hEntity, KeyValues *message )
  616. {
  617. if ( !Q_stricmp( message->GetName(), "EditMaterial" ) )
  618. {
  619. const char *pMaterialName = message->GetString( "material", "debug/debugempty" );
  620. char pLocalPath[ MAX_PATH ];
  621. char pAbsPath[ MAX_PATH ];
  622. if ( pMaterialName[0] == '/' && pMaterialName[1] == '/' && pMaterialName[2] != '/' )
  623. {
  624. Q_strncpy( pAbsPath, pMaterialName, sizeof(pAbsPath) );
  625. Q_DefaultExtension( pAbsPath, ".vmt", sizeof(pAbsPath) );
  626. }
  627. else
  628. {
  629. Q_snprintf( pLocalPath, sizeof(pLocalPath), "materials/%s", pMaterialName );
  630. Q_DefaultExtension( pLocalPath, ".vmt", sizeof(pLocalPath) );
  631. g_pFileSystem->RelativePathToFullPath( pLocalPath, "GAME", pAbsPath, sizeof(pAbsPath) );
  632. }
  633. Q_FixSlashes( pAbsPath );
  634. OpenSpecificFile( pAbsPath );
  635. }
  636. }
  637. //-----------------------------------------------------------------------------
  638. // Derived classes can implement this to get notified when files are saved/loaded
  639. //-----------------------------------------------------------------------------
  640. void CVMTTool::OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues )
  641. {
  642. if ( bWroteFile )
  643. {
  644. OnMarkNotDirty();
  645. }
  646. if ( !pContextKeyValues )
  647. return;
  648. if ( state != FileOpenStateMachine::SUCCESSFUL )
  649. return;
  650. if ( !Q_stricmp( pContextKeyValues->GetName(), "OnNew" ) )
  651. {
  652. PerformNew();
  653. return;
  654. }
  655. if ( !Q_stricmp( pContextKeyValues->GetName(), "OnClose" ) )
  656. {
  657. OnCloseNoSave();
  658. return;
  659. }
  660. if ( !Q_stricmp( pContextKeyValues->GetName(), "OnQuit" ) )
  661. {
  662. OnCloseNoSave();
  663. vgui::ivgui()->PostMessage( GetVPanel(), new KeyValues( "OnExit" ), 0 );
  664. return;
  665. }
  666. }
  667. //-----------------------------------------------------------------------------
  668. // Called by SaveFile to allow clients to set up the save dialog
  669. //-----------------------------------------------------------------------------
  670. void CVMTTool::SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues )
  671. {
  672. // Compute starting directory
  673. char pStartingDir[ MAX_PATH ];
  674. GetModSubdirectory( "materials", pStartingDir, sizeof(pStartingDir) );
  675. if ( bOpenFile )
  676. {
  677. pDialog->SetTitle( "Open Material .VMT File", true );
  678. }
  679. else
  680. {
  681. pDialog->SetTitle( "Save Material .VMT File As", true );
  682. }
  683. pDialog->SetStartDirectoryContext( "vmt_session", pStartingDir );
  684. pDialog->AddFilter( "*.vmt", "VMT (*.vmt)", true );
  685. }
  686. //-----------------------------------------------------------------------------
  687. // Called by SaveFile to allow clients to actually write the file out
  688. //-----------------------------------------------------------------------------
  689. bool CVMTTool::OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
  690. {
  691. OnCloseNoSave();
  692. if ( !LoadDocument( pFileName ) )
  693. return false;
  694. m_RecentFiles.Add( pFileName, pFileFormat );
  695. m_RecentFiles.SaveToRegistry( GetRegistryName() );
  696. UpdateMenuBar();
  697. return true;
  698. }
  699. //-----------------------------------------------------------------------------
  700. // Called by SaveFile to allow clients to actually write the file out
  701. //-----------------------------------------------------------------------------
  702. bool CVMTTool::OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
  703. {
  704. if ( !m_pDoc )
  705. return true;
  706. m_pDoc->SetFileName( pFileName );
  707. if ( !m_pDoc->SaveToFile( ) )
  708. return false;
  709. m_RecentFiles.Add( pFileName, pFileFormat );
  710. m_RecentFiles.SaveToRegistry( GetRegistryName() );
  711. UpdateMenuBar();
  712. return true;
  713. }
  714. //-----------------------------------------------------------------------------
  715. // Command handlers
  716. //-----------------------------------------------------------------------------
  717. void CVMTTool::PerformNew()
  718. {
  719. OnCloseNoSave();
  720. NewDocument();
  721. }
  722. void CVMTTool::OnNew()
  723. {
  724. if ( m_pDoc && m_pDoc->IsDirty() )
  725. {
  726. SaveFile( m_pDoc->GetFileName(), "vmt", FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY,
  727. new KeyValues( "OnNew" ) );
  728. return;
  729. }
  730. PerformNew();
  731. }
  732. void CVMTTool::OnOpen( )
  733. {
  734. int nFlags = 0;
  735. const char *pSaveFileName = NULL;
  736. if ( m_pDoc && m_pDoc->IsDirty() )
  737. {
  738. nFlags = FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY;
  739. pSaveFileName = m_pDoc->GetFileName();
  740. }
  741. OpenFile( "vmt", pSaveFileName, "vmt", nFlags );
  742. }
  743. void CVMTTool::OnSave()
  744. {
  745. if ( m_pDoc )
  746. {
  747. SaveFile( m_pDoc->GetFileName(), "vmt", FOSM_SHOW_PERFORCE_DIALOGS );
  748. }
  749. }
  750. void CVMTTool::OnSaveAs()
  751. {
  752. if ( m_pDoc )
  753. {
  754. SaveFile( NULL, "vmt", FOSM_SHOW_PERFORCE_DIALOGS );
  755. }
  756. }
  757. void CVMTTool::OnClose()
  758. {
  759. if ( m_pDoc && m_pDoc->IsDirty() )
  760. {
  761. SaveFile( m_pDoc->GetFileName(), "vmt", FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY,
  762. new KeyValues( "OnClose" ) );
  763. return;
  764. }
  765. OnCloseNoSave();
  766. }
  767. void CVMTTool::OnCloseNoSave()
  768. {
  769. DestroyTools();
  770. if ( m_pDoc )
  771. {
  772. CAppNotifyScopeGuard sg( "CVMTTool::OnCloseNoSave", NOTIFY_CHANGE_OTHER );
  773. delete m_pDoc;
  774. m_pDoc = NULL;
  775. if ( m_hProperties )
  776. {
  777. m_hProperties->SetObject( NULL );
  778. }
  779. }
  780. UpdateMenuBar( );
  781. }
  782. void CVMTTool::OnMarkNotDirty()
  783. {
  784. if ( m_pDoc )
  785. {
  786. m_pDoc->SetDirty( false );
  787. }
  788. }
  789. //-----------------------------------------------------------------------------
  790. // Open a specific file
  791. //-----------------------------------------------------------------------------
  792. void CVMTTool::OpenSpecificFile( const char *pFileName )
  793. {
  794. int nFlags = 0;
  795. const char *pSaveFileName = NULL;
  796. if ( m_pDoc )
  797. {
  798. // File is already open
  799. if ( !Q_stricmp( m_pDoc->GetFileName(), pFileName ) )
  800. return;
  801. if ( m_pDoc->IsDirty() )
  802. {
  803. nFlags = FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY;
  804. pSaveFileName = m_pDoc->GetFileName();
  805. }
  806. }
  807. OpenFile( pFileName, "vmt", pSaveFileName, "vmt", nFlags );
  808. }
  809. //-----------------------------------------------------------------------------
  810. // Show the save document query dialog
  811. //-----------------------------------------------------------------------------
  812. void CVMTTool::OpenFileFromHistory( int slot, const char *pCommand )
  813. {
  814. const char *pFileName = m_RecentFiles.GetFile( slot );
  815. if ( !pFileName )
  816. return;
  817. OpenSpecificFile( pFileName );
  818. }
  819. bool CVMTTool::CanQuit()
  820. {
  821. if ( m_pDoc && m_pDoc->IsDirty() )
  822. {
  823. // Show Save changes Yes/No/Cancel and re-quit if hit yes/no
  824. SaveFile( m_pDoc->GetFileName(), "vmt", FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY,
  825. new KeyValues( "OnQuit" ) );
  826. return false;
  827. }
  828. return true;
  829. }
  830. //-----------------------------------------------------------------------------
  831. // Various command handlers related to the Edit menu
  832. //-----------------------------------------------------------------------------
  833. void CVMTTool::OnUndo()
  834. {
  835. CDisableUndoScopeGuard guard;
  836. g_pDataModel->Undo();
  837. }
  838. void CVMTTool::OnRedo()
  839. {
  840. CDisableUndoScopeGuard guard;
  841. g_pDataModel->Redo();
  842. }
  843. void CVMTTool::OnDescribeUndo()
  844. {
  845. CUtlVector< UndoInfo_t > list;
  846. g_pDataModel->GetUndoInfo( list );
  847. Msg( "%i operations in stack\n", list.Count() );
  848. for ( int i = list.Count() - 1; i >= 0; --i )
  849. {
  850. UndoInfo_t& entry = list[ i ];
  851. if ( entry.terminator )
  852. {
  853. Msg( "[ '%s' ] - %i operations\n", entry.undo, entry.numoperations );
  854. }
  855. Msg( " +%s\n", entry.desc );
  856. }
  857. }
  858. //-----------------------------------------------------------------------------
  859. // Inherited from IVMTDocCallback
  860. //-----------------------------------------------------------------------------
  861. void CVMTTool::OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
  862. {
  863. UpdateMenuBar();
  864. if ( ( nNotifySource != NOTIFY_SOURCE_PROPERTIES_TREE ) && m_hProperties.Get() )
  865. {
  866. m_hProperties->Refresh();
  867. }
  868. }
  869. //-----------------------------------------------------------------------------
  870. // Purpose:
  871. // Input : -
  872. // Output : CVMTDoc
  873. //-----------------------------------------------------------------------------
  874. CVMTDoc *CVMTTool::GetDocument()
  875. {
  876. return m_pDoc;
  877. }
  878. //-----------------------------------------------------------------------------
  879. // Purpose:
  880. // Input : -
  881. // Output : virtual CBasePropertiesContainer
  882. //-----------------------------------------------------------------------------
  883. CBasePropertiesContainer *CVMTTool::GetProperties()
  884. {
  885. return m_hProperties.Get();
  886. }
  887. CVMTPanel *CVMTTool::GetVMTPreview()
  888. {
  889. return m_hVMTPreview.Get();
  890. }
  891. //-----------------------------------------------------------------------------
  892. // Initializes the tools
  893. //-----------------------------------------------------------------------------
  894. void CVMTTool::InitTools()
  895. {
  896. ShowElementProperties();
  897. // FIXME: There are no tool windows here; how should this work?
  898. // These panels are saved
  899. windowposmgr->RegisterPanel( "properties", m_hProperties, false );
  900. windowposmgr->RegisterPanel( "vmtpanel", m_hVMTPreview, false );
  901. if ( !windowposmgr->LoadPositions( "cfg/vmt.txt", this, &m_ToolWindowFactory, "VMT" ) )
  902. {
  903. OnDefaultLayout();
  904. }
  905. }
  906. //-----------------------------------------------------------------------------
  907. // Loads up a new document
  908. //-----------------------------------------------------------------------------
  909. bool CVMTTool::LoadDocument( char const *pDocName )
  910. {
  911. Assert( !m_pDoc );
  912. DestroyTools();
  913. m_pDoc = new CVMTDoc( this );
  914. if ( !m_pDoc->LoadFromFile( pDocName ) )
  915. {
  916. delete m_pDoc;
  917. m_pDoc = NULL;
  918. Warning( "Fatal error loading '%s'\n", pDocName );
  919. return false;
  920. }
  921. CreateTools( m_pDoc );
  922. InitTools();
  923. return true;
  924. }
  925. //-----------------------------------------------------------------------------
  926. // Loads up a new document
  927. //-----------------------------------------------------------------------------
  928. void CVMTTool::NewDocument( )
  929. {
  930. Assert( !m_pDoc );
  931. m_pDoc = new CVMTDoc( this );
  932. m_pDoc->CreateNew( );
  933. CreateTools( m_pDoc );
  934. UpdateMenuBar( );
  935. InitTools();
  936. }
  937. //-----------------------------------------------------------------------------
  938. // Shows element properties
  939. //-----------------------------------------------------------------------------
  940. void CVMTTool::ShowElementProperties( )
  941. {
  942. if ( !m_pDoc )
  943. return;
  944. if ( !m_pDoc->GetRootObject() )
  945. return;
  946. // It should already exist
  947. Assert( m_hProperties.Get() );
  948. if ( m_hProperties.Get() )
  949. {
  950. m_hProperties->SetObject( m_pDoc->GetRootObject() );
  951. }
  952. }
  953. void CVMTTool::DestroyTools()
  954. {
  955. windowposmgr->SavePositions( "cfg/vmt.txt", "VMT" );
  956. int c = ToolWindow::GetToolWindowCount();
  957. for ( int i = c - 1; i >= 0 ; --i )
  958. {
  959. ToolWindow *kill = ToolWindow::GetToolWindow( i );
  960. delete kill;
  961. }
  962. UnregisterAllToolWindows();
  963. if ( m_hProperties.Get() )
  964. {
  965. windowposmgr->UnregisterPanel( m_hProperties.Get() );
  966. delete m_hProperties.Get();
  967. m_hProperties = NULL;
  968. }
  969. if ( m_hVMTPreview.Get() )
  970. {
  971. windowposmgr->UnregisterPanel( m_hVMTPreview.Get() );
  972. delete m_hVMTPreview.Get();
  973. m_hVMTPreview = NULL;
  974. }
  975. }
  976. void CVMTTool::CreateTools( CVMTDoc *doc )
  977. {
  978. if ( !m_hProperties.Get() )
  979. {
  980. m_hProperties = new CBasePropertiesContainer( NULL, m_pDoc, g_pEditorTypeDict );
  981. }
  982. if ( !m_hVMTPreview.Get() )
  983. {
  984. m_hVMTPreview = new CVMTPanel( NULL, "VMT Preview" );
  985. SETUP_PANEL( m_hVMTPreview.Get() );
  986. m_hVMTPreview->SetMaterial( m_pDoc->GetPreviewMaterial() );
  987. }
  988. RegisterToolWindow( m_hProperties );
  989. RegisterToolWindow( m_hVMTPreview );
  990. }
  991. void CVMTTool::ShowToolWindow( Panel *tool, char const *toolName, bool visible )
  992. {
  993. Assert( tool );
  994. if ( tool->GetParent() == NULL && visible )
  995. {
  996. m_ToolWindowFactory.InstanceToolWindow( this, false, tool, toolName, false );
  997. }
  998. else if ( !visible )
  999. {
  1000. ToolWindow *tw = dynamic_cast< ToolWindow * >( tool->GetParent()->GetParent() );
  1001. Assert( tw );
  1002. tw->RemovePage( tool );
  1003. }
  1004. }
  1005. void CVMTTool::ToggleToolWindow( Panel *tool, char const *toolName )
  1006. {
  1007. Assert( tool );
  1008. if ( tool->GetParent() == NULL )
  1009. {
  1010. ShowToolWindow( tool, toolName, true );
  1011. }
  1012. else
  1013. {
  1014. ShowToolWindow( tool, toolName, false );
  1015. }
  1016. }
  1017. void CVMTTool::DestroyToolContainers()
  1018. {
  1019. int c = ToolWindow::GetToolWindowCount();
  1020. for ( int i = c - 1; i >= 0 ; --i )
  1021. {
  1022. ToolWindow *kill = ToolWindow::GetToolWindow( i );
  1023. delete kill;
  1024. }
  1025. }
  1026. void CVMTTool::OnDefaultLayout()
  1027. {
  1028. int y = m_pMenuBar->GetTall();
  1029. int usew, useh;
  1030. GetSize( usew, useh );
  1031. DestroyToolContainers();
  1032. Assert( ToolWindow::GetToolWindowCount() == 0 );
  1033. CBasePropertiesContainer *properties = GetProperties();
  1034. CVMTPanel *pVMTPreview = GetVMTPreview();
  1035. // Need three containers
  1036. ToolWindow *pPropertyWindow = m_ToolWindowFactory.InstanceToolWindow( GetClientArea(), false, properties, "#VMTProperties", false );
  1037. ToolWindow *pVMTPreviewWindow = m_ToolWindowFactory.InstanceToolWindow( GetClientArea(), false, pVMTPreview, "#VMTPreview", false );
  1038. int halfScreen = usew / 2;
  1039. int bottom = useh - y;
  1040. int sy = (bottom - y) / 2;
  1041. SetMiniViewportBounds( halfScreen, y, halfScreen, sy - y );
  1042. pPropertyWindow->SetBounds( 0, y, halfScreen, bottom );
  1043. pVMTPreviewWindow->SetBounds( halfScreen, sy, halfScreen, bottom - sy );
  1044. }
  1045. void CVMTTool::OnToggleProperties()
  1046. {
  1047. if ( m_hProperties.Get() )
  1048. {
  1049. ToggleToolWindow( m_hProperties.Get(), "#VMTProperties" );
  1050. }
  1051. }
  1052. void CVMTTool::OnToggleVMTPreview()
  1053. {
  1054. if ( m_hVMTPreview.Get() )
  1055. {
  1056. ToggleToolWindow( m_hVMTPreview.Get(), "#VMTPreview" );
  1057. }
  1058. }
  1059. //-----------------------------------------------------------------------------
  1060. // Show/hide tool params + flags
  1061. //-----------------------------------------------------------------------------
  1062. void CVMTTool::OnShowFlags()
  1063. {
  1064. m_bFlagParamsVisible = !m_bFlagParamsVisible;
  1065. int nCount = m_FlagParams.Count();
  1066. for ( int i = 0; i < nCount; ++i )
  1067. {
  1068. CDmeEditorAttributeInfo *pInfo = m_pVMTType->GetAttributeInfo( m_FlagParams[i] );
  1069. Assert( pInfo );
  1070. pInfo->m_bIsVisible = m_bFlagParamsVisible;
  1071. }
  1072. if ( m_hProperties.Get() )
  1073. {
  1074. m_hProperties->Refresh();
  1075. }
  1076. }
  1077. void CVMTTool::OnShowToolParams()
  1078. {
  1079. m_bToolParamsVisible = !m_bToolParamsVisible;
  1080. int nCount = m_ToolParams.Count();
  1081. for ( int i = 0; i < nCount; ++i )
  1082. {
  1083. CDmeEditorAttributeInfo *pInfo = m_pVMTType->GetAttributeInfo( m_ToolParams[i] );
  1084. Assert( pInfo );
  1085. pInfo->m_bIsVisible = m_bToolParamsVisible;
  1086. }
  1087. if ( m_hProperties.Get() )
  1088. {
  1089. m_hProperties->Refresh();
  1090. }
  1091. }
  1092. //-----------------------------------------------------------------------------
  1093. // Sets shader parameters to the default for that shader
  1094. //-----------------------------------------------------------------------------
  1095. void CVMTTool::OnSetParamsToDefault()
  1096. {
  1097. if ( m_pDoc )
  1098. {
  1099. m_pDoc->SetParamsToDefault();
  1100. }
  1101. }
  1102. char const *CVMTTool::GetLogoTextureName()
  1103. {
  1104. return "vgui/tools/vmt/vmt_logo";
  1105. }