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.

209 lines
7.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: P.E.T. (Particle Editing Tool); main UI smarts class
  4. //
  5. //=============================================================================
  6. #ifndef PETTOOL_H
  7. #define PETTOOL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier0/platform.h"
  12. #include "toolutils/basetoolsystem.h"
  13. #include "toolutils/recentfilelist.h"
  14. #include "toolutils/toolmenubar.h"
  15. #include "toolutils/toolswitchmenubutton.h"
  16. #include "toolutils/tooleditmenubutton.h"
  17. #include "toolutils/toolfilemenubutton.h"
  18. #include "toolutils/toolmenubutton.h"
  19. #include "datamodel/dmelement.h"
  20. #include "datamodel/dmehandle.h"
  21. #include "toolframework/ienginetool.h"
  22. #include "toolutils/enginetools_int.h"
  23. #include "toolutils/savewindowpositions.h"
  24. #include "toolutils/toolwindowfactory.h"
  25. #include "movieobjects/dmeparticlesystemdefinition.h"
  26. #include "particles/particles.h"
  27. //-----------------------------------------------------------------------------
  28. // Forward declarations
  29. //-----------------------------------------------------------------------------
  30. class CDmElement;
  31. class CPetDoc;
  32. class CParticleSystemPropertiesContainer;
  33. class CParticleSystemDefinitionBrowser;
  34. class CParticleSystemPreviewPanel;
  35. class CDmeParticleSystemDefinition;
  36. enum ParticleFunctionType_t;
  37. namespace vgui
  38. {
  39. class Panel;
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Allows the doc to call back into the CommEdit editor tool
  43. //-----------------------------------------------------------------------------
  44. abstract_class IPetDocCallback
  45. {
  46. public:
  47. // Called by the doc when the data changes
  48. virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
  49. };
  50. //-----------------------------------------------------------------------------
  51. // Global methods of the commedit tool
  52. //-----------------------------------------------------------------------------
  53. abstract_class IPetTool
  54. {
  55. public:
  56. // Gets at the rool panel (for modal dialogs)
  57. virtual vgui::Panel *GetRootPanel() = 0;
  58. // Gets the registry name (for saving settings)
  59. virtual const char *GetRegistryName() = 0;
  60. };
  61. //-----------------------------------------------------------------------------
  62. // Implementation of the CommEdit tool
  63. //-----------------------------------------------------------------------------
  64. class CPetTool : public CBaseToolSystem, public IFileMenuCallbacks, public IPetDocCallback, public IPetTool
  65. {
  66. DECLARE_CLASS_SIMPLE( CPetTool, CBaseToolSystem );
  67. public:
  68. CPetTool();
  69. // Inherited from IToolSystem
  70. virtual const char *GetToolName() { return "Particle Editor"; }
  71. virtual bool Init( );
  72. virtual void Shutdown();
  73. virtual bool CanQuit();
  74. virtual void OnToolActivate();
  75. virtual void OnToolDeactivate();
  76. virtual void Think( bool finalTick );
  77. // Inherited from IFileMenuCallbacks
  78. virtual int GetFileMenuItemsEnabled( );
  79. virtual void AddRecentFilesToMenu( vgui::Menu *menu );
  80. virtual bool GetPerforceFileName( char *pFileName, int nMaxLen );
  81. // Inherited from IPetDocCallback
  82. virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
  83. virtual vgui::Panel *GetRootPanel() { return this; }
  84. // Inherited from CBaseToolSystem
  85. virtual vgui::HScheme GetToolScheme();
  86. virtual vgui::Menu *CreateActionMenu( vgui::Panel *pParent );
  87. virtual void OnCommand( const char *cmd );
  88. virtual const char *GetRegistryName() { return "PetTool"; }
  89. virtual const char *GetBindingsContextFile() { return "cfg/Pet.kb"; }
  90. virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
  91. MESSAGE_FUNC( Save, "OnSave" );
  92. void SaveAndTest();
  93. public:
  94. MESSAGE_FUNC( OnRestartLevel, "RestartLevel" );
  95. MESSAGE_FUNC( OnNew, "OnNew" );
  96. MESSAGE_FUNC( OnOpen, "OnOpen" );
  97. MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
  98. MESSAGE_FUNC( OnClose, "OnClose" );
  99. MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
  100. MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
  101. MESSAGE_FUNC( OnExit, "OnExit" );
  102. MESSAGE_FUNC( OnCopy, "OnCopy" );
  103. MESSAGE_FUNC( OnPaste, "OnPaste" );
  104. // Commands related to the edit menu
  105. void OnDescribeUndo();
  106. // Methods related to the view menu
  107. MESSAGE_FUNC( OnToggleProperties, "OnToggleProperties" );
  108. MESSAGE_FUNC( OnToggleParticleSystemBrowser, "OnToggleParticleSystemBrowser" );
  109. MESSAGE_FUNC( OnToggleParticlePreview, "OnToggleParticlePreview" );
  110. MESSAGE_FUNC( OnDefaultLayout, "OnDefaultLayout" );
  111. // Keybindings
  112. KEYBINDING_FUNC( undo, KEY_Z, vgui::MODIFIER_CONTROL, OnUndo, "#undo_help", 0 );
  113. KEYBINDING_FUNC( redo, KEY_Z, vgui::MODIFIER_CONTROL | vgui::MODIFIER_SHIFT, OnRedo, "#redo_help", 0 );
  114. KEYBINDING_FUNC_NODECLARE( edit_copy, KEY_C, vgui::MODIFIER_CONTROL, OnCopy, "#edit_copy_help", 0 );
  115. KEYBINDING_FUNC_NODECLARE( edit_paste, KEY_V, vgui::MODIFIER_CONTROL, OnPaste, "#edit_paste_help", 0 );
  116. void PerformNew();
  117. void OpenFileFromHistory( int slot );
  118. void OpenSpecificFile( const char *pFileName );
  119. virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues );
  120. virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  121. virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  122. virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues );
  123. // returns the document
  124. CPetDoc *GetDocument();
  125. // Gets at tool windows
  126. CParticleSystemPropertiesContainer *GetProperties();
  127. CParticleSystemDefinitionBrowser *GetParticleSystemDefinitionBrowser();
  128. CParticleSystemPreviewPanel *GetParticlePreview();
  129. void SetCurrentParticleSystem( CDmeParticleSystemDefinition *pParticleSystem, bool bForceBrowserSelection = true );
  130. CDmeParticleSystemDefinition* GetCurrentParticleSystem( void );
  131. private:
  132. // Creates a new document
  133. void NewDocument( );
  134. // Loads up a new document
  135. bool LoadDocument( const char *pDocName );
  136. // Updates the menu bar based on the current file
  137. void UpdateMenuBar( );
  138. virtual const char *GetLogoTextureName();
  139. // Creates, destroys tools
  140. void CreateTools( CPetDoc *doc );
  141. void DestroyTools();
  142. // Initializes the tools
  143. void InitTools();
  144. // Shows, toggles tool windows
  145. void ToggleToolWindow( Panel *tool, char const *toolName );
  146. void ShowToolWindow( Panel *tool, char const *toolName, bool visible );
  147. // Kills all tool windows
  148. void DestroyToolContainers();
  149. private:
  150. // Document
  151. CPetDoc *m_pDoc;
  152. // The menu bar
  153. CToolFileMenuBar *m_pMenuBar;
  154. // Element properties for editing material
  155. vgui::DHANDLE< CParticleSystemPropertiesContainer > m_hProperties;
  156. // The entity report
  157. vgui::DHANDLE< CParticleSystemDefinitionBrowser > m_hParticleSystemDefinitionBrowser;
  158. // Particle preview window
  159. vgui::DHANDLE< CParticleSystemPreviewPanel > m_hParticlePreview;
  160. // The currently viewed entity
  161. CDmeHandle< CDmeParticleSystemDefinition > m_hCurrentParticleSystem;
  162. // Separate undo context for the act busy tool
  163. CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
  164. };
  165. extern CPetTool *g_pPetTool;
  166. #endif // PETTOOL_H