summaryrefslogtreecommitdiff
path: root/utils/QCGenerator/main.cpp
blob: 67c30ddbaeef48522fcbfea727b042829abd0996 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Configuration utility
//
//===========================================================================//

#include <windows.h>
#include <io.h>
#include <stdio.h>

#include <vgui/ILocalize.h>
#include <vgui/ISurface.h>
#include <vgui/IVGui.h>
#include <vgui_controls/Panel.h>

#include "appframework/tier3app.h"
#include "tier0/icommandline.h"
#include "inputsystem/iinputsystem.h"
#include "matsys_controls/QCGenerator.h"
#include "filesystem_init.h"
#include "CQCGenMain.h"

// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>

#define QCGENERATOR_MAIN_PATH_ID	"MAIN"
#define QCGENERATOR_WRITE_PATH     "DEFAULT_WRITE_PATH"

CQCGenMain *g_pMainFrame = 0;

// Dummy window
static WNDCLASS staticWndclass = { NULL };
static ATOM staticWndclassAtom = 0;
static HWND staticHwnd = 0;

// List of our game configs, as read from the gameconfig.txt file
//HANDLE g_dwChangeHandle = NULL;

char pszPath[MAX_PATH];
char pszScene[MAX_PATH];

//-----------------------------------------------------------------------------
// Purpose: Copy a string into a CUtlVector of characters
//-----------------------------------------------------------------------------
void UtlStrcpy( CUtlVector<char> &dest, const char *pSrc )
{
	dest.EnsureCount( (int) (strlen( pSrc ) + 1) );
	Q_strncpy( dest.Base(), pSrc, dest.Count() );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : const char
//-----------------------------------------------------------------------------
const char *GetBaseDirectory( void )
{
	static char path[MAX_PATH] = {0};
	if ( path[0] == 0 )
	{
		GetModuleFileName( (HMODULE)GetAppInstance(), path, sizeof( path ) );
		Q_StripLastDir( path, sizeof( path ) );	// Get rid of the filename.
		Q_StripTrailingSlash( path );
	}
	return path;
}


//-----------------------------------------------------------------------------
// Purpose: Setup all our VGUI info
//-----------------------------------------------------------------------------
void InitializeVGUI( void )
{
	vgui::ivgui()->SetSleep(false);

	// Init the surface
	vgui::Panel *pPanel = new vgui::Panel( NULL, "TopPanel" );
	pPanel->SetVisible(true);

	vgui::surface()->SetEmbeddedPanel(pPanel->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( "QCGenerator_english.txt");

	// Start vgui
	vgui::ivgui()->Start();

	// add our main window
	g_pMainFrame = new CQCGenMain( pPanel, pszPath, pszScene, "CQCGenMain" );

	// show main window
	g_pMainFrame->MoveToCenterOfScreen();
	g_pMainFrame->Activate();
	g_pMainFrame->SetSizeable( true );
	g_pMainFrame->SetMenuButtonVisible( true );
}

//-----------------------------------------------------------------------------
// Purpose: Stop VGUI
//-----------------------------------------------------------------------------
void ShutdownVGUI( void )
{
	delete g_pMainFrame;
}


//-----------------------------------------------------------------------------
// The application object
//-----------------------------------------------------------------------------
class CQCGeneratorApp : public CVguiSteamApp
{
	typedef CVguiSteamApp BaseClass;

public:
	// Methods of IApplication
	virtual bool Create();
	virtual bool PreInit();
	virtual int Main();
	virtual void PostShutdown();
	virtual void Destroy() {}
};

DEFINE_WINDOWED_STEAM_APPLICATION_OBJECT( CQCGeneratorApp );


//-----------------------------------------------------------------------------
// The application object
//-----------------------------------------------------------------------------
bool CQCGeneratorApp::Create()
{
	AppSystemInfo_t appSystems[] = 
	{
		{ "inputsystem.dll",		INPUTSYSTEM_INTERFACE_VERSION },
		{ "vgui2.dll",				VGUI_IVGUI_INTERFACE_VERSION },
		{ "", "" }	// Required to terminate the list
	};

	return AddSystems( appSystems );
}


//-----------------------------------------------------------------------------
// Purpose: Entry point
//-----------------------------------------------------------------------------
bool CQCGeneratorApp::PreInit()
{
	if ( !BaseClass::PreInit() )
		return false;

	FileSystem_SetErrorMode( FS_ERRORMODE_AUTO );

	// We only want to use the gameinfo.txt that is in the bin\vconfig directory.
	char dirName[MAX_PATH];
	Q_strncpy( dirName, GetBaseDirectory(), sizeof( dirName ) );
	Q_AppendSlash( dirName, sizeof( dirName ) );
	Q_strncat( dirName, "QCGenerator", sizeof( dirName ), COPY_ALL_CHARACTERS );

	if ( !BaseClass::SetupSearchPaths( dirName, true, true ) )
	{
		::MessageBox( NULL, "Error", "Unable to initialize file system\n", MB_OK );
		return false;
	}

	// the "base dir" so we can scan mod name
	g_pFullFileSystem->AddSearchPath( GetBaseDirectory(), QCGENERATOR_MAIN_PATH_ID );	

	// the main platform dir
	g_pFullFileSystem->AddSearchPath( "platform", "PLATFORM", PATH_ADD_TO_HEAD );
	g_pFullFileSystem->AddSearchPath( ".\\QCGenerator\\", QCGENERATOR_WRITE_PATH, PATH_ADD_TO_HEAD );

	return true;
}


void CQCGeneratorApp::PostShutdown()
{
	BaseClass::PostShutdown();
}


//-----------------------------------------------------------------------------
// Purpose: Entry point
//-----------------------------------------------------------------------------
int CQCGeneratorApp::Main()
{
	if ( CommandLine()->ParmValue( "-path" ) )
	{
		Q_strcpy( pszPath, CommandLine()->ParmValue( "-path" ) );
	}
	else
	{
		::MessageBox( NULL, "Usage: QCGenerator.exe -path [path to smd files] -scene [name of scene]\n", "Error", MB_OK );
		return 0;
	}

	if ( CommandLine()->ParmValue( "-scene" ) )
	{
		Q_strcpy( pszScene, CommandLine()->ParmValue( "-scene" ) );
	}
	else
	{
		::MessageBox( NULL, "Usage: QCGenerator.exe -path [path to smd files] -scene [name of scene]\n",  "Error", MB_OK );
		return 0;
	}

	// Run app frame loop
	InitializeVGUI();

	// Run the app
	while (vgui::ivgui()->IsRunning())
	{
		Sleep( 10 );
		vgui::ivgui()->RunFrame();
	}

	ShutdownVGUI();

	return 1;
}