| 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 <wx/settings.h> |
| 21 |
#include "tabs/ModsPage.h" |
| 22 |
#include "global/ids.h" |
| 23 |
#include "global/ProfileKeys.h" |
| 24 |
#include "controls/ModList.h" |
| 25 |
#include "apis/SkinManager.h" |
| 26 |
#include "apis/ProfileManager.h" |
| 27 |
#include "apis/TCManager.h" |
| 28 |
#include "datastructures/FSOExecutable.h" |
| 29 |
#include "generated/configure_launcher.h" |
| 30 |
|
| 31 |
|
| 32 |
#include "global/MemoryDebugging.h" // Last include for memory debugging |
| 33 |
|
| 34 |
const int TEXT_WRAP_WIDTH = TAB_AREA_WIDTH - 225; |
| 35 |
|
| 36 |
ModsPage::ModsPage(wxWindow* parent): wxPanel(parent, wxID_ANY) { |
| 37 |
wxLogDebug(_T("ModsPage is at %p."), this); |
| 38 |
|
| 39 |
SkinSystem::RegisterTCSkinChanged(this); |
| 40 |
|
| 41 |
TCManager::RegisterTCChanged(this); |
| 42 |
wxCommandEvent nullEvent; |
| 43 |
this->OnTCChanged(nullEvent); |
| 44 |
} |
| 45 |
|
| 46 |
BEGIN_EVENT_TABLE(ModsPage, wxPanel) |
| 47 |
EVT_COMMAND(wxID_NONE, EVT_TC_CHANGED, ModsPage::OnTCChanged) |
| 48 |
EVT_COMMAND(wxID_NONE, EVT_TC_SKIN_CHANGED, ModsPage::OnTCSkinChanged) |
| 49 |
END_EVENT_TABLE() |
| 50 |
|
| 51 |
void ModsPage::OnTCChanged(wxCommandEvent &WXUNUSED(event)) { |
| 52 |
wxString tcPath; |
| 53 |
|
| 54 |
ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath, wxEmptyString); |
| 55 |
|
| 56 |
wxSizer* currentSizer = this->GetSizer(); |
| 57 |
if ( currentSizer != NULL ) { |
| 58 |
currentSizer->Clear(true); |
| 59 |
} |
| 60 |
if ( tcPath.IsEmpty()) { |
| 61 |
SkinSystem::GetSkinSystem()->ResetTCSkin(); |
| 62 |
|
| 63 |
wxStaticText* noTC = new wxStaticText(this, wxID_ANY, _("To view a list of available mods, you must first select the root folder of an FS2 Open game on the Basic Settings page."), |
| 64 |
wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); |
| 65 |
noTC->SetFont(SkinSystem::GetSkinSystem()->GetMessageFont()); |
| 66 |
noTC->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); |
| 67 |
noTC->Wrap(TEXT_WRAP_WIDTH); |
| 68 |
|
| 69 |
wxStaticBitmap* infoImage = |
| 70 |
new wxStaticBitmap(this, ID_MODS_PAGE_INFO_IMAGE, SkinSystem::GetSkinSystem()->GetBigInfoIcon()); |
| 71 |
|
| 72 |
wxBoxSizer* noTCSizer = new wxBoxSizer(wxVERTICAL); |
| 73 |
noTCSizer->AddStretchSpacer(1); |
| 74 |
noTCSizer->Add(infoImage,0, wxALL | wxCENTER); |
| 75 |
noTCSizer->AddSpacer(10); |
| 76 |
noTCSizer->Add(noTC, 0, wxALL | wxCENTER); |
| 77 |
noTCSizer->AddStretchSpacer(1); |
| 78 |
|
| 79 |
#if IS_LINUX |
| 80 |
this->SetSizerAndFit(noTCSizer); |
| 81 |
#else |
| 82 |
this->SetSizer(noTCSizer); |
| 83 |
#endif |
| 84 |
} else if ( !wxFileName::DirExists(tcPath) ) { |
| 85 |
SkinSystem::GetSkinSystem()->ResetTCSkin(); |
| 86 |
|
| 87 |
wxStaticText* nonexistentTC = new wxStaticText(this, wxID_ANY, |
| 88 |
_("The selected root folder does not exist.\n\nSelect a valid root folder for an FS2 Open game on the Basic Settings page."), |
| 89 |
wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); |
| 90 |
nonexistentTC->SetFont(SkinSystem::GetSkinSystem()->GetMessageFont()); |
| 91 |
nonexistentTC->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); |
| 92 |
nonexistentTC->Wrap(TEXT_WRAP_WIDTH); |
| 93 |
|
| 94 |
wxStaticBitmap* warningImage = |
| 95 |
new wxStaticBitmap(this, ID_MODS_PAGE_WARNING_IMAGE, SkinSystem::GetSkinSystem()->GetBigWarningIcon()); |
| 96 |
|
| 97 |
wxBoxSizer* nonexistentTCSizer = new wxBoxSizer(wxVERTICAL); |
| 98 |
nonexistentTCSizer->AddStretchSpacer(1); |
| 99 |
nonexistentTCSizer->Add(warningImage,0, wxALL | wxCENTER); |
| 100 |
nonexistentTCSizer->AddSpacer(10); |
| 101 |
nonexistentTCSizer->Add(nonexistentTC, 0, wxALL | wxCENTER); |
| 102 |
nonexistentTCSizer->AddStretchSpacer(1); |
| 103 |
|
| 104 |
#if IS_LINUX |
| 105 |
this->SetSizerAndFit(nonexistentTCSizer); |
| 106 |
#else |
| 107 |
this->SetSizer(nonexistentTCSizer); |
| 108 |
#endif |
| 109 |
} else if ( !FSOExecutable::HasFSOExecutables(wxFileName(tcPath, wxEmptyString)) ) { |
| 110 |
SkinSystem::GetSkinSystem()->ResetTCSkin(); |
| 111 |
|
| 112 |
wxStaticText* invalidTC = new wxStaticText(this, wxID_ANY, |
| 113 |
_("The selected root folder does not contain any FS2 Open executables.\n\nOn the Basic Settings page, either select a different root folder, or add FS2 Open executables to the selected root folder and press the Refresh button."), |
| 114 |
wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); |
| 115 |
invalidTC->SetFont(SkinSystem::GetSkinSystem()->GetMessageFont()); |
| 116 |
invalidTC->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); |
| 117 |
invalidTC->Wrap(TEXT_WRAP_WIDTH); |
| 118 |
|
| 119 |
wxStaticBitmap* warningImage = |
| 120 |
new wxStaticBitmap(this, ID_MODS_PAGE_WARNING_IMAGE, SkinSystem::GetSkinSystem()->GetBigWarningIcon()); |
| 121 |
|
| 122 |
wxBoxSizer* invalidTCSizer = new wxBoxSizer(wxVERTICAL); |
| 123 |
invalidTCSizer->AddStretchSpacer(1); |
| 124 |
invalidTCSizer->Add(warningImage,0, wxALL | wxCENTER); |
| 125 |
invalidTCSizer->AddSpacer(10); |
| 126 |
invalidTCSizer->Add(invalidTC, 0, wxALL | wxCENTER); |
| 127 |
invalidTCSizer->AddStretchSpacer(1); |
| 128 |
|
| 129 |
#if IS_LINUX |
| 130 |
this->SetSizerAndFit(invalidTCSizer); |
| 131 |
#else |
| 132 |
this->SetSizer(invalidTCSizer); |
| 133 |
#endif |
| 134 |
} else { |
| 135 |
#if 0 |
| 136 |
wxStaticText* header = new wxStaticText(this, wxID_ANY, |
| 137 |
_("Installed mods. Click on Install/Update in the left to search, download, and install additional mods and updates."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); |
| 138 |
header->Wrap(TAB_AREA_WIDTH); |
| 139 |
#endif |
| 140 |
wxSize modGridSize(TAB_AREA_WIDTH - 20, TAB_AREA_HEIGHT); // FIXME for left and right borders of 5 pixels each -- but why does it have to be 20? |
| 141 |
ModList* modGrid = new ModList(this, modGridSize, tcPath); |
| 142 |
modGrid->SetMinSize(modGridSize); |
| 143 |
|
| 144 |
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); |
| 145 |
#if 0 |
| 146 |
sizer->Add(header); |
| 147 |
#endif |
| 148 |
sizer->Add(modGrid, wxSizerFlags().Center().Border(wxALL,5)); |
| 149 |
|
| 150 |
this->SetMaxSize(wxSize(TAB_AREA_WIDTH, TAB_AREA_HEIGHT)); |
| 151 |
this->SetSizer(sizer); |
| 152 |
} |
| 153 |
this->Layout(); |
| 154 |
} |
| 155 |
|
| 156 |
void ModsPage::OnTCSkinChanged(wxCommandEvent &WXUNUSED(event)) { |
| 157 |
wxStaticBitmap* infoImage = dynamic_cast<wxStaticBitmap*>( |
| 158 |
wxWindow::FindWindowById(ID_MODS_PAGE_INFO_IMAGE, this)); |
| 159 |
|
| 160 |
if (infoImage != NULL) { |
| 161 |
infoImage->SetBitmap(SkinSystem::GetSkinSystem()->GetBigInfoIcon()); |
| 162 |
} |
| 163 |
|
| 164 |
wxStaticBitmap* warningImage = dynamic_cast<wxStaticBitmap*>( |
| 165 |
wxWindow::FindWindowById(ID_MODS_PAGE_WARNING_IMAGE, this)); |
| 166 |
|
| 167 |
if (warningImage != NULL) { |
| 168 |
warningImage->SetBitmap(SkinSystem::GetSkinSystem()->GetBigWarningIcon()); |
| 169 |
} |
| 170 |
} |