2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
12 #include "launchersetup.h"
13 #include "osregistry.h"
15 #include "wx/valnum.h"
18 wxBEGIN_EVENT_TABLE(LauncherSetup, wxDialog)
19 EVT_BUTTON(wxID_OK, LauncherSetup::onOk)
20 EVT_CHECKBOX(ID_CB_MSAA, LauncherSetup::onToggleMSAA)
24 LauncherSetup::LauncherSetup( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
26 this->SetSizeHints( wxSize(370, -1), wxDefaultSize );
29 wxNotebook *nbook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
33 initTab_Joystick(nbook);
35 initTab_Network(nbook);
37 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
38 bSizer->Add( nbook, 0, wxALL|wxEXPAND, 5 );
41 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
42 sdbSizer->AddButton( new wxButton(this, wxID_OK) );
43 sdbSizer->AddButton( new wxButton(this, wxID_CANCEL) );
46 bSizer->Add( sdbSizer, 0, wxALL|wxEXPAND, 5 );
49 this->SetSizer( bSizer );
54 this->Centre( wxBOTH );
57 LauncherSetup::~LauncherSetup()
61 void LauncherSetup::initTab_Video(wxNotebook *parent)
63 unsigned int checked = 0;
65 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
67 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
71 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Renderer") ), wxVERTICAL );
73 m_Video_Renderer = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
74 sbSizer->Add( m_Video_Renderer, 1, wxALL|wxEXPAND, 5 );
76 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
78 m_Video_Renderer->Append( wxT("OpenGL") );
79 m_Video_Renderer->SetSelection( 0 );
82 m_Video_Fullscreen = new wxCheckBox( panel, wxID_ANY, wxT("Fullscreen"), wxDefaultPosition, wxDefaultSize, 0 );
83 bSizer->Add( m_Video_Fullscreen, 0, wxALL, 5 );
85 checked = os_config_read_uint("Video", "Fullscreen", 1);
87 m_Video_Fullscreen->SetValue( (checked == 1) );
90 m_Video_ShowFPS = new wxCheckBox( panel, wxID_ANY, wxT("Show FPS"), wxDefaultPosition, wxDefaultSize, 0 );
91 bSizer->Add( m_Video_ShowFPS, 0, wxALL, 5 );
93 checked = os_config_read_uint("Video", "ShowFPS", 0);
95 m_Video_ShowFPS->SetValue( (checked == 1) );
98 wxBoxSizer* bSizer_aa = new wxBoxSizer( wxHORIZONTAL );
100 m_Video_MSAA = new wxCheckBox( panel, ID_CB_MSAA, wxT("Anti-Alias"), wxDefaultPosition, wxDefaultSize, 0 );
101 bSizer_aa->Add( m_Video_MSAA, 0, wxALIGN_CENTER_VERTICAL, 5 );
103 const wxString msaa_samples[] = { wxT("2x"), wxT("4x"), wxT("8x"), wxT("16x") };
104 const int num_msaa_samples = sizeof( msaa_samples ) / sizeof( wxString );
105 m_Video_MSAASamples = new wxChoice( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, num_msaa_samples, msaa_samples, 0 );
106 bSizer_aa->Add( m_Video_MSAASamples, 0, wxLEFT, 15 );
108 bSizer->Add( bSizer_aa, 0, wxALL, 5 );
110 checked = os_config_read_uint("Video", "AntiAlias", 0);
113 m_Video_MSAA->SetValue(true);
116 m_Video_MSAASamples->SetSelection(0);
117 } else if (checked < 8) {
118 m_Video_MSAASamples->SetSelection(1);
119 } else if (checked < 16) {
120 m_Video_MSAASamples->SetSelection(2);
122 m_Video_MSAASamples->SetSelection(3);
125 m_Video_MSAA->SetValue(false);
126 m_Video_MSAASamples->SetSelection(wxNOT_FOUND);
127 m_Video_MSAASamples->Disable();
131 panel->SetSizer( bSizer );
134 bSizer->Fit( panel );
136 parent->AddPage( panel, wxT("Video"), true );
139 void LauncherSetup::saveTab_Video()
142 unsigned int msaa = 0;
144 value = m_Video_Renderer->GetValue();
146 os_config_write_string("Video", "Renderer", value.c_str());
148 if ( m_Video_MSAA->IsChecked() ) {
149 int sel = m_Video_MSAASamples->GetSelection();
151 if ( (sel >= 0) && (sel < 4) ) {
156 os_config_write_uint("Video", "AntiAlias", msaa);
158 os_config_write_uint("Video", "Fullscreen", m_Video_Fullscreen->IsChecked() ? 1 : 0);
159 os_config_write_uint("Video", "ShowFPS", m_Video_ShowFPS->IsChecked() ? 1 : 0);
162 void LauncherSetup::initTab_Audio(wxNotebook *parent)
164 unsigned int checked = 0;
165 ALint ver_major = 0, ver_minor = 0;
166 const ALCchar *ptr = NULL;
167 const char *conf_ptr = NULL;
168 bool audio_enabled = false;
170 alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &ver_major);
171 alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &ver_minor);
173 if ( (ver_major >= 1) && (ver_minor >= 1) ) {
174 audio_enabled = true;
177 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
179 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
183 wxStaticBoxSizer* sbSizer_playback = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Playback Device") ), wxVERTICAL );
185 m_Audio_PlaybackDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
186 sbSizer_playback->Add( m_Audio_PlaybackDevice, 0, wxALL|wxEXPAND, 5 );
188 bSizer->Add( sbSizer_playback, 0, wxALL|wxEXPAND, 5 );
190 m_Audio_PlaybackDevice->Append("<Default>");
191 m_Audio_PlaybackDevice->SetSelection(0);
193 conf_ptr = os_config_read_string("Audio", "PlaybackDevice", NULL);
196 if ( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE ) {
197 ptr = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
199 ptr = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
204 m_Audio_PlaybackDevice->Append(ptr);
206 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
207 unsigned int sel = m_Audio_PlaybackDevice->GetCount() - 1;
209 m_Audio_PlaybackDevice->SetSelection(sel);
214 ptr += strlen(ptr) + 1;
220 wxStaticBoxSizer* sbSizer_capture = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Capture Device") ), wxVERTICAL );
222 m_Audio_CaptureDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
223 sbSizer_capture->Add( m_Audio_CaptureDevice, 0, wxALL|wxEXPAND, 5 );
225 bSizer->Add( sbSizer_capture, 0, wxALL|wxEXPAND, 5 );
227 m_Audio_CaptureDevice->Append("<Default>");
228 m_Audio_CaptureDevice->SetSelection(0);
230 conf_ptr = os_config_read_string("Audio", "CaptureDevice", NULL);
233 ptr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
237 m_Audio_CaptureDevice->Append(ptr);
239 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
240 unsigned int sel = m_Audio_CaptureDevice->GetCount() - 1;
242 m_Audio_CaptureDevice->SetSelection(sel);
247 ptr += strlen(ptr) + 1;
253 m_Audio_EFX = new wxCheckBox( panel, wxID_ANY, wxT("EFX / EAX Reverb"), wxDefaultPosition, wxDefaultSize, 0 );
254 bSizer->Add( m_Audio_EFX, 0, wxALL, 5 );
256 checked = os_config_read_uint("Audio", "EFX", 0);
258 m_Audio_EFX->SetValue( (checked == 1) );
262 m_Audio_LauncherSounds = new wxCheckBox( panel, wxID_ANY, wxT("Enable Launcher Sounds"), wxDefaultPosition, wxDefaultSize, 0 );
263 bSizer->Add( m_Audio_LauncherSounds, 0, wxALL, 5 );
265 checked = os_config_read_uint("Audio", "LauncherSoundEnabled", 1);
267 m_Audio_LauncherSounds->SetValue( (checked == 1) );
271 panel->SetSizer( bSizer );
274 bSizer->Fit( panel );
276 parent->AddPage( panel, wxT("Audio"), false );
279 void LauncherSetup::saveTab_Audio()
283 value = m_Audio_PlaybackDevice->GetValue();
285 if ( value.IsSameAs( wxT("<Default>") ) ) {
286 os_config_write_string("Audio", "PlaybackDevice", "");
288 os_config_write_string("Audio", "PlaybackDevice", value.c_str());
291 value = m_Audio_CaptureDevice->GetValue();
293 if ( value.IsSameAs( wxT("<Default>") ) ) {
294 os_config_write_string("Audio", "CaptureDevice", "");
296 os_config_write_string("Audio", "CaptureDevice", value.c_str());
299 os_config_write_uint("Audio", "EFX", m_Audio_EFX->IsChecked() ? 1 : 0);
301 os_config_write_uint("Audio", "LauncherSoundEnabled", m_Audio_LauncherSounds->IsChecked() ? 1 : 0);
303 Launcher* parent = (Launcher*)GetParent();
304 parent->SndEnable( m_Audio_LauncherSounds->IsChecked() );
308 void LauncherSetup::initTab_Joystick(wxNotebook *parent)
310 unsigned int checked = 0;
311 const char *conf_ptr = NULL;
312 bool joystick_enabled = false;
314 if ( !SDL_InitSubSystem(SDL_INIT_JOYSTICK) ) {
315 joystick_enabled = true;
318 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
320 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
322 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Joystick") ), wxVERTICAL );
325 // 'current joystick'
326 m_Joystick_Device = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
327 sbSizer->Add( m_Joystick_Device, 0, wxALL|wxEXPAND, 5 );
329 m_Joystick_Device->Append( wxT("<Default>") );
330 m_Joystick_Device->SetSelection( 0 );
332 conf_ptr = os_config_read_string("Controls", "CurrentJoystick", NULL);
334 if (joystick_enabled) {
335 int num_sticks = SDL_NumJoysticks();
337 for (int i = 0; i < num_sticks; i++) {
338 const char *jname = SDL_JoystickNameForIndex(i);
341 m_Joystick_Device->Append(jname);
343 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, jname) ) {
344 unsigned int sel = m_Joystick_Device->GetCount() - 1;
346 m_Joystick_Device->SetSelection(sel);
353 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
356 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
359 m_Joystick_FF = new wxCheckBox( panel, wxID_ANY, wxT("Enable Force Feedback"), wxDefaultPosition, wxDefaultSize, 0 );
360 bSizer->Add( m_Joystick_FF, 0, wxALL|wxEXPAND, 5 );
362 checked = os_config_read_uint("Controls", "EnableJoystickFF", 0);
364 m_Joystick_FF->SetValue( (checked == 1) );
367 m_Joystick_Directional = new wxCheckBox( panel, wxID_ANY, wxT("Enable directional hit effect (Force Feedback)"), wxDefaultPosition, wxDefaultSize, 0 );
368 bSizer->Add( m_Joystick_Directional, 0, wxALL|wxEXPAND, 5 );
370 checked = os_config_read_uint("Controls", "EnableHitEffect", 0);
372 m_Joystick_Directional->SetValue( (checked == 1) );
375 panel->SetSizer( bSizer );
378 bSizer->Fit( panel );
380 parent->AddPage( panel, wxT("Joystick"), false );
383 void LauncherSetup::saveTab_Joystick()
387 value = m_Joystick_Device->GetValue();
389 if ( value.IsSameAs( wxT("<Default>") ) ) {
390 os_config_write_string("Controls", "CurrentJoystick", "");
392 os_config_write_string("Controls", "CurrentJoystick", value.c_str());
395 os_config_write_uint("Controls", "EnableJoystickFF", m_Joystick_FF->IsChecked() ? 1 : 0);
396 os_config_write_uint("Controls", "EnableHitEffect", m_Joystick_Directional->IsChecked() ? 1 : 0);
399 void LauncherSetup::initTab_Speed(wxNotebook *parent)
401 unsigned int detail_lvl = 0;
403 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
405 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
408 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Default Detail Level") ), wxVERTICAL );
410 m_Speed_DefaultDetail = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN );
411 sbSizer->Add( m_Speed_DefaultDetail, 0, wxALL|wxEXPAND, 5 );
413 m_Speed_DefaultDetail->Append( wxT("Low") );
414 m_Speed_DefaultDetail->Append( wxT("Medium") );
415 m_Speed_DefaultDetail->Append( wxT("High") );
416 m_Speed_DefaultDetail->Append( wxT("Very High") );
418 detail_lvl = os_config_read_uint(NULL, "ComputerSpeed", 2);
420 if (detail_lvl > 3) {
424 m_Speed_DefaultDetail->SetSelection(detail_lvl);
427 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
429 panel->SetSizer( bSizer );
432 bSizer->Fit( panel );
434 parent->AddPage( panel, wxT("Speed"), false );
437 void LauncherSetup::saveTab_Speed()
441 sel = m_Speed_DefaultDetail->GetSelection();
443 if ( (sel < 0) || (sel > 3) ) {
447 os_config_write_uint(NULL, "ComputerSpeed", sel);
450 void LauncherSetup::initTab_Network(wxNotebook* parent)
452 const char *conf_ptr = NULL;
453 unsigned int val = 0;
455 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
457 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
460 const wxString conn_types[] = { wxT("None"), wxT("Dialup Networking"), wxT("LAN/Direct Connection") };
461 const int num_conn_types = sizeof( conn_types ) / sizeof( wxString );
462 m_Network_Connection = new wxRadioBox( panel, wxID_ANY, wxT("Internet Connection"), wxDefaultPosition, wxDefaultSize, num_conn_types, conn_types, 1, wxRA_SPECIFY_COLS );
463 bSizer->Add( m_Network_Connection, 0, wxALL|wxEXPAND, 5 );
465 conf_ptr = os_config_read_string("Network", "NetworkConnection", NULL);
469 if ( !SDL_strcasecmp(conf_ptr, "dialup") ) {
471 } else if ( !SDL_strcasecmp(conf_ptr, "lan") ) {
476 m_Network_Connection->SetSelection(val);
478 // 'connection speed'
479 const wxString speed_types[] = { wxT("None Specified"), wxT("Slower than 56K Modem"), wxT("56K Modem"), wxT("Single Channel ISDN"), wxT("Dual Channel ISDN, Cable Modems"), wxT("T1, ADSL, T3, etc.") };
480 const int num_speed_types = sizeof( speed_types ) / sizeof( wxString );
481 m_Network_Speed = new wxRadioBox( panel, wxID_ANY, wxT("Connection Speed"), wxDefaultPosition, wxDefaultSize, num_speed_types, speed_types, 1, wxRA_SPECIFY_COLS );
482 bSizer->Add( m_Network_Speed, 0, wxALL|wxEXPAND, 5 );
484 conf_ptr = os_config_read_string("Network", "ConnectionSpeed", NULL);
488 if ( !SDL_strcasecmp(conf_ptr, "Slow") ) {
490 } else if ( !SDL_strcasecmp(conf_ptr, "56K") ) {
492 } else if ( !SDL_strcasecmp(conf_ptr, "ISDN") ) {
494 } else if ( !SDL_strcasecmp(conf_ptr, "Cable") ) {
496 } else if ( !SDL_strcasecmp(conf_ptr, "Fast") ) {
501 m_Network_Speed->SetSelection(val);
504 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Misc") ), wxVERTICAL );
506 wxFlexGridSizer* fgSizer_port = new wxFlexGridSizer( 0, 2, 0, 0 );
507 fgSizer_port->SetFlexibleDirection( wxBOTH );
508 fgSizer_port->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
511 wxStaticText* txt_port = new wxStaticText( panel, wxID_ANY, wxT("Force local port"), wxDefaultPosition, wxDefaultSize, 0 );
512 txt_port->Wrap( -1 );
513 fgSizer_port->Add( txt_port, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
515 m_Network_Port = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
516 fgSizer_port->Add( m_Network_Port, 0, wxALL|wxEXPAND, 5 );
518 wxIntegerValidator<unsigned short> vald( &m_port_validate );
520 m_Network_Port->SetValidator(vald);
522 sbSizer->Add( fgSizer_port, 1, wxEXPAND, 5 );
524 val = os_config_read_uint("Network", "ForcePort", 0);
527 wxString sval = wxString::Format( wxT("%u"), val );
529 m_Network_Port->SetValue(sval);
533 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
535 panel->SetSizer( bSizer );
538 bSizer->Fit( panel );
540 parent->AddPage( panel, wxT("Network"), false );
543 void LauncherSetup::saveTab_Network()
545 const char *conn_types[] = { "none", "dialup", "lan" };
546 const char *conn_speed[] = { "none", "Slow", "56K", "ISDN", "Cable", "Fast" };
550 sel = m_Network_Connection->GetSelection();
552 if ( (sel < 0) || (sel > 2) ) {
556 os_config_write_string("Network", "NetworkConnection", conn_types[sel]);
558 sel = m_Network_Speed->GetSelection();
560 if ( (sel < 0) || (sel > 5) ) {
564 os_config_write_string("Network", "ConnectionSpeed", conn_speed[sel]);
566 if ( !m_Network_Port->GetValue().IsEmpty() ) {
567 m_Network_Port->GetValue().ToLong(&port);
568 wxASSERT( port <= USHRT_MAX );
571 os_config_write_uint("Network", "ForcePort", (unsigned int)port);
574 void LauncherSetup::save_settings()
576 const char *ptr = NULL;
579 ptr = os_config_read_string(NULL, "Language", NULL);
582 os_config_write_string(NULL, "Language", ptr);
584 os_config_write_string(NULL, "Language", "");
587 ptr = os_config_read_string(NULL, "LastPlayer", NULL);
590 os_config_write_string(NULL, "LastPlayer", ptr);
592 os_config_write_string(NULL, "LastPlayer", "");
595 ptr = os_config_read_string(NULL, "ExtrasPath", NULL);
598 os_config_write_string(NULL, "ExtrasPath", ptr);
600 os_config_write_string(NULL, "ExtrasPath", "");
603 os_config_write_uint(NULL, "StraightToSetup", 0);
613 // 'Controls' section
620 void LauncherSetup::onOk(wxCommandEvent& WXUNUSED(event))
622 if ( Validate() && TransferDataFromWindow() ) {
628 SetReturnCode(wxID_OK);
634 void LauncherSetup::onToggleMSAA(wxCommandEvent& event)
636 if ( event.IsChecked() ) {
637 m_Video_MSAASamples->Enable();
639 if (m_Video_MSAASamples->GetSelection() == wxNOT_FOUND) {
640 m_Video_MSAASamples->SetSelection(0);
643 m_Video_MSAASamples->Disable();