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.

160 lines
4.8 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 "vgui_rootpanel_tf.h"
  11. #include "vgui/IVGui.h"
  12. #include "tier2/fileutils.h"
  13. #include "icommandline.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. C_TFRootPanel *g_pRootPanel = NULL;
  17. static ConVar tf_ui_version( "tf_ui_version", "1", FCVAR_DEVELOPMENTONLY );
  18. extern const char *COM_GetModDirectory();
  19. void CheckCustomModSearchPaths()
  20. {
  21. const char *pszCustomPathID = "custom_mod";
  22. CUtlVector< CUtlString > searchPaths;
  23. GetSearchPath( searchPaths, pszCustomPathID );
  24. FOR_EACH_VEC( searchPaths, i )
  25. {
  26. const char *pszSearchPath = searchPaths[i].String();
  27. // check each path for version file
  28. char szVersionFile[MAX_PATH];
  29. V_ComposeFileName( pszSearchPath, "info.vdf", szVersionFile, sizeof( szVersionFile ) );
  30. KeyValuesAD versionKV( pszCustomPathID );
  31. if ( versionKV->LoadFromFile( g_pFullFileSystem, szVersionFile ) )
  32. {
  33. // mod must declare this ConVar
  34. if ( tf_ui_version.GetInt() == versionKV->GetInt( "ui_version" ) )
  35. {
  36. continue;
  37. }
  38. DevMsg( "'ui_version' mismatch. expected version %d. Removed search path '%s' from all pathIDs.\n", tf_ui_version.GetInt(), pszSearchPath );
  39. // remove from all path ids
  40. g_pFullFileSystem->RemoveSearchPath( pszSearchPath, pszCustomPathID );
  41. g_pFullFileSystem->RemoveSearchPath( pszSearchPath, "game" );
  42. g_pFullFileSystem->RemoveSearchPath( pszSearchPath, "mod" );
  43. }
  44. else
  45. {
  46. DevMsg( "missing 'info.vdf'. Removed search path '%s' from '%s' pathID.\n", pszSearchPath, pszCustomPathID );
  47. g_pFullFileSystem->RemoveSearchPath( pszSearchPath, pszCustomPathID );
  48. }
  49. }
  50. // only allow to load loose files when using insecure mode
  51. if ( CommandLine()->FindParm( "-insecure" ) )
  52. {
  53. // allow lose files in these search paths
  54. g_pFullFileSystem->AddSearchPath( "tf", "vgui" );
  55. g_pFullFileSystem->AddSearchPath( "hl2", "vgui" );
  56. g_pFullFileSystem->AddSearchPath( "platform", "vgui" );
  57. }
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Global functions.
  61. //-----------------------------------------------------------------------------
  62. void VGUI_CreateClientDLLRootPanel( void )
  63. {
  64. // do this before creating any vgui panels
  65. CheckCustomModSearchPaths();
  66. g_pRootPanel = new C_TFRootPanel( enginevgui->GetPanel( PANEL_CLIENTDLL ) );
  67. }
  68. void VGUI_DestroyClientDLLRootPanel( void )
  69. {
  70. g_pRootPanel->MarkForDeletion();
  71. g_pRootPanel = NULL;
  72. }
  73. vgui::VPANEL VGui_GetClientDLLRootPanel( void )
  74. {
  75. return g_pRootPanel->GetVPanel();
  76. }
  77. //-----------------------------------------------------------------------------
  78. // C_TFRootPanel implementation.
  79. //-----------------------------------------------------------------------------
  80. C_TFRootPanel::C_TFRootPanel( vgui::VPANEL parent )
  81. : BaseClass( NULL, "TF Root Panel" )
  82. {
  83. SetParent( parent );
  84. SetPaintEnabled( false );
  85. SetPaintBorderEnabled( false );
  86. SetPaintBackgroundEnabled( false );
  87. // This panel does post child painting
  88. SetPostChildPaintEnabled( true );
  89. // Make it screen sized
  90. SetBounds( 0, 0, ScreenWidth(), ScreenHeight() );
  91. // Ask for OnTick messages
  92. vgui::ivgui()->AddTickSignal( GetVPanel() );
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose:
  96. //-----------------------------------------------------------------------------
  97. C_TFRootPanel::~C_TFRootPanel( void )
  98. {
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Purpose:
  102. //-----------------------------------------------------------------------------
  103. void C_TFRootPanel::PostChildPaint()
  104. {
  105. BaseClass::PostChildPaint();
  106. // Draw all panel effects
  107. RenderPanelEffects();
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose: For each panel effect, check if it wants to draw and draw it on
  111. // this panel/surface if so
  112. //-----------------------------------------------------------------------------
  113. void C_TFRootPanel::RenderPanelEffects( void )
  114. {
  115. }
  116. //-----------------------------------------------------------------------------
  117. // Purpose:
  118. //-----------------------------------------------------------------------------
  119. void C_TFRootPanel::OnTick( void )
  120. {
  121. }
  122. //-----------------------------------------------------------------------------
  123. // Purpose: Reset effects on level load/shutdown
  124. //-----------------------------------------------------------------------------
  125. void C_TFRootPanel::LevelInit( void )
  126. {
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose:
  130. //-----------------------------------------------------------------------------
  131. void C_TFRootPanel::LevelShutdown( void )
  132. {
  133. }