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();
150 wxASSERT( sel != wxNOT_FOUND );
155 os_config_write_uint("Video", "AntiAlias", msaa);
157 os_config_write_uint("Video", "Fullscreen", m_Video_Fullscreen->IsChecked() ? 1 : 0);
158 os_config_write_uint("Video", "ShowFPS", m_Video_ShowFPS->IsChecked() ? 1 : 0);
161 void LauncherSetup::initTab_Audio(wxNotebook *parent)
163 unsigned int checked = 0;
164 ALint ver_major = 0, ver_minor = 0;
165 const ALCchar *ptr = NULL;
166 const char *conf_ptr = NULL;
167 bool audio_enabled = false;
169 alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &ver_major);
170 alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &ver_minor);
172 if ( (ver_major >= 1) && (ver_minor >= 1) ) {
173 audio_enabled = true;
176 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
178 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
182 wxStaticBoxSizer* sbSizer_playback = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Playback Device") ), wxVERTICAL );
184 m_Audio_PlaybackDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
185 sbSizer_playback->Add( m_Audio_PlaybackDevice, 0, wxALL|wxEXPAND, 5 );
187 bSizer->Add( sbSizer_playback, 0, wxALL|wxEXPAND, 5 );
189 m_Audio_PlaybackDevice->Append("<Default>");
190 m_Audio_PlaybackDevice->SetSelection(0);
192 conf_ptr = os_config_read_string("Audio", "PlaybackDevice", NULL);
195 if ( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE ) {
196 ptr = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
198 ptr = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
203 m_Audio_PlaybackDevice->Append(ptr);
205 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
206 unsigned int sel = m_Audio_PlaybackDevice->GetCount() - 1;
208 m_Audio_PlaybackDevice->SetSelection(sel);
213 ptr += strlen(ptr) + 1;
219 wxStaticBoxSizer* sbSizer_capture = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Capture Device") ), wxVERTICAL );
221 m_Audio_CaptureDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
222 sbSizer_capture->Add( m_Audio_CaptureDevice, 0, wxALL|wxEXPAND, 5 );
224 bSizer->Add( sbSizer_capture, 0, wxALL|wxEXPAND, 5 );
226 m_Audio_CaptureDevice->Append("<Default>");
227 m_Audio_CaptureDevice->SetSelection(0);
229 conf_ptr = os_config_read_string("Audio", "CaptureDevice", NULL);
232 ptr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
236 m_Audio_CaptureDevice->Append(ptr);
238 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
239 unsigned int sel = m_Audio_CaptureDevice->GetCount() - 1;
241 m_Audio_CaptureDevice->SetSelection(sel);
246 ptr += strlen(ptr) + 1;
252 m_Audio_EFX = new wxCheckBox( panel, wxID_ANY, wxT("EFX / EAX Reverb"), wxDefaultPosition, wxDefaultSize, 0 );
253 bSizer->Add( m_Audio_EFX, 0, wxALL, 5 );
255 checked = os_config_read_uint("Audio", "EFX", 0);
257 m_Audio_EFX->SetValue( (checked == 1) );
261 m_Audio_LauncherSounds = new wxCheckBox( panel, wxID_ANY, wxT("Enable Launcher Sounds"), wxDefaultPosition, wxDefaultSize, 0 );
262 bSizer->Add( m_Audio_LauncherSounds, 0, wxALL, 5 );
264 checked = os_config_read_uint("Audio", "LauncherSoundEnabled", 1);
266 m_Audio_LauncherSounds->SetValue( (checked == 1) );
270 panel->SetSizer( bSizer );
273 bSizer->Fit( panel );
275 parent->AddPage( panel, wxT("Audio"), false );
278 void LauncherSetup::saveTab_Audio()
282 value = m_Audio_PlaybackDevice->GetValue();
284 if ( value.IsSameAs( wxT("<Default>") ) ) {
285 os_config_write_string("Audio", "PlaybackDevice", "");
287 os_config_write_string("Audio", "PlaybackDevice", value.c_str());
290 value = m_Audio_CaptureDevice->GetValue();
292 if ( value.IsSameAs( wxT("<Default>") ) ) {
293 os_config_write_string("Audio", "CaptureDevice", "");
295 os_config_write_string("Audio", "CaptureDevice", value.c_str());
298 os_config_write_uint("Audio", "EFX", m_Audio_EFX->IsChecked() ? 1 : 0);
300 os_config_write_uint("Audio", "LauncherSoundEnabled", m_Audio_LauncherSounds->IsChecked() ? 1 : 0);
302 Launcher* parent = (Launcher*)GetParent();
303 parent->SndEnable( m_Audio_LauncherSounds->IsChecked() );
307 void LauncherSetup::initTab_Joystick(wxNotebook *parent)
309 unsigned int checked = 0;
310 const char *conf_ptr = NULL;
311 bool joystick_enabled = false;
313 if ( !SDL_InitSubSystem(SDL_INIT_JOYSTICK) ) {
314 joystick_enabled = true;
317 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
319 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
321 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Joystick") ), wxVERTICAL );
324 // 'current joystick'
325 m_Joystick_Device = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
326 sbSizer->Add( m_Joystick_Device, 0, wxALL|wxEXPAND, 5 );
328 m_Joystick_Device->Append( wxT("<Default>") );
329 m_Joystick_Device->SetSelection( 0 );
331 conf_ptr = os_config_read_string("Controls", "CurrentJoystick", NULL);
333 if (joystick_enabled) {
334 int num_sticks = SDL_NumJoysticks();
336 for (int i = 0; i < num_sticks; i++) {
337 const char *jname = SDL_JoystickNameForIndex(i);
340 m_Joystick_Device->Append(jname);
342 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, jname) ) {
343 unsigned int sel = m_Joystick_Device->GetCount() - 1;
345 m_Joystick_Device->SetSelection(sel);
352 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
355 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
358 m_Joystick_FF = new wxCheckBox( panel, wxID_ANY, wxT("Enable Force Feedback"), wxDefaultPosition, wxDefaultSize, 0 );
359 bSizer->Add( m_Joystick_FF, 0, wxALL|wxEXPAND, 5 );
361 checked = os_config_read_uint("Controls", "EnableJoystickFF", 0);
363 m_Joystick_FF->SetValue( (checked == 1) );
366 m_Joystick_Directional = new wxCheckBox( panel, wxID_ANY, wxT("Enable directional hit effect (Force Feedback)"), wxDefaultPosition, wxDefaultSize, 0 );
367 bSizer->Add( m_Joystick_Directional, 0, wxALL|wxEXPAND, 5 );
369 checked = os_config_read_uint("Controls", "EnableHitEffect", 0);
371 m_Joystick_Directional->SetValue( (checked == 1) );
374 panel->SetSizer( bSizer );
377 bSizer->Fit( panel );
379 parent->AddPage( panel, wxT("Joystick"), false );
382 void LauncherSetup::saveTab_Joystick()
386 value = m_Joystick_Device->GetValue();
388 if ( value.IsSameAs( wxT("<Default>") ) ) {
389 os_config_write_string("Controls", "CurrentJoystick", "");
391 os_config_write_string("Controls", "CurrentJoystick", value.c_str());
394 os_config_write_uint("Controls", "EnableJoystickFF", m_Joystick_FF->IsChecked() ? 1 : 0);
395 os_config_write_uint("Controls", "EnableHitEffect", m_Joystick_Directional->IsChecked() ? 1 : 0);
398 void LauncherSetup::initTab_Speed(wxNotebook *parent)
400 unsigned int detail_lvl = 0;
402 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
404 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
407 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Default Detail Level") ), wxVERTICAL );
409 m_Speed_DefaultDetail = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN );
410 sbSizer->Add( m_Speed_DefaultDetail, 0, wxALL|wxEXPAND, 5 );
412 m_Speed_DefaultDetail->Append( wxT("Low") );
413 m_Speed_DefaultDetail->Append( wxT("Medium") );
414 m_Speed_DefaultDetail->Append( wxT("High") );
415 m_Speed_DefaultDetail->Append( wxT("Very High") );
417 detail_lvl = os_config_read_uint(NULL, "ComputerSpeed", 2);
419 if (detail_lvl > 3) {
423 m_Speed_DefaultDetail->SetSelection(detail_lvl);
426 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
428 panel->SetSizer( bSizer );
431 bSizer->Fit( panel );
433 parent->AddPage( panel, wxT("Speed"), false );
436 void LauncherSetup::saveTab_Speed()
440 sel = m_Speed_DefaultDetail->GetSelection();
442 if ( (sel < 0) || (sel > 3) ) {
446 os_config_write_uint(NULL, "ComputerSpeed", sel);
449 void LauncherSetup::initTab_Network(wxNotebook* parent)
451 const char *conf_ptr = NULL;
452 unsigned int val = 0;
454 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
456 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
459 const wxString conn_types[] = { wxT("None"), wxT("Dialup Networking"), wxT("LAN/Direct Connection") };
460 const int num_conn_types = sizeof( conn_types ) / sizeof( wxString );
461 m_Network_Connection = new wxRadioBox( panel, wxID_ANY, wxT("Internet Connection"), wxDefaultPosition, wxDefaultSize, num_conn_types, conn_types, 1, wxRA_SPECIFY_COLS );
462 bSizer->Add( m_Network_Connection, 0, wxALL|wxEXPAND, 5 );
464 conf_ptr = os_config_read_string("Network", "NetworkConnection", NULL);
468 if ( !SDL_strcasecmp(conf_ptr, "dialup") ) {
470 } else if ( !SDL_strcasecmp(conf_ptr, "lan") ) {
475 m_Network_Connection->SetSelection(val);
477 // 'connection speed'
478 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.") };
479 const int num_speed_types = sizeof( speed_types ) / sizeof( wxString );
480 m_Network_Speed = new wxRadioBox( panel, wxID_ANY, wxT("Connection Speed"), wxDefaultPosition, wxDefaultSize, num_speed_types, speed_types, 1, wxRA_SPECIFY_COLS );
481 bSizer->Add( m_Network_Speed, 0, wxALL|wxEXPAND, 5 );
483 conf_ptr = os_config_read_string("Network", "ConnectionSpeed", NULL);
487 if ( !SDL_strcasecmp(conf_ptr, "Slow") ) {
489 } else if ( !SDL_strcasecmp(conf_ptr, "56K") ) {
491 } else if ( !SDL_strcasecmp(conf_ptr, "ISDN") ) {
493 } else if ( !SDL_strcasecmp(conf_ptr, "Cable") ) {
495 } else if ( !SDL_strcasecmp(conf_ptr, "Fast") ) {
500 m_Network_Speed->SetSelection(val);
503 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Misc") ), wxVERTICAL );
505 wxFlexGridSizer* fgSizer_port = new wxFlexGridSizer( 0, 2, 0, 0 );
506 fgSizer_port->SetFlexibleDirection( wxBOTH );
507 fgSizer_port->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
510 wxStaticText* txt_port = new wxStaticText( panel, wxID_ANY, wxT("Force local port"), wxDefaultPosition, wxDefaultSize, 0 );
511 txt_port->Wrap( -1 );
512 fgSizer_port->Add( txt_port, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
514 m_Network_Port = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
515 fgSizer_port->Add( m_Network_Port, 0, wxALL|wxEXPAND, 5 );
517 wxIntegerValidator<unsigned short> vald( &m_port_validate );
519 m_Network_Port->SetValidator(vald);
521 sbSizer->Add( fgSizer_port, 1, wxEXPAND, 5 );
523 val = os_config_read_uint("Network", "ForcePort", 0);
526 wxString sval = wxString::Format( wxT("%u"), val );
528 m_Network_Port->SetValue(sval);
532 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
534 panel->SetSizer( bSizer );
537 bSizer->Fit( panel );
539 parent->AddPage( panel, wxT("Network"), false );
542 void LauncherSetup::saveTab_Network()
544 const char *conn_types[] = { "none", "dialup", "lan" };
545 const char *conn_speed[] = { "none", "Slow", "56K", "ISDN", "Cable", "Fast" };
549 sel = m_Network_Connection->GetSelection();
551 if ( (sel < 0) || (sel > 2) ) {
555 os_config_write_string("Network", "NetworkConnection", conn_types[sel]);
557 sel = m_Network_Speed->GetSelection();
559 if ( (sel < 0) || (sel > 5) ) {
563 os_config_write_string("Network", "ConnectionSpeed", conn_speed[sel]);
565 if ( !m_Network_Port->GetValue().IsEmpty() ) {
566 m_Network_Port->GetValue().ToLong(&port);
567 wxASSERT( port <= USHRT_MAX );
570 os_config_write_uint("Network", "ForcePort", (unsigned int)port);
573 void LauncherSetup::save_settings()
575 const char *ptr = NULL;
578 ptr = os_config_read_string(NULL, "Language", NULL);
581 os_config_write_string(NULL, "Language", ptr);
583 os_config_write_string(NULL, "Language", "");
586 ptr = os_config_read_string(NULL, "LastPlayer", NULL);
589 os_config_write_string(NULL, "LastPlayer", ptr);
591 os_config_write_string(NULL, "LastPlayer", "");
594 ptr = os_config_read_string(NULL, "ExtrasPath", NULL);
597 os_config_write_string(NULL, "ExtrasPath", ptr);
599 os_config_write_string(NULL, "ExtrasPath", "");
602 os_config_write_uint(NULL, "StraightToSetup", 0);
612 // 'Controls' section
619 void LauncherSetup::onOk(wxCommandEvent& WXUNUSED(event))
621 if ( Validate() && TransferDataFromWindow() ) {
627 SetReturnCode(wxID_OK);
633 void LauncherSetup::onToggleMSAA(wxCommandEvent& event)
635 if ( event.IsChecked() ) {
636 m_Video_MSAASamples->Enable();
638 if (m_Video_MSAASamples->GetSelection() == wxNOT_FOUND) {
639 m_Video_MSAASamples->SetSelection(0);
642 m_Video_MSAASamples->Disable();