]> icculus.org git repositories - taylor/freespace2.git/blob - src/launcher/launchersetup.cpp
fix linker issue with wxWidgets
[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 #include "wx/access.h"
17
18
19 wxBEGIN_EVENT_TABLE(LauncherSetup, wxDialog)
20         EVT_BUTTON(wxID_OK, LauncherSetup::onOk)
21         EVT_CHECKBOX(ID_CB_MSAA, LauncherSetup::onToggleMSAA)
22 wxEND_EVENT_TABLE()
23
24
25 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 {
27         this->SetSizeHints( wxSize(370, -1), wxDefaultSize );
28
29
30         wxNotebook *nbook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
31
32         initTab_Video(nbook);
33         initTab_Audio(nbook);
34         initTab_Joystick(nbook);
35         initTab_Speed(nbook);
36         initTab_Network(nbook);
37         initTab_PXO(nbook);
38
39         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
40         bSizer->Add( nbook, 0, wxALL|wxEXPAND, 5 );
41
42
43         wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
44         sdbSizer->AddButton( new wxButton(this, wxID_OK) );
45         sdbSizer->AddButton( new wxButton(this, wxID_CANCEL) );
46         sdbSizer->Realize();
47
48         bSizer->Add( sdbSizer, 0, wxALL|wxEXPAND, 5 );
49
50
51         this->SetSizer( bSizer );
52         this->Layout();
53         bSizer->Fit( this );
54
55
56         this->Centre( wxBOTH );
57 }
58
59 LauncherSetup::~LauncherSetup()
60 {
61 }
62
63 void LauncherSetup::initTab_Video(wxNotebook *parent)
64 {
65         unsigned int checked = 0;
66
67         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
68
69         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
70
71
72         // 'renderer'
73         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Renderer") ), wxVERTICAL );
74
75         m_Video_Renderer = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
76         sbSizer->Add( m_Video_Renderer, 1, wxALL|wxEXPAND, 5 );
77
78         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
79
80         m_Video_Renderer->Append( wxT("OpenGL") );
81         m_Video_Renderer->SetSelection( 0 );
82
83         // 'fullscreen'
84         m_Video_Fullscreen = new wxCheckBox( panel, wxID_ANY, wxT("Fullscreen"), wxDefaultPosition, wxDefaultSize, 0 );
85         bSizer->Add( m_Video_Fullscreen, 0, wxALL, 5 );
86
87         checked = os_config_read_uint("Video", "Fullscreen", 1);
88
89         m_Video_Fullscreen->SetValue( (checked == 1) );
90
91         // 'show fps'
92         m_Video_ShowFPS = new wxCheckBox( panel, wxID_ANY, wxT("Show FPS"), wxDefaultPosition, wxDefaultSize, 0 );
93         bSizer->Add( m_Video_ShowFPS, 0, wxALL, 5 );
94
95         checked = os_config_read_uint("Video", "ShowFPS", 0);
96
97         m_Video_ShowFPS->SetValue( (checked == 1) );
98
99         // 'anti-alias'
100         wxBoxSizer* bSizer_aa = new wxBoxSizer( wxHORIZONTAL );
101
102         m_Video_MSAA = new wxCheckBox( panel, ID_CB_MSAA, wxT("Anti-Alias"), wxDefaultPosition, wxDefaultSize, 0 );
103         bSizer_aa->Add( m_Video_MSAA, 0, wxALIGN_CENTER_VERTICAL, 5 );
104
105         const wxString msaa_samples[] = { wxT("2x"), wxT("4x"), wxT("8x"), wxT("16x") };
106         const int num_msaa_samples = sizeof( msaa_samples ) / sizeof( wxString );
107         m_Video_MSAASamples = new wxChoice( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, num_msaa_samples, msaa_samples, 0 );
108         bSizer_aa->Add( m_Video_MSAASamples, 0, wxLEFT, 15 );
109
110         bSizer->Add( bSizer_aa, 0, wxALL, 5 );
111
112         checked = os_config_read_uint("Video", "AntiAlias", 0);
113
114         if (checked) {
115                 m_Video_MSAA->SetValue(true);
116
117                 if (checked < 4) {
118                         m_Video_MSAASamples->SetSelection(0);
119                 } else if (checked < 8) {
120                         m_Video_MSAASamples->SetSelection(1);
121                 } else if (checked < 16) {
122                         m_Video_MSAASamples->SetSelection(2);
123                 } else {
124                         m_Video_MSAASamples->SetSelection(3);
125                 }
126         } else {
127                 m_Video_MSAA->SetValue(false);
128                 m_Video_MSAASamples->SetSelection(wxNOT_FOUND);
129                 m_Video_MSAASamples->Disable();
130         }
131
132
133         panel->SetSizer( bSizer );
134         panel->Layout();
135
136         bSizer->Fit( panel );
137
138         parent->AddPage( panel, wxT("Video"), true );
139 }
140
141 void LauncherSetup::saveTab_Video()
142 {
143         wxString value;
144         unsigned int msaa = 0;
145
146         value = m_Video_Renderer->GetValue();
147
148         os_config_write_string("Video", "Renderer", value.c_str());
149
150         if ( m_Video_MSAA->IsChecked() ) {
151                 int sel = m_Video_MSAASamples->GetSelection();
152
153                 if ( (sel >= 0) && (sel < 4) ) {
154                         msaa = 2 << sel;
155                 }
156         }
157
158         os_config_write_uint("Video", "AntiAlias", msaa);
159
160         os_config_write_uint("Video", "Fullscreen", m_Video_Fullscreen->IsChecked() ? 1 : 0);
161         os_config_write_uint("Video", "ShowFPS", m_Video_ShowFPS->IsChecked() ? 1 : 0);
162 }
163
164 void LauncherSetup::initTab_Audio(wxNotebook *parent)
165 {
166         unsigned int checked = 0;
167         ALint ver_major = 0, ver_minor = 0;
168         const ALCchar *ptr = NULL;
169         const char *conf_ptr = NULL;
170         bool audio_enabled = false;
171
172         alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &ver_major);
173         alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &ver_minor);
174
175         if ( (ver_major >= 1) && (ver_minor >= 1) ) {
176                 audio_enabled = true;
177         }
178
179         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
180
181         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
182
183
184         // 'playback device'
185         wxStaticBoxSizer* sbSizer_playback = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Playback Device") ), wxVERTICAL );
186
187         m_Audio_PlaybackDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
188         sbSizer_playback->Add( m_Audio_PlaybackDevice, 0, wxALL|wxEXPAND, 5 );
189
190         bSizer->Add( sbSizer_playback, 0, wxALL|wxEXPAND, 5 );
191
192         m_Audio_PlaybackDevice->Append("<Default>");
193         m_Audio_PlaybackDevice->SetSelection(0);
194
195         conf_ptr = os_config_read_string("Audio", "PlaybackDevice", NULL);
196
197         if (audio_enabled) {
198                 if ( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE ) {
199                         ptr = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
200                 } else {
201                         ptr = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
202                 }
203
204                 if (ptr) {
205                         while (*ptr) {
206                                 m_Audio_PlaybackDevice->Append(ptr);
207
208                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
209                                         unsigned int sel = m_Audio_PlaybackDevice->GetCount() - 1;
210
211                                         m_Audio_PlaybackDevice->SetSelection(sel);
212
213                                         conf_ptr = NULL;
214                                 }
215
216                                 ptr += strlen(ptr) + 1;
217                         }
218                 }
219         }
220
221         // 'capture device'
222         wxStaticBoxSizer* sbSizer_capture = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Capture Device") ), wxVERTICAL );
223
224         m_Audio_CaptureDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
225         sbSizer_capture->Add( m_Audio_CaptureDevice, 0, wxALL|wxEXPAND, 5 );
226
227         bSizer->Add( sbSizer_capture, 0, wxALL|wxEXPAND, 5 );
228
229         m_Audio_CaptureDevice->Append("<Default>");
230         m_Audio_CaptureDevice->SetSelection(0);
231
232         conf_ptr = os_config_read_string("Audio", "CaptureDevice", NULL);
233
234         if (audio_enabled) {
235                 ptr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
236
237                 if (ptr) {
238                         while (*ptr) {
239                                 m_Audio_CaptureDevice->Append(ptr);
240
241                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
242                                         unsigned int sel = m_Audio_CaptureDevice->GetCount() - 1;
243
244                                         m_Audio_CaptureDevice->SetSelection(sel);
245
246                                         conf_ptr = NULL;
247                                 }
248
249                                 ptr += strlen(ptr) + 1;
250                         }
251                 }
252         }
253
254         // 'efx'
255         m_Audio_EFX = new wxCheckBox( panel, wxID_ANY, wxT("EFX / EAX Reverb"), wxDefaultPosition, wxDefaultSize, 0 );
256         bSizer->Add( m_Audio_EFX, 0, wxALL, 5 );
257
258         checked = os_config_read_uint("Audio", "EFX", 0);
259
260         m_Audio_EFX->SetValue( (checked == 1) );
261
262         // 'launcher sounds'
263 #ifndef MAKE_FS1
264         m_Audio_LauncherSounds = new wxCheckBox( panel, wxID_ANY, wxT("Enable Launcher Sounds"), wxDefaultPosition, wxDefaultSize, 0 );
265         bSizer->Add( m_Audio_LauncherSounds, 0, wxALL, 5 );
266
267         checked = os_config_read_uint("Audio", "LauncherSoundEnabled", 1);
268
269         m_Audio_LauncherSounds->SetValue( (checked == 1) );
270 #endif
271
272
273         panel->SetSizer( bSizer );
274         panel->Layout();
275
276         bSizer->Fit( panel );
277
278         parent->AddPage( panel, wxT("Audio"), false );
279 }
280
281 void LauncherSetup::saveTab_Audio()
282 {
283         wxString value;
284
285         value = m_Audio_PlaybackDevice->GetValue();
286
287         if ( value.IsSameAs( wxT("<Default>") ) ) {
288                 os_config_write_string("Audio", "PlaybackDevice", "");
289         } else {
290                 os_config_write_string("Audio", "PlaybackDevice", value.c_str());
291         }
292
293         value = m_Audio_CaptureDevice->GetValue();
294
295         if ( value.IsSameAs( wxT("<Default>") ) ) {
296                 os_config_write_string("Audio", "CaptureDevice", "");
297         } else {
298                 os_config_write_string("Audio", "CaptureDevice", value.c_str());
299         }
300
301         os_config_write_uint("Audio", "EFX", m_Audio_EFX->IsChecked() ? 1 : 0);
302 #ifndef MAKE_FS1
303         os_config_write_uint("Audio", "LauncherSoundEnabled", m_Audio_LauncherSounds->IsChecked() ? 1 : 0);
304
305         Launcher* parent = (Launcher*)GetParent();
306         parent->SndEnable( m_Audio_LauncherSounds->IsChecked() );
307 #endif
308 }
309
310 void LauncherSetup::initTab_Joystick(wxNotebook *parent)
311 {
312         unsigned int checked = 0;
313         const char *conf_ptr = NULL;
314         bool joystick_enabled = false;
315
316         if ( !SDL_InitSubSystem(SDL_INIT_JOYSTICK) ) {
317                 joystick_enabled = true;
318         }
319
320         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
321
322         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
323
324         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Joystick") ), wxVERTICAL );
325
326
327         // 'current joystick'
328         m_Joystick_Device = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
329         sbSizer->Add( m_Joystick_Device, 0, wxALL|wxEXPAND, 5 );
330
331         m_Joystick_Device->Append( wxT("<Default>") );
332         m_Joystick_Device->SetSelection( 0 );
333
334         conf_ptr = os_config_read_string("Controls", "CurrentJoystick", NULL);
335
336         if (joystick_enabled) {
337                 int num_sticks = SDL_NumJoysticks();
338
339                 for (int i = 0; i < num_sticks; i++) {
340                         const char *jname = SDL_JoystickNameForIndex(i);
341
342                         if (jname) {
343                                 m_Joystick_Device->Append(jname);
344
345                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, jname) ) {
346                                         unsigned int sel = m_Joystick_Device->GetCount() - 1;
347
348                                         m_Joystick_Device->SetSelection(sel);
349
350                                         conf_ptr = NULL;
351                                 }
352                         }
353                 }
354
355                 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
356         }
357
358         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
359
360         // 'force feedback'
361         m_Joystick_FF = new wxCheckBox( panel, wxID_ANY, wxT("Enable Force Feedback"), wxDefaultPosition, wxDefaultSize, 0 );
362         bSizer->Add( m_Joystick_FF, 0, wxALL|wxEXPAND, 5 );
363
364         checked = os_config_read_uint("Controls", "EnableJoystickFF", 0);
365
366         m_Joystick_FF->SetValue( (checked == 1) );
367
368         // 'directional hit'
369         m_Joystick_Directional = new wxCheckBox( panel, wxID_ANY, wxT("Enable directional hit effect (Force Feedback)"), wxDefaultPosition, wxDefaultSize, 0 );
370         bSizer->Add( m_Joystick_Directional, 0, wxALL|wxEXPAND, 5 );
371
372         checked = os_config_read_uint("Controls", "EnableHitEffect", 0);
373
374         m_Joystick_Directional->SetValue( (checked == 1) );
375
376
377         panel->SetSizer( bSizer );
378         panel->Layout();
379
380         bSizer->Fit( panel );
381
382         parent->AddPage( panel, wxT("Joystick"), false );
383 }
384
385 void LauncherSetup::saveTab_Joystick()
386 {
387         wxString value;
388
389         value = m_Joystick_Device->GetValue();
390
391         if ( value.IsSameAs( wxT("<Default>") ) ) {
392                 os_config_write_string("Controls", "CurrentJoystick", "");
393         } else {
394                 os_config_write_string("Controls", "CurrentJoystick", value.c_str());
395         }
396
397         os_config_write_uint("Controls", "EnableJoystickFF", m_Joystick_FF->IsChecked() ? 1 : 0);
398         os_config_write_uint("Controls", "EnableHitEffect", m_Joystick_Directional->IsChecked() ? 1 : 0);
399 }
400
401 void LauncherSetup::initTab_Speed(wxNotebook *parent)
402 {
403         unsigned int detail_lvl = 0;
404
405         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
406
407         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
408
409         // 'computer speed'
410         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Default Detail Level") ), wxVERTICAL );
411
412         m_Speed_DefaultDetail = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN );
413         sbSizer->Add( m_Speed_DefaultDetail, 0, wxALL|wxEXPAND, 5 );
414
415         m_Speed_DefaultDetail->Append( wxT("Low") );
416         m_Speed_DefaultDetail->Append( wxT("Medium") );
417         m_Speed_DefaultDetail->Append( wxT("High") );
418         m_Speed_DefaultDetail->Append( wxT("Very High") );
419
420         detail_lvl = os_config_read_uint(NULL, "ComputerSpeed", 2);
421
422         if (detail_lvl > 3) {
423                 detail_lvl = 0;
424         }
425
426         m_Speed_DefaultDetail->SetSelection(detail_lvl);
427
428
429         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
430
431         panel->SetSizer( bSizer );
432         panel->Layout();
433
434         bSizer->Fit( panel );
435
436         parent->AddPage( panel, wxT("Speed"), false );
437 }
438
439 void LauncherSetup::saveTab_Speed()
440 {
441         int sel;
442
443         sel = m_Speed_DefaultDetail->GetSelection();
444
445         if ( (sel < 0) || (sel > 3) ) {
446                 sel = 0;
447         }
448
449         os_config_write_uint(NULL, "ComputerSpeed", sel);
450 }
451
452 void LauncherSetup::initTab_Network(wxNotebook* parent)
453 {
454         const char *conf_ptr = NULL;
455         unsigned int val = 0;
456
457         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
458
459         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
460
461         // 'connection type'
462         const wxString conn_types[] = { wxT("None"), wxT("Dialup Networking"), wxT("LAN/Direct Connection") };
463         const int num_conn_types = sizeof( conn_types ) / sizeof( wxString );
464         m_Network_Connection = new wxRadioBox( panel, wxID_ANY, wxT("Internet Connection"), wxDefaultPosition, wxDefaultSize, num_conn_types, conn_types, 1, wxRA_SPECIFY_COLS );
465         bSizer->Add( m_Network_Connection, 0, wxALL|wxEXPAND, 5 );
466
467         conf_ptr = os_config_read_string("Network", "NetworkConnection", NULL);
468         val = 0;
469
470         if (conf_ptr) {
471                 if ( !SDL_strcasecmp(conf_ptr, "dialup") ) {
472                         val = 1;
473                 } else if ( !SDL_strcasecmp(conf_ptr, "lan") ) {
474                         val = 2;
475                 }
476         }
477
478         m_Network_Connection->SetSelection(val);
479
480         // 'connection speed'
481         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.") };
482         const int num_speed_types = sizeof( speed_types ) / sizeof( wxString );
483         m_Network_Speed = new wxRadioBox( panel, wxID_ANY, wxT("Connection Speed"), wxDefaultPosition, wxDefaultSize, num_speed_types, speed_types, 1, wxRA_SPECIFY_COLS );
484         bSizer->Add( m_Network_Speed, 0, wxALL|wxEXPAND, 5 );
485
486         conf_ptr = os_config_read_string("Network", "ConnectionSpeed", NULL);
487         val = 0;
488
489         if (conf_ptr) {
490                 if ( !SDL_strcasecmp(conf_ptr, "Slow") ) {
491                         val = 1;
492                 } else if ( !SDL_strcasecmp(conf_ptr, "56K") ) {
493                         val = 2;
494                 } else if ( !SDL_strcasecmp(conf_ptr, "ISDN") ) {
495                         val = 3;
496                 } else if ( !SDL_strcasecmp(conf_ptr, "Cable") ) {
497                         val = 4;
498                 } else if ( !SDL_strcasecmp(conf_ptr, "Fast") ) {
499                         val = 5;
500                 }
501         }
502
503         m_Network_Speed->SetSelection(val);
504
505         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Misc") ), wxVERTICAL );
506
507         wxFlexGridSizer* fgSizer_port = new wxFlexGridSizer( 0, 2, 0, 0 );
508         fgSizer_port->SetFlexibleDirection( wxBOTH );
509         fgSizer_port->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
510
511         // 'port'
512         wxStaticText* txt_port = new wxStaticText( panel, wxID_ANY, wxT("Force local port"), wxDefaultPosition, wxDefaultSize, 0 );
513         txt_port->Wrap( -1 );
514         fgSizer_port->Add( txt_port, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
515
516         m_Network_Port = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
517         fgSizer_port->Add( m_Network_Port, 0, wxALL|wxEXPAND, 5 );
518
519         m_port_validate = 0;
520         wxIntegerValidator<unsigned short> vald( &m_port_validate );
521         vald.SetStyle(wxNUM_VAL_ZERO_AS_BLANK);
522
523         m_Network_Port->SetValidator(vald);
524
525         sbSizer->Add( fgSizer_port, 1, wxEXPAND, 5 );
526
527         val = os_config_read_uint("Network", "ForcePort", 0);
528
529         if (val) {
530                 wxString sval = wxString::Format( wxT("%u"), val );
531
532                 m_Network_Port->SetValue(sval);
533         }
534
535
536         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
537
538         panel->SetSizer( bSizer );
539         panel->Layout();
540
541         bSizer->Fit( panel );
542
543         parent->AddPage( panel, wxT("Network"), false );
544 }
545
546 void LauncherSetup::saveTab_Network()
547 {
548         const char *conn_types[] = { "none", "dialup", "lan" };
549         const char *conn_speed[] = { "none", "Slow", "56K", "ISDN", "Cable", "Fast" };
550         int sel = 0;
551         long port = 0;
552
553         sel = m_Network_Connection->GetSelection();
554
555         if ( (sel < 0) || (sel > 2) ) {
556                 sel = 0;
557         }
558
559         os_config_write_string("Network", "NetworkConnection", conn_types[sel]);
560
561         sel = m_Network_Speed->GetSelection();
562
563         if ( (sel < 0) || (sel > 5) ) {
564                 sel = 0;
565         }
566
567         os_config_write_string("Network", "ConnectionSpeed", conn_speed[sel]);
568
569         if ( !m_Network_Port->GetValue().IsEmpty() ) {
570                 m_Network_Port->GetValue().ToLong(&port);
571                 wxASSERT( port <= USHRT_MAX );
572         }
573
574         os_config_write_uint("Network", "ForcePort", (unsigned int)port);
575 }
576
577 void LauncherSetup::initTab_PXO(wxNotebook *parent)
578 {
579         const char *conf_ptr = NULL;
580         unsigned int val = 0;
581
582         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
583
584         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
585
586         // PXO
587         wxStaticBoxSizer* sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("PXO Account") ), wxVERTICAL );
588
589         wxBoxSizer*bSizer3 = new wxBoxSizer( wxVERTICAL );
590
591         wxFlexGridSizer* fgSizer2 = new wxFlexGridSizer( 0, 2, 0, 0 );
592         fgSizer2->SetFlexibleDirection( wxBOTH );
593         fgSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
594
595         // login
596         wxStaticText* m_staticText3 = new wxStaticText( panel, wxID_ANY, wxT("Login"), wxDefaultPosition, wxDefaultSize, 0 );
597         m_staticText3->Wrap( -1 );
598         fgSizer2->Add( m_staticText3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
599
600         m_PXO_Login = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
601         m_PXO_Login->SetMaxLength( 31 );
602
603         fgSizer2->Add( m_PXO_Login, 0, wxALL|wxEXPAND, 5 );
604
605         conf_ptr = os_config_read_string("PXO", "Login", NULL);
606
607         if (conf_ptr) {
608                 m_PXO_Login->SetValue(conf_ptr);
609         }
610
611         // password
612         wxStaticText* m_staticText4 = new wxStaticText( panel, wxID_ANY, wxT("Password"), wxDefaultPosition, wxDefaultSize, 0 );
613         m_staticText4->Wrap( -1 );
614         fgSizer2->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
615
616         m_PXO_Password = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
617         m_PXO_Password->SetMaxLength( 16 );
618
619         fgSizer2->Add( m_PXO_Password, 0, wxALL|wxEXPAND, 5 );
620         bSizer3->Add( fgSizer2, 1, wxEXPAND, 5 );
621
622         conf_ptr = os_config_read_string("PXO", "Password", NULL);
623
624         if (conf_ptr) {
625                 m_PXO_Password->SetValue(conf_ptr);
626         }
627
628         // radios
629         wxBoxSizer* bSizer4 = new wxBoxSizer( wxHORIZONTAL );
630
631         m_SkipVerify = new wxCheckBox( panel, wxID_ANY, wxT("Skip version check"), wxDefaultPosition, wxDefaultSize, 0 );
632         bSizer4->Add( m_SkipVerify, 0, wxALL, 5 );
633
634         val = os_config_read_uint("PXO", "SkipVerify", 0);
635
636         m_SkipVerify->SetValue( val ? true : false );
637
638         m_PXOBanners = new wxCheckBox( panel, wxID_ANY, wxT("PXO Banners"), wxDefaultPosition, wxDefaultSize, 0 );
639         bSizer4->Add( m_PXOBanners, 0, wxALL, 5 );
640
641         val = os_config_read_uint("PXO", "PXOBanners", 1);
642
643         m_PXOBanners->SetValue( val ? true : false );
644
645         bSizer3->Add( bSizer4, 0, wxALL|wxEXPAND, 5 );
646         sbSizer1->Add( bSizer3, 0, wxALL|wxEXPAND, 5 );
647
648
649         bSizer->Add( sbSizer1, 0, wxALL|wxEXPAND, 5 );
650
651         panel->SetSizer( bSizer );
652         panel->Layout();
653
654         bSizer->Fit( panel );
655
656         parent->AddPage( panel, wxT("PXO"), false );
657 }
658
659 void LauncherSetup::saveTab_PXO()
660 {
661         wxString value;
662         unsigned int val = 0;
663
664         value = m_PXO_Login->GetValue();
665
666         os_config_write_string("PXO", "Login", value.c_str());
667
668         value = m_PXO_Password->GetValue();
669
670         os_config_write_string("PXO", "Password", value.c_str());
671
672         val = m_SkipVerify->GetValue() ? 1 : 0;
673
674         os_config_write_uint("PXO", "SkipVerify", val);
675
676         val = m_PXOBanners->GetValue() ? 1 : 0;
677
678         os_config_write_uint("PXO", "PXOBanners", val);
679 }
680
681 void LauncherSetup::save_settings()
682 {
683         const char *ptr = NULL;
684
685         // 'Default' section
686         ptr = os_config_read_string(NULL, "Language", NULL);
687
688         if (ptr) {
689                 os_config_write_string(NULL, "Language", ptr);
690         } else {
691                 os_config_write_string(NULL, "Language", "");
692         }
693
694         ptr = os_config_read_string(NULL, "LastPlayer", NULL);
695
696         if (ptr) {
697                 os_config_write_string(NULL, "LastPlayer", ptr);
698         } else {
699                 os_config_write_string(NULL, "LastPlayer", "");
700         }
701
702         ptr = os_config_read_string(NULL, "ExtrasPath", NULL);
703
704         if (ptr) {
705                 os_config_write_string(NULL, "ExtrasPath", ptr);
706         } else {
707                 os_config_write_string(NULL, "ExtrasPath", "");
708         }
709
710         os_config_write_uint(NULL, "StraightToSetup", 0);
711
712         saveTab_Speed();
713
714         // 'Video' section
715         saveTab_Video();
716
717         // 'Audio' section
718         saveTab_Audio();
719
720         // 'Controls' section
721         saveTab_Joystick();
722
723         // 'Network' section
724         saveTab_Network();
725
726         // 'PXO' section
727         saveTab_PXO();
728 }
729
730 void LauncherSetup::onOk(wxCommandEvent& WXUNUSED(event))
731 {
732         if ( Validate() && TransferDataFromWindow() ) {
733                 save_settings();
734
735                 if ( IsModal() ) {
736                         EndModal(wxID_OK);
737                 } else {
738                         SetReturnCode(wxID_OK);
739                         Show(false);
740                 }
741         }
742 }
743
744 void LauncherSetup::onToggleMSAA(wxCommandEvent& event)
745 {
746         if ( event.IsChecked() ) {
747                 m_Video_MSAASamples->Enable();
748
749                 if (m_Video_MSAASamples->GetSelection() == wxNOT_FOUND) {
750                         m_Video_MSAASamples->SetSelection(0);
751                 }
752         } else {
753                 m_Video_MSAASamples->Disable();
754         }
755 }