]> icculus.org git repositories - taylor/freespace2.git/blob - src/launcher/launchersetup.cpp
use app name instead of title for prefs path
[taylor/freespace2.git] / src / launcher / launchersetup.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
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
6  * the source.
7  */
8
9 #include "SDL.h"
10
11 #include "launcher.h"
12 #include "launchersetup.h"
13 #include "osregistry.h"
14
15 #include "wx/valnum.h"
16
17
18 wxBEGIN_EVENT_TABLE(LauncherSetup, wxDialog)
19         EVT_BUTTON(wxID_OK, LauncherSetup::onOk)
20         EVT_CHECKBOX(ID_CB_MSAA, LauncherSetup::onToggleMSAA)
21 wxEND_EVENT_TABLE()
22
23
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 )
25 {
26         this->SetSizeHints( wxSize(370, -1), wxDefaultSize );
27
28
29         wxNotebook *nbook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
30
31         initTab_Video(nbook);
32         initTab_Audio(nbook);
33         initTab_Joystick(nbook);
34         initTab_Speed(nbook);
35         initTab_Network(nbook);
36
37         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
38         bSizer->Add( nbook, 0, wxALL|wxEXPAND, 5 );
39
40
41         wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
42         sdbSizer->AddButton( new wxButton(this, wxID_OK) );
43         sdbSizer->AddButton( new wxButton(this, wxID_CANCEL) );
44         sdbSizer->Realize();
45
46         bSizer->Add( sdbSizer, 0, wxALL|wxEXPAND, 5 );
47
48
49         this->SetSizer( bSizer );
50         this->Layout();
51         bSizer->Fit( this );
52
53
54         this->Centre( wxBOTH );
55 }
56
57 LauncherSetup::~LauncherSetup()
58 {
59 }
60
61 void LauncherSetup::initTab_Video(wxNotebook *parent)
62 {
63         unsigned int checked = 0;
64
65         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
66
67         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
68
69
70         // 'renderer'
71         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Renderer") ), wxVERTICAL );
72
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 );
75
76         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
77
78         m_Video_Renderer->Append( wxT("OpenGL") );
79         m_Video_Renderer->SetSelection( 0 );
80
81         // 'fullscreen'
82         m_Video_Fullscreen = new wxCheckBox( panel, wxID_ANY, wxT("Fullscreen"), wxDefaultPosition, wxDefaultSize, 0 );
83         bSizer->Add( m_Video_Fullscreen, 0, wxALL, 5 );
84
85         checked = os_config_read_uint("Video", "Fullscreen", 1);
86
87         m_Video_Fullscreen->SetValue( (checked == 1) );
88
89         // 'show fps'
90         m_Video_ShowFPS = new wxCheckBox( panel, wxID_ANY, wxT("Show FPS"), wxDefaultPosition, wxDefaultSize, 0 );
91         bSizer->Add( m_Video_ShowFPS, 0, wxALL, 5 );
92
93         checked = os_config_read_uint("Video", "ShowFPS", 0);
94
95         m_Video_ShowFPS->SetValue( (checked == 1) );
96
97         // 'anti-alias'
98         wxBoxSizer* bSizer_aa = new wxBoxSizer( wxHORIZONTAL );
99
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 );
102
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 );
107
108         bSizer->Add( bSizer_aa, 0, wxALL, 5 );
109
110         checked = os_config_read_uint("Video", "AntiAlias", 0);
111
112         if (checked) {
113                 m_Video_MSAA->SetValue(true);
114
115                 if (checked < 4) {
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);
121                 } else {
122                         m_Video_MSAASamples->SetSelection(3);
123                 }
124         } else {
125                 m_Video_MSAA->SetValue(false);
126                 m_Video_MSAASamples->SetSelection(wxNOT_FOUND);
127                 m_Video_MSAASamples->Disable();
128         }
129
130
131         panel->SetSizer( bSizer );
132         panel->Layout();
133
134         bSizer->Fit( panel );
135
136         parent->AddPage( panel, wxT("Video"), true );
137 }
138
139 void LauncherSetup::saveTab_Video()
140 {
141         wxString value;
142         unsigned int msaa = 0;
143
144         value = m_Video_Renderer->GetValue();
145
146         os_config_write_string("Video", "Renderer", value.c_str());
147
148         if ( m_Video_MSAA->IsChecked() ) {
149                 int sel = m_Video_MSAASamples->GetSelection();
150
151                 if ( (sel >= 0) && (sel < 4) ) {
152                         msaa = 2 << sel;
153                 }
154         }
155
156         os_config_write_uint("Video", "AntiAlias", msaa);
157
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);
160 }
161
162 void LauncherSetup::initTab_Audio(wxNotebook *parent)
163 {
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;
169
170         alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &ver_major);
171         alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &ver_minor);
172
173         if ( (ver_major >= 1) && (ver_minor >= 1) ) {
174                 audio_enabled = true;
175         }
176
177         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
178
179         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
180
181
182         // 'playback device'
183         wxStaticBoxSizer* sbSizer_playback = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Playback Device") ), wxVERTICAL );
184
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 );
187
188         bSizer->Add( sbSizer_playback, 0, wxALL|wxEXPAND, 5 );
189
190         m_Audio_PlaybackDevice->Append("<Default>");
191         m_Audio_PlaybackDevice->SetSelection(0);
192
193         conf_ptr = os_config_read_string("Audio", "PlaybackDevice", NULL);
194
195         if (audio_enabled) {
196                 if ( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE ) {
197                         ptr = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
198                 } else {
199                         ptr = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
200                 }
201
202                 if (ptr) {
203                         while (*ptr) {
204                                 m_Audio_PlaybackDevice->Append(ptr);
205
206                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
207                                         unsigned int sel = m_Audio_PlaybackDevice->GetCount() - 1;
208
209                                         m_Audio_PlaybackDevice->SetSelection(sel);
210
211                                         conf_ptr = NULL;
212                                 }
213
214                                 ptr += strlen(ptr) + 1;
215                         }
216                 }
217         }
218
219         // 'capture device'
220         wxStaticBoxSizer* sbSizer_capture = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Capture Device") ), wxVERTICAL );
221
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 );
224
225         bSizer->Add( sbSizer_capture, 0, wxALL|wxEXPAND, 5 );
226
227         m_Audio_CaptureDevice->Append("<Default>");
228         m_Audio_CaptureDevice->SetSelection(0);
229
230         conf_ptr = os_config_read_string("Audio", "CaptureDevice", NULL);
231
232         if (audio_enabled) {
233                 ptr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
234
235                 if (ptr) {
236                         while (*ptr) {
237                                 m_Audio_CaptureDevice->Append(ptr);
238
239                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
240                                         unsigned int sel = m_Audio_CaptureDevice->GetCount() - 1;
241
242                                         m_Audio_CaptureDevice->SetSelection(sel);
243
244                                         conf_ptr = NULL;
245                                 }
246
247                                 ptr += strlen(ptr) + 1;
248                         }
249                 }
250         }
251
252         // 'efx'
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 );
255
256         checked = os_config_read_uint("Audio", "EFX", 0);
257
258         m_Audio_EFX->SetValue( (checked == 1) );
259
260         // 'launcher sounds'
261 #ifndef MAKE_FS1
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 );
264
265         checked = os_config_read_uint("Audio", "LauncherSoundEnabled", 1);
266
267         m_Audio_LauncherSounds->SetValue( (checked == 1) );
268 #endif
269
270
271         panel->SetSizer( bSizer );
272         panel->Layout();
273
274         bSizer->Fit( panel );
275
276         parent->AddPage( panel, wxT("Audio"), false );
277 }
278
279 void LauncherSetup::saveTab_Audio()
280 {
281         wxString value;
282
283         value = m_Audio_PlaybackDevice->GetValue();
284
285         if ( value.IsSameAs( wxT("<Default>") ) ) {
286                 os_config_write_string("Audio", "PlaybackDevice", "");
287         } else {
288                 os_config_write_string("Audio", "PlaybackDevice", value.c_str());
289         }
290
291         value = m_Audio_CaptureDevice->GetValue();
292
293         if ( value.IsSameAs( wxT("<Default>") ) ) {
294                 os_config_write_string("Audio", "CaptureDevice", "");
295         } else {
296                 os_config_write_string("Audio", "CaptureDevice", value.c_str());
297         }
298
299         os_config_write_uint("Audio", "EFX", m_Audio_EFX->IsChecked() ? 1 : 0);
300 #ifndef MAKE_FS1
301         os_config_write_uint("Audio", "LauncherSoundEnabled", m_Audio_LauncherSounds->IsChecked() ? 1 : 0);
302
303         Launcher* parent = (Launcher*)GetParent();
304         parent->SndEnable( m_Audio_LauncherSounds->IsChecked() );
305 #endif
306 }
307
308 void LauncherSetup::initTab_Joystick(wxNotebook *parent)
309 {
310         unsigned int checked = 0;
311         const char *conf_ptr = NULL;
312         bool joystick_enabled = false;
313
314         if ( !SDL_InitSubSystem(SDL_INIT_JOYSTICK) ) {
315                 joystick_enabled = true;
316         }
317
318         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
319
320         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
321
322         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Joystick") ), wxVERTICAL );
323
324
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 );
328
329         m_Joystick_Device->Append( wxT("<Default>") );
330         m_Joystick_Device->SetSelection( 0 );
331
332         conf_ptr = os_config_read_string("Controls", "CurrentJoystick", NULL);
333
334         if (joystick_enabled) {
335                 int num_sticks = SDL_NumJoysticks();
336
337                 for (int i = 0; i < num_sticks; i++) {
338                         const char *jname = SDL_JoystickNameForIndex(i);
339
340                         if (jname) {
341                                 m_Joystick_Device->Append(jname);
342
343                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, jname) ) {
344                                         unsigned int sel = m_Joystick_Device->GetCount() - 1;
345
346                                         m_Joystick_Device->SetSelection(sel);
347
348                                         conf_ptr = NULL;
349                                 }
350                         }
351                 }
352
353                 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
354         }
355
356         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
357
358         // 'force feedback'
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 );
361
362         checked = os_config_read_uint("Controls", "EnableJoystickFF", 0);
363
364         m_Joystick_FF->SetValue( (checked == 1) );
365
366         // 'directional hit'
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 );
369
370         checked = os_config_read_uint("Controls", "EnableHitEffect", 0);
371
372         m_Joystick_Directional->SetValue( (checked == 1) );
373
374
375         panel->SetSizer( bSizer );
376         panel->Layout();
377
378         bSizer->Fit( panel );
379
380         parent->AddPage( panel, wxT("Joystick"), false );
381 }
382
383 void LauncherSetup::saveTab_Joystick()
384 {
385         wxString value;
386
387         value = m_Joystick_Device->GetValue();
388
389         if ( value.IsSameAs( wxT("<Default>") ) ) {
390                 os_config_write_string("Controls", "CurrentJoystick", "");
391         } else {
392                 os_config_write_string("Controls", "CurrentJoystick", value.c_str());
393         }
394
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);
397 }
398
399 void LauncherSetup::initTab_Speed(wxNotebook *parent)
400 {
401         unsigned int detail_lvl = 0;
402
403         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
404
405         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
406
407         // 'computer speed'
408         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Default Detail Level") ), wxVERTICAL );
409
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 );
412
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") );
417
418         detail_lvl = os_config_read_uint(NULL, "ComputerSpeed", 2);
419
420         if (detail_lvl > 3) {
421                 detail_lvl = 0;
422         }
423
424         m_Speed_DefaultDetail->SetSelection(detail_lvl);
425
426
427         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
428
429         panel->SetSizer( bSizer );
430         panel->Layout();
431
432         bSizer->Fit( panel );
433
434         parent->AddPage( panel, wxT("Speed"), false );
435 }
436
437 void LauncherSetup::saveTab_Speed()
438 {
439         int sel;
440
441         sel = m_Speed_DefaultDetail->GetSelection();
442
443         if ( (sel < 0) || (sel > 3) ) {
444                 sel = 0;
445         }
446
447         os_config_write_uint(NULL, "ComputerSpeed", sel);
448 }
449
450 void LauncherSetup::initTab_Network(wxNotebook* parent)
451 {
452         const char *conf_ptr = NULL;
453         unsigned int val = 0;
454
455         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
456
457         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
458
459         // 'connection type'
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 );
464
465         conf_ptr = os_config_read_string("Network", "NetworkConnection", NULL);
466         val = 0;
467
468         if (conf_ptr) {
469                 if ( !SDL_strcasecmp(conf_ptr, "dialup") ) {
470                         val = 1;
471                 } else if ( !SDL_strcasecmp(conf_ptr, "lan") ) {
472                         val = 2;
473                 }
474         }
475
476         m_Network_Connection->SetSelection(val);
477
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 );
483
484         conf_ptr = os_config_read_string("Network", "ConnectionSpeed", NULL);
485         val = 0;
486
487         if (conf_ptr) {
488                 if ( !SDL_strcasecmp(conf_ptr, "Slow") ) {
489                         val = 1;
490                 } else if ( !SDL_strcasecmp(conf_ptr, "56K") ) {
491                         val = 2;
492                 } else if ( !SDL_strcasecmp(conf_ptr, "ISDN") ) {
493                         val = 3;
494                 } else if ( !SDL_strcasecmp(conf_ptr, "Cable") ) {
495                         val = 4;
496                 } else if ( !SDL_strcasecmp(conf_ptr, "Fast") ) {
497                         val = 5;
498                 }
499         }
500
501         m_Network_Speed->SetSelection(val);
502
503
504         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Misc") ), wxVERTICAL );
505
506         wxFlexGridSizer* fgSizer_port = new wxFlexGridSizer( 0, 2, 0, 0 );
507         fgSizer_port->SetFlexibleDirection( wxBOTH );
508         fgSizer_port->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
509
510         // 'port'
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 );
514
515         m_Network_Port = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
516         fgSizer_port->Add( m_Network_Port, 0, wxALL|wxEXPAND, 5 );
517
518         m_port_validate = 0;
519         wxIntegerValidator<unsigned short> vald( &m_port_validate );
520         vald.SetStyle(wxNUM_VAL_ZERO_AS_BLANK);
521
522         m_Network_Port->SetValidator(vald);
523
524         sbSizer->Add( fgSizer_port, 1, wxEXPAND, 5 );
525
526         val = os_config_read_uint("Network", "ForcePort", 0);
527
528         if (val) {
529                 wxString sval = wxString::Format( wxT("%u"), val );
530
531                 m_Network_Port->SetValue(sval);
532         }
533
534
535         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
536
537         panel->SetSizer( bSizer );
538         panel->Layout();
539
540         bSizer->Fit( panel );
541
542         parent->AddPage( panel, wxT("Network"), false );
543 }
544
545 void LauncherSetup::saveTab_Network()
546 {
547         const char *conn_types[] = { "none", "dialup", "lan" };
548         const char *conn_speed[] = { "none", "Slow", "56K", "ISDN", "Cable", "Fast" };
549         int sel = 0;
550         long port = 0;
551
552         sel = m_Network_Connection->GetSelection();
553
554         if ( (sel < 0) || (sel > 2) ) {
555                 sel = 0;
556         }
557
558         os_config_write_string("Network", "NetworkConnection", conn_types[sel]);
559
560         sel = m_Network_Speed->GetSelection();
561
562         if ( (sel < 0) || (sel > 5) ) {
563                 sel = 0;
564         }
565
566         os_config_write_string("Network", "ConnectionSpeed", conn_speed[sel]);
567
568         if ( !m_Network_Port->GetValue().IsEmpty() ) {
569                 m_Network_Port->GetValue().ToLong(&port);
570                 wxASSERT( port <= USHRT_MAX );
571         }
572
573         os_config_write_uint("Network", "ForcePort", (unsigned int)port);
574 }
575
576 void LauncherSetup::save_settings()
577 {
578         const char *ptr = NULL;
579
580         // 'Default' section
581         ptr = os_config_read_string(NULL, "Language", NULL);
582
583         if (ptr) {
584                 os_config_write_string(NULL, "Language", ptr);
585         } else {
586                 os_config_write_string(NULL, "Language", "");
587         }
588
589         ptr = os_config_read_string(NULL, "LastPlayer", NULL);
590
591         if (ptr) {
592                 os_config_write_string(NULL, "LastPlayer", ptr);
593         } else {
594                 os_config_write_string(NULL, "LastPlayer", "");
595         }
596
597         ptr = os_config_read_string(NULL, "ExtrasPath", NULL);
598
599         if (ptr) {
600                 os_config_write_string(NULL, "ExtrasPath", ptr);
601         } else {
602                 os_config_write_string(NULL, "ExtrasPath", "");
603         }
604
605         os_config_write_uint(NULL, "StraightToSetup", 0);
606
607         saveTab_Speed();
608
609         // 'Video' section
610         saveTab_Video();
611
612         // 'Audio' section
613         saveTab_Audio();
614
615         // 'Controls' section
616         saveTab_Joystick();
617
618         // 'Network' section
619         saveTab_Network();
620 }
621
622 void LauncherSetup::onOk(wxCommandEvent& WXUNUSED(event))
623 {
624         if ( Validate() && TransferDataFromWindow() ) {
625                 save_settings();
626
627                 if ( IsModal() ) {
628                         EndModal(wxID_OK);
629                 } else {
630                         SetReturnCode(wxID_OK);
631                         Show(false);
632                 }
633         }
634 }
635
636 void LauncherSetup::onToggleMSAA(wxCommandEvent& event)
637 {
638         if ( event.IsChecked() ) {
639                 m_Video_MSAASamples->Enable();
640
641                 if (m_Video_MSAASamples->GetSelection() == wxNOT_FOUND) {
642                         m_Video_MSAASamples->SetSelection(0);
643                 }
644         } else {
645                 m_Video_MSAASamples->Disable();
646         }
647 }