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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Dialog for selecting game configurations
//
//=====================================================================================//
#include <windows.h>
#include <vgui/IVGui.h>
#include <vgui/IInput.h>
#include <vgui/ISystem.h>
#include <vgui_controls/ComboBox.h>
#include <vgui_controls/MessageBox.h>
#include <KeyValues.h>
#include "vconfig_main.h"
#include "VConfigDialog.h"
#include "ManageGamesDialog.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
CVConfigDialog *g_pVConfigDialog = NULL;
class CConversionInfoMessageBox : public vgui::Frame
{
public:
typedef vgui::Frame BaseClass;
CConversionInfoMessageBox( Panel *pParent, const char *pPanelName )
: BaseClass( pParent, pPanelName )
{
SetSize( 200, 200 );
SetMinimumSize( 250, 100 );
SetSizeable( false );
LoadControlSettings( "convinfobox.res" );
}
virtual void OnCommand( const char *command )
{
BaseClass::OnCommand( command );
// For some weird reason, this dialog can
if ( Q_stricmp( command, "ShowFAQ" ) == 0 )
{
system()->ShellExecute( "open", "http://www.valve-erc.com/srcsdk/faq.html#convertINI" );
}
}
};
class CModalPreserveMessageBox : public vgui::MessageBox
{
public:
CModalPreserveMessageBox(const char *title, const char *text, vgui::Panel *parent)
: vgui::MessageBox( title, text, parent )
{
m_PrevAppFocusPanel = vgui::input()->GetAppModalSurface();
}
~CModalPreserveMessageBox()
{
vgui::input()->SetAppModalSurface( m_PrevAppFocusPanel );
}
public:
vgui::VPANEL m_PrevAppFocusPanel;
};
//-----------------------------------------------------------------------------
// Purpose: Utility function to pop up a VGUI message box
//-----------------------------------------------------------------------------
void VGUIMessageBox( vgui::Panel *pParent, const char *pTitle, const char *pMsg, ... )
{
char msg[4096];
va_list marker;
va_start( marker, pMsg );
Q_vsnprintf( msg, sizeof( msg ), pMsg, marker );
va_end( marker );
vgui::MessageBox *dlg = new CModalPreserveMessageBox( pTitle, msg, pParent );
dlg->DoModal();
dlg->Activate();
dlg->RequestFocus();
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CVConfigDialog::CVConfigDialog( Panel *parent, const char *name ) : BaseClass( parent, name ), m_bChanged( false )
{
Assert( !g_pVConfigDialog );
g_pVConfigDialog = this;
SetSize(384, 420);
SetMinimumSize(200, 100);
SetMinimizeButtonVisible( true );
m_pConfigCombo = new ComboBox( this, "ConfigCombo", 8, false );
PopulateConfigList();
LoadControlSettings( "VConfigDialog.res" );
// See if we converted on load and notify
if ( g_ConfigManager.WasConvertedOnLoad() )
{
//VGUIMessageBox( this, "Update Occured", "Your game configurations have been updated.\n\nA backup file GameCfg.INI.OLD has been created.\n\nPlease visit http://www.valve-erc.com/srcsdk/faq.html#GameConfigUpdate for more information." );
CConversionInfoMessageBox *pDlg = new CConversionInfoMessageBox( this, "ConversionInfo" );
pDlg->RequestFocus();
pDlg->SetVisible( true );
pDlg->MoveToCenterOfScreen();
input()->SetAppModalSurface( pDlg->GetVPanel() );
}
}
//-----------------------------------------------------------------------------
// Destructor
//-----------------------------------------------------------------------------
CVConfigDialog::~CVConfigDialog()
{
delete m_pConfigCombo;
g_pVConfigDialog = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Populate the configuration list for selection
//-----------------------------------------------------------------------------
void CVConfigDialog::PopulateConfigList( bool bSelectActiveConfig /*=true*/ )
{
int activeItem = -1;
char szKeyValue[1024] = "\0";
if ( bSelectActiveConfig )
{
// Get the currently set game configuration
if ( GetVConfigRegistrySetting( GAMEDIR_TOKEN, szKeyValue, sizeof( szKeyValue ) ) == false )
{
//NOTE: We may want to pop an info dialog here if there was no initial VPROJECT setting
activeItem = 0;
}
}
else
{
activeItem = m_pConfigCombo->GetActiveItem();
}
// Purge all our items
m_pConfigCombo->DeleteAllItems();
KeyValues *kv = new KeyValues( "Items" );
// Add all configurations
for ( int i = 0; i < g_Configs.Count(); i++ )
{
// Set the text
kv->SetString( "ModDir", g_Configs[i]->m_ModDir.Base() );
// Add the item into the list
int index = m_pConfigCombo->AddItem( g_Configs[i]->m_Name.Base(), kv );
if ( bSelectActiveConfig )
{
if ( !Q_stricmp( g_Configs[i]->m_ModDir.Base(), szKeyValue ) )
{
activeItem = index;
}
}
}
// Make sure we have an active item
if ( activeItem < 0 )
{
// Give a warning if they have a mismatched directory!
VGUIMessageBox( this, "Invalid Game Directory", "The currently selected game directory: %s is invalid.\nChoose a new directory, or select 'Cancel' to exit.\n", szKeyValue );
// Default to the first config in the list
activeItem = 0;
}
// Set us to the active config
m_pConfigCombo->ActivateItem( activeItem );
kv->deleteThis();
}
//-----------------------------------------------------------------------------
// Purpose: Kills the whole app on close
//-----------------------------------------------------------------------------
void CVConfigDialog::OnClose( void )
{
BaseClass::OnClose();
ivgui()->Stop();
}
//-----------------------------------------------------------------------------
// Purpose: Select the item from the list (updating the environment variable as well)
// Input : index - item to select
//-----------------------------------------------------------------------------
void CVConfigDialog::SetGlobalConfig( const char *modDir )
{
// Set our environment variable
SetMayaScriptSettings( );
SetXSIScriptSettings( );
SetPathSettings( );
SetVConfigRegistrySetting( GAMEDIR_TOKEN, modDir );
}
//-----------------------------------------------------------------------------
// Purpose: Parse commands coming in from the VGUI dialog
//-----------------------------------------------------------------------------
void CVConfigDialog::OnCommand( const char *command )
{
if ( Q_stricmp( command, "Select" ) == 0 )
{
int activeID = m_pConfigCombo->GetActiveItem();
SetGlobalConfig( g_Configs[activeID]->m_ModDir.Base() );
// Save off our data
if ( m_bChanged )
{
SaveConfigs();
}
Close();
}
else if ( Q_stricmp( command, "Manage" ) == 0 )
{
int activeID = m_pConfigCombo->GetActiveItem();
// Launch the edit window
CManageGamesDialog *pDialog = new CManageGamesDialog( this, "ManageGamesDialog", activeID );
pDialog->AddActionSignalTarget( this );
pDialog->SetGameDir( g_Configs[activeID]->m_ModDir.Base() );
pDialog->SetGameName( g_Configs[activeID]->m_Name.Base() );
pDialog->DoModal();
}
else if ( Q_stricmp( command, "AddConfig" ) == 0 )
{
// Launch the edit window, specifying that we're adding a config
CManageGamesDialog *pDialog = new CManageGamesDialog( this, "ManageGamesDialog", NEW_CONFIG_ID );
pDialog->AddActionSignalTarget( this );
pDialog->DoModal();
}
else if ( Q_stricmp( command, "RemoveConfig" ) == 0 )
{
// Don't allow the list to completely vanish
// NOTE: We should display the list as being empty, i.e. "<EMPTY>"
if ( g_Configs.Count() <= 1 )
{
VGUIMessageBox( this, "Error", "Cannot remove last configuration from list!" );
return;
}
// Remove this config from our list
int activeID = m_pConfigCombo->GetActiveItem();
RemoveConfig( activeID );
ReloadConfigs( true );
// Select the next entry
m_pConfigCombo->ActivateItem( g_Configs.Count()-1 );
// Mark that we changed our configs
m_bChanged = true;
}
BaseClass::OnCommand( command );
}
//-----------------------------------------------------------------------------
// Purpose: Manage dialog has reported a need to update
//-----------------------------------------------------------------------------
void CVConfigDialog::OnManageSelect( void )
{
// Publish the config changes to the internal data in the configuration manager
UpdateConfigs();
// Update the configuration list
PopulateConfigList( false );
m_bChanged = true;
}
//-----------------------------------------------------------------------------
// Purpose: Manage dialog has reported that it has added a configuration
//-----------------------------------------------------------------------------
void CVConfigDialog::OnAddSelect( void )
{
// Add the last config we entered
AddConfig( g_Configs.Count()-1 );
// Re-populate the configuration list
ReloadConfigs();
// Select the last entry (which will be the new one)
m_pConfigCombo->ActivateItem( g_Configs.Count()-1 );
// Mark us as changed
m_bChanged = true;
}
|