| 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 <wx/wx.h> |
| 20 |
#include "global/ids.h" |
| 21 |
#include "global/ProfileKeys.h" |
| 22 |
#include "controls/BottomButtons.h" |
| 23 |
#include "controls/ModList.h" |
| 24 |
#include "datastructures/FSOExecutable.h" |
| 25 |
#include "datastructures/ResolutionMap.h" |
| 26 |
#include "apis/FREDManager.h" |
| 27 |
#include "apis/TCManager.h" |
| 28 |
#include "apis/ProfileManager.h" |
| 29 |
|
| 30 |
#include "generated/configure_launcher.h" // needed to check whether OSX is used |
| 31 |
|
| 32 |
#include "global/MemoryDebugging.h" // Last include for memory debugging |
| 33 |
|
| 34 |
|
| 35 |
BottomButtons::BottomButtons(wxWindow* parent, wxPoint &pos, wxSize &size) : wxPanel( |
| 36 |
parent, wxID_ANY, pos, size) { |
| 37 |
this->SetMinSize(size); |
| 38 |
|
| 39 |
bool showFred; |
| 40 |
ProMan::GetProfileManager()->GlobalRead(GBL_CFG_OPT_CONFIG_FRED, &showFred, false); |
| 41 |
#if 0 |
| 42 |
this->close = new wxButton(this, ID_CLOSE_BUTTON, _("Close")); |
| 43 |
#endif |
| 44 |
this->help = new wxButton(this, ID_HELP_BUTTON, _("Help")); |
| 45 |
this->fred = new wxButton(this, ID_FRED_BUTTON, _("FRED")); |
| 46 |
this->fred->Show(showFred); |
| 47 |
|
| 48 |
#if 0 |
| 49 |
this->update = new wxButton(this, ID_UPDATE_BUTTON, _("Update Available")); |
| 50 |
this->update->Hide(); |
| 51 |
#endif |
| 52 |
this->play = new wxButton(this, ID_PLAY_BUTTON, _("Play")); |
| 53 |
wxFont playButtonFont = this->play->GetFont(); |
| 54 |
playButtonFont.SetWeight(wxFONTWEIGHT_BOLD); |
| 55 |
this->play->SetFont(playButtonFont); |
| 56 |
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); |
| 57 |
#if 0 |
| 58 |
sizer->Add(this->close); |
| 59 |
#endif |
| 60 |
sizer->Add(this->help); |
| 61 |
sizer->AddStretchSpacer(1); |
| 62 |
#if 0 |
| 63 |
sizer->Add(this->update, wxSizerFlags().ReserveSpaceEvenIfHidden()); |
| 64 |
sizer->AddStretchSpacer(1); |
| 65 |
#endif |
| 66 |
sizer->Add(this->fred, wxSizerFlags().ReserveSpaceEvenIfHidden()); |
| 67 |
sizer->Add(this->play); |
| 68 |
|
| 69 |
this->SetSizerAndFit(sizer); |
| 70 |
this->Layout(); |
| 71 |
|
| 72 |
wxLogDebug(_T("BottomButtons is at %p."), this); |
| 73 |
|
| 74 |
TCManager::RegisterTCBinaryChanged(this); |
| 75 |
TCManager::RegisterTCChanged(this); |
| 76 |
TCManager::RegisterTCActiveModChanged(this); |
| 77 |
TCManager::RegisterTCFredBinaryChanged(this); |
| 78 |
FREDManager::RegisterFREDEnabledChanged(this); |
| 79 |
ResolutionMap::RegisterResolutionMapChanged(this); |
| 80 |
wxCommandEvent nullEvent; |
| 81 |
this->OnTCChanges(nullEvent); |
| 82 |
} |
| 83 |
|
| 84 |
BEGIN_EVENT_TABLE(BottomButtons, wxPanel) |
| 85 |
EVT_COMMAND(wxID_NONE, EVT_TC_CHANGED, BottomButtons::OnTCChanges) |
| 86 |
EVT_COMMAND(wxID_NONE, EVT_TC_ACTIVE_MOD_CHANGED, BottomButtons::OnTCChanges) |
| 87 |
EVT_COMMAND(wxID_NONE, EVT_TC_BINARY_CHANGED, BottomButtons::OnTCChanges) |
| 88 |
EVT_COMMAND(wxID_NONE, EVT_TC_FRED_BINARY_CHANGED, BottomButtons::OnTCChanges) |
| 89 |
EVT_COMMAND(wxID_NONE, EVT_FRED_ENABLED_CHANGED, BottomButtons::OnFREDEnabledChanged) |
| 90 |
EVT_COMMAND(wxID_NONE, EVT_RESOLUTION_MAP_CHANGED, BottomButtons::OnTCChanges) |
| 91 |
END_EVENT_TABLE() |
| 92 |
|
| 93 |
/** remove the text after ".app" in the executable name. |
| 94 |
A no op on other platforms*/ |
| 95 |
#if IS_APPLE |
| 96 |
wxString FixBinaryName(const wxString& binaryName) { |
| 97 |
wxString fixedBinaryName(binaryName); |
| 98 |
// the trailing / ensures that the .app indicates an extension |
| 99 |
int DotAppIndex = binaryName.Find(_T(".app/")); |
| 100 |
if (DotAppIndex != wxNOT_FOUND) { |
| 101 |
fixedBinaryName = binaryName.Left(DotAppIndex + 4); // 4 so that ".app" is retained |
| 102 |
} |
| 103 |
return fixedBinaryName; |
| 104 |
} |
| 105 |
#else |
| 106 |
#define FixBinaryName(binaryName) binaryName |
| 107 |
#endif |
| 108 |
|
| 109 |
void BottomButtons::OnTCChanges(wxCommandEvent &WXUNUSED(event)) { |
| 110 |
wxString tc, binary, fredBinary; |
| 111 |
ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tc, wxEmptyString); |
| 112 |
ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_BINARY, &binary, wxEmptyString); |
| 113 |
if ( tc.IsEmpty() || binary.IsEmpty() || ModList::GetActiveMod() == NULL || !ResolutionMap::HasEntryForActiveMod()) { |
| 114 |
this->play->Disable(); |
| 115 |
} else if ( wxFileName(tc + wxFileName::GetPathSeparator() + binary).FileExists() ) { |
| 116 |
this->play->Enable(); |
| 117 |
} else { |
| 118 |
wxLogWarning(_("Executable %s does not exist"), FixBinaryName(binary).c_str()); |
| 119 |
this->play->Disable(); |
| 120 |
} |
| 121 |
ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_FRED, &fredBinary, wxEmptyString); |
| 122 |
if ( this->fred == NULL ) { |
| 123 |
// do nothing, no button to manipulate |
| 124 |
} else if ( tc.IsEmpty() || fredBinary.IsEmpty() || (!wxFileName::DirExists(tc)) || |
| 125 |
(!FSOExecutable::HasFSOExecutables(wxFileName(tc, wxEmptyString))) ) { |
| 126 |
this->fred->Disable(); |
| 127 |
#if IS_APPLE |
| 128 |
} else if ( wxFileName(tc + wxFileName::GetPathSeparator() + fredBinary).FileExists() ) { |
| 129 |
#else |
| 130 |
} else if ( wxFileName(tc, fredBinary).FileExists() ) { |
| 131 |
#endif |
| 132 |
this->fred->Enable(); |
| 133 |
} else { |
| 134 |
wxLogWarning(_("FRED executable %s does not exist"), FixBinaryName(fredBinary).c_str()); |
| 135 |
this->fred->Disable(); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
void BottomButtons::OnFREDEnabledChanged(wxCommandEvent &WXUNUSED(event)) { |
| 140 |
bool showFred; |
| 141 |
ProMan::GetProfileManager()->GlobalRead(GBL_CFG_OPT_CONFIG_FRED, &showFred, false); |
| 142 |
|
| 143 |
this->fred->Show(showFred); |
| 144 |
} |