5 #include "launchersetup.h"
6 #include "osregistry.h"
11 wxBEGIN_EVENT_TABLE(LauncherSetup, wxDialog)
12 EVT_BUTTON(wxID_OK, LauncherSetup::onOk)
13 EVT_CHECKBOX(ID_CB_MSAA, LauncherSetup::onToggleMSAA)
17 LauncherSetup::LauncherSetup( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
19 this->SetSizeHints( wxSize(370, -1), wxDefaultSize );
22 wxNotebook *nbook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
26 initTab_Joystick(nbook);
28 initTab_Network(nbook);
30 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
31 bSizer->Add( nbook, 0, wxALL|wxEXPAND, 5 );
34 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
35 sdbSizer->AddButton( new wxButton(this, wxID_OK) );
36 sdbSizer->AddButton( new wxButton(this, wxID_CANCEL) );
39 bSizer->Add( sdbSizer, 0, wxALL|wxEXPAND, 5 );
42 this->SetSizer( bSizer );
47 this->Centre( wxBOTH );
50 LauncherSetup::~LauncherSetup()
54 void LauncherSetup::initTab_Video(wxNotebook *parent)
56 unsigned int checked = 0;
58 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
60 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
64 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Renderer") ), wxVERTICAL );
66 m_Video_Renderer = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
67 sbSizer->Add( m_Video_Renderer, 1, wxALL|wxEXPAND, 5 );
69 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
71 m_Video_Renderer->Append( wxT("OpenGL") );
72 m_Video_Renderer->SetSelection( 0 );
75 m_Video_Fullscreen = new wxCheckBox( panel, wxID_ANY, wxT("Fullscreen"), wxDefaultPosition, wxDefaultSize, 0 );
76 bSizer->Add( m_Video_Fullscreen, 0, wxALL, 5 );
78 checked = os_config_read_uint("Video", "Fullscreen", 1);
80 m_Video_Fullscreen->SetValue( (checked == 1) );
83 m_Video_ShowFPS = new wxCheckBox( panel, wxID_ANY, wxT("Show FPS"), wxDefaultPosition, wxDefaultSize, 0 );
84 bSizer->Add( m_Video_ShowFPS, 0, wxALL, 5 );
86 checked = os_config_read_uint("Video", "ShowFPS", 0);
88 m_Video_ShowFPS->SetValue( (checked == 1) );
91 wxBoxSizer* bSizer_aa = new wxBoxSizer( wxHORIZONTAL );
93 m_Video_MSAA = new wxCheckBox( panel, ID_CB_MSAA, wxT("Anti-Alias"), wxDefaultPosition, wxDefaultSize, 0 );
94 bSizer_aa->Add( m_Video_MSAA, 0, wxALIGN_CENTER_VERTICAL, 5 );
96 const wxString msaa_samples[] = { wxT("2x"), wxT("4x"), wxT("8x"), wxT("16x") };
97 const int num_msaa_samples = sizeof( msaa_samples ) / sizeof( wxString );
98 m_Video_MSAASamples = new wxChoice( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, num_msaa_samples, msaa_samples, 0 );
99 bSizer_aa->Add( m_Video_MSAASamples, 0, wxLEFT, 15 );
101 bSizer->Add( bSizer_aa, 0, wxALL, 5 );
103 checked = os_config_read_uint("Video", "AntiAlias", 0);
106 m_Video_MSAA->SetValue(true);
109 m_Video_MSAASamples->SetSelection(0);
110 } else if (checked < 8) {
111 m_Video_MSAASamples->SetSelection(1);
112 } else if (checked < 16) {
113 m_Video_MSAASamples->SetSelection(2);
115 m_Video_MSAASamples->SetSelection(3);
118 m_Video_MSAA->SetValue(false);
119 m_Video_MSAASamples->SetSelection(wxNOT_FOUND);
120 m_Video_MSAASamples->Disable();
124 panel->SetSizer( bSizer );
127 bSizer->Fit( panel );
129 parent->AddPage( panel, wxT("Video"), true );
132 void LauncherSetup::saveTab_Video()
135 unsigned int msaa = 0;
137 value = m_Video_Renderer->GetValue();
139 os_config_write_string("Video", "Renderer", value.c_str());
141 if ( m_Video_MSAA->IsChecked() ) {
142 int sel = m_Video_MSAASamples->GetSelection();
143 wxASSERT( sel != wxNOT_FOUND );
148 os_config_write_uint("Video", "AntiAlias", msaa);
150 os_config_write_uint("Video", "Fullscreen", m_Video_Fullscreen->IsChecked() ? 1 : 0);
151 os_config_write_uint("Video", "ShowFPS", m_Video_ShowFPS->IsChecked() ? 1 : 0);
154 void LauncherSetup::initTab_Audio(wxNotebook *parent)
156 unsigned int checked = 0;
157 ALint ver_major = 0, ver_minor = 0;
158 const ALCchar *ptr = NULL;
159 const char *conf_ptr = NULL;
160 bool audio_enabled = false;
162 alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &ver_major);
163 alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &ver_minor);
165 if ( (ver_major >= 1) && (ver_minor >= 1) ) {
166 audio_enabled = true;
169 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
171 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
175 wxStaticBoxSizer* sbSizer_playback = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Playback Device") ), wxVERTICAL );
177 m_Audio_PlaybackDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
178 sbSizer_playback->Add( m_Audio_PlaybackDevice, 0, wxALL|wxEXPAND, 5 );
180 bSizer->Add( sbSizer_playback, 0, wxALL|wxEXPAND, 5 );
182 m_Audio_PlaybackDevice->Append("<Default>");
183 m_Audio_PlaybackDevice->SetSelection(0);
185 conf_ptr = os_config_read_string("Audio", "PlaybackDevice", NULL);
188 if ( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE ) {
189 ptr = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
191 ptr = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
196 m_Audio_PlaybackDevice->Append(ptr);
198 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
199 unsigned int sel = m_Audio_PlaybackDevice->GetCount() - 1;
201 m_Audio_PlaybackDevice->SetSelection(sel);
206 ptr += strlen(ptr) + 1;
212 wxStaticBoxSizer* sbSizer_capture = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Capture Device") ), wxVERTICAL );
214 m_Audio_CaptureDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
215 sbSizer_capture->Add( m_Audio_CaptureDevice, 0, wxALL|wxEXPAND, 5 );
217 bSizer->Add( sbSizer_capture, 0, wxALL|wxEXPAND, 5 );
219 m_Audio_CaptureDevice->Append("<Default>");
220 m_Audio_CaptureDevice->SetSelection(0);
222 conf_ptr = os_config_read_string("Audio", "CaptureDevice", NULL);
225 ptr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
229 m_Audio_CaptureDevice->Append(ptr);
231 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
232 unsigned int sel = m_Audio_CaptureDevice->GetCount() - 1;
234 m_Audio_CaptureDevice->SetSelection(sel);
239 ptr += strlen(ptr) + 1;
245 m_Audio_EFX = new wxCheckBox( panel, wxID_ANY, wxT("EFX / EAX Reverb"), wxDefaultPosition, wxDefaultSize, 0 );
246 bSizer->Add( m_Audio_EFX, 0, wxALL, 5 );
248 checked = os_config_read_uint("Audio", "EFX", 0);
250 m_Audio_EFX->SetValue( (checked == 1) );
254 m_Audio_LauncherSounds = new wxCheckBox( panel, wxID_ANY, wxT("Enable Launcher Sounds"), wxDefaultPosition, wxDefaultSize, 0 );
255 bSizer->Add( m_Audio_LauncherSounds, 0, wxALL, 5 );
257 checked = os_config_read_uint("Audio", "LauncherSoundEnabled", 1);
259 m_Audio_LauncherSounds->SetValue( (checked == 1) );
263 panel->SetSizer( bSizer );
266 bSizer->Fit( panel );
268 parent->AddPage( panel, wxT("Audio"), false );
271 void LauncherSetup::saveTab_Audio()
275 value = m_Audio_PlaybackDevice->GetValue();
277 if ( value.IsSameAs( wxT("<Default>") ) ) {
278 os_config_write_string("Audio", "PlaybackDevice", "");
280 os_config_write_string("Audio", "PlaybackDevice", value.c_str());
283 value = m_Audio_CaptureDevice->GetValue();
285 if ( value.IsSameAs( wxT("<Default>") ) ) {
286 os_config_write_string("Audio", "CaptureDevice", "");
288 os_config_write_string("Audio", "CaptureDevice", value.c_str());
291 os_config_write_uint("Audio", "EFX", m_Audio_EFX->IsChecked() ? 1 : 0);
293 os_config_write_uint("Audio", "LauncherSoundEnabled", m_Audio_LauncherSounds->IsChecked() ? 1 : 0);
295 Launcher* parent = (Launcher*)GetParent();
296 parent->SndEnable( m_Audio_LauncherSounds->IsChecked() );
300 void LauncherSetup::initTab_Joystick(wxNotebook *parent)
302 unsigned int checked = 0;
303 const char *conf_ptr = NULL;
304 bool joystick_enabled = false;
306 if ( !SDL_InitSubSystem(SDL_INIT_JOYSTICK) ) {
307 joystick_enabled = true;
310 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
312 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
314 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Joystick") ), wxVERTICAL );
317 // 'current joystick'
318 m_Joystick_Device = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
319 sbSizer->Add( m_Joystick_Device, 0, wxALL|wxEXPAND, 5 );
321 m_Joystick_Device->Append( wxT("<Default>") );
322 m_Joystick_Device->SetSelection( 0 );
324 conf_ptr = os_config_read_string("Controls", "CurrentJoystick", NULL);
326 if (joystick_enabled) {
327 int num_sticks = SDL_NumJoysticks();
329 for (int i = 0; i < num_sticks; i++) {
330 const char *jname = SDL_JoystickNameForIndex(i);
333 m_Joystick_Device->Append(jname);
335 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, jname) ) {
336 unsigned int sel = m_Joystick_Device->GetCount() - 1;
338 m_Joystick_Device->SetSelection(sel);
345 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
348 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
351 m_Joystick_FF = new wxCheckBox( panel, wxID_ANY, wxT("Enable Force Feedback"), wxDefaultPosition, wxDefaultSize, 0 );
352 bSizer->Add( m_Joystick_FF, 0, wxALL|wxEXPAND, 5 );
354 checked = os_config_read_uint("Controls", "EnableJoystickFF", 0);
356 m_Joystick_FF->SetValue( (checked == 1) );
359 m_Joystick_Directional = new wxCheckBox( panel, wxID_ANY, wxT("Enable directional hit effect (Force Feedback)"), wxDefaultPosition, wxDefaultSize, 0 );
360 bSizer->Add( m_Joystick_Directional, 0, wxALL|wxEXPAND, 5 );
362 checked = os_config_read_uint("Controls", "EnableHitEffect", 0);
364 m_Joystick_Directional->SetValue( (checked == 1) );
367 panel->SetSizer( bSizer );
370 bSizer->Fit( panel );
372 parent->AddPage( panel, wxT("Joystick"), false );
375 void LauncherSetup::saveTab_Joystick()
379 value = m_Joystick_Device->GetValue();
381 if ( value.IsSameAs( wxT("<Default>") ) ) {
382 os_config_write_string("Controls", "CurrentJoystick", "");
384 os_config_write_string("Controls", "CurrentJoystick", value.c_str());
387 os_config_write_uint("Controls", "EnableJoystickFF", m_Joystick_FF->IsChecked() ? 1 : 0);
388 os_config_write_uint("Controls", "EnableHitEffect", m_Joystick_Directional->IsChecked() ? 1 : 0);
391 void LauncherSetup::initTab_Speed(wxNotebook *parent)
393 unsigned int detail_lvl = 0;
395 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
397 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
400 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Default Detail Level") ), wxVERTICAL );
402 m_Speed_DefaultDetail = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN );
403 sbSizer->Add( m_Speed_DefaultDetail, 0, wxALL|wxEXPAND, 5 );
405 m_Speed_DefaultDetail->Append( wxT("Low") );
406 m_Speed_DefaultDetail->Append( wxT("Medium") );
407 m_Speed_DefaultDetail->Append( wxT("High") );
408 m_Speed_DefaultDetail->Append( wxT("Very High") );
410 detail_lvl = os_config_read_uint(NULL, "ComputerSpeed", 2);
412 if (detail_lvl > 3) {
416 m_Speed_DefaultDetail->SetSelection(detail_lvl);
419 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
421 panel->SetSizer( bSizer );
424 bSizer->Fit( panel );
426 parent->AddPage( panel, wxT("Speed"), false );
429 void LauncherSetup::saveTab_Speed()
433 sel = m_Speed_DefaultDetail->GetSelection();
435 if ( (sel < 0) || (sel > 3) ) {
439 os_config_write_uint(NULL, "ComputerSpeed", sel);
442 void LauncherSetup::initTab_Network(wxNotebook* parent)
444 const char *conf_ptr = NULL;
445 unsigned int val = 0;
447 wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
449 wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
452 const wxString conn_types[] = { wxT("None"), wxT("Dialup Networking"), wxT("LAN/Direct Connection") };
453 const int num_conn_types = sizeof( conn_types ) / sizeof( wxString );
454 m_Network_Connection = new wxRadioBox( panel, wxID_ANY, wxT("Internet Connection"), wxDefaultPosition, wxDefaultSize, num_conn_types, conn_types, 1, wxRA_SPECIFY_COLS|wxSTATIC_BORDER );
455 bSizer->Add( m_Network_Connection, 0, wxALL|wxEXPAND, 5 );
457 conf_ptr = os_config_read_string("Network", "NetworkConnection", NULL);
461 if ( !SDL_strcasecmp(conf_ptr, "dialup") ) {
463 } else if ( !SDL_strcasecmp(conf_ptr, "lan") ) {
468 m_Network_Connection->SetSelection(val);
470 // 'connection speed'
471 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.") };
472 const int num_speed_types = sizeof( speed_types ) / sizeof( wxString );
473 m_Network_Speed = new wxRadioBox( panel, wxID_ANY, wxT("Connection Speed"), wxDefaultPosition, wxDefaultSize, num_speed_types, speed_types, 1, wxRA_SPECIFY_COLS );
474 bSizer->Add( m_Network_Speed, 0, wxALL|wxEXPAND, 5 );
476 conf_ptr = os_config_read_string("Network", "ConnectionSpeed", NULL);
480 if ( !SDL_strcasecmp(conf_ptr, "Slow") ) {
482 } else if ( !SDL_strcasecmp(conf_ptr, "56K") ) {
484 } else if ( !SDL_strcasecmp(conf_ptr, "ISDN") ) {
486 } else if ( !SDL_strcasecmp(conf_ptr, "Cable") ) {
488 } else if ( !SDL_strcasecmp(conf_ptr, "Fast") ) {
493 m_Network_Speed->SetSelection(val);
496 wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Misc") ), wxVERTICAL );
498 wxFlexGridSizer* fgSizer_port = new wxFlexGridSizer( 0, 2, 0, 0 );
499 fgSizer_port->SetFlexibleDirection( wxBOTH );
500 fgSizer_port->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
503 wxStaticText* txt_port = new wxStaticText( panel, wxID_ANY, wxT("Force local port"), wxDefaultPosition, wxDefaultSize, 0 );
504 txt_port->Wrap( -1 );
505 fgSizer_port->Add( txt_port, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
507 m_Network_Port = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
508 fgSizer_port->Add( m_Network_Port, 0, wxALL|wxEXPAND, 5 );
510 wxIntegerValidator<unsigned short> vald( &m_port_validate );
512 m_Network_Port->SetValidator(vald);
514 sbSizer->Add( fgSizer_port, 1, wxEXPAND, 5 );
516 val = os_config_read_uint("Network", "ForcePort", 0);
519 wxString sval = wxString::Format( wxT("%u"), val );
521 m_Network_Port->SetValue(sval);
525 bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
527 panel->SetSizer( bSizer );
530 bSizer->Fit( panel );
532 parent->AddPage( panel, wxT("Network"), false );
535 void LauncherSetup::saveTab_Network()
537 const char *conn_types[] = { "none", "dialup", "lan" };
538 const char *conn_speed[] = { "none", "Slow", "56K", "ISDN", "Cable", "Fast" };
542 sel = m_Network_Connection->GetSelection();
544 if ( (sel < 0) || (sel > 2) ) {
548 os_config_write_string("Network", "NetworkConnection", conn_types[sel]);
550 sel = m_Network_Speed->GetSelection();
552 if ( (sel < 0) || (sel > 5) ) {
556 os_config_write_string("Network", "ConnectionSpeed", conn_speed[sel]);
558 if ( !m_Network_Port->GetValue().IsEmpty() ) {
559 m_Network_Port->GetValue().ToLong(&port);
560 wxASSERT( port <= USHRT_MAX );
563 os_config_write_uint("Network", "ForcePort", (unsigned int)port);
566 void LauncherSetup::save_settings()
568 const char *ptr = NULL;
571 ptr = os_config_read_string(NULL, "Language", NULL);
574 os_config_write_string(NULL, "Language", ptr);
576 os_config_write_string(NULL, "Language", "");
579 ptr = os_config_read_string(NULL, "LastPlayer", NULL);
582 os_config_write_string(NULL, "LastPlayer", ptr);
584 os_config_write_string(NULL, "LastPlayer", "");
587 ptr = os_config_read_string(NULL, "ExtrasPath", NULL);
590 os_config_write_string(NULL, "ExtrasPath", ptr);
592 os_config_write_string(NULL, "ExtrasPath", "");
595 os_config_write_uint(NULL, "StraightToSetup", 0);
605 // 'Controls' section
612 void LauncherSetup::onOk(wxCommandEvent& WXUNUSED(event))
614 if ( Validate() && TransferDataFromWindow() ) {
620 SetReturnCode(wxID_OK);
626 void LauncherSetup::onToggleMSAA(wxCommandEvent& event)
628 if ( event.IsChecked() ) {
629 m_Video_MSAASamples->Enable();
631 if (m_Video_MSAASamples->GetSelection() == wxNOT_FOUND) {
632 m_Video_MSAASamples->SetSelection(0);
635 m_Video_MSAASamples->Disable();