File: ModsPage.cpp

package info (click to toggle)
freespace2-launcher-wxlauncher 0.11.0%2Bdfsg-3
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye
  • size: 2,368 kB
  • sloc: cpp: 13,446; python: 797; makefile: 12; sh: 12
file content (170 lines) | stat: -rw-r--r-- 6,516 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
Copyright (C) 2009-2010 wxLauncher Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include <wx/wx.h>
#include <wx/settings.h>
#include "tabs/ModsPage.h"
#include "global/ids.h"
#include "global/ProfileKeys.h"
#include "controls/ModList.h"
#include "apis/SkinManager.h"
#include "apis/ProfileManager.h"
#include "apis/TCManager.h"
#include "datastructures/FSOExecutable.h"
#include "generated/configure_launcher.h"


#include "global/MemoryDebugging.h" // Last include for memory debugging

const int TEXT_WRAP_WIDTH = TAB_AREA_WIDTH - 225;

ModsPage::ModsPage(wxWindow* parent): wxPanel(parent, wxID_ANY) {
	wxLogDebug(_T("ModsPage is at %p."), this);
	
	SkinSystem::RegisterTCSkinChanged(this);

	TCManager::RegisterTCChanged(this);
	wxCommandEvent nullEvent;
	this->OnTCChanged(nullEvent);
}

BEGIN_EVENT_TABLE(ModsPage, wxPanel)
EVT_COMMAND(wxID_NONE, EVT_TC_CHANGED, ModsPage::OnTCChanged)
EVT_COMMAND(wxID_NONE, EVT_TC_SKIN_CHANGED, ModsPage::OnTCSkinChanged)
END_EVENT_TABLE()

void ModsPage::OnTCChanged(wxCommandEvent &WXUNUSED(event)) {
	wxString tcPath;

	ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath, wxEmptyString);

	wxSizer* currentSizer = this->GetSizer();
	if ( currentSizer != NULL ) {
		currentSizer->Clear(true);
	}
	if ( tcPath.IsEmpty()) {
		SkinSystem::GetSkinSystem()->ResetTCSkin();
		
		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."),
											  wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
		noTC->SetFont(SkinSystem::GetSkinSystem()->GetMessageFont());
		noTC->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
		noTC->Wrap(TEXT_WRAP_WIDTH);

		wxStaticBitmap* infoImage =
			new wxStaticBitmap(this, ID_MODS_PAGE_INFO_IMAGE, SkinSystem::GetSkinSystem()->GetBigInfoIcon());

		wxBoxSizer* noTCSizer = new wxBoxSizer(wxVERTICAL);
		noTCSizer->AddStretchSpacer(1);
		noTCSizer->Add(infoImage,0, wxALL | wxCENTER);
		noTCSizer->AddSpacer(10);
		noTCSizer->Add(noTC, 0, wxALL | wxCENTER);
		noTCSizer->AddStretchSpacer(1);

#if IS_LINUX
		this->SetSizerAndFit(noTCSizer);
#else
		this->SetSizer(noTCSizer);
#endif
	} else if ( !wxFileName::DirExists(tcPath)  ) {
		SkinSystem::GetSkinSystem()->ResetTCSkin();
		
		wxStaticText* nonexistentTC = new wxStaticText(this, wxID_ANY,
			_("The selected root folder does not exist.\n\nSelect a valid root folder for an FS2 Open game on the Basic Settings page."),
			wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
		nonexistentTC->SetFont(SkinSystem::GetSkinSystem()->GetMessageFont());
		nonexistentTC->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
		nonexistentTC->Wrap(TEXT_WRAP_WIDTH);

		wxStaticBitmap* warningImage =
			new wxStaticBitmap(this, ID_MODS_PAGE_WARNING_IMAGE, SkinSystem::GetSkinSystem()->GetBigWarningIcon());

		wxBoxSizer* nonexistentTCSizer = new wxBoxSizer(wxVERTICAL);
		nonexistentTCSizer->AddStretchSpacer(1);
		nonexistentTCSizer->Add(warningImage,0, wxALL | wxCENTER);
		nonexistentTCSizer->AddSpacer(10);
		nonexistentTCSizer->Add(nonexistentTC, 0, wxALL | wxCENTER);
		nonexistentTCSizer->AddStretchSpacer(1);

#if IS_LINUX
		this->SetSizerAndFit(nonexistentTCSizer);
#else
		this->SetSizer(nonexistentTCSizer);
#endif
	} else if ( !FSOExecutable::HasFSOExecutables(wxFileName(tcPath, wxEmptyString)) ) {
		SkinSystem::GetSkinSystem()->ResetTCSkin();
		
		wxStaticText* invalidTC = new wxStaticText(this, wxID_ANY,
			_("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."),
			wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
		invalidTC->SetFont(SkinSystem::GetSkinSystem()->GetMessageFont());
		invalidTC->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
		invalidTC->Wrap(TEXT_WRAP_WIDTH);
		
		wxStaticBitmap* warningImage =
			new wxStaticBitmap(this, ID_MODS_PAGE_WARNING_IMAGE, SkinSystem::GetSkinSystem()->GetBigWarningIcon());
		
		wxBoxSizer* invalidTCSizer = new wxBoxSizer(wxVERTICAL);
		invalidTCSizer->AddStretchSpacer(1);
		invalidTCSizer->Add(warningImage,0, wxALL | wxCENTER);
		invalidTCSizer->AddSpacer(10);
		invalidTCSizer->Add(invalidTC, 0, wxALL | wxCENTER);
		invalidTCSizer->AddStretchSpacer(1);

#if IS_LINUX
		this->SetSizerAndFit(invalidTCSizer);
#else
		this->SetSizer(invalidTCSizer);
#endif
	} else {
#if 0
		wxStaticText* header = new wxStaticText(this, wxID_ANY,
			_("Installed mods.  Click on Install/Update in the left to search, download, and install additional mods and updates."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE);
		header->Wrap(TAB_AREA_WIDTH);
#endif
		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?
		ModList* modGrid = new ModList(this, modGridSize, tcPath);
		modGrid->SetMinSize(modGridSize);

		wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
#if 0
		sizer->Add(header);
#endif
		sizer->Add(modGrid, wxSizerFlags().Center().Border(wxALL,5));

		this->SetMaxSize(wxSize(TAB_AREA_WIDTH, TAB_AREA_HEIGHT));
		this->SetSizer(sizer);
	}
	this->Layout();
}

void ModsPage::OnTCSkinChanged(wxCommandEvent &WXUNUSED(event)) {
	wxStaticBitmap* infoImage = dynamic_cast<wxStaticBitmap*>(
		wxWindow::FindWindowById(ID_MODS_PAGE_INFO_IMAGE, this));
	
	if (infoImage != NULL) {
		infoImage->SetBitmap(SkinSystem::GetSkinSystem()->GetBigInfoIcon());
	}
	
	wxStaticBitmap* warningImage = dynamic_cast<wxStaticBitmap*>(
		wxWindow::FindWindowById(ID_MODS_PAGE_WARNING_IMAGE, this));
	
	if (warningImage != NULL) {
		warningImage->SetBitmap(SkinSystem::GetSkinSystem()->GetBigWarningIcon());
	}
}