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.

308 lines
7.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "vgui_int.h"
  9. #include "ienginevgui.h"
  10. #include "itextmessage.h"
  11. #include "vguicenterprint.h"
  12. #include "iloadingdisc.h"
  13. #include "ifpspanel.h"
  14. #include "imessagechars.h"
  15. #include "inetgraphpanel.h"
  16. #include "idebugoverlaypanel.h"
  17. #include <vgui/ISurface.h>
  18. #include <vgui/IVGui.h>
  19. #include <vgui/IInput.h>
  20. #include "tier0/vprof.h"
  21. #include "iclientmode.h"
  22. #include <vgui_controls/Panel.h>
  23. #include <KeyValues.h>
  24. #include "filesystem.h"
  25. #include "matsys_controls/matsyscontrols.h"
  26. #ifdef SIXENSE
  27. #include "sixense/in_sixense.h"
  28. #endif
  29. #if defined( TF_CLIENT_DLL )
  30. #include "tf_gamerules.h"
  31. #endif
  32. using namespace vgui;
  33. void MP3Player_Create( vgui::VPANEL parent );
  34. void MP3Player_Destroy();
  35. #include <vgui/IInputInternal.h>
  36. vgui::IInputInternal *g_InputInternal = NULL;
  37. #include <vgui_controls/Controls.h>
  38. // memdbgon must be the last include file in a .cpp file!!!
  39. #include "tier0/memdbgon.h"
  40. void GetVGUICursorPos( int& x, int& y )
  41. {
  42. vgui::input()->GetCursorPos(x, y);
  43. }
  44. void SetVGUICursorPos( int x, int y )
  45. {
  46. if ( !g_bTextMode )
  47. {
  48. vgui::input()->SetCursorPos(x, y);
  49. }
  50. }
  51. class CHudTextureHandleProperty : public vgui::IPanelAnimationPropertyConverter
  52. {
  53. public:
  54. virtual void GetData( Panel *panel, KeyValues *kv, PanelAnimationMapEntry *entry )
  55. {
  56. void *data = ( void * )( (*entry->m_pfnLookup)( panel ) );
  57. CHudTextureHandle *pHandle = ( CHudTextureHandle * )data;
  58. // lookup texture name for id
  59. if ( pHandle->Get() )
  60. {
  61. kv->SetString( entry->name(), pHandle->Get()->szShortName );
  62. }
  63. else
  64. {
  65. kv->SetString( entry->name(), "" );
  66. }
  67. }
  68. virtual void SetData( Panel *panel, KeyValues *kv, PanelAnimationMapEntry *entry )
  69. {
  70. void *data = ( void * )( (*entry->m_pfnLookup)( panel ) );
  71. CHudTextureHandle *pHandle = ( CHudTextureHandle * )data;
  72. const char *texturename = kv->GetString( entry->name() );
  73. if ( texturename && texturename[ 0 ] )
  74. {
  75. CHudTexture *currentTexture = gHUD.GetIcon( texturename );
  76. pHandle->Set( currentTexture );
  77. }
  78. else
  79. {
  80. pHandle->Set( NULL );
  81. }
  82. }
  83. virtual void InitFromDefault( Panel *panel, PanelAnimationMapEntry *entry )
  84. {
  85. void *data = ( void * )( (*entry->m_pfnLookup)( panel ) );
  86. CHudTextureHandle *pHandle = ( CHudTextureHandle * )data;
  87. const char *texturename = entry->defaultvalue();
  88. if ( texturename && texturename[ 0 ] )
  89. {
  90. CHudTexture *currentTexture = gHUD.GetIcon( texturename );
  91. pHandle->Set( currentTexture );
  92. }
  93. else
  94. {
  95. pHandle->Set( NULL );
  96. }
  97. }
  98. };
  99. static CHudTextureHandleProperty textureHandleConverter;
  100. static void VGui_VideoMode_AdjustForModeChange( void )
  101. {
  102. // Kill all our panels. We need to do this in case any of them
  103. // have pointers to objects (eg: iborders) that will get freed
  104. // when schemes get destroyed and recreated (eg: mode change).
  105. netgraphpanel->Destroy();
  106. debugoverlaypanel->Destroy();
  107. #if defined( TRACK_BLOCKING_IO )
  108. iopanel->Destroy();
  109. #endif
  110. fps->Destroy();
  111. messagechars->Destroy();
  112. loadingdisc->Destroy();
  113. // Recreate our panels.
  114. VPANEL gameToolParent = enginevgui->GetPanel( PANEL_CLIENTDLL_TOOLS );
  115. VPANEL toolParent = enginevgui->GetPanel( PANEL_TOOLS );
  116. #if defined( TRACK_BLOCKING_IO )
  117. VPANEL gameDLLPanel = enginevgui->GetPanel( PANEL_GAMEDLL );
  118. #endif
  119. loadingdisc->Create( gameToolParent );
  120. messagechars->Create( gameToolParent );
  121. // Debugging or related tool
  122. fps->Create( toolParent );
  123. #if defined( TRACK_BLOCKING_IO )
  124. iopanel->Create( gameDLLPanel );
  125. #endif
  126. netgraphpanel->Create( toolParent );
  127. debugoverlaypanel->Create( gameToolParent );
  128. }
  129. static void VGui_OneTimeInit()
  130. {
  131. static bool initialized = false;
  132. if ( initialized )
  133. return;
  134. initialized = true;
  135. vgui::Panel::AddPropertyConverter( "CHudTextureHandle", &textureHandleConverter );
  136. g_pMaterialSystem->AddModeChangeCallBack( &VGui_VideoMode_AdjustForModeChange );
  137. }
  138. bool VGui_Startup( CreateInterfaceFn appSystemFactory )
  139. {
  140. if ( !vgui::VGui_InitInterfacesList( "CLIENT", &appSystemFactory, 1 ) )
  141. return false;
  142. if ( !vgui::VGui_InitMatSysInterfacesList( "CLIENT", &appSystemFactory, 1 ) )
  143. return false;
  144. g_InputInternal = (IInputInternal *)appSystemFactory( VGUI_INPUTINTERNAL_INTERFACE_VERSION, NULL );
  145. if ( !g_InputInternal )
  146. {
  147. return false; // c_vguiscreen.cpp needs this!
  148. }
  149. VGui_OneTimeInit();
  150. // Create any root panels for .dll
  151. VGUI_CreateClientDLLRootPanel();
  152. // Make sure we have a panel
  153. VPANEL root = VGui_GetClientDLLRootPanel();
  154. if ( !root )
  155. {
  156. return false;
  157. }
  158. return true;
  159. }
  160. //-----------------------------------------------------------------------------
  161. // Purpose:
  162. //-----------------------------------------------------------------------------
  163. void VGui_CreateGlobalPanels( void )
  164. {
  165. VPANEL gameToolParent = enginevgui->GetPanel( PANEL_CLIENTDLL_TOOLS );
  166. VPANEL toolParent = enginevgui->GetPanel( PANEL_TOOLS );
  167. #if defined( TRACK_BLOCKING_IO )
  168. VPANEL gameDLLPanel = enginevgui->GetPanel( PANEL_GAMEDLL );
  169. #endif
  170. // Part of game
  171. internalCenterPrint->Create( gameToolParent );
  172. loadingdisc->Create( gameToolParent );
  173. messagechars->Create( gameToolParent );
  174. // Debugging or related tool
  175. fps->Create( toolParent );
  176. #if defined( TRACK_BLOCKING_IO )
  177. iopanel->Create( gameDLLPanel );
  178. #endif
  179. netgraphpanel->Create( toolParent );
  180. debugoverlaypanel->Create( gameToolParent );
  181. #ifndef _X360
  182. // Create mp3 player off of tool parent panel
  183. MP3Player_Create( toolParent );
  184. #endif
  185. #ifdef SIXENSE
  186. g_pSixenseInput->CreateGUI( gameToolParent );
  187. #endif
  188. }
  189. void VGui_Shutdown()
  190. {
  191. VGUI_DestroyClientDLLRootPanel();
  192. #ifndef _X360
  193. MP3Player_Destroy();
  194. #endif
  195. netgraphpanel->Destroy();
  196. debugoverlaypanel->Destroy();
  197. #if defined( TRACK_BLOCKING_IO )
  198. iopanel->Destroy();
  199. #endif
  200. fps->Destroy();
  201. messagechars->Destroy();
  202. loadingdisc->Destroy();
  203. internalCenterPrint->Destroy();
  204. if ( g_pClientMode )
  205. {
  206. g_pClientMode->VGui_Shutdown();
  207. }
  208. // Make sure anything "marked for deletion"
  209. // actually gets deleted before this dll goes away
  210. vgui::ivgui()->RunFrame();
  211. }
  212. static ConVar cl_showpausedimage( "cl_showpausedimage", "1", 0, "Show the 'Paused' image when game is paused." );
  213. //-----------------------------------------------------------------------------
  214. // Things to do before rendering vgui stuff...
  215. //-----------------------------------------------------------------------------
  216. void VGui_PreRender()
  217. {
  218. VPROF( "VGui_PreRender" );
  219. tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ );
  220. // 360 does not use these plaques
  221. if ( IsPC() )
  222. {
  223. loadingdisc->SetLoadingVisible( engine->IsDrawingLoadingImage() && !engine->IsPlayingDemo() );
  224. bool bShowPausedImage = !enginevgui->IsGameUIVisible() && cl_showpausedimage.GetBool() && engine->IsPaused() && !engine->IsTakingScreenshot() && !engine->IsPlayingDemo();
  225. #if !defined( TF_CLIENT_DLL )
  226. loadingdisc->SetPausedVisible( bShowPausedImage, engine->GetPausedExpireTime() );
  227. #else
  228. bShowPausedImage &= ( TFGameRules() && !TFGameRules()->IsInTraining() );
  229. loadingdisc->SetPausedVisible( bShowPausedImage, engine->GetPausedExpireTime() );
  230. #endif
  231. }
  232. }
  233. void VGui_PostRender()
  234. {
  235. }
  236. //-----------------------------------------------------------------------------
  237. // Purpose:
  238. // Input : cl_panelanimation -
  239. //-----------------------------------------------------------------------------
  240. CON_COMMAND( cl_panelanimation, "Shows panel animation variables: <panelname | blank for all panels>." )
  241. {
  242. if ( args.ArgC() == 2 )
  243. {
  244. PanelAnimationDumpVars( args[1] );
  245. }
  246. else
  247. {
  248. PanelAnimationDumpVars( NULL );
  249. }
  250. }
  251. void GetHudSize( int& w, int &h )
  252. {
  253. vgui::surface()->GetScreenSize( w, h );
  254. VPANEL hudParent = enginevgui->GetPanel( PANEL_CLIENTDLL );
  255. if ( hudParent )
  256. {
  257. vgui::ipanel()->GetSize( hudParent, w, h );
  258. }
  259. }