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.

239 lines
7.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: VcdBlock tool; main UI smarts class
  4. //
  5. //=============================================================================
  6. #ifndef VCDBLOCKTOOL_H
  7. #define VCDBLOCKTOOL_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 "dmevmfentity.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 CVcdBlockDoc;
  30. class CInfoTargetPropertiesPanel;
  31. class CInfoTargetBrowserPanel;
  32. namespace vgui
  33. {
  34. class Panel;
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Allows the doc to call back into the VcdBlock editor tool
  38. //-----------------------------------------------------------------------------
  39. abstract_class IVcdBlockDocCallback
  40. {
  41. public:
  42. // Called by the doc when the data changes
  43. virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags ) = 0;
  44. };
  45. //-----------------------------------------------------------------------------
  46. // Global methods of the VCD Blocking tool
  47. //-----------------------------------------------------------------------------
  48. abstract_class IVcdBlockTool
  49. {
  50. public:
  51. // Gets at the rool panel (for modal dialogs)
  52. virtual vgui::Panel *GetRootPanel() = 0;
  53. // Gets the registry name (for saving settings)
  54. virtual const char *GetRegistryName() = 0;
  55. // Shows a particular entity in the entity properties dialog
  56. virtual void ShowEntityInEntityProperties( CDmeVMFEntity *pEntity ) = 0;
  57. };
  58. //-----------------------------------------------------------------------------
  59. // Implementation of the VcdBlock tool
  60. //-----------------------------------------------------------------------------
  61. class CVcdBlockTool : public CBaseToolSystem, public IFileMenuCallbacks, public IVcdBlockDocCallback, public IVcdBlockTool
  62. {
  63. DECLARE_CLASS_SIMPLE( CVcdBlockTool, CBaseToolSystem );
  64. public:
  65. CVcdBlockTool();
  66. // Inherited from IToolSystem
  67. virtual const char *GetToolName() { return "VCD Blocking Tool"; }
  68. virtual bool Init( );
  69. virtual void Shutdown();
  70. virtual bool CanQuit();
  71. virtual void OnToolActivate();
  72. virtual void OnToolDeactivate();
  73. virtual void ServerLevelInitPostEntity();
  74. virtual void DrawEntitiesInEngine( bool bDrawInEngine );
  75. virtual void ClientLevelInitPostEntity();
  76. virtual void ClientLevelShutdownPreEntity();
  77. virtual bool TrapKey( ButtonCode_t key, bool down );
  78. virtual void ClientPreRender();
  79. // Inherited from IFileMenuCallbacks
  80. virtual int GetFileMenuItemsEnabled( );
  81. virtual void AddRecentFilesToMenu( vgui::Menu *menu );
  82. virtual bool GetPerforceFileName( char *pFileName, int nMaxLen );
  83. // Inherited from IVcdBlockDocCallback
  84. virtual void OnDocChanged( const char *pReason, int nNotifySource, int nNotifyFlags );
  85. virtual vgui::Panel *GetRootPanel() { return this; }
  86. virtual void ShowEntityInEntityProperties( CDmeVMFEntity *pEntity );
  87. // Inherited from CBaseToolSystem
  88. virtual vgui::HScheme GetToolScheme();
  89. virtual vgui::Menu *CreateActionMenu( vgui::Panel *pParent );
  90. virtual void OnCommand( const char *cmd );
  91. virtual const char *GetRegistryName() { return "VcdBlockTool"; }
  92. virtual const char *GetBindingsContextFile() { return "cfg/VcdBlock.kb"; }
  93. virtual vgui::MenuBar *CreateMenuBar( CBaseToolSystem *pParent );
  94. MESSAGE_FUNC( Save, "OnSave" );
  95. void SaveAndTest();
  96. void RestartMap();
  97. // Enter mode where we preview dropping nodes
  98. void EnterTargetDropMode();
  99. void LeaveTargetDropMode();
  100. bool IsMiniViewportCursor( int x, int y, Vector &org, Vector &forward );
  101. // Save/Load game state
  102. void SetRememberPlayerPosition( bool state = true ) { m_bRememberPlayerPosition = state; };
  103. bool GetRememberPlayerPosition( void ) { return m_bRememberPlayerPosition; };
  104. void QuickLoad();
  105. void QuickSave();
  106. bool IsInNodeDrag( void ) { return m_bInNodeDragMode; };
  107. public:
  108. MESSAGE_FUNC( OnRestartLevel, "RestartLevel" );
  109. MESSAGE_FUNC( OnNew, "OnNew" );
  110. MESSAGE_FUNC( OnOpen, "OnOpen" );
  111. MESSAGE_FUNC( OnSaveAs, "OnSaveAs" );
  112. MESSAGE_FUNC( OnClose, "OnClose" );
  113. MESSAGE_FUNC( OnCloseNoSave, "OnCloseNoSave" );
  114. MESSAGE_FUNC( OnMarkNotDirty, "OnMarkNotDirty" );
  115. MESSAGE_FUNC( OnExit, "OnExit" );
  116. // Commands related to the edit menu
  117. void OnDescribeUndo();
  118. // Methods related to the VcdBlock menu
  119. MESSAGE_FUNC( OnAddNewNodes, "AddNewNodes" );
  120. MESSAGE_FUNC( OnCopyEditsToVMF, "CopyEditsToVMF" );
  121. MESSAGE_FUNC( OnRememberPosition, "RememberPosition" );
  122. // Methods related to the view menu
  123. MESSAGE_FUNC( OnToggleProperties, "OnToggleProperties" );
  124. MESSAGE_FUNC( OnToggleEntityReport, "OnToggleEntityReport" );
  125. MESSAGE_FUNC( OnDefaultLayout, "OnDefaultLayout" );
  126. // Keybindings
  127. KEYBINDING_FUNC( undo, KEY_Z, vgui::MODIFIER_CONTROL, OnUndo, "#undo_help", 0 );
  128. KEYBINDING_FUNC( redo, KEY_Z, vgui::MODIFIER_CONTROL | vgui::MODIFIER_SHIFT, OnRedo, "#redo_help", 0 );
  129. KEYBINDING_FUNC_NODECLARE( VcdBlockAddNewNodes, KEY_A, vgui::MODIFIER_CONTROL, OnAddNewNodes, "#VcdBlockAddNewNodesHelp", 0 );
  130. void OpenFileFromHistory( int slot );
  131. void OpenSpecificFile( const char *pFileName );
  132. virtual void SetupFileOpenDialog( vgui::FileOpenDialog *pDialog, bool bOpenFile, const char *pFileFormat, KeyValues *pContextKeyValues );
  133. virtual bool OnReadFileFromDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  134. virtual bool OnWriteFileToDisk( const char *pFileName, const char *pFileFormat, KeyValues *pContextKeyValues );
  135. virtual void OnFileOperationCompleted( const char *pFileType, bool bWroteFile, vgui::FileOpenStateMachine::CompletionState_t state, KeyValues *pContextKeyValues );
  136. void AttachAllEngineEntities();
  137. // returns the document
  138. CVcdBlockDoc *GetDocument();
  139. // Gets at tool windows
  140. CInfoTargetPropertiesPanel *GetProperties();
  141. CInfoTargetBrowserPanel *GetInfoTargetBrowser();
  142. CDmeHandle< CDmeVMFEntity > GetCurrentEntity( void ) { return m_hCurrentEntity; }
  143. private:
  144. // Loads up a new document
  145. bool LoadDocument( const char *pDocName );
  146. // Updates the menu bar based on the current file
  147. void UpdateMenuBar( );
  148. // Shows element properties
  149. void ShowElementProperties( );
  150. virtual const char *GetLogoTextureName();
  151. // Creates, destroys tools
  152. void CreateTools( CVcdBlockDoc *doc );
  153. void DestroyTools();
  154. // Initializes the tools
  155. void InitTools();
  156. // Shows, toggles tool windows
  157. void ToggleToolWindow( Panel *tool, char const *toolName );
  158. void ShowToolWindow( Panel *tool, char const *toolName, bool visible );
  159. // Kills all tool windows
  160. void DestroyToolContainers();
  161. // Gets the position of the preview object
  162. void GetPlacementInfo( Vector &vecOrigin, QAngle &angles );
  163. private:
  164. // Document
  165. CVcdBlockDoc *m_pDoc;
  166. // The menu bar
  167. CToolFileMenuBar *m_pMenuBar;
  168. // Element properties for editing material
  169. vgui::DHANDLE< CInfoTargetPropertiesPanel > m_hProperties;
  170. // The entity report
  171. vgui::DHANDLE< CInfoTargetBrowserPanel > m_hInfoTargetBrowser;
  172. // The currently viewed entity
  173. CDmeHandle< CDmeVMFEntity > m_hCurrentEntity;
  174. // Separate undo context for the act busy tool
  175. bool m_bInNodeDropMode;
  176. bool m_bInNodeDragMode;
  177. int m_iDragX;
  178. int m_iDragY;
  179. CDmeHandle< CDmeVMFEntity > m_hPreviewTarget;
  180. CToolWindowFactory< ToolWindow > m_ToolWindowFactory;
  181. // remembered player position
  182. bool m_bRememberPlayerPosition;
  183. bool m_bHasPlayerPosition;
  184. Vector m_vecPlayerOrigin;
  185. QAngle m_vecPlayerAngles;
  186. };
  187. extern CVcdBlockTool *g_pVcdBlockTool;
  188. #endif // VCDBLOCKTOOL_H