summaryrefslogtreecommitdiff
path: root/dedicated/vgui/vguihelpers.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /dedicated/vgui/vguihelpers.cpp
downloadarchived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.tar.xz
archived-source-engine-2018-hl2-src-3bf9df6b2785fa6d951086978a3e66f49427166a.zip
Diffstat (limited to 'dedicated/vgui/vguihelpers.cpp')
-rw-r--r--dedicated/vgui/vguihelpers.cpp187
1 files changed, 187 insertions, 0 deletions
diff --git a/dedicated/vgui/vguihelpers.cpp b/dedicated/vgui/vguihelpers.cpp
new file mode 100644
index 0000000..11cf33e
--- /dev/null
+++ b/dedicated/vgui/vguihelpers.cpp
@@ -0,0 +1,187 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//===========================================================================//
+#ifdef _WIN32
+#include <windows.h>
+#include <direct.h>
+
+// includes for the VGUI version
+#include <vgui_controls/Panel.h>
+#include <vgui_controls/Controls.h>
+#include <vgui/ISystem.h>
+#include <vgui/IVGui.h>
+#include <vgui/IPanel.h>
+#include "filesystem.h"
+#include <vgui/ILocalize.h>
+#include <vgui/IScheme.h>
+#include <vgui/ISurface.h>
+#include <IVGuiModule.h>
+
+#include "vgui/MainPanel.h"
+#include "IAdminServer.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+
+static CMainPanel *g_pMainPanel = NULL; // the main panel to show
+static CSysModule *g_hAdminServerModule;
+IAdminServer *g_pAdminServer = NULL;
+static IVGuiModule *g_pAdminVGuiModule = NULL;
+
+void* DedicatedFactory(const char *pName, int *pReturnCode);
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Starts up the VGUI system and loads the base panel
+//-----------------------------------------------------------------------------
+int StartVGUI( CreateInterfaceFn dedicatedFactory )
+{
+ // the "base dir" so we can scan mod name
+ g_pFullFileSystem->AddSearchPath(".", "MAIN");
+ // the main platform dir
+ g_pFullFileSystem->AddSearchPath( "platform", "PLATFORM", PATH_ADD_TO_HEAD);
+
+ vgui::ivgui()->SetSleep(false);
+
+ // find our configuration directory
+ char szConfigDir[512];
+ const char *steamPath = getenv("SteamInstallPath");
+ if (steamPath)
+ {
+ // put the config dir directly under steam
+ Q_snprintf(szConfigDir, sizeof(szConfigDir), "%s/config", steamPath);
+ }
+ else
+ {
+ // we're not running steam, so just put the config dir under the platform
+ Q_strncpy( szConfigDir, "platform/config", sizeof(szConfigDir));
+ }
+ g_pFullFileSystem->CreateDirHierarchy("config", "PLATFORM");
+ g_pFullFileSystem->AddSearchPath(szConfigDir, "CONFIG", PATH_ADD_TO_HEAD);
+
+ // initialize the user configuration file
+ vgui::system()->SetUserConfigFile("DedicatedServerDialogConfig.vdf", "CONFIG");
+
+ // Init the surface
+ g_pMainPanel = new CMainPanel( );
+ g_pMainPanel->SetVisible(true);
+
+ vgui::surface()->SetEmbeddedPanel(g_pMainPanel->GetVPanel());
+
+ // load the scheme
+ vgui::scheme()->LoadSchemeFromFile("Resource/SourceScheme.res", NULL);
+
+ // localization
+ g_pVGuiLocalize->AddFile( "Resource/platform_%language%.txt" );
+ g_pVGuiLocalize->AddFile( "Resource/vgui_%language%.txt" );
+ g_pVGuiLocalize->AddFile( "Admin/server_%language%.txt" );
+
+ // Start vgui
+ vgui::ivgui()->Start();
+
+ // load the module
+ g_pFullFileSystem->GetLocalCopy("bin/AdminServer.dll");
+ g_hAdminServerModule = g_pFullFileSystem->LoadModule("AdminServer");
+ Assert(g_hAdminServerModule != NULL);
+ CreateInterfaceFn adminFactory = NULL;
+
+ if (!g_hAdminServerModule)
+ {
+ vgui::ivgui()->DPrintf2("Admin Error: module version (Admin/AdminServer.dll, %s) invalid, not loading\n", IMANAGESERVER_INTERFACE_VERSION );
+ }
+ else
+ {
+ // make sure we get the right version
+ adminFactory = Sys_GetFactory(g_hAdminServerModule);
+ g_pAdminServer = (IAdminServer *)adminFactory(ADMINSERVER_INTERFACE_VERSION, NULL);
+ g_pAdminVGuiModule = (IVGuiModule *)adminFactory("VGuiModuleAdminServer001", NULL);
+ Assert(g_pAdminServer != NULL);
+ Assert(g_pAdminVGuiModule != NULL);
+ if (!g_pAdminServer || !g_pAdminVGuiModule)
+ {
+ vgui::ivgui()->DPrintf2("Admin Error: module version (Admin/AdminServer.dll, %s) invalid, not loading\n", IMANAGESERVER_INTERFACE_VERSION );
+ }
+ }
+
+ // finish initializing admin module
+ g_pAdminVGuiModule->Initialize( &dedicatedFactory, 1 );
+ g_pAdminVGuiModule->PostInitialize(&adminFactory, 1);
+ g_pAdminVGuiModule->SetParent( g_pMainPanel->GetVPanel() );
+
+ // finish setting up main panel
+ g_pMainPanel->Initialize( );
+ g_pMainPanel->Open();
+
+ return 0;
+}
+
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Shuts down the VGUI system
+//-----------------------------------------------------------------------------
+void StopVGUI()
+{
+ SetEvent(g_pMainPanel->GetShutdownHandle());
+
+ delete g_pMainPanel;
+ g_pMainPanel = NULL;
+
+ if (g_hAdminServerModule)
+ {
+ g_pAdminVGuiModule->Shutdown( );
+ Sys_UnloadModule(g_hAdminServerModule);
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Run a single VGUI frame
+//-----------------------------------------------------------------------------
+void RunVGUIFrame()
+{
+ vgui::ivgui()->RunFrame();
+}
+
+
+bool VGUIIsStopping()
+{
+ return g_pMainPanel->Stopping();
+}
+
+
+bool VGUIIsRunning()
+{
+ return vgui::ivgui()->IsRunning();
+}
+
+bool VGUIIsInConfig()
+{
+ return g_pMainPanel->IsInConfig();
+}
+
+void VGUIFinishedConfig()
+{
+ Assert( g_pMainPanel );
+ if(g_pMainPanel) // engine is loaded, pass the message on
+ {
+ SetEvent(g_pMainPanel->GetShutdownHandle());
+ }
+}
+
+void VGUIPrintf( const char *msg )
+{
+ if ( !g_pMainPanel || VGUIIsInConfig() || VGUIIsStopping() )
+ {
+ OutputDebugStringA( msg );
+ }
+ else if ( g_pMainPanel )
+ {
+ g_pMainPanel->AddConsoleText( msg );
+ }
+}
+
+#endif // _WIN32
+