]> icculus.org git repositories - taylor/freespace2.git/blob - src/launcher/launchersetup.cpp
Merge branch 'sdl2'
[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                 wxASSERT( sel != wxNOT_FOUND );
151
152                 msaa = 2 << sel;
153         }
154
155         os_config_write_uint("Video", "AntiAlias", msaa);
156
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);
159 }
160
161 void LauncherSetup::initTab_Audio(wxNotebook *parent)
162 {
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;
168
169         alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &ver_major);
170         alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &ver_minor);
171
172         if ( (ver_major >= 1) && (ver_minor >= 1) ) {
173                 audio_enabled = true;
174         }
175
176         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
177
178         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
179
180
181         // 'playback device'
182         wxStaticBoxSizer* sbSizer_playback = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Playback Device") ), wxVERTICAL );
183
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 );
186
187         bSizer->Add( sbSizer_playback, 0, wxALL|wxEXPAND, 5 );
188
189         m_Audio_PlaybackDevice->Append("<Default>");
190         m_Audio_PlaybackDevice->SetSelection(0);
191
192         conf_ptr = os_config_read_string("Audio", "PlaybackDevice", NULL);
193
194         if (audio_enabled) {
195                 if ( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE ) {
196                         ptr = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
197                 } else {
198                         ptr = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
199                 }
200
201                 if (ptr) {
202                         while (*ptr) {
203                                 m_Audio_PlaybackDevice->Append(ptr);
204
205                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
206                                         unsigned int sel = m_Audio_PlaybackDevice->GetCount() - 1;
207
208                                         m_Audio_PlaybackDevice->SetSelection(sel);
209
210                                         conf_ptr = NULL;
211                                 }
212
213                                 ptr += strlen(ptr) + 1;
214                         }
215                 }
216         }
217
218         // 'capture device'
219         wxStaticBoxSizer* sbSizer_capture = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Capture Device") ), wxVERTICAL );
220
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 );
223
224         bSizer->Add( sbSizer_capture, 0, wxALL|wxEXPAND, 5 );
225
226         m_Audio_CaptureDevice->Append("<Default>");
227         m_Audio_CaptureDevice->SetSelection(0);
228
229         conf_ptr = os_config_read_string("Audio", "CaptureDevice", NULL);
230
231         if (audio_enabled) {
232                 ptr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
233
234                 if (ptr) {
235                         while (*ptr) {
236                                 m_Audio_CaptureDevice->Append(ptr);
237
238                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
239                                         unsigned int sel = m_Audio_CaptureDevice->GetCount() - 1;
240
241                                         m_Audio_CaptureDevice->SetSelection(sel);
242
243                                         conf_ptr = NULL;
244                                 }
245
246                                 ptr += strlen(ptr) + 1;
247                         }
248                 }
249         }
250
251         // 'efx'
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 );
254
255         checked = os_config_read_uint("Audio", "EFX", 0);
256
257         m_Audio_EFX->SetValue( (checked == 1) );
258
259         // 'launcher sounds'
260 #ifndef MAKE_FS1
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 );
263
264         checked = os_config_read_uint("Audio", "LauncherSoundEnabled", 1);
265
266         m_Audio_LauncherSounds->SetValue( (checked == 1) );
267 #endif
268
269
270         panel->SetSizer( bSizer );
271         panel->Layout();
272
273         bSizer->Fit( panel );
274
275         parent->AddPage( panel, wxT("Audio"), false );
276 }
277
278 void LauncherSetup::saveTab_Audio()
279 {
280         wxString value;
281
282         value = m_Audio_PlaybackDevice->GetValue();
283
284         if ( value.IsSameAs( wxT("<Default>") ) ) {
285                 os_config_write_string("Audio", "PlaybackDevice", "");
286         } else {
287                 os_config_write_string("Audio", "PlaybackDevice", value.c_str());
288         }
289
290         value = m_Audio_CaptureDevice->GetValue();
291
292         if ( value.IsSameAs( wxT("<Default>") ) ) {
293                 os_config_write_string("Audio", "CaptureDevice", "");
294         } else {
295                 os_config_write_string("Audio", "CaptureDevice", value.c_str());
296         }
297
298         os_config_write_uint("Audio", "EFX", m_Audio_EFX->IsChecked() ? 1 : 0);
299 #ifndef MAKE_FS1
300         os_config_write_uint("Audio", "LauncherSoundEnabled", m_Audio_LauncherSounds->IsChecked() ? 1 : 0);
301
302         Launcher* parent = (Launcher*)GetParent();
303         parent->SndEnable( m_Audio_LauncherSounds->IsChecked() );
304 #endif
305 }
306
307 void LauncherSetup::initTab_Joystick(wxNotebook *parent)
308 {
309         unsigned int checked = 0;
310         const char *conf_ptr = NULL;
311         bool joystick_enabled = false;
312
313         if ( !SDL_InitSubSystem(SDL_INIT_JOYSTICK) ) {
314                 joystick_enabled = true;
315         }
316
317         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
318
319         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
320
321         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Joystick") ), wxVERTICAL );
322
323
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 );
327
328         m_Joystick_Device->Append( wxT("<Default>") );
329         m_Joystick_Device->SetSelection( 0 );
330
331         conf_ptr = os_config_read_string("Controls", "CurrentJoystick", NULL);
332
333         if (joystick_enabled) {
334                 int num_sticks = SDL_NumJoysticks();
335
336                 for (int i = 0; i < num_sticks; i++) {
337                         const char *jname = SDL_JoystickNameForIndex(i);
338
339                         if (jname) {
340                                 m_Joystick_Device->Append(jname);
341
342                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, jname) ) {
343                                         unsigned int sel = m_Joystick_Device->GetCount() - 1;
344
345                                         m_Joystick_Device->SetSelection(sel);
346
347                                         conf_ptr = NULL;
348                                 }
349                         }
350                 }
351
352                 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
353         }
354
355         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
356
357         // 'force feedback'
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 );
360
361         checked = os_config_read_uint("Controls", "EnableJoystickFF", 0);
362
363         m_Joystick_FF->SetValue( (checked == 1) );
364
365         // 'directional hit'
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 );
368
369         checked = os_config_read_uint("Controls", "EnableHitEffect", 0);
370
371         m_Joystick_Directional->SetValue( (checked == 1) );
372
373
374         panel->SetSizer( bSizer );
375         panel->Layout();
376
377         bSizer->Fit( panel );
378
379         parent->AddPage( panel, wxT("Joystick"), false );
380 }
381
382 void LauncherSetup::saveTab_Joystick()
383 {
384         wxString value;
385
386         value = m_Joystick_Device->GetValue();
387
388         if ( value.IsSameAs( wxT("<Default>") ) ) {
389                 os_config_write_string("Controls", "CurrentJoystick", "");
390         } else {
391                 os_config_write_string("Controls", "CurrentJoystick", value.c_str());
392         }
393
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);
396 }
397
398 void LauncherSetup::initTab_Speed(wxNotebook *parent)
399 {
400         unsigned int detail_lvl = 0;
401
402         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
403
404         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
405
406         // 'computer speed'
407         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Default Detail Level") ), wxVERTICAL );
408
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 );
411
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") );
416
417         detail_lvl = os_config_read_uint(NULL, "ComputerSpeed", 2);
418
419         if (detail_lvl > 3) {
420                 detail_lvl = 0;
421         }
422
423         m_Speed_DefaultDetail->SetSelection(detail_lvl);
424
425
426         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
427
428         panel->SetSizer( bSizer );
429         panel->Layout();
430
431         bSizer->Fit( panel );
432
433         parent->AddPage( panel, wxT("Speed"), false );
434 }
435
436 void LauncherSetup::saveTab_Speed()
437 {
438         int sel;
439
440         sel = m_Speed_DefaultDetail->GetSelection();
441
442         if ( (sel < 0) || (sel > 3) ) {
443                 sel = 0;
444         }
445
446         os_config_write_uint(NULL, "ComputerSpeed", sel);
447 }
448
449 void LauncherSetup::initTab_Network(wxNotebook* parent)
450 {
451         const char *conf_ptr = NULL;
452         unsigned int val = 0;
453
454         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
455
456         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
457
458         // 'connection type'
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 );
463
464         conf_ptr = os_config_read_string("Network", "NetworkConnection", NULL);
465         val = 0;
466
467         if (conf_ptr) {
468                 if ( !SDL_strcasecmp(conf_ptr, "dialup") ) {
469                         val = 1;
470                 } else if ( !SDL_strcasecmp(conf_ptr, "lan") ) {
471                         val = 2;
472                 }
473         }
474
475         m_Network_Connection->SetSelection(val);
476
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 );
482
483         conf_ptr = os_config_read_string("Network", "ConnectionSpeed", NULL);
484         val = 0;
485
486         if (conf_ptr) {
487                 if ( !SDL_strcasecmp(conf_ptr, "Slow") ) {
488                         val = 1;
489                 } else if ( !SDL_strcasecmp(conf_ptr, "56K") ) {
490                         val = 2;
491                 } else if ( !SDL_strcasecmp(conf_ptr, "ISDN") ) {
492                         val = 3;
493                 } else if ( !SDL_strcasecmp(conf_ptr, "Cable") ) {
494                         val = 4;
495                 } else if ( !SDL_strcasecmp(conf_ptr, "Fast") ) {
496                         val = 5;
497                 }
498         }
499
500         m_Network_Speed->SetSelection(val);
501
502
503         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Misc") ), wxVERTICAL );
504
505         wxFlexGridSizer* fgSizer_port = new wxFlexGridSizer( 0, 2, 0, 0 );
506         fgSizer_port->SetFlexibleDirection( wxBOTH );
507         fgSizer_port->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
508
509         // 'port'
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 );
513
514         m_Network_Port = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
515         fgSizer_port->Add( m_Network_Port, 0, wxALL|wxEXPAND, 5 );
516
517         wxIntegerValidator<unsigned short> vald( &m_port_validate );
518
519         m_Network_Port->SetValidator(vald);
520
521         sbSizer->Add( fgSizer_port, 1, wxEXPAND, 5 );
522
523         val = os_config_read_uint("Network", "ForcePort", 0);
524
525         if (val) {
526                 wxString sval = wxString::Format( wxT("%u"), val );
527
528                 m_Network_Port->SetValue(sval);
529         }
530
531
532         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
533
534         panel->SetSizer( bSizer );
535         panel->Layout();
536
537         bSizer->Fit( panel );
538
539         parent->AddPage( panel, wxT("Network"), false );
540 }
541
542 void LauncherSetup::saveTab_Network()
543 {
544         const char *conn_types[] = { "none", "dialup", "lan" };
545         const char *conn_speed[] = { "none", "Slow", "56K", "ISDN", "Cable", "Fast" };
546         int sel = 0;
547         long port = 0;
548
549         sel = m_Network_Connection->GetSelection();
550
551         if ( (sel < 0) || (sel > 2) ) {
552                 sel = 0;
553         }
554
555         os_config_write_string("Network", "NetworkConnection", conn_types[sel]);
556
557         sel = m_Network_Speed->GetSelection();
558
559         if ( (sel < 0) || (sel > 5) ) {
560                 sel = 0;
561         }
562
563         os_config_write_string("Network", "ConnectionSpeed", conn_speed[sel]);
564
565         if ( !m_Network_Port->GetValue().IsEmpty() ) {
566                 m_Network_Port->GetValue().ToLong(&port);
567                 wxASSERT( port <= USHRT_MAX );
568         }
569
570         os_config_write_uint("Network", "ForcePort", (unsigned int)port);
571 }
572
573 void LauncherSetup::save_settings()
574 {
575         const char *ptr = NULL;
576
577         // 'Default' section
578         ptr = os_config_read_string(NULL, "Language", NULL);
579
580         if (ptr) {
581                 os_config_write_string(NULL, "Language", ptr);
582         } else {
583                 os_config_write_string(NULL, "Language", "");
584         }
585
586         ptr = os_config_read_string(NULL, "LastPlayer", NULL);
587
588         if (ptr) {
589                 os_config_write_string(NULL, "LastPlayer", ptr);
590         } else {
591                 os_config_write_string(NULL, "LastPlayer", "");
592         }
593
594         ptr = os_config_read_string(NULL, "ExtrasPath", NULL);
595
596         if (ptr) {
597                 os_config_write_string(NULL, "ExtrasPath", ptr);
598         } else {
599                 os_config_write_string(NULL, "ExtrasPath", "");
600         }
601
602         os_config_write_uint(NULL, "StraightToSetup", 0);
603
604         saveTab_Speed();
605
606         // 'Video' section
607         saveTab_Video();
608
609         // 'Audio' section
610         saveTab_Audio();
611
612         // 'Controls' section
613         saveTab_Joystick();
614
615         // 'Network' section
616         saveTab_Network();
617 }
618
619 void LauncherSetup::onOk(wxCommandEvent& WXUNUSED(event))
620 {
621         if ( Validate() && TransferDataFromWindow() ) {
622                 save_settings();
623
624                 if ( IsModal() ) {
625                         EndModal(wxID_OK);
626                 } else {
627                         SetReturnCode(wxID_OK);
628                         Show(false);
629                 }
630         }
631 }
632
633 void LauncherSetup::onToggleMSAA(wxCommandEvent& event)
634 {
635         if ( event.IsChecked() ) {
636                 m_Video_MSAASamples->Enable();
637
638                 if (m_Video_MSAASamples->GetSelection() == wxNOT_FOUND) {
639                         m_Video_MSAASamples->SetSelection(0);
640                 }
641         } else {
642                 m_Video_MSAASamples->Disable();
643         }
644 }