]> icculus.org git repositories - taylor/freespace2.git/blob - src/launcher/launchersetup.cpp
initial launchersetup merge
[taylor/freespace2.git] / src / launcher / launchersetup.cpp
1
2 #include "SDL.h"
3
4 #include "launcher.h"
5 #include "launchersetup.h"
6 #include "osregistry.h"
7
8 #include "wx/valnum.h"
9
10
11 LauncherSetup::LauncherSetup( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
12 {
13         this->SetSizeHints( wxSize(370, -1), wxDefaultSize );
14
15
16         wxNotebook *nbook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
17
18         initTab_Video(nbook);
19         initTab_Audio(nbook);
20         initTab_Joystick(nbook);
21         initTab_Speed(nbook);
22         initTab_Network(nbook);
23         initTab_PXO(nbook);
24
25         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
26         bSizer->Add( nbook, 0, wxALL|wxEXPAND, 5 );
27
28
29         wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
30         sdbSizer->AddButton( new wxButton(this, wxID_OK) );
31         sdbSizer->AddButton( new wxButton(this, wxID_CANCEL) );
32         sdbSizer->Realize();
33
34         bSizer->Add( sdbSizer, 0, wxALL|wxEXPAND, 5 );
35
36
37         this->SetSizer( bSizer );
38         this->Layout();
39         bSizer->Fit( this );
40
41
42         this->Centre( wxBOTH );
43 }
44
45 LauncherSetup::~LauncherSetup()
46 {
47 }
48
49 void LauncherSetup::initTab_Video(wxNotebook *parent)
50 {
51         unsigned int checked = 0;
52
53         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
54
55         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
56
57
58         // 'renderer'
59         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Renderer") ), wxVERTICAL );
60
61         m_Video_Renderer = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
62         sbSizer->Add( m_Video_Renderer, 1, wxALL|wxEXPAND, 5 );
63
64         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
65
66         m_Video_Renderer->Append( wxT("OpenGL") );
67         m_Video_Renderer->SetSelection( 0 );
68
69         // 'fullscreen'
70         m_Video_Fullscreen = new wxCheckBox( panel, wxID_ANY, wxT("Fullscreen"), wxDefaultPosition, wxDefaultSize, 0 );
71         bSizer->Add( m_Video_Fullscreen, 0, wxALL, 5 );
72
73         checked = os_config_read_uint("Video", "Fullscreen", 1);
74
75         m_Video_Fullscreen->SetValue( (checked == 1) );
76
77         // 'show fps'
78         m_Video_ShowFPS = new wxCheckBox( panel, wxID_ANY, wxT("Show FPS"), wxDefaultPosition, wxDefaultSize, 0 );
79         bSizer->Add( m_Video_ShowFPS, 0, wxALL, 5 );
80
81         checked = os_config_read_uint("Video", "ShowFPS", 0);
82
83         m_Video_ShowFPS->SetValue( (checked == 1) );
84
85         // 'anti-alias'
86         wxBoxSizer* bSizer_aa = new wxBoxSizer( wxHORIZONTAL );
87
88         m_Video_MSAA = new wxCheckBox( panel, wxID_ANY, wxT("Anti-Alias"), wxDefaultPosition, wxDefaultSize, 0 );
89         bSizer_aa->Add( m_Video_MSAA, 0, wxALIGN_CENTER_VERTICAL, 5 );
90
91         const wxString msaa_samples[] = { wxT("2x"), wxT("4x"), wxT("8x"), wxT("16x") };
92         const int num_msaa_samples = sizeof( msaa_samples ) / sizeof( wxString );
93         m_Video_MSAASamples = new wxChoice( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, num_msaa_samples, msaa_samples, 0 );
94         bSizer_aa->Add( m_Video_MSAASamples, 0, wxLEFT, 15 );
95
96         bSizer->Add( bSizer_aa, 0, wxALL, 5 );
97
98         checked = os_config_read_uint("Video", "AntiAlias", 0);
99
100         if (checked) {
101                 m_Video_MSAA->SetValue(true);
102
103                 if (checked < 4) {
104                         m_Video_MSAASamples->SetSelection(0);
105                 } else if (checked < 8) {
106                         m_Video_MSAASamples->SetSelection(1);
107                 } else if (checked < 16) {
108                         m_Video_MSAASamples->SetSelection(2);
109                 } else {
110                         m_Video_MSAASamples->SetSelection(3);
111                 }
112         } else {
113                 m_Video_MSAA->SetValue(false);
114                 m_Video_MSAASamples->Disable();
115         }
116
117
118         panel->SetSizer( bSizer );
119         panel->Layout();
120
121         bSizer->Fit( panel );
122
123         parent->AddPage( panel, wxT("Video"), true );
124 }
125
126 void LauncherSetup::initTab_Audio(wxNotebook *parent)
127 {
128         unsigned int checked = 0;
129         ALint ver_major = 0, ver_minor = 0;
130         const ALCchar *ptr = NULL;
131         const char *conf_ptr = NULL;
132         bool audio_enabled = false;
133
134         alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &ver_major);
135         alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &ver_minor);
136
137         if ( (ver_major >= 1) && (ver_minor >= 1) ) {
138                 audio_enabled = true;
139         }
140
141         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
142
143         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
144
145
146         // 'playback device'
147         wxStaticBoxSizer* sbSizer_playback = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Playback Device") ), wxVERTICAL );
148
149         m_Audio_PlaybackDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
150         sbSizer_playback->Add( m_Audio_PlaybackDevice, 0, wxALL|wxEXPAND, 5 );
151
152         bSizer->Add( sbSizer_playback, 0, wxALL|wxEXPAND, 5 );
153
154         m_Audio_PlaybackDevice->Append("<Default>");
155         m_Audio_PlaybackDevice->SetSelection(0);
156
157         conf_ptr = os_config_read_string("Audio", "PlaybackDevice", NULL);
158
159         if (audio_enabled) {
160                 if ( alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE ) {
161                         ptr = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
162                 } else {
163                         ptr = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
164                 }
165
166                 if (ptr) {
167                         while (*ptr) {
168                                 m_Audio_PlaybackDevice->Append(ptr);
169
170                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
171                                         unsigned int sel = m_Audio_PlaybackDevice->GetCount() - 1;
172
173                                         m_Audio_PlaybackDevice->SetSelection(sel);
174
175                                         conf_ptr = NULL;
176                                 }
177
178                                 ptr += strlen(ptr) + 1;
179                         }
180                 }
181         }
182
183         // 'capture device'
184         wxStaticBoxSizer* sbSizer_capture = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Capture Device") ), wxVERTICAL );
185
186         m_Audio_CaptureDevice = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxCB_READONLY );
187         sbSizer_capture->Add( m_Audio_CaptureDevice, 0, wxALL|wxEXPAND, 5 );
188
189         bSizer->Add( sbSizer_capture, 0, wxALL|wxEXPAND, 5 );
190
191         m_Audio_CaptureDevice->Append("<Default>");
192         m_Audio_CaptureDevice->SetSelection(0);
193
194         conf_ptr = os_config_read_string("Audio", "CaptureDevice", NULL);
195
196         if (audio_enabled) {
197                 ptr = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
198
199                 if (ptr) {
200                         while (*ptr) {
201                                 m_Audio_CaptureDevice->Append(ptr);
202
203                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, ptr) ) {
204                                         unsigned int sel = m_Audio_CaptureDevice->GetCount() - 1;
205
206                                         m_Audio_CaptureDevice->SetSelection(sel);
207
208                                         conf_ptr = NULL;
209                                 }
210
211                                 ptr += strlen(ptr) + 1;
212                         }
213                 }
214         }
215
216         // 'efx'
217         m_Audio_EFX = new wxCheckBox( panel, wxID_ANY, wxT("EFX / EAX Reverb"), wxDefaultPosition, wxDefaultSize, 0 );
218         bSizer->Add( m_Audio_EFX, 0, wxALL, 5 );
219
220         checked = os_config_read_uint("Audio", "EFX", 0);
221
222         m_Audio_EFX->SetValue( (checked == 1) );
223
224         // 'launcher sounds'
225 #ifndef MAKE_FS1
226         m_Audio_LauncherSounds = new wxCheckBox( panel, wxID_ANY, wxT("Enable Launcher Sounds"), wxDefaultPosition, wxDefaultSize, 0 );
227         bSizer->Add( m_Audio_LauncherSounds, 0, wxALL, 5 );
228
229         checked = os_config_read_uint("Audio", "LauncherSoundEnabled", 1);
230
231         m_Audio_LauncherSounds->SetValue( (checked == 1) );
232 #endif
233
234
235 //      bSizer->Add( fgSizer, 1, wxEXPAND, 5 );
236
237         panel->SetSizer( bSizer );
238         panel->Layout();
239
240         bSizer->Fit( panel );
241
242         parent->AddPage( panel, wxT("Audio"), false );
243 }
244
245 void LauncherSetup::initTab_Joystick(wxNotebook *parent)
246 {
247         unsigned int checked = 0;
248         const char *conf_ptr = NULL;
249         bool joystick_enabled = false;
250
251         if ( !SDL_InitSubSystem(SDL_INIT_JOYSTICK) ) {
252                 joystick_enabled = true;
253         }
254
255         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
256
257         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
258
259         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Joystick") ), wxVERTICAL );
260
261
262         // 'current joystick'
263         m_Joystick_Device = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
264         sbSizer->Add( m_Joystick_Device, 0, wxALL|wxEXPAND, 5 );
265
266         m_Joystick_Device->Append( wxT("<Default>") );
267         m_Joystick_Device->SetSelection( 0 );
268
269         conf_ptr = os_config_read_string("Controls", "CurrentJoystick", NULL);
270
271         if (joystick_enabled) {
272                 int num_sticks = SDL_NumJoysticks();
273
274                 for (int i = 0; i < num_sticks; i++) {
275                         const char *jname = SDL_JoystickNameForIndex(i);
276
277                         if (jname) {
278                                 m_Joystick_Device->Append(jname);
279
280                                 if ( conf_ptr && !SDL_strcasecmp(conf_ptr, jname) ) {
281                                         unsigned int sel = m_Joystick_Device->GetCount() - 1;
282
283                                         m_Joystick_Device->SetSelection(sel);
284
285                                         conf_ptr = NULL;
286                                 }
287                         }
288                 }
289
290                 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
291         }
292
293         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
294
295         // 'force feedback'
296         m_Joystick_FF = new wxCheckBox( panel, wxID_ANY, wxT("Enable Force Feedback"), wxDefaultPosition, wxDefaultSize, 0 );
297         bSizer->Add( m_Joystick_FF, 0, wxALL|wxEXPAND, 5 );
298
299         checked = os_config_read_uint("Controls", "EnableJoystickFF", 0);
300
301         m_Joystick_FF->SetValue( (checked == 1) );
302
303         // 'directional hit'
304         m_Joystick_Directional = new wxCheckBox( panel, wxID_ANY, wxT("Enable directional hit effect (Force Feedback)"), wxDefaultPosition, wxDefaultSize, 0 );
305         bSizer->Add( m_Joystick_Directional, 0, wxALL|wxEXPAND, 5 );
306
307         checked = os_config_read_uint("Controls", "EnableHitEffect", 0);
308
309         m_Joystick_Directional->SetValue( (checked == 1) );
310
311
312         panel->SetSizer( bSizer );
313         panel->Layout();
314
315         bSizer->Fit( panel );
316
317         parent->AddPage( panel, wxT("Joystick"), false );
318 }
319
320 void LauncherSetup::initTab_Speed(wxNotebook *parent)
321 {
322         unsigned int detail_lvl = 0;
323
324         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
325
326         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
327
328         // 'computer speed'
329         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Default Detail Level") ), wxVERTICAL );
330
331         m_Speed_DefaultDetail = new wxComboBox( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN );
332         sbSizer->Add( m_Speed_DefaultDetail, 0, wxALL|wxEXPAND, 5 );
333
334         m_Speed_DefaultDetail->Append( wxT("Low") );
335         m_Speed_DefaultDetail->Append( wxT("Medium") );
336         m_Speed_DefaultDetail->Append( wxT("High") );
337         m_Speed_DefaultDetail->Append( wxT("Very High") );
338
339         detail_lvl = os_config_read_uint(NULL, "ComputerSpeed", 2);
340
341         if (detail_lvl > 3) {
342                 detail_lvl = 0;
343         }
344
345         m_Speed_DefaultDetail->SetSelection(detail_lvl);
346
347
348         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
349
350         panel->SetSizer( bSizer );
351         panel->Layout();
352
353         bSizer->Fit( panel );
354
355         parent->AddPage( panel, wxT("Speed"), false );
356 }
357
358 void LauncherSetup::initTab_Network(wxNotebook* parent)
359 {
360         const char *conf_ptr = NULL;
361         unsigned int val = 0;
362
363         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
364
365         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
366
367         // 'connection type'
368         const wxString conn_types[] = { wxT("None"), wxT("Dialup Networking"), wxT("LAN/Direct Connection") };
369         const int num_conn_types = sizeof( conn_types ) / sizeof( wxString );
370         m_Network_Connection = new wxRadioBox( panel, wxID_ANY, wxT("Internet Connection"), wxDefaultPosition, wxDefaultSize, num_conn_types, conn_types, 1, wxRA_SPECIFY_COLS|wxSTATIC_BORDER );
371         bSizer->Add( m_Network_Connection, 0, wxALL|wxEXPAND, 5 );
372
373         conf_ptr = os_config_read_string("Network", "NetworkConnection", NULL);
374         val = 0;
375
376         if (conf_ptr) {
377                 if ( !SDL_strcasecmp(conf_ptr, "dialup") ) {
378                         val = 1;
379                 } else if ( !SDL_strcasecmp(conf_ptr, "lan") ) {
380                         val = 2;
381                 }
382         }
383
384         m_Network_Connection->SetSelection(val);
385
386         // 'connection speed'
387         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.") };
388         const int num_speed_types = sizeof( speed_types ) / sizeof( wxString );
389         m_Network_Speed = new wxRadioBox( panel, wxID_ANY, wxT("Connection Speed"), wxDefaultPosition, wxDefaultSize, num_speed_types, speed_types, 1, wxRA_SPECIFY_COLS );
390         bSizer->Add( m_Network_Speed, 0, wxALL|wxEXPAND, 5 );
391
392         conf_ptr = os_config_read_string("Network", "ConnectionSpeed", NULL);
393         val = 0;
394
395         if (conf_ptr) {
396                 if ( !SDL_strcasecmp(conf_ptr, "Slow") ) {
397                         val = 1;
398                 } else if ( !SDL_strcasecmp(conf_ptr, "56K") ) {
399                         val = 2;
400                 } else if ( !SDL_strcasecmp(conf_ptr, "ISDN") ) {
401                         val = 3;
402                 } else if ( !SDL_strcasecmp(conf_ptr, "Cable") ) {
403                         val = 4;
404                 } else if ( !SDL_strcasecmp(conf_ptr, "Fast") ) {
405                         val = 5;
406                 }
407         }
408
409         m_Network_Speed->SetSelection(val);
410
411
412         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("Misc") ), wxVERTICAL );
413
414         wxFlexGridSizer* fgSizer_port = new wxFlexGridSizer( 0, 2, 0, 0 );
415         fgSizer_port->SetFlexibleDirection( wxBOTH );
416         fgSizer_port->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
417
418         // 'port'
419         wxStaticText* txt_port = new wxStaticText( panel, wxID_ANY, wxT("Force local port"), wxDefaultPosition, wxDefaultSize, 0 );
420         txt_port->Wrap( -1 );
421         fgSizer_port->Add( txt_port, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
422
423         m_Network_Port = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
424         fgSizer_port->Add( m_Network_Port, 0, wxALL|wxEXPAND, 5 );
425
426         wxIntegerValidator<unsigned short> vald( &m_port_validate );
427
428         m_Network_Port->SetValidator(vald);
429
430         sbSizer->Add( fgSizer_port, 1, wxEXPAND, 5 );
431
432         val = os_config_read_uint("Network", "ForcePort", 0);
433
434         if (val) {
435                 wxString sval = wxString::Format( wxT("%u"), val );
436
437                 m_Network_Port->SetValue(sval);
438         }
439
440
441         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
442
443         panel->SetSizer( bSizer );
444         panel->Layout();
445
446         bSizer->Fit( panel );
447
448         parent->AddPage( panel, wxT("Network"), false );
449 }
450
451 void LauncherSetup::initTab_PXO(wxNotebook* parent)
452 {
453         const char *conf_ptr = NULL;
454         unsigned int checked = 0;
455
456         wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
457
458         wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
459
460         wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox( panel, wxID_ANY, wxT("PXO Account") ), wxVERTICAL );
461
462         wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 0, 2, 0, 0 );
463         fgSizer->SetFlexibleDirection( wxBOTH );
464         fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_ALL );
465
466         // 'pxo login'
467         wxStaticText* pxo_login = new wxStaticText( panel, wxID_ANY, wxT("Login"), wxDefaultPosition, wxDefaultSize, 0 );
468         pxo_login->Wrap( -1 );
469         fgSizer->Add( pxo_login, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
470
471         m_PXO_Username = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
472         fgSizer->Add( m_PXO_Username, 0, wxALL|wxEXPAND, 5 );
473
474         m_PXO_Username->SetMaxLength(32);
475
476         conf_ptr = os_config_read_string("PXO", "Login", NULL);
477
478         if (conf_ptr) {
479                 m_PXO_Username->SetValue(conf_ptr);
480         }
481
482         // 'pxo password'
483         wxStaticText* pxo_pass = new wxStaticText( panel, wxID_ANY, wxT("Password"), wxDefaultPosition, wxDefaultSize, 0 );
484         pxo_pass->Wrap( -1 );
485         fgSizer->Add( pxo_pass, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
486
487         m_PXO_Password = new wxTextCtrl( panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD );
488         fgSizer->Add( m_PXO_Password, 0, wxALL|wxEXPAND, 5 );
489
490         m_PXO_Password->SetMaxLength(32);
491
492         conf_ptr = os_config_read_string("PXO", "Password", NULL);
493
494         if (conf_ptr) {
495                 m_PXO_Password->SetValue(conf_ptr);
496         }
497
498         sbSizer->Add( fgSizer, 1, wxEXPAND, 5 );
499
500         bSizer->Add( sbSizer, 0, wxALL|wxEXPAND, 5 );
501
502         // 'multi version check'
503         m_PXO_SkipVerify = new wxCheckBox( panel, wxID_ANY, wxT("Skip version check in PXO"), wxDefaultPosition, wxDefaultSize, 0 );
504         bSizer->Add( m_PXO_SkipVerify, 0, wxALL, 5 );
505
506         checked = os_config_read_uint("PXO", "SkipVerify", 0);
507
508         m_PXO_SkipVerify->SetValue( (checked == 1) );
509
510         // 'banners'
511         m_PXO_Banners = new wxCheckBox( panel, wxID_ANY, wxT("PXO Banners"), wxDefaultPosition, wxDefaultSize, 0 );
512         bSizer->Add( m_PXO_Banners, 0, wxALL, 5 );
513
514         checked = os_config_read_uint("PXO", "Banners", 1);
515
516         m_PXO_Banners->SetValue( (checked == 1) );
517
518
519         panel->SetSizer( bSizer );
520         panel->Layout();
521
522         bSizer->Fit( panel );
523
524         parent->AddPage( panel, wxT("PXO"), false );
525 }