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.

236 lines
6.5 KiB

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