Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1348 lines
38 KiB

  1. //====== Copyright � 1996-2005, 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( const char *pExitMsg );
  74. virtual void PostToolMessage( 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. bool UTIL_IsDedicatedServer( void )
  227. {
  228. return false;
  229. }
  230. //-----------------------------------------------------------------------------
  231. // Tool activation/deactivation
  232. //-----------------------------------------------------------------------------
  233. void CVMTTool::OnToolActivate()
  234. {
  235. BaseClass::OnToolActivate();
  236. }
  237. void CVMTTool::OnToolDeactivate()
  238. {
  239. BaseClass::OnToolDeactivate();
  240. }
  241. //-----------------------------------------------------------------------------
  242. // Hides standard fields
  243. //-----------------------------------------------------------------------------
  244. void CVMTTool::HideStandardFields( CDmeEditorType *pEditorType, int nFieldFlags )
  245. {
  246. CDmeEditorAttributeInfo *pInfo;
  247. if ( nFieldFlags & EDITOR_FIELD_NAME )
  248. {
  249. pInfo = CreateElement< CDmeEditorAttributeInfo >( "name info", pEditorType->GetFileId() );
  250. pEditorType->AddAttributeInfo( "name", pInfo );
  251. pInfo->m_bIsVisible = false;
  252. m_toolElements.AddToTail( pInfo->GetHandle() );
  253. }
  254. if ( nFieldFlags & EDITOR_FIELD_TYPE )
  255. {
  256. pInfo = CreateElement< CDmeEditorAttributeInfo >( "type info", pEditorType->GetFileId() );
  257. pInfo->m_bIsVisible = false;
  258. pEditorType->AddAttributeInfo( "type", pInfo );
  259. m_toolElements.AddToTail( pInfo->GetHandle() );
  260. }
  261. if ( nFieldFlags & EDITOR_FIELD_ID )
  262. {
  263. pInfo = CreateElement< CDmeEditorAttributeInfo >( "id info", pEditorType->GetFileId() );
  264. pInfo->m_bIsVisible = false;
  265. pEditorType->AddAttributeInfo( "id", pInfo );
  266. m_toolElements.AddToTail( pInfo->GetHandle() );
  267. }
  268. if ( nFieldFlags & EDITOR_FIELD_EDITORTYPE )
  269. {
  270. pInfo = CreateElement< CDmeEditorAttributeInfo >( "editor type info", pEditorType->GetFileId() );
  271. pInfo->m_bIsVisible = false;
  272. pEditorType->AddAttributeInfo( "editorType", pInfo );
  273. m_toolElements.AddToTail( pInfo->GetHandle() );
  274. }
  275. }
  276. //-----------------------------------------------------------------------------
  277. // Update the editor dict based on the current material parameters
  278. //-----------------------------------------------------------------------------
  279. void CVMTTool::AddShaderParameter( const char *pParam, const char *pWidget, const char *pTextType )
  280. {
  281. // anims only accept activity names
  282. CDmeEditorAttributeInfo *pInfo = CreateElement< CDmeEditorAttributeInfo >( "shader param info", m_pVMTType->GetFileId() );
  283. m_pVMTType->AddAttributeInfo( pParam, pInfo );
  284. pInfo->m_Widget = pWidget;
  285. if ( pTextType )
  286. {
  287. pInfo->SetValue( "texttype", pTextType );
  288. }
  289. m_toolElements.AddToTail( pInfo->GetHandle() );
  290. }
  291. //-----------------------------------------------------------------------------
  292. // Update the editor dict based on the current material parameters
  293. //-----------------------------------------------------------------------------
  294. void CVMTTool::RemoveShaderParameter( const char *pParam )
  295. {
  296. m_pVMTType->RemoveAttributeInfo( pParam );
  297. }
  298. //-----------------------------------------------------------------------------
  299. // Which parameters are visible?
  300. //-----------------------------------------------------------------------------
  301. inline bool CVMTTool::IsFlagParamsVisible() const
  302. {
  303. return m_bFlagParamsVisible;
  304. }
  305. inline bool CVMTTool::IsToolParamsVisible() const
  306. {
  307. return m_bToolParamsVisible;
  308. }
  309. //-----------------------------------------------------------------------------
  310. // Adds flags, tool parameters
  311. //-----------------------------------------------------------------------------
  312. void CVMTTool::AddFlagParameter( const char *pParam )
  313. {
  314. Assert( m_pVMTType->GetAttributeInfo( pParam ) == NULL );
  315. int i = m_FlagParams.AddToTail( );
  316. m_FlagParams[i] = pParam;
  317. CDmeEditorAttributeInfo *pInfo = CreateElement< CDmeEditorAttributeInfo >( "flag param info", m_pVMTType->GetFileId() );
  318. m_pVMTType->AddAttributeInfo( pParam, pInfo );
  319. pInfo->m_bIsVisible = m_bFlagParamsVisible;
  320. pInfo->m_Widget = NULL;
  321. m_toolElements.AddToTail( pInfo->GetHandle() );
  322. }
  323. void CVMTTool::AddToolParameter( const char *pParam, const char *pWidget, const char *pTextType )
  324. {
  325. Assert( m_pVMTType->GetAttributeInfo( pParam ) == NULL );
  326. int i = m_ToolParams.AddToTail( );
  327. m_ToolParams[i] = pParam;
  328. CDmeEditorAttributeInfo *pInfo = CreateElement< CDmeEditorAttributeInfo >( "tool param info", m_pVMTType->GetFileId() );
  329. m_pVMTType->AddAttributeInfo( pParam, pInfo );
  330. pInfo->m_bIsVisible = m_bToolParamsVisible;
  331. pInfo->m_Widget = pWidget;
  332. if ( pTextType )
  333. {
  334. pInfo->SetValue( "texttype", pTextType );
  335. }
  336. m_toolElements.AddToTail( pInfo->GetHandle() );
  337. }
  338. void CVMTTool::RemoveAllFlagParameters()
  339. {
  340. int nCount = m_FlagParams.Count();
  341. for ( int i = 0; i < nCount; ++i )
  342. {
  343. RemoveShaderParameter( m_FlagParams[i] );
  344. }
  345. m_FlagParams.RemoveAll();
  346. }
  347. void CVMTTool::RemoveAllToolParameters()
  348. {
  349. int nCount = m_ToolParams.Count();
  350. for ( int i = 0; i < nCount; ++i )
  351. {
  352. RemoveShaderParameter( m_ToolParams[i] );
  353. }
  354. m_ToolParams.RemoveAll();
  355. }
  356. //-----------------------------------------------------------------------------
  357. // Create custom editors
  358. //-----------------------------------------------------------------------------
  359. void CVMTTool::InitEditorDict()
  360. {
  361. CDmeEditorAttributeInfo *pInfo;
  362. // FIXME: This eventually will move to an .fgd-like file.
  363. g_pEditorTypeDict = CreateElement< CDmeEditorTypeDictionary >( "DmeEditorTypeDictionary", DMFILEID_INVALID );
  364. m_toolElements.AddToTail( g_pEditorTypeDict->GetHandle() );
  365. m_pVMTType = CreateElement< CDmeEditorType >( "vmt", DMFILEID_INVALID );
  366. HideStandardFields( m_pVMTType, EDITOR_FIELD_NAME | EDITOR_FIELD_TYPE | EDITOR_FIELD_ID | EDITOR_FIELD_EDITORTYPE );
  367. g_pEditorTypeDict->AddEditorType( m_pVMTType );
  368. m_toolElements.AddToTail( m_pVMTType->GetHandle() );
  369. // Create a picker for the shader name
  370. pInfo = CreateElement< CDmeEditorAttributeInfo >( "shader name info", DMFILEID_INVALID );
  371. m_pVMTType->AddAttributeInfo( "shader", pInfo );
  372. pInfo->m_Widget = "shaderpicker";
  373. pInfo->SetValue( "texttype", "shaderName" );
  374. m_toolElements.AddToTail( pInfo->GetHandle() );
  375. }
  376. //-----------------------------------------------------------------------------
  377. //
  378. // The Material menu
  379. //
  380. //-----------------------------------------------------------------------------
  381. class CVMTMaterialMenuButton : public CToolMenuButton
  382. {
  383. DECLARE_CLASS_SIMPLE( CVMTMaterialMenuButton, CToolMenuButton );
  384. public:
  385. CVMTMaterialMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget );
  386. virtual void OnShowMenu(vgui::Menu *menu);
  387. };
  388. CVMTMaterialMenuButton::CVMTMaterialMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget )
  389. : BaseClass( parent, panelName, text, pActionSignalTarget )
  390. {
  391. AddMenuItem( "default", "#VMTSetToDefault", new KeyValues( "OnSetParamsToDefault" ), pActionSignalTarget );
  392. SetMenu(m_pMenu);
  393. }
  394. void CVMTMaterialMenuButton::OnShowMenu(vgui::Menu *menu)
  395. {
  396. BaseClass::OnShowMenu( menu );
  397. // Update the menu
  398. int id;
  399. CVMTDoc *pDoc = g_pVMTTool->GetDocument();
  400. if ( pDoc )
  401. {
  402. id = m_Items.Find( "default" );
  403. m_pMenu->SetItemEnabled( id, true );
  404. }
  405. else
  406. {
  407. id = m_Items.Find( "default" );
  408. m_pMenu->SetItemEnabled( id, false );
  409. }
  410. }
  411. //-----------------------------------------------------------------------------
  412. //
  413. // The View menu
  414. //
  415. //-----------------------------------------------------------------------------
  416. class CVMTViewMenuButton : public CToolMenuButton
  417. {
  418. DECLARE_CLASS_SIMPLE( CVMTViewMenuButton, CToolMenuButton );
  419. public:
  420. CVMTViewMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget );
  421. virtual void OnShowMenu(vgui::Menu *menu);
  422. };
  423. CVMTViewMenuButton::CVMTViewMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionSignalTarget )
  424. : BaseClass( parent, panelName, text, pActionSignalTarget )
  425. {
  426. AddCheckableMenuItem( "properties", "#VMTProperties", new KeyValues( "OnToggleProperties" ), pActionSignalTarget );
  427. AddCheckableMenuItem( "preview", "#VMTPreview", new KeyValues( "OnToggleVMTPreview" ), pActionSignalTarget );
  428. AddSeparator();
  429. AddCheckableMenuItem( "showflagparams", "#VMTShowFlags", new KeyValues( "OnShowFlags" ), pActionSignalTarget );
  430. AddCheckableMenuItem( "showtoolparams", "#VMTShowToolParams", new KeyValues( "OnShowToolParams" ), pActionSignalTarget );
  431. AddSeparator();
  432. AddMenuItem( "defaultlayout", "#VMTViewDefault", new KeyValues( "OnDefaultLayout" ), pActionSignalTarget );
  433. SetMenu(m_pMenu);
  434. }
  435. void CVMTViewMenuButton::OnShowMenu(vgui::Menu *menu)
  436. {
  437. BaseClass::OnShowMenu( menu );
  438. // Update the menu
  439. int id;
  440. CVMTDoc *pDoc = g_pVMTTool->GetDocument();
  441. if ( pDoc )
  442. {
  443. id = m_Items.Find( "properties" );
  444. m_pMenu->SetItemEnabled( id, true );
  445. Panel *p;
  446. p = g_pVMTTool->GetProperties();
  447. Assert( p );
  448. m_pMenu->SetMenuItemChecked( id, ( p && p->GetParent() ) ? true : false );
  449. id = m_Items.Find( "preview" );
  450. m_pMenu->SetItemEnabled( id, true );
  451. p = g_pVMTTool->GetVMTPreview();
  452. Assert( p );
  453. m_pMenu->SetMenuItemChecked( id, ( p && p->GetParent() ) ? true : false );
  454. id = m_Items.Find( "showflagparams" );
  455. m_pMenu->SetItemEnabled( id, true );
  456. m_pMenu->SetMenuItemChecked( id, g_pVMTTool->IsFlagParamsVisible() );
  457. id = m_Items.Find( "showtoolparams" );
  458. m_pMenu->SetItemEnabled( id, true );
  459. m_pMenu->SetMenuItemChecked( id, g_pVMTTool->IsToolParamsVisible() );
  460. }
  461. else
  462. {
  463. id = m_Items.Find( "properties" );
  464. m_pMenu->SetItemEnabled( id, false );
  465. id = m_Items.Find( "preview" );
  466. m_pMenu->SetItemEnabled( id, false );
  467. id = m_Items.Find( "showflagparams" );
  468. m_pMenu->SetItemEnabled( id, false );
  469. id = m_Items.Find( "showtoolparams" );
  470. m_pMenu->SetItemEnabled( id, false );
  471. }
  472. }
  473. //-----------------------------------------------------------------------------
  474. // Initializes the menu bar
  475. //-----------------------------------------------------------------------------
  476. vgui::MenuBar *CVMTTool::CreateMenuBar( CBaseToolSystem *pParent )
  477. {
  478. m_pMenuBar = new CToolFileMenuBar( pParent, "VMTMenuBar" );
  479. // Sets info in the menu bar
  480. char title[ 64 ];
  481. ComputeMenuBarTitle( title, sizeof( title ) );
  482. m_pMenuBar->SetInfo( title );
  483. m_pMenuBar->SetToolName( GetToolName() );
  484. UpdateMenuBar();
  485. // Add menu buttons
  486. CToolMenuButton *pFileButton = CreateToolFileMenuButton( m_pMenuBar, "File", "&File", GetActionTarget(), this );
  487. CToolMenuButton *pEditButton = CreateToolEditMenuButton( m_pMenuBar, "Edit", "&Edit", GetActionTarget() );
  488. CToolMenuButton *pMaterialButton = new CVMTMaterialMenuButton( m_pMenuBar, "Material", "&Material", GetActionTarget() );
  489. CToolMenuButton *pSwitchButton = CreateToolSwitchMenuButton( m_pMenuBar, "Switcher", "&Tools", GetActionTarget() );
  490. CVMTViewMenuButton *pViewButton = new CVMTViewMenuButton( m_pMenuBar, "View", "&View", GetActionTarget() );
  491. m_pMenuBar->AddButton( pFileButton );
  492. m_pMenuBar->AddButton( pEditButton );
  493. m_pMenuBar->AddButton( pMaterialButton );
  494. m_pMenuBar->AddButton( pViewButton );
  495. m_pMenuBar->AddButton( pSwitchButton );
  496. return m_pMenuBar;
  497. }
  498. //-----------------------------------------------------------------------------
  499. // Updates the menu bar based on the current file
  500. //-----------------------------------------------------------------------------
  501. void CVMTTool::UpdateMenuBar( )
  502. {
  503. if ( !m_pDoc )
  504. {
  505. m_pMenuBar->SetFileName( "#VMTNoFile" );
  506. return;
  507. }
  508. if ( m_pDoc->IsDirty() )
  509. {
  510. char sz[ 512 ];
  511. Q_snprintf( sz, sizeof( sz ), "* %s", m_pDoc->GetFileName() );
  512. m_pMenuBar->SetFileName( sz );
  513. }
  514. else
  515. {
  516. m_pMenuBar->SetFileName( m_pDoc->GetFileName() );
  517. }
  518. }
  519. //-----------------------------------------------------------------------------
  520. // Inherited from IFileMenuCallbacks
  521. //-----------------------------------------------------------------------------
  522. int CVMTTool::GetFileMenuItemsEnabled( )
  523. {
  524. int nFlags;
  525. if ( !m_pDoc )
  526. {
  527. nFlags = FILE_NEW | FILE_OPEN | FILE_RECENT | FILE_EXIT;
  528. }
  529. else
  530. {
  531. nFlags = FILE_ALL;
  532. }
  533. if ( m_RecentFiles.IsEmpty() )
  534. {
  535. nFlags &= ~FILE_RECENT;
  536. }
  537. return nFlags;
  538. }
  539. void CVMTTool::AddRecentFilesToMenu( vgui::Menu *pMenu )
  540. {
  541. m_RecentFiles.AddToMenu( pMenu, GetActionTarget(), "OnRecent" );
  542. }
  543. //-----------------------------------------------------------------------------
  544. // Returns the file name for perforce
  545. //-----------------------------------------------------------------------------
  546. bool CVMTTool::GetPerforceFileName( char *pFileName, int nMaxLen )
  547. {
  548. if ( !m_pDoc )
  549. return false;
  550. Q_strncpy( pFileName, m_pDoc->GetFileName(), nMaxLen );
  551. return true;
  552. }
  553. //-----------------------------------------------------------------------------
  554. // Derived classes can implement this to get a new scheme to be applied to this tool
  555. //-----------------------------------------------------------------------------
  556. vgui::HScheme CVMTTool::GetToolScheme()
  557. {
  558. return vgui::scheme()->LoadSchemeFromFile( "Resource/BoxRocket.res", "BoxRocket" );
  559. }
  560. //-----------------------------------------------------------------------------
  561. // Creates the action menu
  562. //-----------------------------------------------------------------------------
  563. vgui::Menu *CVMTTool::CreateActionMenu( vgui::Panel *pParent )
  564. {
  565. vgui::Menu *pActionMenu = new Menu( pParent, "ActionMenu" );
  566. pActionMenu->AddMenuItem( "#ToolHide", new KeyValues( "Command", "command", "HideActionMenu" ), GetActionTarget() );
  567. return pActionMenu;
  568. }
  569. //-----------------------------------------------------------------------------
  570. // Purpose:
  571. // Input : -
  572. //-----------------------------------------------------------------------------
  573. void CVMTTool::OnExit()
  574. {
  575. // Throw up a "save" dialog?
  576. enginetools->Command( "quit\n" );
  577. }
  578. //-----------------------------------------------------------------------------
  579. // Handle commands from the action menu and other menus
  580. //-----------------------------------------------------------------------------
  581. void CVMTTool::OnCommand( const char *cmd )
  582. {
  583. if ( !V_stricmp( cmd, "HideActionMenu" ) )
  584. {
  585. if ( GetActionMenu() )
  586. {
  587. GetActionMenu()->SetVisible( false );
  588. }
  589. }
  590. else if ( !V_stricmp( cmd, "OnUndo" ) )
  591. {
  592. OnUndo();
  593. }
  594. else if ( !V_stricmp( cmd, "OnRedo" ) )
  595. {
  596. OnRedo();
  597. }
  598. else if ( !V_stricmp( cmd, "OnDescribeUndo" ) )
  599. {
  600. OnDescribeUndo();
  601. }
  602. else if ( const char *pSuffix = StringAfterPrefix( cmd, "OnRecent" ) )
  603. {
  604. int idx = Q_atoi( pSuffix );
  605. g_pVMTTool->OpenFileFromHistory( idx, cmd );
  606. }
  607. else if ( const char *pSuffix = StringAfterPrefix( cmd, "OnTool" ) )
  608. {
  609. int idx = Q_atoi( pSuffix );
  610. enginetools->SwitchToTool( idx );
  611. }
  612. else
  613. {
  614. BaseClass::OnCommand( cmd );
  615. }
  616. }
  617. //-----------------------------------------------------------------------------
  618. // Messages from the engine
  619. //-----------------------------------------------------------------------------
  620. void CVMTTool::PostToolMessage( HTOOLHANDLE hEntity, KeyValues *message )
  621. {
  622. if ( !Q_stricmp( message->GetName(), "EditMaterial" ) )
  623. {
  624. const char *pMaterialName = message->GetString( "material", "debug/debugempty" );
  625. char pLocalPath[ MAX_PATH ];
  626. char pAbsPath[ MAX_PATH ];
  627. if ( pMaterialName[0] == '/' && pMaterialName[1] == '/' && pMaterialName[2] != '/' )
  628. {
  629. Q_strncpy( pAbsPath, pMaterialName, sizeof(pAbsPath) );
  630. Q_DefaultExtension( pAbsPath, ".vmt", sizeof(pAbsPath) );
  631. }
  632. else
  633. {
  634. Q_snprintf( pLocalPath, sizeof(pLocalPath), "materials/%s", pMaterialName );
  635. Q_DefaultExtension( pLocalPath, ".vmt", sizeof(pLocalPath) );
  636. g_pFileSystem->RelativePathToFullPath( pLocalPath, "GAME", pAbsPath, sizeof(pAbsPath) );
  637. }
  638. Q_FixSlashes( pAbsPath );
  639. OpenSpecificFile( pAbsPath );
  640. }
  641. }
  642. //-----------------------------------------------------------------------------
  643. // Derived classes can implement this to get notified when files are saved/loaded
  644. //-----------------------------------------------------------------------------
  645. void CVMTTool::OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues )
  646. {
  647. if ( bWroteFile )
  648. {
  649. OnMarkNotDirty();
  650. }
  651. if ( !pContextKeyValues )
  652. return;
  653. if ( state != FileOpenStateMachine::SUCCESSFUL )
  654. return;
  655. if ( !Q_stricmp( pContextKeyValues->GetName(), "OnNew" ) )
  656. {
  657. PerformNew();
  658. return;
  659. }
  660. if ( !Q_stricmp( pContextKeyValues->GetName(), "OnClose" ) )
  661. {
  662. OnCloseNoSave();
  663. return;
  664. }
  665. if ( !Q_stricmp( pContextKeyValues->GetName(), "OnQuit" ) )
  666. {
  667. OnCloseNoSave();
  668. vgui::ivgui()->PostMessage( GetVPanel(), new KeyValues( "OnExit" ), 0 );
  669. return;
  670. }
  671. if ( !Q_stricmp( pContextKeyValues->GetName(), "OnUnload" ) )
  672. {
  673. enginetools->Command( "toolunload vmt -nosave\n" );
  674. return;
  675. }
  676. }
  677. //-----------------------------------------------------------------------------
  678. // Called by SaveFile to allow clients to set up the save dialog
  679. //-----------------------------------------------------------------------------
  680. void CVMTTool::SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues )
  681. {
  682. // Compute starting directory
  683. char pStartingDir[ MAX_PATH ];
  684. GetModSubdirectory( "materials", pStartingDir, sizeof(pStartingDir) );
  685. if ( bOpenFile )
  686. {
  687. pDialog->SetTitle( "Open Material .VMT File", true );
  688. }
  689. else
  690. {
  691. pDialog->SetTitle( "Save Material .VMT File As", true );
  692. }
  693. pDialog->SetStartDirectoryContext( "vmt_session", pStartingDir );
  694. pDialog->AddFilter( "*.vmt", "VMT (*.vmt)", true );
  695. }
  696. //-----------------------------------------------------------------------------
  697. // Called by SaveFile to allow clients to actually write the file out
  698. //-----------------------------------------------------------------------------
  699. bool CVMTTool::OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
  700. {
  701. OnCloseNoSave();
  702. if ( !LoadDocument( pFileName ) )
  703. return false;
  704. m_RecentFiles.Add( pFileName, pFileFormat );
  705. m_RecentFiles.SaveToRegistry( GetRegistryName() );
  706. UpdateMenuBar();
  707. return true;
  708. }
  709. //-----------------------------------------------------------------------------
  710. // Called by SaveFile to allow clients to actually write the file out
  711. //-----------------------------------------------------------------------------
  712. bool CVMTTool::OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues )
  713. {
  714. if ( !m_pDoc )
  715. return true;
  716. m_pDoc->SetFileName( pFileName );
  717. if ( !m_pDoc->SaveToFile( ) )
  718. return false;
  719. m_RecentFiles.Add( pFileName, pFileFormat );
  720. m_RecentFiles.SaveToRegistry( GetRegistryName() );
  721. UpdateMenuBar();
  722. return true;
  723. }
  724. //-----------------------------------------------------------------------------
  725. // Command handlers
  726. //-----------------------------------------------------------------------------
  727. void CVMTTool::PerformNew()
  728. {
  729. OnCloseNoSave();
  730. NewDocument();
  731. }
  732. void CVMTTool::OnNew()
  733. {
  734. if ( m_pDoc && m_pDoc->IsDirty() )
  735. {
  736. SaveFile( m_pDoc->GetFileName(), "vmt", FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY,
  737. new KeyValues( "OnNew" ) );
  738. return;
  739. }
  740. PerformNew();
  741. }
  742. void CVMTTool::OnOpen( )
  743. {
  744. int nFlags = 0;
  745. const char *pSaveFileName = NULL;
  746. if ( m_pDoc && m_pDoc->IsDirty() )
  747. {
  748. nFlags = FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY;
  749. pSaveFileName = m_pDoc->GetFileName();
  750. }
  751. OpenFile( "vmt", pSaveFileName, "vmt", nFlags );
  752. }
  753. void CVMTTool::OnSave()
  754. {
  755. if ( m_pDoc )
  756. {
  757. SaveFile( m_pDoc->GetFileName(), "vmt", FOSM_SHOW_PERFORCE_DIALOGS );
  758. }
  759. }
  760. void CVMTTool::OnSaveAs()
  761. {
  762. if ( m_pDoc )
  763. {
  764. SaveFile( NULL, "vmt", FOSM_SHOW_PERFORCE_DIALOGS );
  765. }
  766. }
  767. void CVMTTool::OnClose()
  768. {
  769. if ( m_pDoc && m_pDoc->IsDirty() )
  770. {
  771. SaveFile( m_pDoc->GetFileName(), "vmt", FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY,
  772. new KeyValues( "OnClose" ) );
  773. return;
  774. }
  775. OnCloseNoSave();
  776. }
  777. void CVMTTool::OnCloseNoSave()
  778. {
  779. DestroyTools();
  780. if ( m_pDoc )
  781. {
  782. CAppNotifyScopeGuard sg( "CVMTTool::OnCloseNoSave", NOTIFY_CHANGE_OTHER );
  783. delete m_pDoc;
  784. m_pDoc = NULL;
  785. if ( m_hProperties )
  786. {
  787. m_hProperties->SetObject( NULL );
  788. }
  789. }
  790. UpdateMenuBar( );
  791. }
  792. void CVMTTool::OnMarkNotDirty()
  793. {
  794. if ( m_pDoc )
  795. {
  796. m_pDoc->SetDirty( false );
  797. }
  798. }
  799. //-----------------------------------------------------------------------------
  800. // Open a specific file
  801. //-----------------------------------------------------------------------------
  802. void CVMTTool::OpenSpecificFile( const char *pFileName )
  803. {
  804. int nFlags = 0;
  805. const char *pSaveFileName = NULL;
  806. if ( m_pDoc )
  807. {
  808. // File is already open
  809. if ( !Q_stricmp( m_pDoc->GetFileName(), pFileName ) )
  810. return;
  811. if ( m_pDoc->IsDirty() )
  812. {
  813. nFlags = FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY;
  814. pSaveFileName = m_pDoc->GetFileName();
  815. }
  816. }
  817. OpenFile( pFileName, "vmt", pSaveFileName, "vmt", nFlags );
  818. }
  819. //-----------------------------------------------------------------------------
  820. // Show the save document query dialog
  821. //-----------------------------------------------------------------------------
  822. void CVMTTool::OpenFileFromHistory( int slot, const char *pCommand )
  823. {
  824. const char *pFileName = m_RecentFiles.GetFile( slot );
  825. if ( !pFileName )
  826. return;
  827. OpenSpecificFile( pFileName );
  828. }
  829. bool CVMTTool::CanQuit( const char *pExitMsg )
  830. {
  831. if ( m_pDoc && m_pDoc->IsDirty() )
  832. {
  833. // Show Save changes Yes/No/Cancel and re-quit if hit yes/no
  834. SaveFile( m_pDoc->GetFileName(), "vmt", FOSM_SHOW_PERFORCE_DIALOGS | FOSM_SHOW_SAVE_QUERY, new KeyValues( pExitMsg ) );
  835. return false;
  836. }
  837. return true;
  838. }
  839. //-----------------------------------------------------------------------------
  840. // Various command handlers related to the Edit menu
  841. //-----------------------------------------------------------------------------
  842. void CVMTTool::OnUndo()
  843. {
  844. CDisableUndoScopeGuard guard;
  845. g_pDataModel->Undo();
  846. }
  847. void CVMTTool::OnRedo()
  848. {
  849. CDisableUndoScopeGuard guard;
  850. g_pDataModel->Redo();
  851. }
  852. void CVMTTool::OnDescribeUndo()
  853. {
  854. CUtlVector< UndoInfo_t > list;
  855. g_pDataModel->GetUndoInfo( list );
  856. Msg( "%i operations in stack\n", list.Count() );
  857. for ( int i = list.Count() - 1; i >= 0; --i )
  858. {
  859. UndoInfo_t& entry = list[ i ];
  860. if ( entry.terminator )
  861. {
  862. Msg( "[ '%s' ] - %i operations\n", entry.undo, entry.numoperations );
  863. }
  864. Msg( " +%s\n", entry.desc );
  865. }
  866. }
  867. //-----------------------------------------------------------------------------
  868. // Inherited from IVMTDocCallback
  869. //-----------------------------------------------------------------------------
  870. void CVMTTool::OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags )
  871. {
  872. UpdateMenuBar();
  873. if ( ( nNotifySource != NOTIFY_SOURCE_PROPERTIES_TREE ) && m_hProperties.Get() )
  874. {
  875. m_hProperties->Refresh();
  876. }
  877. }
  878. //-----------------------------------------------------------------------------
  879. // Purpose:
  880. // Input : -
  881. // Output : CVMTDoc
  882. //-----------------------------------------------------------------------------
  883. CVMTDoc *CVMTTool::GetDocument()
  884. {
  885. return m_pDoc;
  886. }
  887. //-----------------------------------------------------------------------------
  888. // Purpose:
  889. // Input : -
  890. // Output : virtual CBasePropertiesContainer
  891. //-----------------------------------------------------------------------------
  892. CBasePropertiesContainer *CVMTTool::GetProperties()
  893. {
  894. return m_hProperties.Get();
  895. }
  896. CVMTPanel *CVMTTool::GetVMTPreview()
  897. {
  898. return m_hVMTPreview.Get();
  899. }
  900. //-----------------------------------------------------------------------------
  901. // Initializes the tools
  902. //-----------------------------------------------------------------------------
  903. void CVMTTool::InitTools()
  904. {
  905. ShowElementProperties();
  906. // FIXME: There are no tool windows here; how should this work?
  907. // These panels are saved
  908. windowposmgr->RegisterPanel( "properties", m_hProperties, false );
  909. windowposmgr->RegisterPanel( "vmtpanel", m_hVMTPreview, false );
  910. if ( !windowposmgr->LoadPositions( "cfg/vmt.txt", this, &m_ToolWindowFactory, "VMT" ) )
  911. {
  912. OnDefaultLayout();
  913. }
  914. }
  915. //-----------------------------------------------------------------------------
  916. // Loads up a new document
  917. //-----------------------------------------------------------------------------
  918. bool CVMTTool::LoadDocument( char const *pDocName )
  919. {
  920. Assert( !m_pDoc );
  921. DestroyTools();
  922. m_pDoc = new CVMTDoc( this );
  923. if ( !m_pDoc->LoadFromFile( pDocName ) )
  924. {
  925. delete m_pDoc;
  926. m_pDoc = NULL;
  927. Warning( "Fatal error loading '%s'\n", pDocName );
  928. return false;
  929. }
  930. CreateTools( m_pDoc );
  931. InitTools();
  932. return true;
  933. }
  934. //-----------------------------------------------------------------------------
  935. // Loads up a new document
  936. //-----------------------------------------------------------------------------
  937. void CVMTTool::NewDocument( )
  938. {
  939. Assert( !m_pDoc );
  940. m_pDoc = new CVMTDoc( this );
  941. m_pDoc->CreateNew( );
  942. CreateTools( m_pDoc );
  943. UpdateMenuBar( );
  944. InitTools();
  945. }
  946. //-----------------------------------------------------------------------------
  947. // Shows element properties
  948. //-----------------------------------------------------------------------------
  949. void CVMTTool::ShowElementProperties( )
  950. {
  951. if ( !m_pDoc )
  952. return;
  953. if ( !m_pDoc->GetRootObject() )
  954. return;
  955. // It should already exist
  956. Assert( m_hProperties.Get() );
  957. if ( m_hProperties.Get() )
  958. {
  959. m_hProperties->SetObject( m_pDoc->GetRootObject() );
  960. }
  961. }
  962. void CVMTTool::DestroyTools()
  963. {
  964. windowposmgr->SavePositions( "cfg/vmt.txt", "VMT" );
  965. int c = ToolWindow::GetToolWindowCount();
  966. for ( int i = c - 1; i >= 0 ; --i )
  967. {
  968. ToolWindow *kill = ToolWindow::GetToolWindow( i );
  969. delete kill;
  970. }
  971. UnregisterAllToolWindows();
  972. if ( m_hProperties.Get() )
  973. {
  974. windowposmgr->UnregisterPanel( m_hProperties.Get() );
  975. delete m_hProperties.Get();
  976. m_hProperties = NULL;
  977. }
  978. if ( m_hVMTPreview.Get() )
  979. {
  980. windowposmgr->UnregisterPanel( m_hVMTPreview.Get() );
  981. delete m_hVMTPreview.Get();
  982. m_hVMTPreview = NULL;
  983. }
  984. }
  985. void CVMTTool::CreateTools( CVMTDoc *doc )
  986. {
  987. if ( !m_hProperties.Get() )
  988. {
  989. m_hProperties = new CBasePropertiesContainer( NULL, m_pDoc, g_pEditorTypeDict );
  990. }
  991. if ( !m_hVMTPreview.Get() )
  992. {
  993. m_hVMTPreview = new CVMTPanel( NULL, "VMT Preview" );
  994. SETUP_PANEL( m_hVMTPreview.Get() );
  995. m_hVMTPreview->SetMaterial( m_pDoc->GetPreviewMaterial() );
  996. }
  997. RegisterToolWindow( m_hProperties );
  998. RegisterToolWindow( m_hVMTPreview );
  999. }
  1000. void CVMTTool::ShowToolWindow( Panel *tool, char const *toolName, bool visible )
  1001. {
  1002. Assert( tool );
  1003. if ( tool->GetParent() == NULL && visible )
  1004. {
  1005. m_ToolWindowFactory.InstanceToolWindow( this, false, tool, toolName, false );
  1006. }
  1007. else if ( !visible )
  1008. {
  1009. ToolWindow *tw = dynamic_cast< ToolWindow * >( tool->GetParent()->GetParent() );
  1010. Assert( tw );
  1011. tw->RemovePage( tool );
  1012. }
  1013. }
  1014. void CVMTTool::ToggleToolWindow( Panel *tool, char const *toolName )
  1015. {
  1016. Assert( tool );
  1017. if ( tool->GetParent() == NULL )
  1018. {
  1019. ShowToolWindow( tool, toolName, true );
  1020. }
  1021. else
  1022. {
  1023. ShowToolWindow( tool, toolName, false );
  1024. }
  1025. }
  1026. void CVMTTool::DestroyToolContainers()
  1027. {
  1028. int c = ToolWindow::GetToolWindowCount();
  1029. for ( int i = c - 1; i >= 0 ; --i )
  1030. {
  1031. ToolWindow *kill = ToolWindow::GetToolWindow( i );
  1032. delete kill;
  1033. }
  1034. }
  1035. void CVMTTool::OnDefaultLayout()
  1036. {
  1037. int y = m_pMenuBar->GetTall();
  1038. int usew, useh;
  1039. GetSize( usew, useh );
  1040. DestroyToolContainers();
  1041. Assert( ToolWindow::GetToolWindowCount() == 0 );
  1042. CBasePropertiesContainer *properties = GetProperties();
  1043. CVMTPanel *pVMTPreview = GetVMTPreview();
  1044. // Need three containers
  1045. ToolWindow *pPropertyWindow = m_ToolWindowFactory.InstanceToolWindow( GetClientArea(), false, properties, "#VMTProperties", false );
  1046. ToolWindow *pVMTPreviewWindow = m_ToolWindowFactory.InstanceToolWindow( GetClientArea(), false, pVMTPreview, "#VMTPreview", false );
  1047. int halfScreen = usew / 2;
  1048. int bottom = useh - y;
  1049. int sy = (bottom - y) / 2;
  1050. SetMiniViewportBounds( halfScreen, y, halfScreen, sy - y );
  1051. pPropertyWindow->SetBounds( 0, y, halfScreen, bottom );
  1052. pVMTPreviewWindow->SetBounds( halfScreen, sy, halfScreen, bottom - sy );
  1053. }
  1054. void CVMTTool::OnToggleProperties()
  1055. {
  1056. if ( m_hProperties.Get() )
  1057. {
  1058. ToggleToolWindow( m_hProperties.Get(), "#VMTProperties" );
  1059. }
  1060. }
  1061. void CVMTTool::OnToggleVMTPreview()
  1062. {
  1063. if ( m_hVMTPreview.Get() )
  1064. {
  1065. ToggleToolWindow( m_hVMTPreview.Get(), "#VMTPreview" );
  1066. }
  1067. }
  1068. //-----------------------------------------------------------------------------
  1069. // Show/hide tool params + flags
  1070. //-----------------------------------------------------------------------------
  1071. void CVMTTool::OnShowFlags()
  1072. {
  1073. m_bFlagParamsVisible = !m_bFlagParamsVisible;
  1074. int nCount = m_FlagParams.Count();
  1075. for ( int i = 0; i < nCount; ++i )
  1076. {
  1077. CDmeEditorAttributeInfo *pInfo = m_pVMTType->GetAttributeInfo( m_FlagParams[i] );
  1078. Assert( pInfo );
  1079. pInfo->m_bIsVisible = m_bFlagParamsVisible;
  1080. }
  1081. if ( m_hProperties.Get() )
  1082. {
  1083. m_hProperties->Refresh();
  1084. }
  1085. }
  1086. void CVMTTool::OnShowToolParams()
  1087. {
  1088. m_bToolParamsVisible = !m_bToolParamsVisible;
  1089. int nCount = m_ToolParams.Count();
  1090. for ( int i = 0; i < nCount; ++i )
  1091. {
  1092. CDmeEditorAttributeInfo *pInfo = m_pVMTType->GetAttributeInfo( m_ToolParams[i] );
  1093. Assert( pInfo );
  1094. pInfo->m_bIsVisible = m_bToolParamsVisible;
  1095. }
  1096. if ( m_hProperties.Get() )
  1097. {
  1098. m_hProperties->Refresh();
  1099. }
  1100. }
  1101. //-----------------------------------------------------------------------------
  1102. // Sets shader parameters to the default for that shader
  1103. //-----------------------------------------------------------------------------
  1104. void CVMTTool::OnSetParamsToDefault()
  1105. {
  1106. if ( m_pDoc )
  1107. {
  1108. m_pDoc->SetParamsToDefault();
  1109. }
  1110. }
  1111. char const *CVMTTool::GetLogoTextureName()
  1112. {
  1113. return "vgui/tools/vmt/vmt_logo";
  1114. }