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.

239 lines
7.8 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: CommEdit tool; main UI smarts class
  4. //
  5. //=============================================================================
  6. #ifndef COMMEDITTOOL_H
  7. #define COMMEDITTOOL_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 "dmecommentarynodeentity.h"
  21. #include "toolframework/ienginetool.h"
  22. #include "toolutils/enginetools_int.h"
  23. #include "toolutils/savewindowpositions.h"
  24. #include "toolutils/toolwindowfactory.h"
  25. //-----------------------------------------------------------------------------
  26. // Forward declarations
  27. //-----------------------------------------------------------------------------
  28. class CDmElement;
  29. class CConsolePage;
  30. class CCommEditDoc;
  31. class CCommentaryPropertiesPanel;
  32. class CCommentaryNodeBrowserPanel;
  33. namespace vgui
  34. {
  35. class Panel;
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Allows the doc to call back into the CommEdit editor tool
  39. //-----------------------------------------------------------------------------
  40. abstract_class ICommEditDocCallback
  41. {
  42. public:
  43. // Called by the doc when the data changes
  44. virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
  45. };
  46. //-----------------------------------------------------------------------------
  47. // Global methods of the commedit tool
  48. //-----------------------------------------------------------------------------
  49. abstract_class ICommEditTool
  50. {
  51. public:
  52. // Gets at the rool panel (for modal dialogs)
  53. virtual vgui::Panel *GetRootPanel() = 0;
  54. // Gets the registry name (for saving settings)
  55. virtual const char *GetRegistryName() = 0;
  56. // Shows a particular entity in the entity properties dialog
  57. virtual void ShowEntityInEntityProperties( CDmeCommentaryNodeEntity *pEntity ) = 0;
  58. };
  59. //-----------------------------------------------------------------------------
  60. // Implementation of the CommEdit tool
  61. //-----------------------------------------------------------------------------
  62. class CCommEditTool : public CBaseToolSystem, public IFileMenuCallbacks, public ICommEditDocCallback, public ICommEditTool
  63. {
  64. DECLARE_CLASS_SIMPLE( CCommEditTool, CBaseToolSystem );
  65. public:
  66. CCommEditTool();
  67. // Inherited from IToolSystem
  68. virtual const char *GetToolName() { return "Commentary Editor"; }
  69. virtual bool Init( );
  70. virtual void Shutdown();
  71. virtual bool CanQuit( const char *pExitMsg );
  72. virtual void OnToolActivate();
  73. virtual void OnToolDeactivate();
  74. virtual const char* GetEntityData( const char *pActualEntityData );
  75. virtual void DrawCommentaryNodeEntitiesInEngine( bool bDrawInEngine );
  76. virtual void ClientLevelInitPostEntity();
  77. virtual void ClientLevelShutdownPreEntity();
  78. virtual bool TrapKey( ButtonCode_t key, bool down );
  79. virtual void ClientPreRender();
  80. // Inherited from IFileMenuCallbacks
  81. virtual int GetFileMenuItemsEnabled( );
  82. virtual void AddRecentFilesToMenu( vgui::Menu *menu );
  83. virtual bool GetPerforceFileName( char *pFileName, int nMaxLen );
  84. // Inherited from ICommEditDocCallback
  85. virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
  86. virtual vgui::Panel *GetRootPanel() { return this; }
  87. virtual void ShowEntityInEntityProperties( CDmeCommentaryNodeEntity *pEntity );
  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 "CommEditTool"; }
  93. virtual const char *GetBindingsContextFile() { return "cfg/CommEdit.kb"; }
  94. virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
  95. MESSAGE_FUNC( Save, "OnSave" );
  96. void SaveAndTest();
  97. void CenterView( CDmeCommentaryNodeEntity* pEntity );
  98. // Enter mode where we preview dropping nodes
  99. void EnterNodeDropMode();
  100. void LeaveNodeDropMode();
  101. public:
  102. MESSAGE_FUNC( OnRestartLevel, "RestartLevel" );
  103. MESSAGE_FUNC( OnNew, "OnNew" );
  104. MESSAGE_FUNC( OnOpen, "OnOpen" );
  105. MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
  106. MESSAGE_FUNC( OnClose, "OnClose" );
  107. MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
  108. MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
  109. MESSAGE_FUNC( OnExit, "OnExit" );
  110. // Commands related to the edit menu
  111. void OnDescribeUndo();
  112. // Methods related to the CommEdit menu
  113. MESSAGE_FUNC( OnAddNewNodes, "AddNewNodes" );
  114. // Methods related to the view menu
  115. MESSAGE_FUNC( OnToggleProperties, "OnToggleProperties" );
  116. MESSAGE_FUNC( OnToggleEntityReport, "OnToggleEntityReport" );
  117. MESSAGE_FUNC( OnToggleConsole, "ToggleConsole" );
  118. MESSAGE_FUNC( OnDefaultLayout, "OnDefaultLayout" );
  119. // Keybindings
  120. KEYBINDING_FUNC( undo, KEY_Z, vgui::MODIFIER_CONTROL, OnUndo, "#undo_help", 0 );
  121. KEYBINDING_FUNC( redo, KEY_Z, vgui::MODIFIER_CONTROL | vgui::MODIFIER_SHIFT, OnRedo, "#redo_help", 0 );
  122. KEYBINDING_FUNC_NODECLARE( CommEditAddNewNodes, KEY_A, vgui::MODIFIER_CONTROL, OnAddNewNodes, "#CommEditAddNewNodesHelp", 0 );
  123. void PerformNew();
  124. void OpenFileFromHistory( int slot );
  125. void OpenSpecificFile( const char *pFileName );
  126. virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues );
  127. virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  128. virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  129. virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues );
  130. void AttachAllEngineEntities();
  131. // returns the document
  132. CCommEditDoc *GetDocument();
  133. // Gets at tool windows
  134. CCommentaryPropertiesPanel *GetProperties();
  135. CCommentaryNodeBrowserPanel *GetCommentaryNodeBrowser();
  136. CConsolePage *GetConsole();
  137. CDmeHandle< CDmeCommentaryNodeEntity > GetCurrentEntity( void ) { return m_hCurrentEntity; }
  138. private:
  139. // Loads up a new document
  140. bool LoadDocument( const char *pDocName );
  141. // Updates the menu bar based on the current file
  142. void UpdateMenuBar( );
  143. // Shows element properties
  144. void ShowElementProperties( );
  145. virtual const char *GetLogoTextureName();
  146. // Creates, destroys tools
  147. void CreateTools( CCommEditDoc *doc );
  148. void DestroyTools();
  149. // Initializes the tools
  150. void InitTools();
  151. // Shows, toggles tool windows
  152. void ToggleToolWindow( Panel *tool, char const *toolName );
  153. void ShowToolWindow( Panel *tool, char const *toolName, bool visible );
  154. // Kills all tool windows
  155. void DestroyToolContainers();
  156. // Gets the position of the preview object
  157. void GetPlacementInfo( Vector &vecOrigin, QAngle &angles );
  158. // Brings the console to front
  159. void BringConsoleToFront();
  160. private:
  161. enum DropNodeMode_t
  162. {
  163. DROP_MODE_COMMENTARY = 0,
  164. DROP_MODE_TARGET,
  165. DROP_MODE_REMARKABLE,
  166. DROP_MODE_COUNT,
  167. };
  168. // Document
  169. CCommEditDoc *m_pDoc;
  170. // The menu bar
  171. CToolFileMenuBar *m_pMenuBar;
  172. // Element properties for editing material
  173. vgui::DHANDLE< CCommentaryPropertiesPanel > m_hProperties;
  174. // The entity report
  175. vgui::DHANDLE< CCommentaryNodeBrowserPanel > m_hCommentaryNodeBrowser;
  176. // The console
  177. vgui::DHANDLE< CConsolePage > m_hConsole;
  178. // The currently viewed entity
  179. CDmeHandle< CDmeCommentaryNodeEntity > m_hCurrentEntity;
  180. // Separate undo context for the act busy tool
  181. bool m_bInNodeDropMode;
  182. DropNodeMode_t m_nDropMode;
  183. CDmeHandle< CDmeCommentaryNodeEntity > m_hPreviewEntity[DROP_MODE_COUNT];
  184. CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
  185. };
  186. extern CCommEditTool *g_pCommEditTool;
  187. #endif // COMMEDITTOOL_H