Debian Codegraph @

code/tabs/BasicSettingsPage.cpp

raw
1 /*
2 Copyright (C) 2009-2010 wxLauncher Team
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include <algorithm>
20
21 #include <wx/wx.h>
22 #include <wx/filename.h>
23 #include <wx/choicebk.h>
24 #include <wx/gbsizer.h>
25 #include <wx/hyperlink.h>
26
27 #include "generated/configure_launcher.h"
28
29 #if HAS_SDL == 1
30 #include "SDL.h"
31 #endif
32
33 #include "tabs/BasicSettingsPage.h"
34 #include "global/BasicDefaults.h"
35 #include "global/ids.h"
36 #include "global/ProfileKeys.h"
37 #include "apis/FlagListManager.h"
38 #include "apis/FREDManager.h"
39 #include "apis/ProfileManager.h"
40 #include "apis/TCManager.h"
41 #include "apis/SpeechManager.h"
42 #include "apis/OpenALManager.h"
43 #include "apis/JoystickManager.h"
44 #include "apis/resolution_manager.hpp"
45 #include "apis/HelpManager.h"
46 #include "controls/ModList.h"
47 #include "datastructures/FSOExecutable.h"
48 #include "datastructures/ResolutionMap.h"
49
50 #include "global/MemoryDebugging.h" // Last include for memory debugging
51
52 namespace
53 {
54 const int BUILD_CAP_SDL = 1 << 3;
55 }
56
57 /** A mechanism for allowing a network settings option's description (GUI label)
58 to differ from its corresponding registry value. */
59 class NetworkSettingsOption {
60 public:
61 NetworkSettingsOption(const wxString& regValue, const wxString& guiDesc);
62 const wxString& GetRegistryValue() const { return this->regValue; }
63 const wxString& GetDescription() const { return this->guiDesc; }
64 private:
65 NetworkSettingsOption();
66 wxString regValue;
67 wxString guiDesc;
68 };
69
70 typedef std::vector<NetworkSettingsOption> NetworkSettingsOptions;
71 NetworkSettingsOptions networkTypeOptions;
72 NetworkSettingsOptions networkSpeedOptions;
73
74 NetworkSettingsOption::NetworkSettingsOption(
75 const wxString& regValue,
76 const wxString& guiDesc)
77 : regValue(regValue), guiDesc(guiDesc) {
78 wxASSERT(!regValue.IsEmpty());
79 wxASSERT(!guiDesc.IsEmpty());
80 }
81
82 void InitializeNetworkOptions() {
83 wxASSERT(networkTypeOptions.empty());
84 wxASSERT(networkSpeedOptions.empty());
85
86 networkTypeOptions.push_back(NetworkSettingsOption(_T("None"), _T("None")));
87 networkTypeOptions.push_back(NetworkSettingsOption(_T("Dialup"), _T("Dialup")));
88 networkTypeOptions.push_back(NetworkSettingsOption(_T("LAN"), _T("Broadband/LAN")));
89
90 networkSpeedOptions.push_back(NetworkSettingsOption(_T("None"), _T("None")));
91 networkSpeedOptions.push_back(NetworkSettingsOption(_T("Slow"), _T("28k modem")));
92 networkSpeedOptions.push_back(NetworkSettingsOption(_T("56K"), _T("56k modem")));
93 networkSpeedOptions.push_back(NetworkSettingsOption(_T("ISDN"), _T("ISDN")));
94 networkSpeedOptions.push_back(NetworkSettingsOption(_T("Cable"), _T("DSL")));
95 networkSpeedOptions.push_back(NetworkSettingsOption(_T("Fast"), _T("Cable/LAN")));
96 }
97
98 int FindOptionIndexWithRegistryValue(
99 const NetworkSettingsOptions &options,
100 const wxString& regValue) {
101 wxCHECK_MSG(!options.empty(), -1,
102 _T("FindOptionIndexGivenRegistryValue(): passed in options is empty."));
103 wxCHECK_MSG(!regValue.IsEmpty(), -1,
104 _T("FindOptionIndexGivenRegistryValue(): passed in registry value is empty."));
105
106 for (int i = 0, n = options.size(); i < n; ++i) {
107 if (options[i].GetRegistryValue() == regValue) {
108 return i;
109 }
110 }
111
112 return -1; // not found
113 }
114
115 /** The index in the basic settings page's sizer where the settings sizer is located. */
116 const size_t SETTINGS_SIZER_INDEX = 1;
117
118 class ProxyChoice: public wxChoicebook {
119 public:
120 ProxyChoice(wxWindow *parent, wxWindowID id);
121 virtual ~ProxyChoice();
122
123 void OnChangeServer(wxCommandEvent &event);
124 void OnChangePort(wxCommandEvent &event);
125 void OnProxyTypeChange(wxChoicebookEvent &event);
126
127 private:
128
129
130 DECLARE_EVENT_TABLE();
131 };
132
133 class ExeChoice: public wxChoice {
134 public:
135 ExeChoice(wxWindow * parent, wxWindowID id) : wxChoice(parent, id) {}
136 bool FindAndSetSelectionWithClientData(wxString item) {
137 size_t number = this->GetStrings().size();
138 for( size_t i = 0; i < number; i++ ) {
139 FSOExecutable* data = dynamic_cast<FSOExecutable*>(this->GetClientObject(i));
140 wxCHECK2_MSG( data != NULL, continue, _T("Client data is not a FSOVersion pointer"));
141 if ( data->GetExecutableName() == item ) {
142 this->SetSelection(i);
143 return true;
144 }
145 }
146 return false;
147 }
148 };
149
150 BasicSettingsPage::BasicSettingsPage(wxWindow* parent): wxPanel(parent, wxID_ANY) {
151 wxLogDebug(_T("BasicSettingsPage is at %p."), this);
152
153 this->InitializeMemberVariables();
154
155 if (networkTypeOptions.empty() || networkSpeedOptions.empty()) {
156 InitializeNetworkOptions();
157 }
158
159 TCManager::Initialize();
160 TCManager::RegisterTCChanged(this);
161 TCManager::RegisterTCActiveModChanged(this);
162 TCManager::RegisterTCBinaryChanged(this);
163 TCManager::RegisterTCFredBinaryChanged(this);
164 ProMan::GetProfileManager()->AddEventHandler(this);
165 FlagListManager::GetFlagListManager()->RegisterFlagFileProcessingStatusChanged(this);
166 FREDManager::RegisterFREDEnabledChanged(this);
167 wxCommandEvent event(this->GetId());
168 this->ProfileChanged(event);
169 }
170
171 void BasicSettingsPage::ProfileChanged(wxCommandEvent &WXUNUSED(event)) {
172 if (this->GetSizer() != NULL) {
173 this->GetSizer()->Clear(true);
174 }
175
176 this->InitializeMemberVariables();
177
178 ProMan* proman = ProMan::GetProfileManager();
179 // exe Selection
180 wxStaticBox* exeBox = new wxStaticBox(this, wxID_ANY, _("FS2 Open game root folder and executable"));
181
182 wxStaticText* rootFolderText = new wxStaticText(this, ID_EXE_ROOT_FOLDER_BOX_TEXT, _("Game root folder:"));
183 wxTextCtrl* rootFolderBox = new wxTextCtrl(this, ID_EXE_ROOT_FOLDER_BOX);
184 wxButton* selectButton = new wxButton(this, ID_EXE_SELECT_ROOT_BUTTON, _T("Browse..."));
185
186 rootFolderBox->SetEditable(false);
187
188 wxStaticText* useExeText = new wxStaticText(this, wxID_ANY, _("FS2 Open executable:"));
189 ExeChoice* useExeChoice = new ExeChoice(this, ID_EXE_CHOICE_BOX);
190 wxButton* exeChoiceRefreshButton = new wxButton(this, ID_EXE_CHOICE_REFRESH_BUTTON, _("Refresh"));
191
192 wxStaticText* useFredText = new wxStaticText(this, ID_EXE_FRED_CHOICE_TEXT, _("FRED2 Open executable:"));
193 ExeChoice* useFredChoice = new ExeChoice(this, ID_EXE_FRED_CHOICE_BOX);
194 wxButton* exeFredChoiceRefreshButton = new wxButton(this, ID_EXE_FRED_CHOICE_REFRESH_BUTTON, _("Refresh"));
195
196 wxCommandEvent nullEvent;
197 OnFREDEnabledChanged(nullEvent);
198
199 // new sizer layout that should line things up nicely
200 // inspired by the thread http://markmail.org/message/rlgv6y6xbw5dkvyy#query:+page:1+mid:5cqagz2jbygwqt2x+state:results
201 // or "RE: [wxPython-users] wx.FlexGridSizer..." Mar 31, 2005 in com.googlegroups.wxpython-users
202 // this idea could also work on, say, the video box, if you needed, for Windows
203 wxFlexGridSizer* exeInsideSizer = new wxFlexGridSizer(3,3,0,0);
204 exeInsideSizer->AddGrowableCol(1);
205
206 exeInsideSizer->Add(rootFolderText, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
207 exeInsideSizer->Add(rootFolderBox, wxSizerFlags().Proportion(1).Expand());
208 exeInsideSizer->Add(selectButton, wxSizerFlags().Expand().Border(wxLEFT, 5));
209 exeInsideSizer->Add(useExeText, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
210 exeInsideSizer->Add(useExeChoice, wxSizerFlags().Proportion(1).Expand());
211 exeInsideSizer->Add(exeChoiceRefreshButton, wxSizerFlags().Expand().Border(wxLEFT, 5));
212
213 exeInsideSizer->Add(useFredText, 0, wxALIGN_CENTER_VERTICAL|wxRESERVE_SPACE_EVEN_IF_HIDDEN|wxRIGHT, 5);
214 exeInsideSizer->Add(useFredChoice, wxSizerFlags().Proportion(1).Expand().ReserveSpaceEvenIfHidden());
215 exeInsideSizer->Add(exeFredChoiceRefreshButton, wxSizerFlags().Expand().ReserveSpaceEvenIfHidden().Border(wxLEFT, 5));
216
217 wxStaticBoxSizer* exeSizer = new wxStaticBoxSizer(exeBox, wxHORIZONTAL);
218 exeSizer->Add(exeInsideSizer, wxSizerFlags().Proportion(1).Expand().Border(wxLEFT|wxRIGHT|wxBOTTOM, 5));
219
220 // Video Section
221 wxStaticBox* videoBox = new wxStaticBox(this, ID_VIDEO_STATIC_BOX, _("Video"));
222
223 wxStaticText* resolutionText =
224 new wxStaticText(this, wxID_ANY, _("Resolution:"));
225 wxChoice* resolutionCombo = new wxChoice(this, ID_RESOLUTION_COMBO);
226
227 SetUpResolution();
228
229 wxStaticText* depthText =
230 new wxStaticText(this, wxID_ANY, _("Depth:"));
231 wxChoice* depthCombo = new wxChoice(this, ID_DEPTH_COMBO);
232 long bitDepth;
233 depthCombo->Append(_("16-bit"));
234 depthCombo->Append(_("32-bit"));
235 proman->ProfileRead(PRO_CFG_VIDEO_BIT_DEPTH, &bitDepth, DEFAULT_VIDEO_BIT_DEPTH, true);
236 depthCombo->SetSelection((bitDepth == 16) ? 0 : 1);
237
238 wxStaticText* textureFilterText =
239 new wxStaticText(this, wxID_ANY, _("Texture filter:"));
240 wxChoice* textureFilterCombo = new wxChoice(this, ID_TEXTURE_FILTER_COMBO);
241 wxString filter;
242 textureFilterCombo->Append(_("Bilinear"));
243 textureFilterCombo->Append(_("Trilinear"));
244 proman->ProfileRead(PRO_CFG_VIDEO_TEXTURE_FILTER, &filter, DEFAULT_VIDEO_TEXTURE_FILTER, true);
245 // FIXME shouldn't need case folding. comparison should be case-sensitive:
246 // either Bilinear or Trilinear.
247 // although now we've created legacy texture filter values. hmm.
248 filter.MakeLower();
249 textureFilterCombo->SetSelection( (filter == _T("bilinear")) ? 0 : 1);
250
251 #if !IS_WIN32 // AF/AA don't yet work on Windows
252 wxStaticText* anisotropicText =
253 new wxStaticText(this, wxID_ANY, _("Anisotropic:"));
254 wxChoice* anisotropicCombo = new wxChoice(this, ID_ANISOTROPIC_COMBO);
255 long anisotropic;
256 anisotropicCombo->Append(_("Off"));
257 anisotropicCombo->Append(_T(" 1x"));
258 anisotropicCombo->Append(_T(" 2x"));
259 anisotropicCombo->Append(_T(" 4x"));
260 anisotropicCombo->Append(_T(" 8x"));
261 anisotropicCombo->Append(_T("16x"));
262 proman->ProfileRead(PRO_CFG_VIDEO_ANISOTROPIC, &anisotropic, DEFAULT_VIDEO_ANISOTROPIC, true);
263 switch(anisotropic) {
264 case 0:
265 anisotropic = 0;
266 break;
267 case 1:
268 anisotropic = 1;
269 break;
270 case 2:
271 anisotropic = 2;
272 break;
273 case 4:
274 anisotropic = 3;
275 break;
276 case 8:
277 anisotropic = 4;
278 break;
279 case 16:
280 anisotropic = 5;
281 break;
282 default:
283 wxLogWarning(_T("invalid anisotropic factor %ld, setting to 0"),
284 anisotropic);
285 proman->ProfileWrite(PRO_CFG_VIDEO_ANISOTROPIC, static_cast<long>(0));
286 anisotropic = 0;
287 }
288 anisotropicCombo->SetSelection(anisotropic);
289
290
291 wxStaticText* aaText = new wxStaticText(this, wxID_ANY, _("Anti-aliasing:"));
292 wxChoice* aaCombo = new wxChoice(this, ID_AA_COMBO);
293 long antialias;
294 aaCombo->Append(_("Off"));
295 aaCombo->Append(_T(" 2x"));
296 aaCombo->Append(_T(" 4x"));
297 aaCombo->Append(_T(" 8x"));
298 aaCombo->Append(_T("16x"));
299 proman->ProfileRead(PRO_CFG_VIDEO_ANTI_ALIAS, &antialias, DEFAULT_VIDEO_ANTI_ALIAS, true);
300 switch(antialias) {
301 case 0:
302 antialias = 0;
303 break;
304 case 2:
305 antialias = 1;
306 break;
307 case 4:
308 antialias = 2;
309 break;
310 case 8:
311 antialias = 3;
312 break;
313 case 16:
314 antialias = 4;
315 break;
316 default:
317 wxLogWarning(_T("invalid anti-aliasing factor %ld, setting to 0"),
318 antialias);
319 proman->ProfileWrite(PRO_CFG_VIDEO_ANTI_ALIAS, static_cast<long>(0));
320 antialias = 0;
321 }
322 aaCombo->SetSelection(antialias);
323 #endif
324
325 // Sizer for graphics, resolution, depth, etc
326 wxGridSizer* videoSizerL = new wxFlexGridSizer(2);
327 videoSizerL->Add(resolutionText, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
328 videoSizerL->Add(resolutionCombo, wxSizerFlags().Expand());
329 videoSizerL->Add(depthText, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
330 videoSizerL->Add(depthCombo, wxSizerFlags().Expand());
331
332 wxGridSizer* videoSizerR = new wxFlexGridSizer(2);
333 videoSizerR->Add(textureFilterText, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
334 videoSizerR->Add(textureFilterCombo, wxSizerFlags().Expand());
335 #if !IS_WIN32 // AF/AA don't yet work on Windows
336 videoSizerR->Add(anisotropicText, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
337 videoSizerR->Add(anisotropicCombo, wxSizerFlags().Expand());
338 videoSizerR->Add(aaText, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
339 videoSizerR->Add(aaCombo, wxSizerFlags().Expand());
340 #endif
341
342 wxStaticBoxSizer* videoSizer = new wxStaticBoxSizer(videoBox, wxHORIZONTAL);
343 #if IS_WIN32
344 videoSizer->Add(videoSizerL, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);
345 videoSizer->Add(videoSizerR, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
346 #else
347 videoSizer->Add(videoSizerL, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxBOTTOM, 5);
348 videoSizer->AddStretchSpacer(5);
349 videoSizer->Add(videoSizerR, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
350 videoSizer->AddStretchSpacer(5);
351 #endif
352
353 #if IS_WIN32
354 // Speech
355 wxStaticBox* speechBox = new wxStaticBox(this, wxID_ANY, _("Speech"));
356 wxTextCtrl* speechTestText = new wxTextCtrl(this, ID_SPEECH_TEST_TEXT,
357 _("Press play to test this string."),
358 wxDefaultPosition, wxDefaultSize);
359 wxChoice* speechVoiceCombo = new wxChoice(this, ID_SPEECH_VOICE_COMBO);
360 wxStaticText* speechVolumeLabel = new wxStaticText(this, wxID_ANY, _T("Volume"));
361 wxSlider* speechVoiceVolume =
362 new wxSlider(this, ID_SPEECH_VOICE_VOLUME, 50, 0, 100);
363 wxButton* speechPlayButton =
364 new wxButton(this, ID_SPEECH_PLAY_BUTTON, _("Play"));
365 wxStaticText* speechUseInText =
366 new wxStaticText(this, wxID_ANY, _("Use simulated speech in:"));
367 wxCheckBox* speechInTechroomCheck =
368 new wxCheckBox(this, ID_SPEECH_IN_TECHROOM, _("Tech room"));
369 wxCheckBox* speechInBriefingCheck =
370 new wxCheckBox(this, ID_SPEECH_IN_BRIEFING, _("Briefings"));
371 wxCheckBox* speechInGameCheck =
372 new wxCheckBox(this, ID_SPEECH_IN_GAME, _("In-game"));
373 wxCheckBox* speechInMultiCheck=
374 new wxCheckBox(this, ID_SPEECH_IN_MULTI, _("Multiplayer"));
375
376 wxButton* speechMoreVoicesButton =
377 new wxButton(this, ID_SPEECH_MORE_VOICES_BUTTON, _("Get more voices"));
378
379 wxGridBagSizer* speechLeftSizer = new wxGridBagSizer();
380 speechLeftSizer->Add(speechVoiceCombo, wxGBPosition(0,0), wxGBSpan(1,1), wxEXPAND|wxRIGHT, 10);
381 speechLeftSizer->Add(speechMoreVoicesButton, wxGBPosition(0,2), wxGBSpan(1,1), wxEXPAND);
382 speechLeftSizer->Add(speechTestText, wxGBPosition(1,0), wxGBSpan(2,3), wxEXPAND|wxTOP|wxBOTTOM, 5);
383 speechLeftSizer->Add(speechPlayButton, wxGBPosition(3,0), wxGBSpan(1,1), wxALIGN_CENTER_HORIZONTAL|wxRIGHT, 10);
384 speechLeftSizer->Add(speechVolumeLabel, wxGBPosition(3,1), wxGBSpan(1,1), wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxTOP, 5);
385 speechLeftSizer->Add(speechVoiceVolume, wxGBPosition(3,2), wxGBSpan(1,1), wxEXPAND);
386
387 wxBoxSizer* speechRightSizer = new wxBoxSizer(wxVERTICAL);
388 speechRightSizer->Add(speechUseInText, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
389 speechRightSizer->Add(speechInTechroomCheck, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
390 speechRightSizer->Add(speechInBriefingCheck, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
391 speechRightSizer->Add(speechInGameCheck, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
392 speechRightSizer->Add(speechInMultiCheck, wxSizerFlags().Expand());
393
394 wxStaticBoxSizer* speechSizer = new wxStaticBoxSizer(speechBox, wxHORIZONTAL);
395 speechSizer->Add(speechLeftSizer, wxSizerFlags().Expand().Border(wxLEFT|wxBOTTOM, 5));
396 speechSizer->AddStretchSpacer(3);
397 speechSizer->Add(speechRightSizer, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
398 speechSizer->AddStretchSpacer(2);
399
400 if ( SpeechMan::WasBuiltIn() && SpeechMan::Initialize() ) {
401
402 speechVoiceCombo->Append(SpeechMan::EnumVoices());
403
404 // FIXME consolidate this code and similar code in AdvSettingsPage.cpp
405 wxClientDC dc(this);
406 wxArrayString voices = speechVoiceCombo->GetStrings();
407 wxFont font(this->GetFont());
408 int maxStringWidth = 0;
409 int x, y;
410
411 for (int i = 0, n = voices.GetCount(); i < n; ++i) {
412 dc.GetTextExtent(voices[i], &x, &y, NULL, NULL, &font);
413
414 if (x > maxStringWidth) {
415 maxStringWidth = x;
416 }
417 }
418
419 speechVoiceCombo->SetMinSize(wxSize(maxStringWidth + 40, // 40 to include drop down box control
420 speechVoiceCombo->GetSize().GetHeight()));
421 this->Layout();
422
423 long speechVoice;
424 int speechSystemVoice = SpeechMan::GetVoice();
425 if ( speechSystemVoice < 0 ) {
426 wxLogWarning(_T("Had problem retrieving the system voice, using voice %d"),
427 DEFAULT_SPEECH_VOICE);
428 speechSystemVoice = DEFAULT_SPEECH_VOICE;
429 }
430 // set the voice to what is in the profile, if not set in profile use
431 // system settings
432 proman->ProfileRead(PRO_CFG_SPEECH_VOICE, &speechVoice, speechSystemVoice, true);
433 // there should not be more than MAX_INT voices installed on a system so
434 // the cast of an unsigned int to a signed int should not result in a
435 // loss of data.
436 if ( speechVoice >= static_cast<int>(speechVoiceCombo->GetCount()) ) {
437 wxLogWarning(_T("Profile speech voice index out of range,")
438 _T(" setting to system default"));
439 speechVoice = speechSystemVoice;
440 }
441 speechVoiceCombo->SetSelection(speechVoice);
442
443 long speechVolume;
444 int speechSystemVolume = SpeechMan::GetVolume();
445 if (speechSystemVolume < 0) {
446 wxLogWarning(_T("Had problem in retrieving the system speech volume,")
447 _T(" setting to %d"), DEFAULT_SPEECH_VOLUME);
448 speechSystemVolume = DEFAULT_SPEECH_VOLUME;
449 }
450 proman->ProfileRead(PRO_CFG_SPEECH_VOLUME, &speechVolume, speechSystemVolume, true);
451 if ( speechVolume < 0 || speechVolume > 100 ) {
452 wxLogWarning(_T("Speech Volume recorded in profile is out of range,")
453 _T(" resetting to %d"), DEFAULT_SPEECH_VOLUME);
454 speechVolume = DEFAULT_SPEECH_VOLUME;
455 }
456 speechVoiceVolume->SetValue(speechVolume);
457
458
459 bool speechInTechroom;
460 proman->ProfileRead(
461 PRO_CFG_SPEECH_IN_TECHROOM, &speechInTechroom, DEFAULT_SPEECH_IN_TECHROOM, true);
462 speechInTechroomCheck->SetValue(speechInTechroom);
463
464 bool speechInBriefings;
465 proman->ProfileRead(
466 PRO_CFG_SPEECH_IN_BRIEFINGS, &speechInBriefings, DEFAULT_SPEECH_IN_BRIEFINGS, true);
467 speechInBriefingCheck->SetValue(speechInBriefings);
468
469 bool speechInGame;
470 proman->ProfileRead(
471 PRO_CFG_SPEECH_IN_GAME, &speechInGame, DEFAULT_SPEECH_IN_GAME, true);
472 speechInGameCheck->SetValue(speechInGame);
473
474 bool speechInMulti;
475 proman->ProfileRead(
476 PRO_CFG_SPEECH_IN_MULTI, &speechInMulti, DEFAULT_SPEECH_IN_MULTI, true);
477 speechInMultiCheck->SetValue(speechInMulti);
478 } else {
479 speechBox->Disable();
480 speechTestText->Disable();
481 speechVoiceCombo->Disable();
482 speechVoiceVolume->Disable();
483 speechPlayButton->Disable();
484 speechUseInText->Disable();
485 speechInTechroomCheck->Disable();
486 speechInBriefingCheck->Disable();
487 speechInGameCheck->Disable();
488 speechInMultiCheck->Disable();
489 speechMoreVoicesButton->Disable();
490 }
491 #endif
492
493 // Network
494 wxStaticBox* networkBox = new wxStaticBox(this, wxID_ANY, _("Network"));
495
496 wxChoice* networkType = new wxChoice(this, ID_NETWORK_TYPE);
497 for (NetworkSettingsOptions::const_iterator
498 it = networkTypeOptions.begin(),
499 end = networkTypeOptions.end();
500 it != end; ++it) {
501 networkType->Append(it->GetDescription());
502 }
503
504 wxString type;
505 proman->ProfileRead(PRO_CFG_NETWORK_TYPE, &type,
506 DEFAULT_NETWORK_TYPE, true);
507
508 int networkTypeSelection =
509 FindOptionIndexWithRegistryValue(networkTypeOptions, type);
510 if (networkTypeSelection < 0) {
511 wxLogError(
512 _T("Profile value '%s' was not found in list of type options. ")
513 _T("Using default '%s'."),
514 type.c_str(),
515 DEFAULT_NETWORK_TYPE.c_str());
516
517 networkTypeSelection =
518 FindOptionIndexWithRegistryValue(networkTypeOptions, DEFAULT_NETWORK_TYPE);
519 if (networkTypeSelection < 0) {
520 wxLogError(
521 _T("Default value '%s' was not found in list of type options. ")
522 _T("Using first entry '%s'."),
523 DEFAULT_NETWORK_TYPE.c_str(),
524 networkTypeOptions[0].GetRegistryValue().c_str());
525 networkTypeSelection = 0;
526 }
527 }
528
529 networkType->SetSelection(networkTypeSelection);
530
531 wxChoice* networkSpeed = new wxChoice(this, ID_NETWORK_SPEED);
532 for (NetworkSettingsOptions::const_iterator
533 it = networkSpeedOptions.begin(),
534 end = networkSpeedOptions.end();
535 it != end; ++it) {
536 networkSpeed->Append(it->GetDescription());
537 }
538
539 wxString speed;
540 proman->ProfileRead(PRO_CFG_NETWORK_SPEED, &speed,
541 DEFAULT_NETWORK_SPEED, true);
542
543 int networkSpeedSelection =
544 FindOptionIndexWithRegistryValue(networkSpeedOptions, speed);
545 if (networkSpeedSelection < 0) {
546 wxLogError(
547 _T("Profile value '%s' was not found in list of speed options. ")
548 _T("Using default '%s'."),
549 speed.c_str(),
550 DEFAULT_NETWORK_SPEED.c_str());
551
552 networkSpeedSelection =
553 FindOptionIndexWithRegistryValue(networkSpeedOptions, DEFAULT_NETWORK_SPEED);
554 if (networkSpeedSelection < 0) {
555 wxLogError(
556 _T("Default value '%s' was not found in list of speed options. ")
557 _T("Using first entry '%s'."),
558 DEFAULT_NETWORK_SPEED.c_str(),
559 networkSpeedOptions[0].GetRegistryValue().c_str());
560 networkSpeedSelection = 0;
561 }
562 }
563
564 networkSpeed->SetSelection(networkSpeedSelection);
565
566 wxTextCtrl* networkPort =
567 new wxTextCtrl(this, ID_NETWORK_PORT, wxEmptyString);
568 long port;
569 proman->ProfileRead(PRO_CFG_NETWORK_PORT, &port, DEFAULT_NETWORK_PORT, true);
570 if (port != DEFAULT_NETWORK_PORT) {
571 networkPort->ChangeValue(wxString::Format(_T("%ld"), port));
572 }
573 networkPort->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
574 networkPort->SetMaxLength(5);
575
576 wxTextCtrl* networkIP = new wxTextCtrl(this, ID_NETWORK_IP, wxEmptyString);
577 wxString ip;
578 proman->ProfileRead(PRO_CFG_NETWORK_IP, &ip, DEFAULT_NETWORK_IP, true);
579 networkIP->ChangeValue(ip);
580 networkIP->SetMaxLength(15); // for ###.###.###.###
581
582 wxGridSizer* networkInsideSizerL = new wxFlexGridSizer(2);
583 networkInsideSizerL->Add(new wxStaticText(this, wxID_ANY, _("Connection type:")), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
584 networkInsideSizerL->Add(networkType, wxSizerFlags().Expand());
585 networkInsideSizerL->Add(new wxStaticText(this, wxID_ANY, _("Connection speed:")), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
586 networkInsideSizerL->Add(networkSpeed, wxSizerFlags().Expand());
587
588 wxGridSizer* networkInsideSizerR = new wxFlexGridSizer(2);
589 networkInsideSizerR->Add(new wxStaticText(this, wxID_ANY, _("Force local port:")), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
590 networkInsideSizerR->Add(networkPort, wxSizerFlags().Expand());
591 networkInsideSizerR->Add(new wxStaticText(this, wxID_ANY, _("Force IP address:")), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
592 networkInsideSizerR->Add(networkIP, wxSizerFlags().Expand());
593
594 wxStaticBoxSizer* networkSizer = new wxStaticBoxSizer(networkBox, wxHORIZONTAL);
595 networkSizer->Add(networkInsideSizerL, wxSizerFlags().Expand().Border(wxLEFT|wxBOTTOM, 5));
596 networkSizer->AddStretchSpacer(5);
597 networkSizer->Add(networkInsideSizerR, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
598 networkSizer->AddStretchSpacer(5);
599
600 // Audio
601 wxStaticBox* audioBox = new wxStaticBox(this, wxID_ANY, _("Audio"));
602
603 this->soundDeviceText = new wxStaticText(this, wxID_ANY, _("Sound device:"));
604 this->soundDeviceCombo = new TruncatableChoice(this, ID_SELECT_SOUND_DEVICE);
605
606 this->captureDeviceText = new wxStaticText(this, wxID_ANY, _("Capture device:"));
607 this->captureDeviceCombo = new TruncatableChoice(this, ID_SELECT_CAPTURE_DEVICE);
608
609 wxCheckBox* efxCheckBox = new wxCheckBox(this, ID_ENABLE_EFX, _("Enable EFX"));
610
611 wxStaticText* sampleRateText = new wxStaticText(this, wxID_ANY, _("Sample rate:"));
612 wxTextCtrl* sampleRateBox = new wxTextCtrl(this, ID_AUDIO_SAMPLE_RATE);
613
614 sampleRateBox->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
615 sampleRateBox->SetMaxLength(5);
616
617 this->openALVersion = new wxStaticText(this, wxID_ANY, wxEmptyString);
618
619 this->downloadOpenALButton = new wxButton(this, ID_DOWNLOAD_OPENAL, _("Download OpenAL"));
620 this->detectOpenALButton = new wxButton(this, ID_DETECT_OPENAL, _("Detect OpenAL"));
621
622 this->audioOldSoundSizer = new wxBoxSizer(wxVERTICAL);
623 this->audioOldSoundSizer->Add(soundDeviceText, wxSizerFlags().Border(wxBOTTOM, 5));
624 this->audioOldSoundSizer->Add(soundDeviceCombo,
625 wxSizerFlags().Expand());
626 this->audioOldSoundSizer->Add(openALVersion,
627 wxSizerFlags().Center().Border(wxTOP, 5));
628
629 this->audioNewSoundDeviceSizer = new wxFlexGridSizer(2);
630 this->audioNewSoundDeviceSizer->Add(captureDeviceText, 0,
631 wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
632 this->audioNewSoundDeviceSizer->Add(captureDeviceCombo, wxSizerFlags().Expand());
633
634 this->audioNewSoundSizer = new wxBoxSizer(wxHORIZONTAL);
635 this->audioNewSoundSizer->Add(this->audioNewSoundDeviceSizer);
636 this->audioNewSoundSizer->AddStretchSpacer(5);
637 this->audioNewSoundSizer->Add(efxCheckBox, 0,
638 wxALIGN_CENTER_VERTICAL|wxRESERVE_SPACE_EVEN_IF_HIDDEN);
639 this->audioNewSoundSizer->AddStretchSpacer(5);
640 this->audioNewSoundSizer->Add(sampleRateText, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
641 this->audioNewSoundSizer->Add(sampleRateBox, 0, wxALIGN_CENTER_VERTICAL);
642 this->audioNewSoundSizer->AddStretchSpacer(5);
643
644 this->audioButtonsSizer = new wxBoxSizer(wxVERTICAL);
645 this->audioButtonsSizer->Add(downloadOpenALButton, wxSizerFlags().Expand());
646 this->audioButtonsSizer->Add(detectOpenALButton, wxSizerFlags().Expand());
647
648 this->audioSizer = new wxStaticBoxSizer(audioBox, wxHORIZONTAL);
649 this->audioSizer->Add(audioOldSoundSizer,
650 wxSizerFlags().Proportion(1).Expand().Border(wxLEFT|wxRIGHT|wxBOTTOM, 5));
651 this->audioSizer->Add(audioNewSoundSizer);
652 this->audioSizer->Hide(audioNewSoundSizer, true);
653 this->audioSizer->Add(audioButtonsSizer, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxBOTTOM, 5);
654
655 // Joystick
656 wxStaticBox* joystickBox = new wxStaticBox(this, wxID_ANY, _("Joystick"));
657
658 this->joystickSelected = new wxChoice(this, ID_JOY_SELECTED);
659 this->joystickForceFeedback = new wxCheckBox(this, ID_JOY_FORCE_FEEDBACK, _("Force feedback"));
660 this->joystickDirectionalHit = new wxCheckBox(this, ID_JOY_DIRECTIONAL_HIT, _("Directional hit"));
661 this->joystickDetectButton = new wxButton(this, ID_JOY_DETECT_BUTTON, _("Detect"));
662 #if IS_WIN32
663 this->joystickCalibrateButton = new wxButton(this, ID_JOY_CALIBRATE_BUTTON, _("Calibrate"));
664 #endif
665
666 wxBoxSizer* joystickDetectionSizer = new wxBoxSizer(wxVERTICAL);
667 joystickDetectionSizer->Add(joystickSelected, wxSizerFlags().Proportion(1).Expand().Border(wxBOTTOM, 5));
668 joystickDetectionSizer->Add(joystickDetectButton, wxSizerFlags().Right());
669
670 wxBoxSizer* joystickExtrasSizer = new wxBoxSizer(wxVERTICAL);
671 joystickExtrasSizer->Add(joystickForceFeedback, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
672 joystickExtrasSizer->Add(joystickDirectionalHit, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
673 #if IS_WIN32
674 joystickExtrasSizer->Add(joystickCalibrateButton, wxSizerFlags().Expand());
675 #endif
676
677 wxStaticBoxSizer* joystickSizer = new wxStaticBoxSizer(joystickBox, wxHORIZONTAL);
678 joystickSizer->Add(joystickDetectionSizer, 1, wxALIGN_BOTTOM|wxLEFT|wxRIGHT|wxBOTTOM, 5);
679 joystickSizer->Add(joystickExtrasSizer, wxSizerFlags().Expand().Border(wxLEFT|wxRIGHT|wxBOTTOM, 5));
680
681 // Proxy
682 // sorry, but there won't be space for the proxy on any platform
683 #if 0
684 wxStaticBox* proxyBox = new wxStaticBox(this, wxID_ANY, _("Proxy"));
685
686 wxChoicebook* proxyChoice = new ProxyChoice(this, ID_PROXY_TYPE);
687
688 wxStaticBoxSizer* proxySizer = new wxStaticBoxSizer(proxyBox, wxVERTICAL);
689 proxySizer->Add(proxyChoice, wxSizerFlags().Expand().Border(wxLEFT|wxRIGHT, 5));
690 #endif
691
692 // Final Layout
693 wxBoxSizer* settingsSizer = new wxBoxSizer(wxVERTICAL);
694
695 settingsSizer->Add(videoSizer, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
696 settingsSizer->Add(audioSizer, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
697 #if IS_WIN32
698 settingsSizer->Add(speechSizer, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
699 #endif
700 settingsSizer->Add(joystickSizer, wxSizerFlags().Expand().Border(wxBOTTOM, 5));
701 settingsSizer->Add(networkSizer, wxSizerFlags().Expand());
702
703 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
704 sizer->SetMinSize(wxSize(TAB_AREA_WIDTH-5, -1)); // 5 being for the border
705 sizer->Add(exeSizer, wxSizerFlags().Expand().Border(wxALL, 5));
706 sizer->Add(settingsSizer, wxSizerFlags().Expand().Border(wxLEFT|wxRIGHT|wxBOTTOM, 5));
707
708 this->SetSizer(sizer);
709 this->Layout();
710 }
711
712 BasicSettingsPage::~BasicSettingsPage() {
713 TCManager::DeInitialize();
714 if ( SpeechMan::IsInitialized() ) {
715 SpeechMan::DeInitialize();
716 }
717 JoyMan::DeInitialize();
718 OpenALMan::DeInitialize();
719 }
720
721 /// Event Handling
722 BEGIN_EVENT_TABLE(BasicSettingsPage, wxPanel)
723 EVT_BUTTON(ID_EXE_SELECT_ROOT_BUTTON, BasicSettingsPage::OnSelectTC)
724 EVT_CHOICE(ID_EXE_CHOICE_BOX, BasicSettingsPage::OnSelectExecutable)
725 EVT_BUTTON(ID_EXE_CHOICE_REFRESH_BUTTON, BasicSettingsPage::OnPressExecutableChoiceRefreshButton)
726 EVT_CHOICE(ID_EXE_FRED_CHOICE_BOX, BasicSettingsPage::OnSelectFredExecutable)
727 EVT_BUTTON(ID_EXE_FRED_CHOICE_REFRESH_BUTTON, BasicSettingsPage::OnPressFredExecutableChoiceRefreshButton)
728 EVT_COMMAND(wxID_NONE, EVT_TC_CHANGED, BasicSettingsPage::OnTCChanged)
729 EVT_COMMAND(wxID_NONE, EVT_TC_ACTIVE_MOD_CHANGED, BasicSettingsPage::OnActiveModChanged)
730 EVT_COMMAND(wxID_NONE, EVT_TC_BINARY_CHANGED, BasicSettingsPage::OnCurrentBinaryChanged)
731 EVT_COMMAND(wxID_NONE, EVT_TC_FRED_BINARY_CHANGED, BasicSettingsPage::OnCurrentFredBinaryChanged)
732 EVT_COMMAND(wxID_NONE, EVT_FLAG_FILE_PROCESSING_STATUS_CHANGED,
733 BasicSettingsPage::OnFlagFileProcessingStatusChanged)
734 EVT_COMMAND(wxID_NONE, EVT_FRED_ENABLED_CHANGED, BasicSettingsPage::OnFREDEnabledChanged)
735
736 // Video controls
737 EVT_CHOICE(ID_RESOLUTION_COMBO, BasicSettingsPage::OnSelectVideoResolution)
738 EVT_CHOICE(ID_DEPTH_COMBO, BasicSettingsPage::OnSelectVideoDepth)
739 EVT_CHOICE(ID_TEXTURE_FILTER_COMBO, BasicSettingsPage::OnSelectVideoTextureFilter)
740 EVT_CHOICE(ID_ANISOTROPIC_COMBO, BasicSettingsPage::OnSelectVideoAnisotropic)
741 EVT_CHOICE(ID_AA_COMBO, BasicSettingsPage::OnSelectVideoAntiAlias)
742
743 // Speech Controls
744 EVT_CHOICE(ID_SPEECH_VOICE_COMBO, BasicSettingsPage::OnSelectSpeechVoice)
745 EVT_SLIDER(ID_SPEECH_VOICE_VOLUME, BasicSettingsPage::OnChangeSpeechVolume)
746 EVT_BUTTON(ID_SPEECH_PLAY_BUTTON, BasicSettingsPage::OnPlaySpeechText)
747 EVT_CHECKBOX(ID_SPEECH_IN_TECHROOM, BasicSettingsPage::OnToggleSpeechInTechroom)
748 EVT_CHECKBOX(ID_SPEECH_IN_BRIEFING, BasicSettingsPage::OnToggleSpeechInBriefing)
749 EVT_CHECKBOX(ID_SPEECH_IN_GAME, BasicSettingsPage::OnToggleSpeechInGame)
750 EVT_CHECKBOX(ID_SPEECH_IN_MULTI, BasicSettingsPage::OnToggleSpeechInMulti)
751 EVT_BUTTON(ID_SPEECH_MORE_VOICES_BUTTON, BasicSettingsPage::OnGetMoreVoices)
752
753 // Network
754 EVT_CHOICE(ID_NETWORK_TYPE, BasicSettingsPage::OnSelectNetworkType)
755 EVT_CHOICE(ID_NETWORK_SPEED, BasicSettingsPage::OnSelectNetworkSpeed)
756 EVT_TEXT(ID_NETWORK_PORT, BasicSettingsPage::OnChangePort)
757 EVT_TEXT(ID_NETWORK_IP, BasicSettingsPage::OnChangeIP)
758
759 // OpenAL
760 EVT_CHOICE(ID_SELECT_SOUND_DEVICE, BasicSettingsPage::OnSelectSoundDevice)
761 EVT_CHOICE(ID_SELECT_CAPTURE_DEVICE, BasicSettingsPage::OnSelectCaptureDevice)
762 EVT_CHECKBOX(ID_ENABLE_EFX, BasicSettingsPage::OnToggleEnableEFX)
763 EVT_TEXT(ID_AUDIO_SAMPLE_RATE, BasicSettingsPage::OnChangeSampleRate)
764 EVT_BUTTON(ID_DOWNLOAD_OPENAL, BasicSettingsPage::OnDownloadOpenAL)
765 EVT_BUTTON(ID_DETECT_OPENAL, BasicSettingsPage::OnDetectOpenAL)
766
767 // Joystick
768 EVT_CHOICE(ID_JOY_SELECTED, BasicSettingsPage::OnSelectJoystick)
769 EVT_CHECKBOX(ID_JOY_FORCE_FEEDBACK, BasicSettingsPage::OnCheckForceFeedback)
770 EVT_CHECKBOX(ID_JOY_DIRECTIONAL_HIT, BasicSettingsPage::OnCheckDirectionalHit)
771 EVT_BUTTON(ID_JOY_CALIBRATE_BUTTON, BasicSettingsPage::OnCalibrateJoystick)
772 EVT_BUTTON(ID_JOY_DETECT_BUTTON, BasicSettingsPage::OnDetectJoystick)
773
774 // Profile
775 EVT_COMMAND(wxID_NONE, EVT_CURRENT_PROFILE_CHANGED, BasicSettingsPage::ProfileChanged)
776
777 END_EVENT_TABLE()
778
779 void BasicSettingsPage::OnFlagFileProcessingStatusChanged(wxCommandEvent& event) {
780 const FlagListManager::FlagFileProcessingStatus status =
781 static_cast<FlagListManager::FlagFileProcessingStatus>(event.GetInt());
782
783 if (status == FlagListManager::FLAG_FILE_PROCESSING_OK) {
784 this->SetupOpenALSection();
785 this->SetupJoystickSection();
786 this->SetUpResolution();
787 }
788 }
789
790 void BasicSettingsPage::OnFREDEnabledChanged(wxCommandEvent& WXUNUSED(event)) {
791 wxStaticText* useFredText = dynamic_cast<wxStaticText*>(
792 wxWindow::FindWindowById(ID_EXE_FRED_CHOICE_TEXT, this));
793 wxCHECK_RET(useFredText != NULL,
794 _T("Cannot find use FRED text"));
795
796 ExeChoice* useFredChoice = dynamic_cast<ExeChoice*>(
797 wxWindow::FindWindowById(ID_EXE_FRED_CHOICE_BOX, this));
798 wxCHECK_RET(useFredChoice != NULL,
799 _T("Cannot find use FRED choice"));
800
801 wxButton* exeFredChoiceRefreshButton = dynamic_cast<wxButton*>(
802 wxWindow::FindWindowById(ID_EXE_FRED_CHOICE_REFRESH_BUTTON, this));
803 wxCHECK_RET(exeFredChoiceRefreshButton != NULL,
804 _T("Cannot find FRED exe choice refresh button"));
805
806 bool fredEnabled;
807 ProMan::GetProfileManager()->GlobalRead(GBL_CFG_OPT_CONFIG_FRED, &fredEnabled, false);
808
809 useFredText->Show(fredEnabled);
810 useFredChoice->Show(fredEnabled);
811 exeFredChoiceRefreshButton->Show(fredEnabled);
812 }
813
814 void BasicSettingsPage::OnSelectTC(wxCommandEvent &WXUNUSED(event)) {
815 wxString directory;
816 ProMan* proman = ProMan::GetProfileManager();
817 proman->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &directory, wxEmptyString);
818 wxDirDialog filechooser(this, _T("Choose the root folder of an FS2 Open game."),
819 directory, wxDD_DEFAULT_STYLE|wxDD_DIR_MUST_EXIST);
820
821 wxString chosenDirectory;
822 wxFileName path;
823 while (true) {
824 if ( wxID_CANCEL == filechooser.ShowModal() ) {
825 return;
826 }
827 chosenDirectory = filechooser.GetPath();
828 if ( chosenDirectory == directory ) {
829 wxLogInfo(_T("The game root folder selection was not changed."));
830 return; // User canceled, bail out.
831 }
832 path.SetPath(chosenDirectory);
833 if ( !path.IsOk() ) {
834 wxLogWarning(_T("Folder is not valid"));
835 continue;
836 } else if ( FSOExecutable::IsRootFolderValid(path) ) {
837 break;
838 } else {
839 wxString folderName;
840 if (path.GetDirCount() != 0) {
841 folderName = path.GetDirs().Last();
842 } else {
843 folderName = path.GetVolume();
844 if (folderName.IsEmpty()) { // occurs on Unix, according to wx docs
845 folderName = _T("/");
846 }
847 }
848 wxLogWarning(_T("Folder \"%s\" does not have any supported executables"),
849 folderName.c_str());
850 wxLogDebug(_T("Folder \"%s\" does not have any supported executables"),
851 path.GetFullPath().c_str());
852 }
853 }
854 wxLogDebug(_T("User chose '%s' as the TC root folder"), path.GetPath().c_str());
855 proman->ProfileWrite(PRO_CFG_TC_ROOT_FOLDER, path.GetPath());
856 TCManager::GenerateTCChanged();
857 }
858
859 /** Handles TCChanged events from TCManager.
860 //FIXME rewrite OnTCChanged() documentation once revisions are complete
861 Currently function only changes the executable dropbox control (clearing, and
862 filling in the executables that are in the new TC folder) and removes the
863 currently select executable from the active profile only if the executable
864 specified in the profile does not exist in the TC.
865
866 \note clearing the selected executable disables the play button.
867 \note Emits a EVT_TC_BINARY_CHANGED in any case.*/
868 void BasicSettingsPage::OnTCChanged(wxCommandEvent &WXUNUSED(event)) {
869 ExeChoice* exeChoice = dynamic_cast<ExeChoice*>(
870 wxWindow::FindWindowById(ID_EXE_CHOICE_BOX, this));
871 wxCHECK_RET( exeChoice != NULL,
872 _T("Cannot find executable choice control"));
873
874 wxButton* exeChoiceRefreshButton = dynamic_cast<wxButton*>(
875 wxWindow::FindWindowById(ID_EXE_CHOICE_REFRESH_BUTTON, this));
876 wxCHECK_RET( exeChoiceRefreshButton != NULL,
877 _T("Cannot find executable choice refresh button"));
878
879 bool fredEnabled;
880 ProMan::GetProfileManager()->GlobalRead(GBL_CFG_OPT_CONFIG_FRED, &fredEnabled, false);
881
882 ExeChoice* fredChoice = NULL;
883 wxButton* fredChoiceRefreshButton = NULL;
884 if (fredEnabled) {
885 fredChoice = dynamic_cast<ExeChoice*>(
886 wxWindow::FindWindowById(ID_EXE_FRED_CHOICE_BOX, this));
887 wxCHECK_RET( fredChoice != NULL,
888 _T("Cannot find FRED executable choice control"));
889
890 fredChoiceRefreshButton = dynamic_cast<wxButton*>(
891 wxWindow::FindWindowById(ID_EXE_FRED_CHOICE_REFRESH_BUTTON, this));
892 wxCHECK_RET( fredChoiceRefreshButton != NULL,
893 _T("Cannot find FRED executable choice refresh button"));
894 }
895
896 wxTextCtrl* tcFolder = dynamic_cast<wxTextCtrl*>(
897 wxWindow::FindWindowById(ID_EXE_ROOT_FOLDER_BOX, this));
898 wxCHECK_RET( tcFolder != NULL,
899 _T("Cannot find Text Control to show folder in."));
900
901 wxString tcPath, binaryName, fredBinaryName;
902 exeChoice->Clear();
903 if (fredEnabled) {
904 fredChoice->Clear();
905 }
906
907 if ( ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath) ) {
908 wxLogInfo(_T("The current game root folder is %s"), tcPath.c_str());
909 tcFolder->ChangeValue(tcPath);
910
911 // note that disabling the controls is necessary if we reached this code from the
912 // "refresh list of FSO execs" button being pressed
913 if (!wxFileName::DirExists(tcPath)) {
914 this->isTcRootFolderValid = false;
915 this->DisableExecutableChoiceControls(NONEXISTENT_TC_ROOT_FOLDER);
916 } else if (!FSOExecutable::HasFSOExecutables(wxFileName(tcPath, wxEmptyString))) {
917 this->isTcRootFolderValid = false;
918 this->DisableExecutableChoiceControls(INVALID_TC_ROOT_FOLDER);
919 } else { // the root folder is valid
920 this->isTcRootFolderValid = true;
921
922 this->FillFSOExecutableDropBox(exeChoice, wxFileName(tcPath, wxEmptyString));
923 exeChoice->Enable();
924 exeChoiceRefreshButton->Enable();
925
926 if (fredEnabled) {
927 this->FillFredExecutableDropBox(fredChoice, wxFileName(tcPath, wxEmptyString));
928 fredChoice->Enable();
929 fredChoiceRefreshButton->Enable();
930 }
931
932 // set selection to profile entry for current binary if there is one, noting if selected binary can't be found
933 bool hasBinary = ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_BINARY, &binaryName);
934 if ( hasBinary && !exeChoice->FindAndSetSelectionWithClientData(binaryName) ) {
935 // no need for a warning, since classes handling the EVT_TC_BINARY_CHANGED will issue warnings
936 wxLogDebug(_T("BasicSettingsPage::OnTCChanged(): couldn't find selected FSO executable %s in list of executables"),
937 binaryName.c_str());
938 }
939
940 if (fredEnabled) {
941 // set selection to profile entry for current FRED binary if there is one,
942 // noting if the FRED binary can't be found
943 bool hasFredBinary =
944 ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_FRED, &fredBinaryName);
945 if ( hasFredBinary && !fredChoice->FindAndSetSelectionWithClientData(fredBinaryName) ) {
946 // no need for a warning, since classes handling the EVT_TC_FRED_BINARY_CHANGED will issue warnings
947 wxLogDebug(_T("BasicSettingsPage::OnTCChanged(): couldn't find selected FRED executable %s in list of executables"),
948 fredBinaryName.c_str());
949 }
950 }
951 }
952 wxLogDebug(_T("The current root folder is %s."), this->isTcRootFolderValid ? _T("valid") : _T("invalid"));
953 } else {
954 wxLogDebug(_T("The current profile has no entry for root folder."));
955 this->isTcRootFolderValid = false;
956 this->DisableExecutableChoiceControls(MISSING_TC_ROOT_FOLDER);
957 }
958 this->GetSizer()->Layout();
959
960 // TCManager::CurrentProfileChanged() (which calls TCManager::GenerateTCChanged())
961 // assumes that TCManager::GenerateTCBinaryChanged() is called here unconditionally
962 TCManager::GenerateTCBinaryChanged();
963 // TCManager::CurrentProfileChanged() also assumes that TCManager::GenerateTCFredBinaryChanged()
964 // is called here unconditionally if FRED launching is enabled
965 if (fredEnabled) {
966 TCManager::GenerateTCFredBinaryChanged();
967 }
968 }
969
970 /** Puts the pretty description of all of the executables in the TCs folder
971 into the Executable DropBox. This function does nothing else to the choice
972 control, not even clearing the drop box (call the Clear function if you don't
973 want the old items to stay. */
974 void BasicSettingsPage::FillFSOExecutableDropBox(wxChoice* exeChoice, wxFileName path) {
975 BasicSettingsPage::FillExecutableDropBox(exeChoice, FSOExecutable::GetBinariesFromRootFolder(path));
976 }
977
978 void BasicSettingsPage::FillFredExecutableDropBox(wxChoice* exeChoice, wxFileName path) {
979 BasicSettingsPage::FillExecutableDropBox(exeChoice, FSOExecutable::GetFredBinariesFromRootFolder(path));
980 }
981
982 bool compareExecutables(FSOExecutable exe1, FSOExecutable exe2) {
983 return exe1.GetVersionString().CmpNoCase(exe2.GetVersionString()) < 0;
984 }
985
986 void BasicSettingsPage::FillExecutableDropBox(wxChoice* exeChoice, wxArrayString exes) {
987 std::vector<FSOExecutable> fsoExes;
988
989 wxArrayString::iterator iter = exes.begin();
990 while ( iter != exes.end() ) {
991 wxFileName path(*iter);
992 #if IS_APPLE // need complete path through app bundle to executable
993 FSOExecutable ver = FSOExecutable::GetBinaryVersion(path.GetFullPath());
994 #else
995 FSOExecutable ver = FSOExecutable::GetBinaryVersion(path.GetFullName());
996 #endif
997
998 fsoExes.push_back(ver);
999 iter++;
1000 }
1001
1002 sort(fsoExes.begin(), fsoExes.end(), compareExecutables);
1003
1004 for (std::vector<FSOExecutable>::const_iterator
1005 it = fsoExes.begin(), end = fsoExes.end();
1006 it != end; ++it) {
1007 exeChoice->Append(it->GetVersionString(), new FSOExecutable(*it));
1008 }
1009 }
1010
1011 void BasicSettingsPage::OnSelectExecutable(wxCommandEvent &WXUNUSED(event)) {
1012 ExeChoice* choice = dynamic_cast<ExeChoice*>(
1013 wxWindow::FindWindowById(ID_EXE_CHOICE_BOX, this));
1014 wxCHECK_RET( choice != NULL,
1015 _T("OnSelectExecutable: cannot find FS2 Open choice drop down box"));
1016
1017 FSOExecutable* ver = dynamic_cast<FSOExecutable*>(
1018 choice->GetClientObject(choice->GetSelection()));
1019 wxCHECK_RET( ver != NULL,
1020 _T("OnSelectExecutable: choice does not have FSOVersion data"));
1021 wxLogDebug(_T("Have selected ver for %s"), ver->GetExecutableName().c_str());
1022
1023 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_TC_CURRENT_BINARY, ver->GetExecutableName());
1024 TCManager::GenerateTCBinaryChanged();
1025 }
1026
1027 void BasicSettingsPage::OnPressExecutableChoiceRefreshButton(wxCommandEvent &WXUNUSED(event)) {
1028 ExeChoice* exeChoice = dynamic_cast<ExeChoice*>(
1029 wxWindow::FindWindowById(ID_EXE_CHOICE_BOX, this));
1030 wxCHECK_RET( exeChoice != NULL,
1031 _T("Cannot find executable choice control"));
1032
1033 wxString tcPath, binaryName;
1034 wxCHECK_RET(ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath),
1035 _T("OnPressExecutableChoiceRefreshButton: root folder entry not found"));
1036
1037 if (!wxFileName::DirExists(tcPath)) {
1038 // warning not needed, since it will be issued by DisableExecutableChoiceControls
1039 wxLogDebug(_T("OnPressExecutableChoiceRefreshButton: root folder '%s' no longer exists"),
1040 tcPath.c_str());
1041 TCManager::GenerateTCChanged();
1042 return;
1043 }
1044
1045 exeChoice->Clear();
1046
1047 this->FillFSOExecutableDropBox(exeChoice, wxFileName(tcPath, wxEmptyString));
1048
1049 if (exeChoice->IsEmpty()) {
1050 // current root folder has no FSO executables. update GUI if there were FSO executables before
1051 if (this->isTcRootFolderValid) {
1052 wxLogWarning(_T("after refreshing list of FSO executables, none were found"));
1053 TCManager::GenerateTCChanged();
1054 }
1055 } else if (!this->isTcRootFolderValid) {
1056 wxLogInfo(_T("after refreshing list of FSO executables, some have now been found"));
1057 TCManager::GenerateTCChanged();
1058 } else {
1059 // set selection to profile entry for current binary if there is one,
1060 // noting if selected binary can't be found and could be found before or vice versa
1061 if (ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_BINARY, &binaryName)) {
1062 bool exeFound = exeChoice->FindAndSetSelectionWithClientData(binaryName);
1063 if (!exeFound && this->isCurrentBinaryValid) {
1064 wxLogDebug(_T("OnPressExecutableChoiceRefresh: couldn't find selected FSO executable %s in list of executables"),
1065 binaryName.c_str());
1066 TCManager::GenerateTCBinaryChanged();
1067 } else if (exeFound && !this->isCurrentBinaryValid) {
1068 wxLogDebug(_T("OnPressExecutableChoiceRefresh: found selected FSO executable %s in list after previously unable to do so"),
1069 binaryName.c_str());
1070 TCManager::GenerateTCBinaryChanged();
1071 }
1072 }
1073 }
1074 }
1075
1076 void BasicSettingsPage::OnSelectFredExecutable(wxCommandEvent &WXUNUSED(event)) {
1077 ExeChoice* choice = dynamic_cast<ExeChoice*>(
1078 wxWindow::FindWindowById(ID_EXE_FRED_CHOICE_BOX, this));
1079 wxCHECK_RET( choice != NULL,
1080 _T("OnSelectExecutable: cannot find FRED choice drop down box"));
1081
1082 FSOExecutable* ver = dynamic_cast<FSOExecutable*>(
1083 choice->GetClientObject(choice->GetSelection()));
1084 wxCHECK_RET( ver != NULL,
1085 _T("OnSelectExecutable: choice does not have FSOVersion data"));
1086 wxLogDebug(_T("Have selected ver for %s"), ver->GetExecutableName().c_str());
1087
1088 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_TC_CURRENT_FRED, ver->GetExecutableName());
1089 TCManager::GenerateTCFredBinaryChanged();
1090 }
1091
1092 void BasicSettingsPage::OnPressFredExecutableChoiceRefreshButton(wxCommandEvent &WXUNUSED(event)) {
1093 bool fredEnabled;
1094 ProMan::GetProfileManager()->GlobalRead(GBL_CFG_OPT_CONFIG_FRED, &fredEnabled, false);
1095
1096 wxCHECK_RET(fredEnabled,
1097 _T("OnPressFredExecutableChoiceRefreshButton called when fredEnabled is false"));
1098
1099 ExeChoice* fredChoice = dynamic_cast<ExeChoice*>(
1100 wxWindow::FindWindowById(ID_EXE_FRED_CHOICE_BOX, this));
1101 wxCHECK_RET( fredChoice != NULL,
1102 _T("Cannot find FRED executable choice control"));
1103
1104 wxString tcPath, fredBinaryName;
1105 wxCHECK_RET(ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath),
1106 _T("OnPressFredExecutableChoiceRefreshButton: root folder entry not found"));
1107
1108 if (!wxFileName::DirExists(tcPath)) {
1109 // warning not needed, since it will be issued by DisableExecutableChoiceControls
1110 wxLogDebug(_T("OnPressExecutableChoiceRefreshButton: root folder '%s' no longer exists"),
1111 tcPath.c_str());
1112 TCManager::GenerateTCChanged();
1113 return;
1114 }
1115
1116 fredChoice->Clear();
1117
1118 this->FillFredExecutableDropBox(fredChoice, wxFileName(tcPath, wxEmptyString));
1119
1120 // set selection to profile entry for current FRED binary if there is one,
1121 // noting if selected FRED binary can't be found and could be found before or vice versa
1122 if (ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_FRED, &fredBinaryName)) {
1123 bool fredExeFound = fredChoice->FindAndSetSelectionWithClientData(fredBinaryName);
1124 if (!fredExeFound && this-isCurrentFredBinaryValid) {
1125 wxLogDebug(_T("OnPressFredExecutableChoiceRefresh: couldn't find selected FRED exec %s in list of executables"),
1126 fredBinaryName.c_str());
1127 TCManager::GenerateTCFredBinaryChanged();
1128 } else if (fredExeFound && !this->isCurrentFredBinaryValid) {
1129 wxLogDebug(
1130 _T("OnPressFredExecutableChoiceRefresh: found selected FRED exec %s in list after previously unable to do so"),
1131 fredBinaryName.c_str());
1132 TCManager::GenerateTCFredBinaryChanged();
1133 }
1134 }
1135 }
1136
1137 /** Initializes member variables, such as setting pointers to NULL. Made into a
1138 function, since it needs to be done at multiple places in the code. */
1139 void BasicSettingsPage::InitializeMemberVariables() {
1140 // following the order in BasicSettingsPage.h
1141 this->soundDeviceText = NULL;
1142 this->soundDeviceCombo = NULL;
1143 this->captureDeviceText = NULL;
1144 this->captureDeviceCombo = NULL;
1145 this->openALVersion = NULL;
1146 this->downloadOpenALButton = NULL;
1147 this->detectOpenALButton = NULL;
1148
1149 this->audioButtonsSizer = NULL;
1150 this->audioOldSoundSizer = NULL;
1151 this->audioNewSoundSizer = NULL;
1152 this->audioNewSoundDeviceSizer = NULL;
1153 this->audioSizer = NULL;
1154
1155 this->joystickSelected = NULL;
1156 this->joystickForceFeedback = NULL;
1157 this->joystickDirectionalHit = NULL;
1158 this->joystickDetectButton = NULL;
1159 #if IS_WIN32
1160 this->joystickCalibrateButton = NULL;
1161 #endif
1162 this->isTcRootFolderValid = false;
1163 this->isCurrentBinaryValid = false;
1164 this->isCurrentFredBinaryValid = false;
1165
1166 }
1167
1168 /** Disables the executable choice and refresh button controls, such as would occur
1169 if the currently loaded TC root folder doesn't exist or has no FSO executables. */
1170 void BasicSettingsPage::DisableExecutableChoiceControls(const ReasonForExecutableDisabling reason) {
1171
1172 wxString tcFolderPath;
1173 bool hasTcPath = ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcFolderPath);
1174 wxCHECK_RET(hasTcPath || (reason == MISSING_TC_ROOT_FOLDER),
1175 _T("DisableChoiceExecutableControls: profile has no root folder entry, but reason is not a missing root folder"));
1176 wxCHECK_RET((!hasTcPath) || (reason != MISSING_TC_ROOT_FOLDER),
1177 _T("DisableChoiceExecutableControls: reason is a missing root folder, but profile has a root folder entry"));
1178
1179 switch (reason) {
1180 case MISSING_TC_ROOT_FOLDER:
1181 // no user-facing message needed, since this is not an error state
1182 wxLogDebug(_T("disabling executable controls, since root folder entry is missing"));
1183 break;
1184 case NONEXISTENT_TC_ROOT_FOLDER:
1185 wxLogWarning(_("Selected root folder does not exist."));
1186 break;
1187 case INVALID_TC_ROOT_FOLDER:
1188 wxLogWarning(_("Selected root folder has no FS2 Open executables"));
1189 break;
1190 default:
1191 wxCHECK_RET(false, _T("DisableExecutableChoiceControls called with invalid reason"));
1192 break;
1193 }
1194
1195 ExeChoice *exeChoice = dynamic_cast<ExeChoice*>(
1196 wxWindow::FindWindowById(ID_EXE_CHOICE_BOX, this));
1197 wxCHECK_RET( exeChoice != NULL,
1198 _T("Cannot find executable choice control"));
1199
1200 wxButton* exeChoiceRefreshButton = dynamic_cast<wxButton*>(
1201 wxWindow::FindWindowById(ID_EXE_CHOICE_REFRESH_BUTTON, this));
1202 wxCHECK_RET( exeChoiceRefreshButton != NULL,
1203 _T("Cannot find executable choice refresh button"));
1204
1205 exeChoice->Clear();
1206 exeChoice->Disable();
1207 if (reason == NONEXISTENT_TC_ROOT_FOLDER || reason == MISSING_TC_ROOT_FOLDER) {
1208 exeChoiceRefreshButton->Disable();
1209 }
1210
1211 bool fredEnabled;
1212 ProMan::GetProfileManager()->GlobalRead(GBL_CFG_OPT_CONFIG_FRED, &fredEnabled, false);
1213
1214 if (fredEnabled) {
1215 ExeChoice* fredChoice = dynamic_cast<ExeChoice*>(
1216 wxWindow::FindWindowById(ID_EXE_FRED_CHOICE_BOX, this));
1217 wxCHECK_RET( fredChoice != NULL,
1218 _T("Cannot find FRED executable choice control"));
1219
1220 wxButton* fredChoiceRefreshButton = dynamic_cast<wxButton*>(
1221 wxWindow::FindWindowById(ID_EXE_FRED_CHOICE_REFRESH_BUTTON, this));
1222 wxCHECK_RET( fredChoiceRefreshButton != NULL,
1223 _T("Cannot find FRED executable choice refresh button"));
1224
1225 fredChoice->Clear();
1226 fredChoice->Disable();
1227 fredChoiceRefreshButton->Disable();
1228 }
1229 }
1230
1231 void BasicSettingsPage::SetUpResolution(const long minHorizRes, const long minVertRes) {
1232 const ModItem* activeMod = ModList::GetActiveMod();
1233 if (activeMod == NULL) {
1234 // activeMod is only NULL when there is no FSO root available
1235 // thus nothing to show on here either
1236 // This would be better handled by not trying to set this combobox up when
1237 // it can not possibly be needed.
1238 return;
1239 }
1240 if (!FlagListManager::GetFlagListManager()->IsProcessingOK()) {
1241 // We don't have a selected binary so we can't fill the resolution
1242 // selection box correctly
1243 return;
1244 }
1245 ProMan* proman = ProMan::GetProfileManager();
1246
1247 wxChoice* resolutionCombo = dynamic_cast<wxChoice*>(
1248 wxWindow::FindWindowById(ID_RESOLUTION_COMBO, this));
1249 wxCHECK_RET(resolutionCombo != NULL, _T("Unable to find resolution combo"));
1250
1251 FillResolutionDropBox(resolutionCombo, minHorizRes, minVertRes);
1252
1253 long width = 0, height = 0;
1254
1255 const wxString& shortname(activeMod->shortname);
1256
1257 bool hasValidRes = false;
1258 wxString resString;
1259
1260 // first try reading from ResolutionMap
1261 const ResolutionData* resDataPtr = ResolutionMap::ResolutionRead(shortname);
1262
1263 if (resDataPtr != NULL) {
1264 width = resDataPtr->width;
1265 height = resDataPtr->height;
1266
1267 resString =
1268 wxString::Format(
1269 CFG_RES_FORMAT_STRING,
1270 static_cast<int>(width),
1271 static_cast<int>(height));
1272 hasValidRes = resolutionCombo->SetStringSelection(resString);
1273 }
1274
1275 // then try reading resolution from profile
1276 if (!hasValidRes) {
1277 if (!resString.IsEmpty()) {
1278 wxLogDebug(_T("map resolution %s not found, attempting to use profile value"),
1279 resString.c_str());
1280 resString.Clear();
1281 } else {
1282 wxLogDebug(_T("no resolution found in map, attempting to use profile value"));
1283 }
1284
1285 bool hasResWidth = proman->ProfileRead(PRO_CFG_VIDEO_RESOLUTION_WIDTH, &width);
1286 bool hasResHeight = proman->ProfileRead(PRO_CFG_VIDEO_RESOLUTION_HEIGHT, &height);
1287
1288 if (hasResWidth && hasResHeight) {
1289 resString =
1290 wxString::Format(
1291 CFG_RES_FORMAT_STRING,
1292 static_cast<int>(width),
1293 static_cast<int>(height));
1294 hasValidRes = resolutionCombo->SetStringSelection(resString);
1295 }
1296 }
1297
1298 // last resort, use default (max supported resolution)
1299 if (!hasValidRes) {
1300 if (!resString.IsEmpty()) {
1301 wxLogDebug(_T("resolution map value %s not found, using default max supported resolution"),
1302 resString.c_str());
1303 } else {
1304 wxLogDebug(_T("no resolution found in map, using default max supported resolution"));
1305 }
1306
1307 int maxResIndex = GetMaxSupportedResolution(*resolutionCombo, width, height);
1308
1309 if (maxResIndex != wxNOT_FOUND) {
1310 resolutionCombo->SetSelection(maxResIndex);
1311 } else {
1312 const wxString InsufficientResolutionMsg(
1313 wxString::Format(
1314 _T("Your system does not support the minimum resolution needed to play this mod (%ldx%ld)."),
1315 minHorizRes, minVertRes));
1316
1317 wxLogError(InsufficientResolutionMsg);
1318 wxMessageBox(InsufficientResolutionMsg, _T("Mod not supported"), wxOK | wxICON_ERROR);
1319
1320 return;
1321 }
1322 }
1323
1324 // update profile and ResolutionMap
1325 proman->ProfileWrite(PRO_CFG_VIDEO_RESOLUTION_WIDTH, width);
1326 proman->ProfileWrite(PRO_CFG_VIDEO_RESOLUTION_HEIGHT, height);
1327
1328 ResolutionMap::ResolutionWrite(shortname, ResolutionData(width, height));
1329 }
1330
1331 /** Adjust the resolution drop down box according to the active mod's restrictions. */
1332 void BasicSettingsPage::OnActiveModChanged(wxCommandEvent& event) {
1333 wxChoice* resChoice = dynamic_cast<wxChoice*>(
1334 wxWindow::FindWindowById(ID_RESOLUTION_COMBO, this));
1335 wxCHECK_RET(resChoice != NULL, _T("Unable to find resolution combo"));
1336
1337 resChoice->Clear();
1338
1339 const ModItem* activeMod = ModList::GetActiveMod();
1340 wxCHECK_RET(activeMod != NULL,
1341 _T("BSP::OnActiveModChanged(): activeMod is NULL!"));
1342
1343 SetUpResolution(activeMod->minhorizontalres, activeMod->minverticalres);
1344 }
1345
1346 /** Updates the status of whether the currently selected FSO binary is valid. */
1347 void BasicSettingsPage::OnCurrentBinaryChanged(wxCommandEvent& event) {
1348 wxString tcPath, binaryName;
1349
1350 if (!ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath)) {
1351 this->isCurrentBinaryValid = false;
1352 this->ShowSettings(this->isCurrentBinaryValid);
1353 return;
1354 }
1355
1356 if ((!FSOExecutable::IsRootFolderValid(wxFileName(tcPath, wxEmptyString), true)) && this->isTcRootFolderValid) {
1357 this->isCurrentBinaryValid = false;
1358 this->ShowSettings(this->isCurrentBinaryValid);
1359 TCManager::GenerateTCChanged();
1360 return;
1361 }
1362
1363 bool hasBinary = ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_BINARY, &binaryName);
1364 this->isCurrentBinaryValid =
1365 this->isTcRootFolderValid && hasBinary && wxFileName::FileExists(tcPath + wxFileName::GetPathSeparator() + binaryName);
1366
1367 if (hasBinary) {
1368 wxLogDebug(_T("The current profile's listed FSO executable '%s' is %s."),
1369 binaryName.c_str(),
1370 this->isCurrentBinaryValid ? _T("valid") : _T("invalid"));
1371 } else {
1372 wxLogDebug(_T("The current profile has no FSO executable listed."));
1373 }
1374
1375 this->ShowSettings(this->isCurrentBinaryValid);
1376 }
1377
1378 /** Updates the status of whether the currently selected FRED binary is valid. */
1379 void BasicSettingsPage::OnCurrentFredBinaryChanged(wxCommandEvent& event) {
1380 bool fredEnabled;
1381 ProMan::GetProfileManager()->GlobalRead(GBL_CFG_OPT_CONFIG_FRED, &fredEnabled, false);
1382 wxCHECK_RET(fredEnabled, _T("OnCurrentFredBinaryChanged called while fredEnabled is false"));
1383
1384 wxString tcPath, fredBinaryName;
1385
1386 if (!ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath)) {
1387 this->isCurrentFredBinaryValid = false;
1388 return;
1389 }
1390
1391 if ((!FSOExecutable::IsRootFolderValid(wxFileName(tcPath, wxEmptyString), true)) && this->isTcRootFolderValid) {
1392 TCManager::GenerateTCChanged();
1393 return;
1394 }
1395
1396 bool hasFredBinary = ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_FRED, &fredBinaryName);
1397 this->isCurrentFredBinaryValid =
1398 this->isTcRootFolderValid && hasFredBinary && wxFileName::FileExists(tcPath + wxFileName::GetPathSeparator() + fredBinaryName);
1399
1400 if (hasFredBinary) {
1401 wxLogDebug(_T("The current profile's listed FRED executable '%s' is %s."),
1402 fredBinaryName.c_str(),
1403 this->isCurrentFredBinaryValid ? _T("valid") : _T("invalid"));
1404 } else {
1405 wxLogDebug(_T("The current profile has no FRED executable listed."));
1406 }
1407 }
1408
1409 /** Hides or shows the settings. */
1410 void BasicSettingsPage::ShowSettings(const bool showSettings) {
1411 if (showSettings) {
1412 if (!this->GetSizer()->GetItem(SETTINGS_SIZER_INDEX)->IsShown()) {
1413 this->GetSizer()->Show(SETTINGS_SIZER_INDEX);
1414 this->Layout();
1415 }
1416 } else { // using else rather than else-if to make the code easier to read (indentation-wise)
1417 if (this->GetSizer()->GetItem(SETTINGS_SIZER_INDEX)->IsShown()) {
1418 this->GetSizer()->Hide(SETTINGS_SIZER_INDEX);
1419 this->Layout();
1420 }
1421 }
1422 }
1423
1424 void BasicSettingsPage::FillResolutionDropBox(wxChoice *resChoice,
1425 const long minHorizontalRes, const long minVerticalRes)
1426 {
1427 ResolutionMan::ResolutionArray resolutions;
1428 ResolutionMan::ApiType apiType;
1429 auto flagListManager = FlagListManager::GetFlagListManager();
1430
1431 if (flagListManager->IsProcessingOK()) {
1432 #if IS_WIN32
1433 // If the current executable is a SDL exe, use that API
1434 if (flagListManager->GetBuildCaps() & BUILD_CAP_SDL) {
1435 apiType = ResolutionMan::API_SDL;
1436 } else {
1437 apiType = ResolutionMan::API_WIN32;
1438 }
1439 #else
1440 // OSX and Linux always use the SDL api
1441 apiType = ResolutionMan::API_SDL;
1442 #endif
1443 ResolutionMan::EnumerateGraphicsModes(apiType, resolutions,
1444 minHorizontalRes, minVerticalRes);
1445
1446 for (auto it = resolutions.begin(), end = resolutions.end();
1447 it != end; ++it)
1448 {
1449 auto p = dynamic_cast<ResolutionMan::Resolution*>(*it);
1450 resChoice->Append(p->GetResString(), p);
1451 }
1452 }
1453 }
1454
1455 /** Takes a resolution drop down box, finds the maximum resolution, updates the provided
1456 width and height variables, and returns the index at which the maximum resolution
1457 was found, returning wxNOT_FOUND on error. */
1458 int BasicSettingsPage::GetMaxSupportedResolution(const wxChoice& resChoice, long& width, long& height) {
1459 if (resChoice.IsEmpty()) {
1460 wxLogError(_T("GetMaxSupportedResolution() given empty resChoice."));
1461 return wxNOT_FOUND;
1462 }
1463
1464 int maxResIndex = -1;
1465 int maxResProduct = 0;
1466 ResolutionMan::Resolution* res;
1467
1468 for (unsigned int i = 0; i < resChoice.GetCount(); ++i) {
1469 res = dynamic_cast<ResolutionMan::Resolution*>(
1470 resChoice.GetClientObject(i));
1471 wxCHECK_MSG(res != NULL, wxNOT_FOUND,
1472 wxString::Format(
1473 _T("choice does not have Resolution object at index %u"), i));
1474
1475 // We could store somewhere the highest resolutions for each
1476 // aspect ratio but 'n' is pretty small, so it is not
1477 // worth the space or complexity tradeoff
1478 if (!res->IsHeader()) {
1479 int resProduct = res->GetWidth() * res->GetHeight();
1480 if (resProduct > maxResProduct) {
1481 maxResIndex = i;
1482 maxResProduct = resProduct;
1483 }
1484 }
1485 }
1486
1487 wxCHECK_MSG(maxResIndex > -1, wxNOT_FOUND,
1488 _T("maximum Resolution was not found"));
1489
1490 res = dynamic_cast<ResolutionMan::Resolution*>(
1491 resChoice.GetClientObject(maxResIndex));
1492 wxCHECK_MSG(res != NULL, wxNOT_FOUND,
1493 _T("Choice is missing max Resolution object"));
1494 width = res->GetWidth();
1495 height = res->GetHeight();
1496
1497 wxLogDebug(_T("Found max resolution of %s at index %d"),
1498 res->GetResString().c_str(), maxResIndex);
1499 return maxResIndex;
1500 }
1501
1502 void BasicSettingsPage::OnSelectVideoResolution(
1503 wxCommandEvent &WXUNUSED(event))
1504 {
1505 wxChoice* choice = dynamic_cast<wxChoice*>(
1506 wxWindow::FindWindowById(ID_RESOLUTION_COMBO, this));
1507 wxCHECK_RET( choice != NULL,
1508 _T("Unable to find resolution combo"));
1509
1510 auto res = dynamic_cast<ResolutionMan::Resolution*>(
1511 choice->GetClientObject(choice->GetSelection()));
1512 wxCHECK_RET( res != NULL,
1513 _T("Choice does not have Resolution objects"));
1514
1515 if (res->IsHeader()) {
1516 // User picked aspect ratio, turn that into a real
1517 // resolution rather than an aspect ratio
1518 choice->SetSelection(choice->GetSelection() + 1);
1519 }
1520
1521 res = dynamic_cast<ResolutionMan::Resolution*>(
1522 choice->GetClientObject(choice->GetSelection()));
1523 wxCHECK_RET( res != NULL,
1524 _T("Cho2ce does not have Resolution objects"));
1525
1526 const long width = static_cast<long>(res->GetWidth());
1527 const long height = static_cast<long>(res->GetHeight());
1528
1529 ProMan::GetProfileManager()->ProfileWrite(
1530 PRO_CFG_VIDEO_RESOLUTION_WIDTH,
1531 width);
1532 ProMan::GetProfileManager()->ProfileWrite(
1533 PRO_CFG_VIDEO_RESOLUTION_HEIGHT,
1534 height);
1535
1536 // update ResolutionMap
1537 const ModItem* activeMod = ModList::GetActiveMod();
1538 wxCHECK_RET(activeMod != NULL,
1539 _T("OnSelectVideoResolution: activeMod is NULL!"));
1540
1541 ResolutionMap::ResolutionWrite(activeMod->shortname,
1542 ResolutionData(width, height));
1543 }
1544
1545 void BasicSettingsPage::OnSelectVideoDepth(wxCommandEvent &WXUNUSED(event)) {
1546 wxChoice* depth = dynamic_cast<wxChoice*>(
1547 wxWindow::FindWindowById(ID_DEPTH_COMBO, this));
1548 wxCHECK_RET( depth != NULL, _T("Unable to find depth choice box"));
1549
1550 ProMan::GetProfileManager()->ProfileWrite(
1551 PRO_CFG_VIDEO_BIT_DEPTH,
1552 (depth->GetSelection() == 0) ? static_cast<long>(16) : static_cast<long>(32));
1553 }
1554
1555 void BasicSettingsPage::OnSelectVideoTextureFilter(wxCommandEvent &WXUNUSED(event)) {
1556 wxChoice* tex = dynamic_cast<wxChoice*>(
1557 wxWindow::FindWindowById(ID_TEXTURE_FILTER_COMBO, this));
1558 wxCHECK_RET( tex != NULL, _T("Unable to find texture filter choice"));
1559
1560 ProMan::GetProfileManager()->ProfileWrite(
1561 PRO_CFG_VIDEO_TEXTURE_FILTER,
1562 (tex->GetSelection() == 0) ? _T("Bilinear") : _T("Trilinear"));
1563 }
1564
1565 void BasicSettingsPage::OnSelectVideoAnisotropic(wxCommandEvent &WXUNUSED(event)) {
1566 wxChoice* as = dynamic_cast<wxChoice*>(
1567 wxWindow::FindWindowById(ID_ANISOTROPIC_COMBO, this));
1568 wxCHECK_RET( as != NULL, _T("Unable to find anisotropic choice"));
1569
1570 ProMan::GetProfileManager()->ProfileWrite(
1571 PRO_CFG_VIDEO_ANISOTROPIC,
1572 (as->GetSelection() == 0) ? static_cast<long>(0) : static_cast<long>(1 << (as->GetSelection()-1)));
1573 }
1574
1575 void BasicSettingsPage::OnSelectVideoAntiAlias(wxCommandEvent &WXUNUSED(event)) {
1576 wxChoice* aa = dynamic_cast<wxChoice*>(
1577 wxWindow::FindWindowById(ID_AA_COMBO, this));
1578 wxCHECK_RET( aa != NULL, _T("Unable to find anti-alias choice"));
1579
1580 ProMan::GetProfileManager()->ProfileWrite(
1581 PRO_CFG_VIDEO_ANTI_ALIAS,
1582 (aa->GetSelection() == 0) ? static_cast<long>(0) : static_cast<long>(1 << (aa->GetSelection())));
1583
1584 }
1585
1586 void BasicSettingsPage::OnSelectSpeechVoice(wxCommandEvent &WXUNUSED(event)) {
1587 wxCHECK_RET( SpeechMan::WasBuiltIn(), _T("Speech was not compiled in."));
1588 wxChoice* voice = dynamic_cast<wxChoice*>(
1589 wxWindow::FindWindowById(ID_SPEECH_VOICE_COMBO, this));
1590 wxCHECK_RET( voice != NULL, _T("Unable to find voice choice box"));
1591
1592 int v = voice->GetSelection();
1593
1594 SpeechMan::SetVoice(v);
1595
1596 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_SPEECH_VOICE, static_cast<long>(v));
1597 }
1598
1599 void BasicSettingsPage::OnChangeSpeechVolume(wxCommandEvent &WXUNUSED(event)) {
1600 wxCHECK_RET( SpeechMan::WasBuiltIn(), _T("Speech was not compiled in."));
1601 wxSlider* volume = dynamic_cast<wxSlider*>(
1602 wxWindow::FindWindowById(ID_SPEECH_VOICE_VOLUME, this));
1603 wxCHECK_RET( volume != NULL, _T("Unable to find speech volume slider"));
1604
1605 int v = volume->GetValue();
1606
1607 SpeechMan::SetVolume(v);
1608
1609 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_SPEECH_VOLUME, static_cast<long>(v));
1610 }
1611
1612 void BasicSettingsPage::OnPlaySpeechText(wxCommandEvent &WXUNUSED(event)) {
1613 wxCHECK_RET( SpeechMan::WasBuiltIn(), _T("Speech was not compiled in."));
1614 wxTextCtrl *text = dynamic_cast<wxTextCtrl*>(
1615 wxWindow::FindWindowById(ID_SPEECH_TEST_TEXT, this));
1616 wxCHECK_RET( text != NULL, _T("Unable to find text control to get play text"));
1617
1618 wxString str = text->GetValue();
1619
1620 SpeechMan::Speak(str);
1621 }
1622
1623 void BasicSettingsPage::OnToggleSpeechInTechroom(wxCommandEvent &event) {
1624 wxCHECK_RET( SpeechMan::WasBuiltIn(), _T("Speech was not compiled in."));
1625 bool checked = event.IsChecked();
1626
1627 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_SPEECH_IN_TECHROOM, checked);
1628 }
1629
1630 void BasicSettingsPage::OnToggleSpeechInBriefing(wxCommandEvent &event) {
1631 wxCHECK_RET( SpeechMan::WasBuiltIn(), _T("Speech was not compiled in."));
1632 bool checked = event.IsChecked();
1633
1634 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_SPEECH_IN_BRIEFINGS, checked);
1635 }
1636
1637 void BasicSettingsPage::OnToggleSpeechInGame(wxCommandEvent &event) {
1638 wxCHECK_RET( SpeechMan::WasBuiltIn(), _T("Speech was not compiled in."));
1639 bool checked = event.IsChecked();
1640
1641 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_SPEECH_IN_GAME, checked);
1642 }
1643
1644 void BasicSettingsPage::OnToggleSpeechInMulti(wxCommandEvent &event) {
1645 wxCHECK_RET( SpeechMan::WasBuiltIn(), _T("Speech was not compiled in."));
1646 bool checked = event.IsChecked();
1647
1648 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_SPEECH_IN_MULTI, checked);
1649 }
1650
1651 void BasicSettingsPage::OnGetMoreVoices(wxCommandEvent &WXUNUSED(event)) {
1652 HelpManager::OpenHelpById(ID_SPEECH_MORE_VOICES_BUTTON);
1653 }
1654
1655 void BasicSettingsPage::OnChangeIP(wxCommandEvent &event) {
1656 wxTextCtrl* ip = dynamic_cast<wxTextCtrl*>(
1657 wxWindow::FindWindowById(event.GetId(), this));
1658 wxCHECK_RET(ip != NULL, _T("Unable to find IP Text Control"));
1659
1660 wxString string(ip->GetValue());
1661
1662 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_NETWORK_IP, string);
1663 }
1664
1665 void BasicSettingsPage::OnChangePort(wxCommandEvent &event) {
1666 wxTextCtrl* port = dynamic_cast<wxTextCtrl*>(
1667 wxWindow::FindWindowById(event.GetId(), this));
1668 wxCHECK_RET(port != NULL, _T("Unable to find Port Text Control"));
1669
1670 if (port->IsEmpty()) {
1671 wxLogDebug(_T("Port field is blank, writing 0 to profile"));
1672 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_NETWORK_PORT, static_cast<long>(0));
1673 return;
1674 }
1675
1676 long portNumber;
1677 if ( port->GetValue().ToLong(&portNumber) ) {
1678 if ( portNumber < 0 ) {
1679 wxLogInfo(_T("Port number must be greater than or equal to 0"));
1680 } else if ( portNumber > 65535 ) {
1681 wxLogInfo(_T("Port number must be less than 65536"));
1682 } else {
1683 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_NETWORK_PORT, portNumber);
1684 }
1685 } else {
1686 wxLogWarning(_T("Port number is not a number"));
1687 }
1688 }
1689
1690 void BasicSettingsPage::OnSelectNetworkSpeed(wxCommandEvent &event) {
1691 wxChoice* networkSpeed = dynamic_cast<wxChoice*>(
1692 wxWindow::FindWindowById(event.GetId(), this));
1693 wxCHECK_RET(networkSpeed != NULL, _T("Unable to find Network speed choice"));
1694
1695 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_NETWORK_SPEED,
1696 networkSpeedOptions[networkSpeed->GetSelection()].GetRegistryValue());
1697 }
1698
1699 void BasicSettingsPage::OnSelectNetworkType(wxCommandEvent &event) {
1700 wxChoice* networkType = dynamic_cast<wxChoice*>(
1701 wxWindow::FindWindowById(event.GetId(), this));
1702 wxCHECK_RET(networkType != NULL, _T("Unable to find Network type choice"));
1703
1704 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_NETWORK_TYPE,
1705 networkTypeOptions[networkType->GetSelection()].GetRegistryValue());
1706 }
1707
1708 void BasicSettingsPage::OnSelectSoundDevice(wxCommandEvent &event) {
1709 wxChoice* openaldevice = dynamic_cast<wxChoice*>(
1710 wxWindow::FindWindowById(event.GetId(), this));
1711 wxCHECK_RET(openaldevice != NULL, _T("Unable to find OpenAL Device choice"));
1712
1713 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_OPENAL_DEVICE, openaldevice->GetStringSelection());
1714
1715 if (OpenALMan::BuildHasNewSoundCode()) {
1716 wxCheckBox* enableEFX = dynamic_cast<wxCheckBox*>(
1717 wxWindow::FindWindowById(ID_ENABLE_EFX));
1718 wxCHECK_RET(enableEFX != NULL, _T("Unable to find enable EFX checkbox"));
1719
1720 enableEFX->Show(OpenALMan::IsEFXSupported(openaldevice->GetStringSelection()));
1721 }
1722 }
1723
1724 void BasicSettingsPage::OnSelectCaptureDevice(wxCommandEvent &event) {
1725 wxCHECK_RET(OpenALMan::BuildHasNewSoundCode(),
1726 _T("Selected FSO build doesn't have new sound code."));
1727
1728 wxChoice* captureDevice = dynamic_cast<wxChoice*>(
1729 wxWindow::FindWindowById(event.GetId(), this));
1730 wxCHECK_RET(captureDevice != NULL, _T("Unable to find capture device choice"));
1731
1732 ProMan::GetProfileManager()->ProfileWrite(
1733 PRO_CFG_OPENAL_CAPTURE_DEVICE, captureDevice->GetStringSelection());
1734 }
1735
1736 void BasicSettingsPage::OnToggleEnableEFX(wxCommandEvent &event) {
1737 wxCHECK_RET(OpenALMan::BuildHasNewSoundCode(),
1738 _T("Selected FSO build doesn't have new sound code."));
1739
1740 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_OPENAL_EFX, event.IsChecked());
1741 }
1742
1743 void BasicSettingsPage::OnChangeSampleRate(wxCommandEvent &event) {
1744 wxCHECK_RET(OpenALMan::BuildHasNewSoundCode(),
1745 _T("Selected FSO build doesn't have new sound code."));
1746
1747 wxTextCtrl* sampleRateBox = dynamic_cast<wxTextCtrl*>(
1748 wxWindow::FindWindowById(event.GetId(), this));
1749 wxCHECK_RET(sampleRateBox != NULL, _T("Unable to find sample rate text control"));
1750
1751 if (sampleRateBox->IsEmpty()) {
1752 wxLogDebug(_T("Sample rate field is blank, writing 0 to profile"));
1753
1754 ProMan::GetProfileManager()->ProfileWrite(
1755 PRO_CFG_OPENAL_SAMPLE_RATE, static_cast<long>(0));
1756 return;
1757 }
1758
1759 long sampleRate;
1760 if ( sampleRateBox->GetValue().ToLong(&sampleRate) ) {
1761 if ( sampleRate <= 0 ) {
1762 wxLogInfo(_T("Sample rate must be greater than 0"));
1763 } else if ( sampleRate > 48000 ) {
1764 wxLogInfo(_T("Sample rate must be at most 48000"));
1765 } else {
1766 ProMan::GetProfileManager()->ProfileWrite(
1767 PRO_CFG_OPENAL_SAMPLE_RATE, sampleRate);
1768 }
1769 } else {
1770 wxLogWarning(_T("Sample rate is not a number"));
1771 }
1772 }
1773
1774 void BasicSettingsPage::OnDownloadOpenAL(wxCommandEvent &WXUNUSED(event)) {
1775 this->OpenNonSCPWebSite(_T("http://connect.creativelabs.com/openal/Downloads/Forms/AllItems.aspx"));
1776 }
1777
1778 void BasicSettingsPage::OnDetectOpenAL(wxCommandEvent& WXUNUSED(event)) {
1779 if ( !OpenALMan::IsInitialized() ) {
1780 this->SetupOpenALSection();
1781 }
1782 }
1783
1784 void BasicSettingsPage::InitializeSoundDeviceDropDownBox(
1785 const SoundDeviceType deviceType) {
1786
1787 wxCHECK_RET((deviceType == PLAYBACK) || (deviceType == CAPTURE),
1788 wxString::Format(_T("Invalid device type %u given."), deviceType));
1789
1790 WindowIDS deviceDropDownBoxID;
1791 wxString deviceTypeNameAdjustment;
1792 wxString deviceProfileEntryName;
1793 wxArrayString availableDevices;
1794 wxString defaultDevice;
1795
1796 if (deviceType == PLAYBACK) {
1797 deviceDropDownBoxID = ID_SELECT_SOUND_DEVICE;
1798 // (deviceTypeNameAdjustment remains empty in this case)
1799 deviceProfileEntryName = PRO_CFG_OPENAL_DEVICE;
1800 availableDevices = OpenALMan::GetAvailablePlaybackDevices();
1801 defaultDevice = OpenALMan::GetSystemDefaultPlaybackDevice();
1802 } else {
1803 deviceDropDownBoxID = ID_SELECT_CAPTURE_DEVICE;
1804 deviceTypeNameAdjustment = _T(" capture");
1805 deviceProfileEntryName = PRO_CFG_OPENAL_CAPTURE_DEVICE;
1806 availableDevices = OpenALMan::GetAvailableCaptureDevices();
1807 defaultDevice = OpenALMan::GetSystemDefaultCaptureDevice();
1808 }
1809
1810 wxChoice* deviceDropDownBox = dynamic_cast<wxChoice*>(
1811 wxWindow::FindWindowById(deviceDropDownBoxID, this));
1812
1813 // validity checking
1814 wxCHECK_RET(deviceDropDownBox != NULL,
1815 wxString::Format(_T("Unable to find the sound%s device drop down box"),
1816 deviceTypeNameAdjustment.c_str()));
1817
1818 wxASSERT_MSG(deviceDropDownBox->IsEmpty(),
1819 wxString::Format(
1820 _T("Sound%s device drop down box has a count of %d")
1821 _T(" when it should be empty; first entry is %s"),
1822 deviceTypeNameAdjustment.c_str(),
1823 deviceDropDownBox->GetCount(),
1824 deviceDropDownBox->GetString(0).c_str()));
1825
1826 wxASSERT(!deviceProfileEntryName.IsEmpty());
1827
1828 if (availableDevices.IsEmpty()) {
1829 if (deviceType == PLAYBACK) {
1830 wxLogWarning(_T("No playback devices were found on the system."));
1831 } else {
1832 wxLogInfo(_T("No capture devices were found on the system."));
1833 }
1834 return;
1835 }
1836
1837 wxASSERT_MSG(!defaultDevice.IsEmpty(),
1838 wxString::Format(_T("No default sound%s device was found."),
1839 deviceTypeNameAdjustment.c_str()));
1840
1841 // update device drop down box and select a device
1842 deviceDropDownBox->Append(availableDevices);
1843
1844 wxString device;
1845
1846 if (ProMan::GetProfileManager()->ProfileRead(deviceProfileEntryName, &device)) {
1847 deviceDropDownBox->SetStringSelection(device);
1848 } else {
1849 wxLogDebug(_T("Reported default sound%s device: %s"),
1850 deviceTypeNameAdjustment.c_str(), defaultDevice.c_str());
1851
1852 if (!defaultDevice.IsEmpty() &&
1853 (deviceDropDownBox->FindString(defaultDevice) != wxNOT_FOUND)) {
1854 deviceDropDownBox->SetStringSelection(defaultDevice);
1855 } else {
1856 wxLogWarning(
1857 _T("Default sound%s device %s not found. Using first entry %s."),
1858 deviceTypeNameAdjustment.c_str(),
1859 defaultDevice.c_str(),
1860 deviceDropDownBox->GetString(0).c_str());
1861 deviceDropDownBox->SetSelection(0);
1862 }
1863 }
1864
1865 // update current profile if necessary
1866 if (!ProMan::GetProfileManager()->ProfileRead(deviceProfileEntryName, &device) ||
1867 (device != deviceDropDownBox->GetStringSelection())) {
1868 wxLogDebug(_T("updating OpenAL sound%s device profile entry to \"%s\""),
1869 deviceTypeNameAdjustment.c_str(),
1870 deviceDropDownBox->GetStringSelection().c_str());
1871 ProMan::GetProfileManager()->ProfileWrite(
1872 deviceProfileEntryName,
1873 deviceDropDownBox->GetStringSelection());
1874 }
1875 }
1876
1877 void BasicSettingsPage::SetupOpenALSection() {
1878 if ( !OpenALMan::WasCompiledIn() ) {
1879 wxLogWarning(_T("Launcher was not compiled to support OpenAL"));
1880 if (this->openALVersion != NULL) {
1881 this->openALVersion->SetLabel(_("Launcher was not compiled to support OpenAL"));
1882 }
1883 this->soundDeviceText->Disable();
1884 this->soundDeviceCombo->Disable();
1885 this->downloadOpenALButton->Disable();
1886 this->detectOpenALButton->Disable();
1887 } else if ( !OpenALMan::Initialize() ) {
1888 wxLogError(_T("Unable to initialize OpenAL"));
1889 if (this->openALVersion != NULL) {
1890 this->openALVersion->SetLabel(_("Unable to initialize OpenAL"));
1891 }
1892 this->soundDeviceText->Disable();
1893 this->soundDeviceCombo->Disable();
1894 this->detectOpenALButton->SetLabel(_("Redetect OpenAL"));
1895 this->downloadOpenALButton->Enable();
1896 } else {
1897 // have working openal
1898 if (this->soundDeviceCombo->IsEmpty()) {
1899 this->InitializeSoundDeviceDropDownBox(PLAYBACK);
1900 }
1901 wxASSERT_MSG(!soundDeviceCombo->IsEmpty(),
1902 _T("sound device combo box is empty!"));
1903
1904 if (OpenALMan::BuildHasNewSoundCode()) {
1905 if (this->captureDeviceCombo->IsEmpty()) {
1906 this->InitializeSoundDeviceDropDownBox(CAPTURE);
1907 }
1908
1909 wxCheckBox* efxCheckBox = dynamic_cast<wxCheckBox*>(
1910 wxWindow::FindWindowById(ID_ENABLE_EFX, this));
1911 wxCHECK_RET(efxCheckBox != NULL,
1912 _T("Cannot find enable EFX checkbox."));
1913
1914 bool enableEFX;
1915 ProMan::GetProfileManager()->ProfileRead(
1916 PRO_CFG_OPENAL_EFX, &enableEFX, false);
1917 efxCheckBox->SetValue(enableEFX);
1918
1919 long sampleRate;
1920 ProMan::GetProfileManager()->ProfileRead(
1921 PRO_CFG_OPENAL_SAMPLE_RATE,
1922 &sampleRate,
1923 DEFAULT_AUDIO_OPENAL_SAMPLE_RATE);
1924
1925 wxTextCtrl* sampleRateBox = dynamic_cast<wxTextCtrl*>(
1926 wxWindow::FindWindowById(ID_AUDIO_SAMPLE_RATE, this));
1927 wxCHECK_RET(sampleRateBox != NULL,
1928 _T("Cannot find sample rate text ctrl."));
1929
1930 if (sampleRate != DEFAULT_AUDIO_OPENAL_SAMPLE_RATE) {
1931 sampleRateBox->ChangeValue(wxString::Format(_T("%ld"), sampleRate));
1932 }
1933
1934 this->soundDeviceText->SetLabel(_("Playback device:"));
1935
1936 if (this->audioOldSoundSizer->GetItem(this->soundDeviceText) != NULL) {
1937 wxASSERT(this->audioOldSoundSizer->GetItem(
1938 this->soundDeviceCombo) != NULL);
1939
1940 this->audioOldSoundSizer->Detach(this->soundDeviceText);
1941 this->audioOldSoundSizer->Detach(this->soundDeviceCombo);
1942
1943 this->audioNewSoundDeviceSizer->Prepend(this->soundDeviceCombo,
1944 wxSizerFlags().Expand());
1945 this->audioNewSoundDeviceSizer->Prepend(this->soundDeviceText,
1946 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
1947 }
1948
1949 this->audioSizer->Hide(this->audioOldSoundSizer, true);
1950 this->audioSizer->Show(this->audioNewSoundSizer, true);
1951
1952 const wxString playbackDevice(this->soundDeviceCombo->GetStringSelection());
1953 if (!OpenALMan::IsEFXSupported(playbackDevice)) {
1954 wxLogDebug(
1955 _T("Playback device '%s' does not support EFX.")
1956 _T(" Hiding Enable EFX checkbox."),
1957 playbackDevice.c_str());
1958 this->audioNewSoundSizer->Hide(efxCheckBox);
1959 }
1960
1961 if (this->captureDeviceCombo->IsEmpty()) {
1962 this->audioNewSoundDeviceSizer->Hide(this->captureDeviceCombo);
1963 this->audioNewSoundDeviceSizer->Hide(this->captureDeviceText);
1964 }
1965
1966 // compute and set max device drop down box length
1967 this->audioNewSoundSizer->Detach(this->audioNewSoundDeviceSizer);
1968
1969 const int minAudioNewSoundSizerWidth =
1970 ClientToWindowSize(audioNewSoundSizer->GetMinSize()).GetWidth();
1971 wxCHECK_RET(minAudioNewSoundSizerWidth > 0,
1972 wxString::Format(
1973 _T("minimum audio new sound sizer width is invalid value %d"),
1974 minAudioNewSoundSizerWidth));
1975 // TODO: Remove the debug statement after further testing.
1976 wxLogDebug(_T("min audio new sound sizer width: %d"),
1977 minAudioNewSoundSizerWidth);
1978
1979 // the 75 is to cover spacing and static box borders (yes, hackish)
1980 const int maxDeviceComboLength =
1981 TAB_AREA_WIDTH - minAudioNewSoundSizerWidth -
1982 this->soundDeviceText->GetSize().GetWidth() - 75;
1983 // TODO: Remove the debug statement after further testing.
1984 wxLogDebug(_T("max device combo length: %d"),
1985 maxDeviceComboLength);
1986
1987 this->soundDeviceCombo->SetMaxLength(maxDeviceComboLength);
1988 this->captureDeviceCombo->SetMaxLength(maxDeviceComboLength);
1989
1990 this->audioNewSoundSizer->Prepend(this->audioNewSoundDeviceSizer);
1991
1992 this->audioSizer->Detach(this->audioNewSoundSizer);
1993 this->audioSizer->Add(this->audioNewSoundSizer,
1994 wxSizerFlags().Proportion(1).Expand().Border(wxLEFT|wxRIGHT|wxBOTTOM, 5));
1995 } else {
1996 this->soundDeviceText->SetLabel(_("Sound device:"));
1997 this->soundDeviceCombo->SetMaxLength(0); // reset
1998
1999 if (this->audioNewSoundDeviceSizer->GetItem(
2000 this->soundDeviceText) != NULL) {
2001 wxASSERT(this->audioNewSoundDeviceSizer->GetItem(
2002 this->soundDeviceCombo) != NULL);
2003
2004 this->audioNewSoundDeviceSizer->Detach(this->soundDeviceText);
2005 this->audioNewSoundDeviceSizer->Detach(this->soundDeviceCombo);
2006
2007 this->audioOldSoundSizer->Add(soundDeviceText,
2008 wxSizerFlags().Border(wxBOTTOM, 5));
2009 this->audioOldSoundSizer->Add(soundDeviceCombo,
2010 wxSizerFlags().Proportion(1).Expand());
2011 }
2012
2013 this->audioSizer->Hide(this->audioNewSoundSizer, true);
2014 this->audioSizer->Show(this->audioOldSoundSizer, true);
2015
2016 this->audioSizer->Detach(this->audioOldSoundSizer);
2017 this->audioSizer->Add(this->audioOldSoundSizer,
2018 wxSizerFlags().Proportion(1).Expand().Border(wxLEFT|wxRIGHT|wxBOTTOM, 5));
2019 }
2020
2021 this->audioSizer->Hide(this->audioButtonsSizer, true);
2022
2023 this->soundDeviceText->Enable();
2024 this->soundDeviceCombo->Enable();
2025
2026 wxLogInfo(OpenALMan::GetCurrentVersion());
2027
2028 this->audioOldSoundSizer->Hide(this->openALVersion);
2029
2030 this->Layout();
2031 this->Refresh();
2032 }
2033 }
2034
2035 void BasicSettingsPage::OpenNonSCPWebSite(wxString url) {
2036 ::wxLaunchDefaultBrowser(url);
2037 }
2038
2039 /** Client data for the Joystick Choice box. Stores the joysticks
2040 Windows ID so that we can pass it back correctly to the engine. */
2041 class JoyNumber: public wxClientData {
2042 public:
2043 JoyNumber(unsigned int i) {
2044 this->number = i;
2045 }
2046 int GetNumber() {
2047 return static_cast<int>(this->number);
2048 }
2049 private:
2050 unsigned int number;
2051 };
2052
2053 void BasicSettingsPage::SetupJoystickSection() {
2054 this->joystickSelected->Clear();
2055 if ( !JoyMan::WasCompiledIn() ) {
2056 this->joystickSelected->Disable();
2057 this->joystickSelected->Append(_("No Launcher Support"));
2058 this->joystickForceFeedback->Disable();
2059 this->joystickDirectionalHit->Disable();
2060 this->joystickDetectButton->Disable();
2061 #if IS_WIN32
2062 this->joystickCalibrateButton->Disable();
2063 #endif
2064 }
2065 else
2066 {
2067 JoyMan::ApiType apiType;
2068
2069 #if IS_APPLE || IS_LINUX
2070 // Unix always uses SDL
2071 apiType = JoyMan::API_SDL;
2072 #else
2073 // If the current executable is a SDL exe, use that API
2074 if (FlagListManager::GetFlagListManager()->GetBuildCaps() & BUILD_CAP_SDL)
2075 {
2076 apiType = JoyMan::API_SDL;
2077 }
2078 else
2079 {
2080 apiType = JoyMan::API_NATIVE;
2081 }
2082 #endif
2083
2084 if (!JoyMan::Initialize(apiType)) {
2085 this->joystickSelected->Disable();
2086 this->joystickSelected->Append(_("Initialize Failed"));
2087 this->joystickForceFeedback->Disable();
2088 this->joystickDirectionalHit->Disable();
2089 this->joystickDetectButton->Enable();
2090 #if IS_WIN32
2091 this->joystickCalibrateButton->Disable();
2092 #endif
2093 }
2094 else {
2095 this->joystickSelected
2096 ->Append(_("No Joystick"), new JoyNumber(DEFAULT_JOYSTICK_ID));
2097 for (unsigned int i = 0; i < JoyMan::NumberOfJoysticks(); i++) {
2098 if (JoyMan::IsJoystickPluggedIn(i)) {
2099 this->joystickSelected
2100 ->Append(JoyMan::JoystickName(i), new JoyNumber(i));
2101 }
2102 }
2103
2104 if (JoyMan::NumberOfPluggedInJoysticks() == 0) {
2105 this->joystickSelected->SetSelection(0);
2106 this->joystickSelected->Disable();
2107 this->joystickForceFeedback->Disable();
2108 this->joystickDirectionalHit->Disable();
2109 this->joystickDetectButton->Enable();
2110 #if IS_WIN32
2111 this->joystickCalibrateButton->Disable();
2112 #endif
2113 }
2114 else {
2115 long profileJoystick;
2116 unsigned int i;
2117 this->joystickSelected->Enable();
2118 #if IS_WIN32
2119 this->joystickDetectButton->Enable();
2120 #endif
2121 ProMan::GetProfileManager()->
2122 ProfileRead(PRO_CFG_JOYSTICK_ID,
2123 &profileJoystick,
2124 DEFAULT_JOYSTICK_ID,
2125 true);
2126 // set current joystick
2127 for (i = 0; i < this->joystickSelected->GetCount(); i++) {
2128 JoyNumber* data = dynamic_cast<JoyNumber*>(
2129 this->joystickSelected->GetClientObject(i));
2130 wxCHECK2_MSG(data != NULL, continue,
2131 _T("JoyNumber is not the clientObject in joystickSelected"));
2132
2133 if (profileJoystick == data->GetNumber()) {
2134 this->joystickSelected->SetSelection(i);
2135 this->SetupControlsForJoystick(i);
2136 return; // All joystick controls are now setup
2137 }
2138 }
2139 // Getting here means that the joystick is no longer installed
2140 // or is not plugged in
2141 if (JoyMan::IsJoystickPluggedIn(profileJoystick)) {
2142 wxLogWarning(_T("Last selected joystick is not plugged in"));
2143 }
2144 else {
2145 wxLogWarning(_T("Last selected joystick does not seem to be installed"));
2146 }
2147 // set to no joystick (the first selection)
2148 this->joystickSelected->SetSelection(0);
2149 this->SetupControlsForJoystick(0);
2150 }
2151 }
2152 }
2153 }
2154
2155 void BasicSettingsPage::SetupControlsForJoystick(unsigned int i) {
2156 JoyNumber* joynumber = dynamic_cast<JoyNumber*>(
2157 this->joystickSelected->GetClientObject(i));
2158 wxCHECK_RET( joynumber != NULL,
2159 _T("JoyNumber is not joystickSelected's client data"));
2160
2161 #if IS_WIN32 // calibration and force feedback don't work on OS X or Linux at the moment
2162 if ( JoyMan::HasCalibrateTool(joynumber->GetNumber()) ) {
2163 this->joystickCalibrateButton->Enable();
2164 } else {
2165 this->joystickCalibrateButton->Disable();
2166 }
2167 #endif
2168
2169 if ( JoyMan::SupportsForceFeedback(joynumber->GetNumber()) ) {
2170 bool ff, direct;
2171 ProMan::GetProfileManager()->ProfileRead(
2172 PRO_CFG_JOYSTICK_DIRECTIONAL, &direct, DEFAULT_JOYSTICK_DIRECTIONAL, true);
2173 ProMan::GetProfileManager()->ProfileRead(
2174 PRO_CFG_JOYSTICK_FORCE_FEEDBACK, &ff, DEFAULT_JOYSTICK_FORCE_FEEDBACK, true);
2175 this->joystickDirectionalHit->SetValue(direct);
2176 this->joystickForceFeedback->SetValue(ff);
2177
2178 this->joystickDirectionalHit->Enable();
2179 this->joystickForceFeedback->Enable();
2180 } else {
2181 this->joystickDirectionalHit->Disable();
2182 this->joystickForceFeedback->Disable();
2183 }
2184
2185 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_JOYSTICK_ID, static_cast<long>(joynumber->GetNumber()));
2186 }
2187
2188 void BasicSettingsPage::OnSelectJoystick(
2189 wxCommandEvent &WXUNUSED(event)) {
2190 this->SetupControlsForJoystick(
2191 this->joystickSelected->GetSelection());
2192 }
2193
2194 void BasicSettingsPage::OnCheckForceFeedback(
2195 wxCommandEvent &event) {
2196 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_JOYSTICK_FORCE_FEEDBACK, event.IsChecked());
2197 }
2198
2199 void BasicSettingsPage::OnCheckDirectionalHit(
2200 wxCommandEvent &event) {
2201 ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_JOYSTICK_DIRECTIONAL, event.IsChecked());
2202 }
2203
2204 void BasicSettingsPage::OnCalibrateJoystick(
2205 wxCommandEvent &WXUNUSED(event)) {
2206 JoyNumber *data = dynamic_cast<JoyNumber*>(
2207 this->joystickSelected->GetClientObject(
2208 this->joystickSelected->GetSelection()));
2209 wxCHECK_RET( data != NULL,
2210 _T("joystickSelected does not have JoyNumber as clientdata"));
2211
2212 JoyMan::LaunchCalibrateTool(data->GetNumber());
2213 }
2214
2215 void BasicSettingsPage::OnDetectJoystick(wxCommandEvent &WXUNUSED(event)) {
2216 if ( JoyMan::DeInitialize() ) {
2217 this->SetupJoystickSection();
2218 }
2219 }
2220
2221 //////////// ProxyChoice
2222 ProxyChoice::ProxyChoice(wxWindow *parent, wxWindowID id)
2223 :wxChoicebook(parent, id) {
2224 wxString type; // NOTE: not adding writeBackIfAbsent to GlobalRead calls, since proxy box not in GUI
2225 ProMan::GetProfileManager()->GlobalRead(GBL_CFG_PROXY_TYPE, &type, _T("none"));
2226
2227 wxPanel* noneProxyPanel = new wxPanel(this);
2228 this->AddPage(noneProxyPanel, _("None"));
2229
2230 /// Manual Proxy
2231 wxPanel* manualProxyPanel = new wxPanel(this);
2232 wxStaticText* proxyHttpText = new wxStaticText(manualProxyPanel, wxID_ANY, _("HTTP Proxy:"));
2233 wxString server;
2234 ProMan::GetProfileManager()->GlobalRead(GBL_CFG_PROXY_SERVER, &server, _T(""));
2235 wxTextCtrl* proxyHttpServer = new wxTextCtrl(manualProxyPanel, ID_PROXY_HTTP_SERVER, server);
2236 wxStaticText* proxyHttpPortText = new wxStaticText(manualProxyPanel, wxID_ANY, _("Port:"));
2237
2238 long port;
2239 ProMan::GetProfileManager()->GlobalRead(GBL_CFG_PROXY_PORT, &port, 0);
2240 wxTextCtrl* proxyHttpPort = new wxTextCtrl(manualProxyPanel, ID_PROXY_HTTP_PORT, wxString::Format(_T("%ld"), port));
2241
2242 wxBoxSizer* manualProxyPortSizer = new wxBoxSizer(wxHORIZONTAL);
2243 manualProxyPortSizer->Add(proxyHttpPortText, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5);
2244 manualProxyPortSizer->Add(proxyHttpPort, wxSizerFlags().Proportion(1));
2245
2246 wxBoxSizer* manualProxySizer = new wxBoxSizer(wxVERTICAL);
2247 manualProxySizer->Add(proxyHttpText);
2248 manualProxySizer->Add(proxyHttpServer, wxSizerFlags().Expand());
2249 manualProxySizer->Add(manualProxyPortSizer, wxSizerFlags().Expand());
2250 manualProxySizer->SetContainingWindow(this);
2251 manualProxyPanel->SetSizer(manualProxySizer);
2252
2253 this->AddPage(manualProxyPanel, _T("Manual"));
2254
2255 if ( type == _T("manual") ) {
2256 this->SetSelection(1);
2257 } else {
2258 this->SetSelection(0);
2259 }
2260 }
2261
2262 ProxyChoice::~ProxyChoice() {
2263 }
2264
2265 BEGIN_EVENT_TABLE(ProxyChoice, wxChoicebook)
2266 EVT_TEXT(ID_PROXY_HTTP_SERVER, ProxyChoice::OnChangeServer)
2267 EVT_TEXT(ID_PROXY_HTTP_PORT, ProxyChoice::OnChangePort)
2268 EVT_CHOICEBOOK_PAGE_CHANGED(ID_PROXY_TYPE, ProxyChoice::OnProxyTypeChange)
2269 END_EVENT_TABLE()
2270
2271 void ProxyChoice::OnChangeServer(wxCommandEvent &event) {
2272 wxString str = event.GetString();
2273
2274 if ( str == wxEmptyString ) {
2275 // do nothing
2276 } else {
2277 ProMan::GetProfileManager()->GlobalWrite(GBL_CFG_PROXY_SERVER, str);
2278 }
2279 }
2280
2281 void ProxyChoice::OnChangePort(wxCommandEvent &event) {
2282 int port = event.GetInt();
2283
2284 ProMan::GetProfileManager()->GlobalWrite(GBL_CFG_PROXY_PORT, static_cast<long>(port));
2285 }
2286
2287 void ProxyChoice::OnProxyTypeChange(wxChoicebookEvent &event) {
2288 int page = event.GetSelection();
2289 wxString str;
2290
2291 switch (page) {
2292 case 0:
2293 str = _T("none");
2294 break;
2295 case 1:
2296 str = _T("manual");
2297 break;
2298 default:
2299 wxFAIL_MSG(wxString::Format(_T("Proxy type changed to invalid id %d"), page));
2300 return;
2301 }
2302
2303 ProMan::GetProfileManager()->GlobalWrite(GBL_CFG_PROXY_TYPE, str);
2304 }