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