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.

147 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #define NOWINRES
  7. #define NOSERVICE
  8. #define NOMCX
  9. #define NOIME
  10. #include <windows.h>
  11. #undef MessageBox
  12. #undef PostMessage
  13. #include "stdafx.h"
  14. #include "appframework/tier3app.h"
  15. #include "tier2/tier2.h"
  16. #include "inputsystem/iinputsystem.h"
  17. #include "vgui_controls/controls.h"
  18. // root panel
  19. vgui::Panel *g_pMainPanel = NULL;
  20. //-----------------------------------------------------------------------------
  21. // Purpose: Adds in any search paths
  22. //-----------------------------------------------------------------------------
  23. void AddFileSystemSearchPaths(const char *pszExeName)
  24. {
  25. // search locally first
  26. char pExeName[MAX_PATH];
  27. if ( ::GetModuleFileName( ( HINSTANCE )GetModuleHandle( NULL ), pExeName, sizeof(pExeName) ) )
  28. {
  29. char pPlatform[MAX_PATH];
  30. Q_StripFilename( pExeName );
  31. Q_snprintf( pPlatform, sizeof(pPlatform), "%s\\..\\platform", pExeName );
  32. g_pFullFileSystem->AddSearchPath( pExeName, "EXECUTABLE_PATH");
  33. g_pFullFileSystem->AddSearchPath( pPlatform, "PLATFORM");
  34. g_pFullFileSystem->AddSearchPath( pPlatform, "SKIN");
  35. }
  36. else
  37. {
  38. g_pFullFileSystem->AddSearchPath(".", "EXECUTABLE_PATH");
  39. g_pFullFileSystem->AddSearchPath("../platform/", "PLATFORM");
  40. g_pFullFileSystem->AddSearchPath("../platform/", "SKIN");
  41. }
  42. // add self as a pack file
  43. // g_pFullFileSystem->AddPackFile(pszExeName, "PLATFORM");
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose: Sets up the main vgui
  47. //-----------------------------------------------------------------------------
  48. bool InitializeVGui( )
  49. {
  50. // add in the search paths
  51. AddFileSystemSearchPaths(NULL);
  52. // Init the surface
  53. g_pMainPanel = new vgui::Panel(NULL, NULL);
  54. vgui::surface()->SetEmbeddedPanel( g_pMainPanel->GetVPanel() );
  55. // load the scheme
  56. g_pMainPanel->SetScheme( vgui::scheme()->LoadSchemeFromFile( "//PLATFORM/Resource/sourcescheme.res", "PLATFORM" ) );
  57. // localization
  58. g_pVGuiLocalize->AddFile( "Resource/platform_%language%.txt");
  59. g_pVGuiLocalize->AddFile( "Resource/vgui_%language%.txt");
  60. // configuration settings
  61. vgui::system()->SetUserConfigFile( "vp4config.txt", "EXECUTABLE_PATH" );
  62. // Start vgui
  63. vgui::ivgui()->Start();
  64. // finish setting up main panel
  65. vgui::SETUP_PANEL( g_pMainPanel );
  66. return true;
  67. }
  68. //-----------------------------------------------------------------------------
  69. // The application object
  70. //-----------------------------------------------------------------------------
  71. class CVP4App : public CVguiSteamApp
  72. {
  73. public:
  74. // Methods of IApplication
  75. virtual bool Create();
  76. virtual int Main();
  77. virtual void Destroy() {}
  78. };
  79. DEFINE_WINDOWED_STEAM_APPLICATION_OBJECT( CVP4App );
  80. //-----------------------------------------------------------------------------
  81. // The application object
  82. //-----------------------------------------------------------------------------
  83. bool CVP4App::Create()
  84. {
  85. AppSystemInfo_t appSystems[] =
  86. {
  87. { "inputsystem.dll", INPUTSYSTEM_INTERFACE_VERSION },
  88. { "vgui2.dll", VGUI_IVGUI_INTERFACE_VERSION },
  89. { "p4lib.dll", P4_INTERFACE_VERSION },
  90. { "", "" } // Required to terminate the list
  91. };
  92. return AddSystems( appSystems );
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Purpose: program entrypoint
  96. //-----------------------------------------------------------------------------
  97. int CVP4App::Main()
  98. {
  99. if ( !InitializeVGui( ) )
  100. {
  101. ::MessageBoxA( NULL, "Fatal Error: Could not initialize vgui.", "Steam - Fatal Error", MB_OK | MB_ICONERROR );
  102. return 0;
  103. }
  104. // open the wizard
  105. CVP4Dialog *dlg = SETUP_PANEL(new CVP4Dialog());
  106. dlg->SetParent(g_pMainPanel);
  107. dlg->Activate();
  108. // run vgui
  109. while (vgui::ivgui()->IsRunning())
  110. {
  111. vgui::ivgui()->RunFrame();
  112. }
  113. // save configuration
  114. vgui::system()->SaveUserConfigFile();
  115. // delete all the panels
  116. delete g_pMainPanel;
  117. return 0;
  118. }