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 "controls/ModList.h"
24 #include "apis/SkinManager.h"
25 #include "apis/ProfileManager.h"
26 #include "apis/TCManager.h"
27 #include "datastructures/FSOExecutable.h"
28 #include "generated/configure_launcher.h"
29
30
31 #include "global/MemoryDebugging.h" // Last include for memory debugging
32
33 const int TEXT_FONT_SIZE = 14;
34 const int TEXT_WRAP_WIDTH = TAB_AREA_WIDTH - 225;
35
ModsPage(wxWindow * parent,SkinSystem * skin)36 ModsPage::ModsPage(wxWindow* parent, SkinSystem *skin): wxPanel(parent, wxID_ANY) {
37 this->skin = skin;
38
39 wxLogDebug(_T("ModsPage is at %p."), this);
40
41 TCManager::RegisterTCChanged(this);
42 wxCommandEvent nullEvent;
43 this->OnTCChanged(nullEvent);
44 }
45
BEGIN_EVENT_TABLE(ModsPage,wxPanel)46 BEGIN_EVENT_TABLE(ModsPage, wxPanel)
47 EVT_COMMAND(wxID_NONE, EVT_TC_CHANGED, ModsPage::OnTCChanged)
48 END_EVENT_TABLE()
49
50 void ModsPage::OnTCChanged(wxCommandEvent &WXUNUSED(event)) {
51 wxString tcPath;
52
53 ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath, wxEmptyString);
54
55 wxSizer* currentSizer = this->GetSizer();
56 if ( currentSizer != NULL ) {
57 currentSizer->Clear(true);
58 }
59 if ( tcPath.IsEmpty()) {
60 wxStaticText* noTC = new wxStaticText(this, wxID_ANY, _("To view a list of available mods, you must first select the folder you installed Diaspora to (or of another FreeSpace 2 Open-based game) on the Basic Settings page."),
61 wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
62 wxFont messageFont(TEXT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
63 noTC->SetFont(messageFont);
64 noTC->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
65 noTC->Wrap(TEXT_WRAP_WIDTH);
66
67 wxFileName infoLocation(_T(RESOURCES_PATH), _T("info_big.png"));
68 wxBitmap infoIcon(infoLocation.GetFullPath(), wxBITMAP_TYPE_ANY);
69 wxASSERT(infoIcon.IsOk());
70 wxStaticBitmap* infoImage = new wxStaticBitmap(this, wxID_ANY, infoIcon);
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 wxStaticText* nonexistentTC = new wxStaticText(this, wxID_ANY,
86 _("The selected root folder does not exist.\n\nSelect a valid root folder for a FreeSpace 2 Open-based game on the Basic Settings page."),
87 wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
88 wxFont messageFont(TEXT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
89 nonexistentTC->SetFont(messageFont);
90 nonexistentTC->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
91 nonexistentTC->Wrap(TEXT_WRAP_WIDTH);
92
93 wxFileName warningLocation(_T(RESOURCES_PATH), _T("warning_big.png"));
94 wxBitmap warningIcon(warningLocation.GetFullPath(), wxBITMAP_TYPE_ANY);
95 wxASSERT(warningIcon.IsOk());
96 wxStaticBitmap* warningImage = new wxStaticBitmap(this, wxID_ANY, warningIcon);
97
98 wxBoxSizer* nonexistentTCSizer = new wxBoxSizer(wxVERTICAL);
99 nonexistentTCSizer->AddStretchSpacer(1);
100 nonexistentTCSizer->Add(warningImage,0, wxALL | wxCENTER);
101 nonexistentTCSizer->AddSpacer(10);
102 nonexistentTCSizer->Add(nonexistentTC, 0, wxALL | wxCENTER);
103 nonexistentTCSizer->AddStretchSpacer(1);
104
105 #if IS_LINUX
106 this->SetSizerAndFit(nonexistentTCSizer);
107 #else
108 this->SetSizer(nonexistentTCSizer);
109 #endif
110 } else if ( !FSOExecutable::HasFSOExecutables(wxFileName(tcPath, wxEmptyString)) ) {
111 wxStaticText* invalidTC = new wxStaticText(this, wxID_ANY,
112 _("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."),
113 wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
114 wxFont messageFont(TEXT_FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
115 invalidTC->SetFont(messageFont);
116 invalidTC->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
117 invalidTC->Wrap(TEXT_WRAP_WIDTH);
118
119 wxFileName warningLocation(_T(RESOURCES_PATH), _T("warning_big.png"));
120 wxBitmap warningIcon(warningLocation.GetFullPath(), wxBITMAP_TYPE_ANY);
121 wxASSERT(warningIcon.IsOk());
122 wxStaticBitmap* warningImage = new wxStaticBitmap(this, wxID_ANY, warningIcon);
123
124 wxBoxSizer* invalidTCSizer = new wxBoxSizer(wxVERTICAL);
125 invalidTCSizer->AddStretchSpacer(1);
126 invalidTCSizer->Add(warningImage,0, wxALL | wxCENTER);
127 invalidTCSizer->AddSpacer(10);
128 invalidTCSizer->Add(invalidTC, 0, wxALL | wxCENTER);
129 invalidTCSizer->AddStretchSpacer(1);
130
131 #if IS_LINUX
132 this->SetSizerAndFit(invalidTCSizer);
133 #else
134 this->SetSizer(invalidTCSizer);
135 #endif
136 } else {
137 #if 0
138 wxStaticText* header = new wxStaticText(this, wxID_ANY,
139 _("Installed mods. Click on Install/Update in the left to search, download, and install additional mods and updates."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
140 header->Wrap(TAB_AREA_WIDTH);
141 #endif
142 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?
143 ModList* modGrid = new ModList(this, modGridSize, skin, tcPath);
144 modGrid->SetMinSize(modGridSize);
145
146 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
147 #if 0
148 sizer->Add(header);
149 #endif
150 sizer->Add(modGrid, wxSizerFlags().Center().Border(wxALL,5));
151
152 this->SetMaxSize(wxSize(TAB_AREA_WIDTH, TAB_AREA_HEIGHT));
153 this->SetSizer(sizer);
154 }
155 this->Layout();
156 }
157