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.

233 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "tier1/utlvector.h"
  7. #include "tier1/convar.h"
  8. #include "icvar.h"
  9. #include "toolframework/itoolsystem.h"
  10. #include "toolframework/itooldictionary.h"
  11. #include "toolframework/ienginetool.h"
  12. #include "toolutils/enginetools_int.h"
  13. #include "ienginevgui.h"
  14. #include "icvar.h"
  15. #include "toolutils/vgui_tools.h"
  16. #include "mathlib/mathlib.h"
  17. #include "iregistry.h"
  18. #include "datamodel/idatamodel.h"
  19. #include "filesystem.h"
  20. #include "p4lib/ip4.h"
  21. #include "engine/ivdebugoverlay.h"
  22. #include "tier3/tier3dm.h"
  23. #include "datamodel/dmelementfactoryhelper.h"
  24. #include "dmserializers/idmserializers.h"
  25. //-----------------------------------------------------------------------------
  26. // Singleton interfaces
  27. //-----------------------------------------------------------------------------
  28. IEngineTool *enginetools = NULL;
  29. IEngineVGui *enginevgui = NULL;
  30. IFileSystem *g_pFileSystem = NULL;
  31. IVDebugOverlay *debugoverlay = NULL;
  32. //-----------------------------------------------------------------------------
  33. // Assumed to be implemented within the specific tool DLL
  34. //-----------------------------------------------------------------------------
  35. bool ConnectTools( CreateInterfaceFn factory );
  36. void CreateTools( );
  37. void DisconnectTools( );
  38. //-----------------------------------------------------------------------------
  39. // Purpose:
  40. //-----------------------------------------------------------------------------
  41. void VGUI_CreateToolRootPanel( void )
  42. {
  43. // Just using PANEL_GAMEDLL in HL2 right now
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose:
  47. //-----------------------------------------------------------------------------
  48. void VGUI_DestroyToolRootPanel( void )
  49. {
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Global accessors for root tool panels
  53. //-----------------------------------------------------------------------------
  54. vgui::VPANEL VGui_GetToolRootPanel( void )
  55. {
  56. vgui::VPANEL root = enginevgui->GetPanel( PANEL_GAMEDLL );
  57. return root;
  58. }
  59. vgui::VPANEL VGui_GetRootPanel( void )
  60. {
  61. vgui::VPANEL root = enginevgui->GetPanel( PANEL_ROOT );
  62. return root;
  63. }
  64. //-----------------------------------------------------------------------------
  65. // Implementation of IToolDictionary
  66. //-----------------------------------------------------------------------------
  67. class CToolDictionary : public CTier3DmAppSystem< IToolDictionary >
  68. {
  69. typedef CTier3DmAppSystem< IToolDictionary > BaseClass;
  70. public:
  71. CToolDictionary();
  72. // Inherited from IAppSystem
  73. virtual bool Connect( CreateInterfaceFn factory );
  74. virtual void Disconnect();
  75. virtual void *QueryInterface( const char *pInterfaceName );
  76. virtual InitReturnVal_t Init();
  77. virtual void Shutdown();
  78. // Inherited from IToolDictionary
  79. virtual void CreateTools();
  80. virtual int GetToolCount() const;
  81. virtual IToolSystem *GetTool( int index );
  82. public:
  83. void RegisterTool( IToolSystem *tool );
  84. private:
  85. CUtlVector< IToolSystem * > m_Tools;
  86. };
  87. //-----------------------------------------------------------------------------
  88. // Singleton interface for tools
  89. //-----------------------------------------------------------------------------
  90. static CToolDictionary g_ToolDictionary;
  91. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CToolDictionary, IToolDictionary, VTOOLDICTIONARY_INTERFACE_VERSION, g_ToolDictionary );
  92. //-----------------------------------------------------------------------------
  93. // Constructor
  94. //-----------------------------------------------------------------------------
  95. CToolDictionary::CToolDictionary()
  96. {
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Inherited from IAppSystem
  100. //-----------------------------------------------------------------------------
  101. bool CToolDictionary::Connect( CreateInterfaceFn factory )
  102. {
  103. if ( !BaseClass::Connect( factory ) )
  104. return false;
  105. // FIXME: This interface pointer is taken care of in tier2 + tier1
  106. g_pFileSystem = g_pFullFileSystem;
  107. enginevgui = ( IEngineVGui * )factory( VENGINE_VGUI_VERSION, NULL );
  108. enginetools = ( IEngineTool * )factory( VENGINETOOL_INTERFACE_VERSION, NULL );
  109. debugoverlay = ( IVDebugOverlay * )factory( VDEBUG_OVERLAY_INTERFACE_VERSION, NULL );
  110. if ( !enginevgui || !debugoverlay || !g_pCVar || !enginetools || !g_pFileSystem )
  111. return false;
  112. if ( !VGui_Startup( factory ) )
  113. return false;
  114. return ConnectTools( factory );
  115. }
  116. void CToolDictionary::Disconnect()
  117. {
  118. DisconnectTools();
  119. enginevgui = NULL;
  120. enginetools = NULL;
  121. debugoverlay = NULL;
  122. g_pFileSystem = NULL;
  123. BaseClass::Disconnect( );
  124. }
  125. void *CToolDictionary::QueryInterface( const char *pInterfaceName )
  126. {
  127. if ( !V_strcmp( pInterfaceName, VTOOLDICTIONARY_INTERFACE_VERSION ) )
  128. return (IToolDictionary*)this;
  129. return NULL;
  130. }
  131. InitReturnVal_t CToolDictionary::Init()
  132. {
  133. InitReturnVal_t nRetVal = BaseClass::Init();
  134. if ( nRetVal != INIT_OK )
  135. return nRetVal;
  136. MathLib_Init( 2.2f, 2.2f, 0.0f, 2.0f );
  137. // Init registry
  138. if ( !registry->Init( "Source\\Tools" ) )
  139. {
  140. Warning( "registry->Init failed\n" );
  141. return INIT_FAILED;
  142. }
  143. // Re-enable this and VGui_Shutdown if we create root tool panels
  144. // VGui_PostInit();
  145. return INIT_OK;
  146. }
  147. void CToolDictionary::Shutdown()
  148. {
  149. // Re-enable this and VGui_PostInit if we create root tool panels
  150. VGui_Shutdown();
  151. registry->Shutdown();
  152. BaseClass::Shutdown();
  153. }
  154. //-----------------------------------------------------------------------------
  155. // Implementation of IToolDictionary methods
  156. //-----------------------------------------------------------------------------
  157. void CToolDictionary::CreateTools()
  158. {
  159. ::CreateTools( );
  160. }
  161. int CToolDictionary::GetToolCount() const
  162. {
  163. return m_Tools.Count();
  164. }
  165. IToolSystem *CToolDictionary::GetTool( int index )
  166. {
  167. if ( index < 0 || index >= m_Tools.Count() )
  168. {
  169. return NULL;
  170. }
  171. return m_Tools[ index ];
  172. }
  173. void CToolDictionary::RegisterTool( IToolSystem *tool )
  174. {
  175. m_Tools.AddToTail( tool );
  176. }
  177. //-----------------------------------------------------------------------------
  178. // Allows tools to install themselves into the dictionary
  179. //-----------------------------------------------------------------------------
  180. void RegisterTool( IToolSystem *tool )
  181. {
  182. g_ToolDictionary.RegisterTool( tool );
  183. }