| 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 |
#include <vector> |
| 21 |
|
| 22 |
#include <wx/wx.h> |
| 23 |
#include <wx/vlbox.h> |
| 24 |
#include <wx/fileconf.h> |
| 25 |
#include <wx/wfstream.h> |
| 26 |
#include <wx/sstream.h> |
| 27 |
#include <wx/mstream.h> |
| 28 |
#include <wx/tokenzr.h> |
| 29 |
#include <wx/arrstr.h> |
| 30 |
#include <wx/filename.h> |
| 31 |
#include <wx/dir.h> |
| 32 |
#include <wx/html/htmlwin.h> |
| 33 |
|
| 34 |
#include "apis/SkinManager.h" |
| 35 |
#include "global/ids.h" |
| 36 |
#include "global/ProfileKeys.h" |
| 37 |
#include "global/ModDefaults.h" |
| 38 |
#include "global/ModIniKeys.h" |
| 39 |
#include "global/Utils.h" |
| 40 |
#include "controls/ModList.h" |
| 41 |
#include "apis/ProfileManager.h" |
| 42 |
#include "apis/TCManager.h" |
| 43 |
|
| 44 |
#include "global/MemoryDebugging.h" |
| 45 |
|
| 46 |
using TextUtils::Words; |
| 47 |
using TextUtils::ArrayOfWords; |
| 48 |
|
| 49 |
const wxString NO_MOD(_("(No mod)")); |
| 50 |
// to keep the presets box from overlapping with flag list |
| 51 |
const size_t MAX_PRESET_NAME_LENGTH = 32; |
| 52 |
|
| •53 |
class ModInfoDialog: public wxDialog { |
| 54 |
public: |
| 55 |
ModInfoDialog(ModItem* item, wxWindow* parent); |
| 56 |
void OnLinkClicked(wxHtmlLinkEvent &event); |
| 57 |
|
| 58 |
private: |
| 59 |
class ImageDrawer: public wxPanel { |
| 60 |
public: |
| 61 |
ImageDrawer(ModInfoDialog* parent); |
| 62 |
|
| 63 |
void OnDraw(wxPaintEvent &event); |
| 64 |
|
| 65 |
private: |
| 66 |
ModInfoDialog* parent; |
| 67 |
|
| 68 |
DECLARE_EVENT_TABLE(); |
| 69 |
}; |
| 70 |
friend class ImageDrawer; |
| 71 |
|
| 72 |
ModItem* item; |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
ConfigPair::ConfigPair(const wxString &shortname, wxFileConfig *config) { |
| 77 |
this->shortname = shortname; |
| 78 |
this->config = config; |
| 79 |
} |
| 80 |
|
| 81 |
ConfigPair::~ConfigPair() { |
| 82 |
if ( this->config != NULL ) { |
| 83 |
delete this->config; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
#include <wx/arrimpl.cpp> |
| 88 |
WX_DEFINE_OBJARRAY(ConfigArray); |
| 89 |
|
| 90 |
bool CompareModItems(ModItem* item1, ModItem* item2) { |
| 91 |
wxASSERT(item1 != NULL); |
| 92 |
wxASSERT(item2 != NULL); |
| 93 |
|
| 94 |
wxString item1Name( |
| 95 |
(!item1->name.IsEmpty()) ? item1->name : item1->shortname); |
| 96 |
|
| 97 |
wxString item2Name( |
| 98 |
(!item2->name.IsEmpty()) ? item2->name : item2->shortname); |
| 99 |
|
| 100 |
// ignore a leading "the" for comparison purposes |
| 101 |
wxString temp; |
| 102 |
|
| 103 |
if (item1Name.Lower().StartsWith(_T("the"), &temp)) { |
| 104 |
item1Name = temp.Trim(false); |
| 105 |
} |
| 106 |
|
| 107 |
if (item2Name.Lower().StartsWith(_T("the"), &temp)) { |
| 108 |
item2Name = temp.Trim(false); |
| 109 |
} |
| 110 |
|
| 111 |
// (No mod) must come before all other mods |
| 112 |
if (!item1->shortname.Cmp(NO_MOD)) { |
| 113 |
return true; |
| 114 |
} else if (!item2->shortname.Cmp(NO_MOD)) { |
| 115 |
return false; |
| 116 |
} else { |
| 117 |
return item1Name.CmpNoCase(item2Name) < 0; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
const ModItem* ModList::activeMod = NULL; |
| 122 |
|
| 123 |
class ModIniFinder: public wxDirTraverser { |
| 124 |
public: |
| 125 |
const wxArrayString& GetFiles() const { |
| 126 |
return files; |
| 127 |
} |
| 128 |
virtual wxDirTraverseResult OnDir(const wxString& dirname) { |
| 129 |
if (ShouldIgnore(dirname)) { |
| 130 |
return wxDIR_IGNORE; |
| 131 |
} else { |
| 132 |
return wxDIR_CONTINUE; |
| 133 |
} |
| 134 |
} |
| 135 |
virtual wxDirTraverseResult OnFile(const wxString& filename) { |
| 136 |
if (filename.EndsWith(_T("mod.ini"))) { |
| 137 |
files.Add(filename); |
| 138 |
} |
| 139 |
return wxDIR_CONTINUE; |
| 140 |
} |
| 141 |
private: |
| 142 |
bool ShouldIgnore(const wxString& dirname) { |
| 143 |
const wxString realDirName(dirname.AfterLast(wxFileName::GetPathSeparator())); |
| 144 |
return realDirName.EndsWith(_T(".app")) || realDirName.StartsWith(_T(".")); |
| 145 |
} |
| 146 |
wxArrayString files; |
| 147 |
}; |
| 148 |
|
| 149 |
void ModList::SetSkinBitmap( |
| 150 |
const wxFileConfig& config, |
| 151 |
const wxString& modIniKey, |
| 152 |
const wxString& tcPath, |
| 153 |
const wxString& bitmapName, |
| 154 |
bool (Skin::* setFnPtr)(const wxBitmap&)) { |
| 155 |
wxCHECK_RET(!modIniKey.IsEmpty(), _T("SetSkinBitmap(): modIniKey is empty!")); |
| 156 |
wxCHECK_RET(!tcPath.IsEmpty(), _T("SetSkinBitmap(): tcPath is empty!")); |
| 157 |
wxCHECK_RET(!bitmapName.IsEmpty(), _T("SetSkinBitmap(): bitmapName is empty!")); |
| 158 |
wxCHECK_RET(setFnPtr != NULL, _T("SetSkinBitmap(): setFnPtr is NULL!")); |
| 159 |
wxCHECK_RET(this->TCSkin != NULL, _T("SetSkinBitmap(): TCSkin is NULL!")); |
| 160 |
|
| 161 |
wxString bitmapPath; |
| 162 |
readIniFileString(&config, modIniKey, bitmapPath); |
| 163 |
|
| 164 |
if ( !bitmapPath.IsEmpty() ) { |
| 165 |
wxFileName filename; |
| 166 |
|
| 167 |
if (SkinSystem::SearchFile(filename, tcPath, wxEmptyString, bitmapPath)) { |
| 168 |
if ((this->TCSkin->*setFnPtr)(wxBitmap(filename.GetFullPath(), wxBITMAP_TYPE_ANY))) { |
| 169 |
wxLogDebug(_T("Set skin %s to '%s'"), |
| 170 |
bitmapName.c_str(), |
| 171 |
filename.GetFullPath().c_str()); |
| 172 |
} else { |
| 173 |
wxLogWarning(_T("Could not set skin %s to '%s'"), |
| 174 |
bitmapName.c_str(), |
| 175 |
filename.GetFullPath().c_str()); |
| 176 |
} |
| 177 |
} else { |
| 178 |
wxLogWarning(_T("Could not find skin %s file '%s%c%s'."), |
| 179 |
bitmapName.c_str(), |
| 180 |
tcPath.c_str(), |
| 181 |
wxFileName::GetPathSeparator(), |
| 182 |
bitmapPath.c_str()); |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
ModList::ModList(wxWindow *parent, wxSize& size, wxString tcPath) |
| 188 |
: configFiles(new ConfigArray()), tableData(new ModItemArray()), TCSkin(NULL) { |
| 189 |
this->Create(parent, ID_MODLISTBOX, wxDefaultPosition, size, |
| 190 |
wxLB_SINGLE | wxLB_ALWAYS_SB | wxBORDER); |
| 191 |
this->SetMargins(10, 10); |
| 192 |
|
| 193 |
SkinSystem::RegisterTCSkinChanged(this); |
| 194 |
|
| 195 |
std::vector<ModItem*> modsTemp; // for use in presorting |
| 196 |
|
| 197 |
// scan for mods in the current TCs directory |
| 198 |
ModIniFinder iniFinder; |
| 199 |
|
| 200 |
wxASSERT(wxDir::Exists(tcPath)); |
| 201 |
wxDir dir(tcPath); |
| 202 |
dir.Traverse(iniFinder, _T("mod.ini")); |
| 203 |
|
| 204 |
wxArrayString foundInis(iniFinder.GetFiles()); |
| 205 |
|
| 206 |
if ( foundInis.Count() > 0 ) { |
| 207 |
wxLogDebug(_T("I found %ld .ini files:"), foundInis.Count()); |
| 208 |
} else { |
| 209 |
wxLogDebug(_T("I did not find any .ini files.")); |
| 210 |
} |
| 211 |
|
| 212 |
// parse mod.ini's in all of the directories that contain one |
| 213 |
|
| 214 |
wxLogDebug(_T("Inserting '(No mod)'")); |
| 215 |
wxFileName tcmodini(tcPath, _T("mod.ini")); |
| 216 |
if ( tcmodini.IsOk() && tcmodini.FileExists() ) { |
| 217 |
wxLogDebug(_T(" Found a mod.ini in the root TC folder. (%s)"), tcmodini.GetFullPath().c_str()); |
| 218 |
|
| 219 |
if (!ParseModIni(tcmodini.GetFullPath(), tcPath, true)) { |
| 220 |
wxLogError(_T(" Error parsing mod.ini in the root TC folder. (%s)"), |
| 221 |
tcmodini.GetFullPath().c_str()); |
| 222 |
} |
| 223 |
|
| 224 |
// make sure that a mod.ini in the root TC folder is not apart of this set |
| 225 |
// because it will be addressed shortly and specificly |
| 226 |
int pos = foundInis.Index(tcmodini.GetFullPath()); |
| 227 |
if ( pos != wxNOT_FOUND ) { |
| 228 |
foundInis.RemoveAt(pos); |
| 229 |
} |
| 230 |
|
| 231 |
} else { |
| 232 |
this->configFiles->Add(new ConfigPair(NO_MOD, new wxFileConfig())); |
| 233 |
wxLogDebug(_T(" Using defaults for TC.")); |
| 234 |
} |
| 235 |
|
| 236 |
wxLogDebug(_T("Starting to parse mod.ini's...")); |
| 237 |
for (size_t i = 0; i < foundInis.Count(); i++) { |
| 238 |
wxLogDebug(_T(" Parsing %s"), foundInis.Item(i).c_str()); |
| 239 |
|
| 240 |
if (!ParseModIni(foundInis.Item(i), tcPath)) { |
| 241 |
wxLogError(_T(" Parsing %s failed."), foundInis.Item(i).c_str()); |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
// create internal repesentation of the mod.ini's |
| 246 |
wxLogDebug(_T("Transforming mod.ini's")); |
| 247 |
|
| 248 |
for(size_t i = 0; i < this->configFiles->size(); i++) { |
| 249 |
wxString shortname = this->configFiles->Item(i).shortname; |
| 250 |
wxFileConfig* config = this->configFiles->Item(i).config; |
| 251 |
ModItem* item = new ModItem(); |
| 252 |
wxLogDebug(_T(" %s"), shortname.c_str()); |
| 253 |
|
| 254 |
item->shortname = shortname; |
| 255 |
|
| 256 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_MOD_NAME, item->name); |
| 257 |
|
| 258 |
wxString image255x112path; |
| 259 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_IMAGE_255X112, image255x112path); |
| 260 |
|
| 261 |
if (!image255x112path.IsEmpty()) { |
| 262 |
wxFileName filename; |
| 263 |
wxString searchShortname((i == 0) ? wxString(wxEmptyString) : shortname); |
| 264 |
|
| 265 |
if (SkinSystem::SearchFile(filename, tcPath, searchShortname, image255x112path)) { |
| 266 |
wxImage image(filename.GetFullPath()); |
| 267 |
|
| 268 |
if (image.IsOk()) { |
| 269 |
if ((image.GetWidth() == SkinSystem::ModInfoDialogImageWidth) && |
| 270 |
(image.GetHeight() == SkinSystem::ModInfoDialogImageHeight)) { |
| 271 |
item->image255x112 = wxBitmap(image); |
| 272 |
} else { |
| 273 |
wxLogWarning(_T("image255x112 has invalid dimensions %dx%d"), |
| 274 |
image.GetWidth(), image.GetHeight()); |
| 275 |
} |
| 276 |
} else { |
| 277 |
wxLogWarning(_T("Could not set image255x112 file to '%s'"), |
| 278 |
filename.GetFullPath().c_str()); |
| 279 |
} |
| 280 |
} else { |
| 281 |
wxLogWarning(_T("Could not find image255x112 file %s%s"), |
| 282 |
(searchShortname.IsEmpty() ? wxEmptyString : |
| 283 |
wxString(searchShortname + wxFileName::GetPathSeparator()).c_str()), |
| 284 |
image255x112path.c_str()); |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
wxString image182x80path; |
| 289 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_IMAGE_182X80, image182x80path); |
| 290 |
|
| 291 |
if (!image182x80path.IsEmpty()) { |
| 292 |
wxFileName filename; |
| 293 |
wxString searchShortname((i == 0) ? wxString(wxEmptyString) : shortname); |
| 294 |
|
| 295 |
if (SkinSystem::SearchFile(filename, tcPath, searchShortname, image182x80path)) { |
| 296 |
wxImage image(filename.GetFullPath()); |
| 297 |
|
| 298 |
if (image.IsOk()) { |
| 299 |
if ((image.GetWidth() == SkinSystem::ModListImageWidth) && |
| 300 |
(image.GetHeight() == SkinSystem::ModListImageHeight)) { |
| 301 |
item->image182x80 = wxBitmap(image); |
| 302 |
} else { |
| 303 |
wxLogWarning(_T("image182x80 has invalid dimensions %dx%d"), |
| 304 |
image.GetWidth(), image.GetHeight()); |
| 305 |
} |
| 306 |
} else { |
| 307 |
wxLogWarning(_T("Could not set image182x80 file to '%s'"), |
| 308 |
filename.GetFullPath().c_str()); |
| 309 |
} |
| 310 |
} else { |
| 311 |
wxLogWarning(_T("Could not find image182x80 file %s%s"), |
| 312 |
(searchShortname.IsEmpty() ? wxEmptyString : |
| 313 |
wxString(searchShortname + wxFileName::GetPathSeparator()).c_str()), |
| 314 |
image182x80path.c_str()); |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
// other cases, which don't require handling here: |
| 319 |
// if both images are Ok, then we just use them |
| 320 |
// if both images are not Ok, then we use SkinSystem::modImage/smallModImage |
| 321 |
if (item->image255x112.IsOk() && !item->image182x80.IsOk()) { |
| 322 |
item->image182x80 = SkinSystem::MakeModListImage(item->image255x112); |
| 323 |
} else if (!item->image255x112.IsOk() && item->image182x80.IsOk()) { |
| 324 |
item->image255x112 = SkinSystem::MakeModInfoDialogImage(item->image182x80); |
| 325 |
} |
| 326 |
|
| 327 |
wxASSERT(item->image255x112.IsOk() == item->image182x80.IsOk()); |
| 328 |
|
| 329 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_INFO_TEXT, item->infotext); |
| 330 |
|
| 331 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_AUTHOR, item->author); |
| 332 |
|
| 333 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_NOTES, item->notes); |
| 334 |
|
| 335 |
config->Read(MOD_INI_KEY_LAUNCHER_WARN, &(item->warn), false); |
| 336 |
|
| 337 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_WEBSITE, item->website); |
| 338 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_FORUM, item->forum); |
| 339 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_BUGS, item->bugs); |
| 340 |
readIniFileString(config, MOD_INI_KEY_LAUNCHER_SUPPORT, item->support); |
| 341 |
|
| 342 |
config->Read( |
| 343 |
MOD_INI_KEY_RESOLUTION_MIN_HORIZONTAL_RES, |
| 344 |
&item->minhorizontalres, |
| 345 |
DEFAULT_MOD_RESOLUTION_MIN_HORIZONTAL_RES); |
| 346 |
config->Read( |
| 347 |
MOD_INI_KEY_RESOLUTION_MIN_VERTICAL_RES, |
| 348 |
&item->minverticalres, |
| 349 |
DEFAULT_MOD_RESOLUTION_MIN_VERTICAL_RES); |
| 350 |
|
| 351 |
if ((item->minhorizontalres < DEFAULT_MOD_RESOLUTION_MIN_HORIZONTAL_RES) || |
| 352 |
(item->minverticalres < DEFAULT_MOD_RESOLUTION_MIN_VERTICAL_RES)) { |
| 353 |
wxLogWarning(_T("Invalid minimum resolution %ldx%ld, using default"), |
| 354 |
item->minhorizontalres, item->minverticalres); |
| 355 |
item->minhorizontalres = DEFAULT_MOD_RESOLUTION_MIN_HORIZONTAL_RES; |
| 356 |
item->minverticalres = DEFAULT_MOD_RESOLUTION_MIN_VERTICAL_RES; |
| 357 |
} |
| 358 |
|
| 359 |
readIniFileString( |
| 360 |
config, |
| 361 |
MOD_INI_KEY_RECOMMENDED_LIGHTING_NAME, |
| 362 |
item->recommendedlightingname); |
| 363 |
readIniFileString( |
| 364 |
config, |
| 365 |
MOD_INI_KEY_RECOMMENDED_LIGHTING_FLAGSET, |
| 366 |
item->recommendedlightingflagset); |
| 367 |
|
| 368 |
if (!item->recommendedlightingflagset.IsEmpty()) { |
| 369 |
if (item->recommendedlightingname.IsEmpty()) { |
| 370 |
item->recommendedlightingname = |
| 371 |
(i == 0) ? _("TC recommended") : _("Mod recommended"); |
| 372 |
|
| 373 |
// required because & is interpreted as setting keyboard shortcut |
| 374 |
// see http://docs.wxwidgets.org/stable/wx_wxcontrol.html#wxcontrolsetlabel |
| 375 |
item->recommendedlightingname.Replace(_T("&"), _T("&&")); |
| 376 |
} else { |
| 377 |
item->recommendedlightingname.Trim(true).Trim(false); |
| 378 |
item->recommendedlightingname.Truncate(MAX_PRESET_NAME_LENGTH); |
| 379 |
} |
| 380 |
} else { |
| 381 |
wxLogDebug(_T("Recommended lighting flagset is missing or empty; using defaults.")); |
| 382 |
item->recommendedlightingname = DEFAULT_MOD_RECOMMENDED_LIGHTING_NAME; |
| 383 |
item->recommendedlightingflagset = DEFAULT_MOD_RECOMMENDED_LIGHTING_FLAGSET; |
| 384 |
} |
| 385 |
|
| 386 |
readIniFileString(config, MOD_INI_KEY_EXTREMEFORCE_FORCED_FLAGS_ON, item->forcedon); |
| 387 |
readIniFileString(config, MOD_INI_KEY_EXTREMEFORCE_FORCED_FLAGS_OFF, item->forcedoff); |
| 388 |
|
| 389 |
readIniFileString(config, MOD_INI_KEY_MULTIMOD_PRIMARY_LIST, item->primarylist); |
| 390 |
// Log the warning for any mod authors, specifically for those who indicate |
| 391 |
// that they are mod authors by their having FRED launching enabled |
| 392 |
bool fredEnabled; |
| 393 |
ProMan::GetProfileManager()->GlobalRead(GBL_CFG_OPT_CONFIG_FRED, &fredEnabled, false); |
| 394 |
|
| 395 |
if ( config->Exists(MOD_INI_KEY_MULTIMOD_SECONDRY_LIST) && fredEnabled) { |
| 396 |
wxLogInfo(_T(" DEPRECATION WARNING: Mod '%s' uses deprecated mod.ini parameter 'secondrylist'"), |
| 397 |
shortname.c_str()); |
| 398 |
} |
| 399 |
readIniFileString(config, MOD_INI_KEY_MULTIMOD_SECONDARY_LIST, item->secondarylist); |
| 400 |
if (item->secondarylist.IsEmpty()) { |
| 401 |
readIniFileString(config, MOD_INI_KEY_MULTIMOD_SECONDRY_LIST, item->secondarylist); |
| 402 |
} |
| 403 |
|
| 404 |
// flag sets |
| 405 |
if ( config->Exists(_T("/flagsetideal")) ) { |
| 406 |
item->flagsets = new FlagSets(); |
| 407 |
|
| 408 |
FlagSetItem* flagset = new FlagSetItem(); |
| 409 |
|
| 410 |
readFlagSet(config, _T("/flagsetideal"), *flagset); |
| 411 |
|
| 412 |
item->flagsets->Add(flagset); |
| 413 |
|
| 414 |
unsigned int counter = 1; |
| 415 |
bool done = false; |
| 416 |
do { |
| 417 |
wxString sectionname = wxString::Format(_T("/flagset%u"), counter); |
| 418 |
if ( config->Exists( sectionname )) { |
| 419 |
FlagSetItem* numberedflagset = new FlagSetItem(); |
| 420 |
|
| 421 |
readFlagSet(config, sectionname, *numberedflagset); |
| 422 |
|
| 423 |
item->flagsets->Add(numberedflagset); |
| 424 |
} else { |
| 425 |
done = true; |
| 426 |
} |
| 427 |
counter++; |
| 428 |
} while ( !done ); |
| 429 |
} else { |
| 430 |
#if 0 // preprocessing out until this functionality is complete |
| 431 |
wxLogDebug(_T(" Does Not Contain An idealflagset Section.")); |
| 432 |
#endif |
| 433 |
} |
| 434 |
|
| 435 |
// skin (only available to TCs) |
| 436 |
if ( i == 0 ) { |
| 437 |
if ( config->Exists(_T("/skin")) ) { |
| 438 |
// deleting any existing TCSkin will be handled by SkinSystem::ResetTCSkin() |
| 439 |
// so it shouldn't be deleted here |
| 440 |
this->TCSkin = new Skin(); |
| 441 |
|
| 442 |
wxString windowTitle; |
| 443 |
readIniFileString(config, MOD_INI_KEY_SKIN_WINDOW_TITLE, windowTitle); |
| 444 |
|
| 445 |
if (!windowTitle.IsEmpty()) { |
| 446 |
this->TCSkin->SetWindowTitle(windowTitle); |
| 447 |
} |
| 448 |
|
| 449 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_BANNER, |
| 450 |
tcPath, _T("banner"), &Skin::SetBanner); |
| 451 |
|
| 452 |
wxString windowIconPath; |
| 453 |
readIniFileString(config, MOD_INI_KEY_SKIN_WINDOW_ICON, windowIconPath); |
| 454 |
|
| 455 |
if (!windowIconPath.IsEmpty()) { |
| 456 |
wxFileName filename; |
| 457 |
|
| 458 |
if (SkinSystem::SearchFile(filename, tcPath, wxEmptyString, windowIconPath)) { |
| 459 |
if (this->TCSkin->SetWindowIcon(wxIcon(filename.GetFullPath(), wxBITMAP_TYPE_ICO))) { |
| 460 |
wxLogDebug(_T("Set skin window icon to '%s'"), |
| 461 |
filename.GetFullPath().c_str()); |
| 462 |
} else { |
| 463 |
wxLogWarning(_T("Could not set skin window icon to '%s'"), |
| 464 |
filename.GetFullPath().c_str()); |
| 465 |
} |
| 466 |
} else { |
| 467 |
wxLogWarning(_T("Could not find skin window icon file.")); |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
wxString welcomeText; |
| 472 |
readIniFileString(config, MOD_INI_KEY_SKIN_WELCOME_TEXT, welcomeText); |
| 473 |
|
| 474 |
if (!welcomeText.IsEmpty()) { |
| 475 |
this->TCSkin->SetWelcomeText(welcomeText); |
| 476 |
} |
| 477 |
|
| 478 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_MOD_IMAGE_255X112, |
| 479 |
tcPath, _T("mod image"), &Skin::SetModImage); |
| 480 |
|
| 481 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_MOD_IMAGE_182X80, |
| 482 |
tcPath, _T("small mod image"), &Skin::SetSmallModImage); |
| 483 |
|
| 484 |
// if one mod image is missing, create it by scaling the other one |
| 485 |
if (this->TCSkin->GetModImage().IsOk() && !this->TCSkin->GetSmallModImage().IsOk()) { |
| 486 |
this->TCSkin->SetSmallModImage( |
| 487 |
SkinSystem::MakeModListImage(this->TCSkin->GetModImage())); |
| 488 |
} else if (!this->TCSkin->GetModImage().IsOk() && this->TCSkin->GetSmallModImage().IsOk()) { |
| 489 |
this->TCSkin->SetModImage( |
| 490 |
SkinSystem::MakeModInfoDialogImage(this->TCSkin->GetSmallModImage())); |
| 491 |
} |
| 492 |
|
| 493 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_ICON_OK, |
| 494 |
tcPath, _T("ok icon"), &Skin::SetOkIcon); |
| 495 |
|
| 496 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_ICON_WARNING, |
| 497 |
tcPath, _T("warning icon"), &Skin::SetWarningIcon); |
| 498 |
|
| 499 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_ICON_WARNING_BIG, |
| 500 |
tcPath, _T("big warning icon"), &Skin::SetBigWarningIcon); |
| 501 |
|
| 502 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_ICON_ERROR, |
| 503 |
tcPath, _T("error icon"), &Skin::SetErrorIcon); |
| 504 |
|
| 505 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_ICON_INFO, |
| 506 |
tcPath, _T("info icon"), &Skin::SetInfoIcon); |
| 507 |
|
| 508 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_ICON_INFO_BIG, |
| 509 |
tcPath, _T("big info icon"), &Skin::SetBigInfoIcon); |
| 510 |
|
| 511 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_ICON_HELP, |
| 512 |
tcPath, _T("help icon"), &Skin::SetHelpIcon); |
| 513 |
|
| 514 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_ICON_HELP_BIG, |
| 515 |
tcPath, _T("big help icon"), &Skin::SetBigHelpIcon); |
| 516 |
|
| 517 |
SetSkinBitmap(*config, MOD_INI_KEY_SKIN_ICON_IDEAL, |
| 518 |
tcPath, _T("ideal icon"), &Skin::SetIdealIcon); |
| 519 |
|
| 520 |
wxString newsSourceName; |
| 521 |
readIniFileString(config, MOD_INI_KEY_SKIN_NEWS_SOURCE, newsSourceName); |
| 522 |
|
| 523 |
if (!newsSourceName.IsEmpty()) { |
| 524 |
const NewsSource* source = NewsSource::FindSource(newsSourceName); |
| 525 |
|
| 526 |
if (source != NULL) { |
| 527 |
this->TCSkin->SetNewsSource(source); |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
SkinSystem::GetSkinSystem()->SetTCSkin(this->TCSkin); |
| 532 |
this->TCSkin = NULL; |
| 533 |
} else { |
| 534 |
wxLogDebug(_T(" Does Not Contain A skin Section.")); |
| 535 |
SkinSystem::GetSkinSystem()->ResetTCSkin(); |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
#ifdef MOD_TEXT_LOCALIZATION // mod text localization is not supported for now |
| 540 |
// langauges |
| 541 |
for ( size_t i = 0; i < SupportedLanguages.Count(); i++ ) { |
| 542 |
wxString section = wxString::Format(_T("/%s"), SupportedLanguages[i].c_str()); |
| 543 |
if ( config->Exists(section) ) { |
| 544 |
if ( item->i18n == NULL ) { |
| 545 |
item->i18n = new I18nData(); |
| 546 |
} |
| 547 |
} |
| 548 |
I18nItem *temp = NULL; |
| 549 |
|
| 550 |
readTranslation(config, SupportedLanguages[i], &temp); |
| 551 |
|
| 552 |
if ( temp != NULL ) { |
| 553 |
(*(item->i18n))[SupportedLanguages[i]] = temp; |
| 554 |
} |
| 555 |
} |
| 556 |
#endif |
| 557 |
|
| 558 |
modsTemp.push_back(item); |
| 559 |
} |
| 560 |
|
| 561 |
std::sort(modsTemp.begin(), modsTemp.end(), CompareModItems); |
| 562 |
|
| 563 |
for (std::vector<ModItem*>::const_iterator it = modsTemp.begin(); |
| 564 |
it != modsTemp.end(); ++it) { |
| 565 |
this->tableData->Add(*it); |
| 566 |
} |
| 567 |
|
| 568 |
this->SetItemCount(this->tableData->Count()); |
| 569 |
|
| 570 |
SetSelectedMod(); |
| 571 |
|
| 572 |
|
| 573 |
this->infoButton = |
| 574 |
new wxButton(this, ID_MODLISTBOX_INFO_BUTTON, _("Info")); |
| 575 |
this->activateButton = |
| 576 |
new wxButton(this, ID_MODLISTBOX_ACTIVATE_BUTTON, _("Activate")); |
| 577 |
this->warnBitmap = |
| 578 |
new wxStaticBitmap(this, wxID_ANY, SkinSystem::GetSkinSystem()->GetWarningIcon()); |
| 579 |
this->warnBitmap->SetToolTip(_("This mod requires your attention before playing it. Click Info for more details.")); |
| 580 |
|
| 581 |
this->buttonSizer = new wxBoxSizer(wxVERTICAL); |
| 582 |
this->buttonSizer->AddStretchSpacer(2); |
| 583 |
this->buttonSizer->Add(this->activateButton, wxSizerFlags().Expand().ReserveSpaceEvenIfHidden()); |
| 584 |
this->buttonSizer->AddStretchSpacer(1); |
| 585 |
this->buttonSizer->Add(this->infoButton, wxSizerFlags().Expand().ReserveSpaceEvenIfHidden()); |
| 586 |
this->buttonSizer->AddStretchSpacer(2); |
| 587 |
|
| 588 |
wxSizer* warningSizer = new wxBoxSizer(wxVERTICAL); |
| 589 |
warningSizer->AddStretchSpacer(1); |
| 590 |
warningSizer->Add(this->warnBitmap, wxSizerFlags().ReserveSpaceEvenIfHidden()); |
| 591 |
warningSizer->AddStretchSpacer(1); |
| 592 |
|
| 593 |
this->sizer = new wxBoxSizer(wxHORIZONTAL); |
| 594 |
this->sizer->AddStretchSpacer(1); |
| 595 |
this->sizer->Add(warningSizer, wxSizerFlags().Expand().ReserveSpaceEvenIfHidden()); |
| 596 |
this->sizer->AddStretchSpacer(1); |
| 597 |
this->sizer->Add(this->buttonSizer, wxSizerFlags().Expand().ReserveSpaceEvenIfHidden()); |
| 598 |
this->sizer->AddStretchSpacer(2); |
| 599 |
this->buttonSizer->Show(false); |
| 600 |
this->warnBitmap->Show(false); |
| 601 |
|
| 602 |
|
| 603 |
} |
| 604 |
|
| 605 |
/** the dtor. Cleans up stuff. */ |
| 606 |
ModList::~ModList() { |
| 607 |
if (SkinSystem::IsInitialized()) { |
| 608 |
SkinSystem::UnRegisterTCSkinChanged(this); |
| 609 |
} |
| 610 |
|
| 611 |
if ( this->configFiles != NULL ) { |
| 612 |
delete this->configFiles; |
| 613 |
} |
| 614 |
|
| 615 |
ModList::activeMod = NULL; |
| 616 |
|
| 617 |
if ( this->tableData != NULL ) { |
| 618 |
delete this->tableData; |
| 619 |
} |
| 620 |
// deleting any existing TCSkin will be handled by SkinSystem::ResetTCSkin() |
| 621 |
// so it shouldn't be deleted here |
| 622 |
if ( this->sizer != NULL ) { |
| 623 |
delete this->sizer; |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
/** Takes the key to search for and sets location to key's value. |
| 628 |
If the key is not found, location is unchanged. */ |
| 629 |
void ModList::readIniFileString(const wxFileConfig* config, |
| 630 |
const wxString& key, wxString& location) { |
| 631 |
wxASSERT(config != NULL); |
| 632 |
|
| 633 |
if ( config->HasEntry(key) ) { |
| 634 |
config->Read(key, &location); |
| 635 |
if ( location.EndsWith(_T(";")) ) { |
| 636 |
location.RemoveLast(); |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
wxLogDebug(wxT_2(" %s:'%s'"), |
| 641 |
key.c_str(), |
| 642 |
location.IsEmpty() ? wxT_2("Not Specified") : escapeSpecials(location).c_str()); |
| 643 |
} |
| 644 |
|
| 645 |
/** re-escape the newlines in the mod.ini values. */ |
| 646 |
wxString ModList::escapeSpecials(const wxString& toEscape) { |
| 647 |
wxString toEscapeTemp(toEscape); |
| 648 |
|
| 649 |
wxString::iterator iter = toEscapeTemp.begin(); |
| 650 |
|
| 651 |
while (iter != toEscapeTemp.end() ) { |
| 652 |
if ( *iter == wxChar('\n') ) { |
| 653 |
wxString::iterator end = iter; |
| 654 |
end++; |
| 655 |
toEscapeTemp.replace(iter, end, _T("\\n")); |
| 656 |
|
| 657 |
// have to start over because we wrote to the string, |
| 658 |
// which invalidated the iterator. |
| 659 |
iter = toEscapeTemp.begin(); |
| 660 |
} else { |
| 661 |
++iter; |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
return toEscapeTemp; |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
/** */ |
| 670 |
void ModList::readFlagSet(const wxFileConfig* config, |
| 671 |
const wxString& keyprefix, FlagSetItem& set) { |
| 672 |
wxCHECK_RET(config != NULL, _T("readFlagSet(): config is NULL!")); |
| 673 |
|
| 674 |
readIniFileString(config, |
| 675 |
wxString::Format(_T("%s/name"), keyprefix.c_str()), |
| 676 |
set.name); |
| 677 |
readIniFileString(config, |
| 678 |
wxString::Format(_T("%s/flagset"), keyprefix.c_str()), |
| 679 |
set.flagset); |
| 680 |
readIniFileString(config, |
| 681 |
wxString::Format(_T("%s/notes"), keyprefix.c_str()), |
| 682 |
set.notes); |
| 683 |
} |
| 684 |
|
| 685 |
#ifdef MOD_TEXT_LOCALIZATION // mod text localization is not supported for now |
| 686 |
void ModList::readTranslation(wxFileConfig* config, wxString langaugename, I18nItem **trans) { |
| 687 |
wxString section = wxString::Format(_T("/%s"), langaugename.c_str()); |
| 688 |
if ( config->Exists(section) ) { |
| 689 |
*trans = new I18nItem(); |
| 690 |
|
| 691 |
readIniFileString(config, |
| 692 |
wxString::Format(_T("%s/modname"), section.c_str()), |
| 693 |
&((*trans)->modname)); |
| 694 |
readIniFileString(config, |
| 695 |
wxString::Format(_T("%s/infotext"), section.c_str()), |
| 696 |
&((*trans)->infotext)); |
| 697 |
|
| 698 |
} else { |
| 699 |
wxLogDebug( |
| 700 |
wxString::Format(_T(" Section '%s' does not exist."), langaugename.c_str())); |
| 701 |
} |
| 702 |
} |
| 703 |
#endif |
| 704 |
|
| 705 |
/** Parses the specified mod.ini file and adds it to configFiles. |
| 706 |
Returns true on success, false otherwise. */ |
| 707 |
bool ModList::ParseModIni(const wxString& modIniPath, const wxString& tcPath, const bool isNoMod) { |
| 708 |
wxFFileInputStream stream(modIniPath); |
| 709 |
|
| 710 |
if ( stream.IsOk() ) { |
| 711 |
wxLogDebug(_T(" Opened ok")); |
| 712 |
} else { |
| 713 |
wxLogError(_T(" Open failed!")); |
| 714 |
return false; |
| 715 |
} |
| 716 |
|
| 717 |
// check if the stream is a UTF-8 File (has a BOM) |
| 718 |
char header[3]; |
| 719 |
stream.Read(reinterpret_cast<void*>(&header), sizeof(header)); |
| 720 |
stream.SeekI(0); |
| 721 |
|
| 722 |
bool isUTF8 = false; |
| 723 |
if ( header[0] == '\357' && header[1] == '\273' && header[2] == '\277' ) { |
| 724 |
// is a UTF-8 file |
| 725 |
isUTF8 = true; |
| 726 |
} |
| 727 |
|
| 728 |
wxMemoryOutputStream tempStream; |
| 729 |
tempStream.Write(stream); |
| 730 |
|
| 731 |
wxStreamBuffer* buf = tempStream.GetOutputStreamBuffer(); |
| 732 |
const size_t size = buf->GetBufferSize(); |
| 733 |
|
| 734 |
char* characterBuffer = new char[size+1]; |
| 735 |
characterBuffer[size] = '\0'; |
| 736 |
|
| 737 |
buf->Seek(0, wxFromStart); |
| 738 |
|
| 739 |
// don't try to read in buffer when there is nothing to read. |
| 740 |
size_t read = (size == 0) ? 0 : buf->Read(reinterpret_cast<void*>(characterBuffer), size); |
| 741 |
if ( read != size ) { |
| 742 |
wxLogError(wxT("read (") SZT wxT(") not equal to size (") SZT wxT(")"), read, size); |
| 743 |
delete[] characterBuffer; |
| 744 |
return false; |
| 745 |
} |
| 746 |
|
| 747 |
const wxMBConv* conv = NULL; |
| 748 |
if ( isUTF8 ) { |
| 749 |
conv = &wxConvUTF8; |
| 750 |
} else { |
| 751 |
conv = &wxConvISO8859_1; |
| 752 |
} |
| 753 |
|
| 754 |
wxString stringBuffer(characterBuffer, *conv); |
| 755 |
|
| 756 |
// A hack to insert a backslash into the stream so that when |
| 757 |
// wxFileConfig escapes the backslashes, the one that is in |
| 758 |
// the file is returned |
| 759 |
stringBuffer.Replace(_T("\\"), _T("\\\\")); |
| 760 |
wxStringInputStream finalBuffer(stringBuffer); |
| 761 |
|
| 762 |
wxFileConfig* config = new wxFileConfig(finalBuffer); |
| 763 |
delete[] characterBuffer; |
| 764 |
|
| 765 |
wxString shortname(isNoMod ? NO_MOD : GetShortName(modIniPath, tcPath)); |
| 766 |
|
| 767 |
if (!isNoMod) { |
| 768 |
wxLogDebug(_T(" Mod fancy name is: %s"), |
| 769 |
config->Read(MOD_INI_KEY_LAUNCHER_MOD_NAME, _T("Not specified")).c_str()); |
| 770 |
|
| 771 |
wxLogDebug(_T(" Mod short name is: %s"), shortname.c_str()); |
| 772 |
} |
| 773 |
|
| 774 |
this->configFiles->Add(new ConfigPair(shortname, config)); |
| 775 |
|
| 776 |
return true; |
| 777 |
} |
| 778 |
|
| 779 |
/** Set currently select mod as selected |
| 780 |
or set (No mod) if none or previous does not exist. */ |
| 781 |
void ModList::SetSelectedMod() { |
| 782 |
wxString currentMod; |
| 783 |
ProMan::GetProfileManager()->ProfileRead( |
| 784 |
PRO_CFG_TC_CURRENT_MOD, ¤tMod, NO_MOD); |
| 785 |
|
| 786 |
size_t i; |
| 787 |
for ( i = 0; i < this->tableData->size(); ++i ) { |
| 788 |
if ( this->tableData->Item(i).shortname == currentMod ) { |
| 789 |
break; |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
if ( i < this->tableData->size() ) { |
| 794 |
// found it |
| 795 |
this->SetSelection(i); |
| 796 |
} else { |
| 797 |
this->SetSelection(0); |
| 798 |
} |
| 799 |
|
| 800 |
wxCommandEvent activateModEvent; |
| 801 |
this->OnActivateMod(activateModEvent); |
| 802 |
} |
| 803 |
|
| 804 |
/** get the mod.ini's short name (base directory) */ |
| 805 |
/** <something>/modfolder/mod.ini |
| 806 |
<something>\modfolder\mod.ini */ |
| 807 |
wxString ModList::GetShortName(const wxString& modIniPath, const wxString& tcPath) { |
| 808 |
wxArrayString tokens = wxStringTokenize(modIniPath, _T("\\/"), |
| 809 |
wxTOKEN_STRTOK); /* breakup on folder markers and never return an |
| 810 |
empty string. */ |
| 811 |
wxArrayString tcTokens = wxStringTokenize(tcPath, _T("\\/"), wxTOKEN_STRTOK); |
| 812 |
|
| 813 |
wxString shortname; |
| 814 |
|
| 815 |
// "tokens.GetCount() - 1" is to skip "mod.ini" at end |
| 816 |
for ( size_t j = tcTokens.GetCount(); j < (tokens.GetCount() - 1); ++j ) { |
| 817 |
if ( !shortname.IsEmpty() ) { |
| 818 |
shortname += _T("/"); |
| 819 |
} |
| 820 |
shortname += tokens[j]; |
| 821 |
} |
| 822 |
|
| 823 |
return shortname; |
| 824 |
} |
| 825 |
|
| 826 |
void ModList::OnDrawItem(wxDC &dc, const wxRect &rect, size_t n) const { |
| 827 |
wxLogDebug(_T(" Draw %04d,%04d = %04d,%04d"), rect.x, rect.y, rect.width, rect.height); |
| 828 |
this->tableData->Item(n).Draw(dc, rect, this->IsSelected(n), this->sizer, this->buttonSizer, this->warnBitmap); |
| 829 |
} |
| 830 |
|
| 831 |
void ModList::OnDrawSeparator(wxDC &WXUNUSED(dc), wxRect& WXUNUSED(rect), size_t WXUNUSED(n)) const { |
| 832 |
//dc.DrawLine(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); |
| 833 |
} |
| 834 |
|
| 835 |
void ModList::OnDrawBackground(wxDC &dc, const wxRect& rect, size_t n) const { |
| 836 |
wxLogDebug(_T(" Background %04d,%04d = %04d,%04d"), rect.x, rect.y, rect.width, rect.height); |
| 837 |
dc.DestroyClippingRegion(); |
| 838 |
wxColour highlighted = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); |
| 839 |
wxColour background = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); |
| 840 |
wxString activeMod; |
| 841 |
ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_MOD, &activeMod, NO_MOD, true); |
| 842 |
wxBrush b; |
| 843 |
wxRect selectedRect(rect.x+2, rect.y+2, rect.width-4, rect.height-4); |
| 844 |
wxRect activeRect(selectedRect.x+3, selectedRect.y+3, selectedRect.width-7, selectedRect.height-7); |
| 845 |
|
| 846 |
if ( this->IsSelected(n) ) { |
| 847 |
b = wxBrush(highlighted, wxTRANSPARENT); |
| 848 |
dc.SetPen(wxPen(highlighted, 4)); |
| 849 |
} else if ( this->isCurrentSelectionAnAppendMod(this->tableData->Item(n).shortname) ) { |
| 850 |
b = wxBrush(highlighted, wxBDIAGONAL_HATCH); |
| 851 |
dc.SetPen(wxPen(highlighted, 1)); |
| 852 |
} else if ( this->isCurrentSelectionAPrependMod(this->tableData->Item(n).shortname) ) { |
| 853 |
b = wxBrush(highlighted, wxFDIAGONAL_HATCH); |
| 854 |
dc.SetPen(wxPen(highlighted, 1)); |
| 855 |
} else { |
| 856 |
b = wxBrush(background); |
| 857 |
dc.SetPen(wxPen(background, 4)); |
| 858 |
} |
| 859 |
dc.SetBackground(b); |
| 860 |
dc.SetBrush(b); |
| 861 |
dc.DrawRoundedRectangle(selectedRect, 10.0); |
| 862 |
|
| 863 |
if ( activeMod == this->tableData->Item(n).shortname ) { |
| 864 |
b = wxBrush(highlighted, wxSOLID); |
| 865 |
dc.SetPen(wxPen(highlighted, 1)); |
| 866 |
} else if ( this->isAnAppendMod(this->tableData->Item(n).shortname) ) { |
| 867 |
b = wxBrush(highlighted, wxBDIAGONAL_HATCH); |
| 868 |
dc.SetPen(wxPen(highlighted, 1)); |
| 869 |
} else if ( this->isAPrependMod(this->tableData->Item(n).shortname) ) { |
| 870 |
b = wxBrush(highlighted, wxFDIAGONAL_HATCH); |
| 871 |
dc.SetPen(wxPen(highlighted, 1)); |
| 872 |
} else { |
| 873 |
b = wxBrush(background, wxSOLID); |
| 874 |
dc.SetPen(wxPen(background, 1)); |
| 875 |
} |
| 876 |
dc.SetBackground(b); |
| 877 |
dc.SetBrush(b); |
| 878 |
dc.DrawRoundedRectangle(activeRect, 10.0); |
| 879 |
} |
| 880 |
|
| 881 |
wxCoord ModList::OnMeasureItem(size_t WXUNUSED(n)) const { |
| 882 |
return 80; |
| 883 |
} |
| 884 |
|
| 885 |
void ModList::OnSelectionChange(wxCommandEvent &event) { |
| 886 |
wxLogDebug(_T("Selection changed to %d (%s)."), |
| 887 |
event.GetInt(), |
| 888 |
this->tableData->Item(event.GetInt()).shortname.c_str()); |
| 889 |
this->Refresh(); |
| 890 |
} |
| 891 |
|
| 892 |
void ModList::OnActivateMod(wxCommandEvent &WXUNUSED(event)) { |
| 893 |
int selected = this->GetSelection(); |
| 894 |
wxCHECK_RET(selected != wxNOT_FOUND, _T("Do not have a valid selection.")); |
| 895 |
|
| 896 |
ModList::activeMod = &this->tableData->Item(selected); |
| 897 |
|
| 898 |
wxString modline; |
| 899 |
const wxString& shortname(this->tableData->Item(selected).shortname); |
| 900 |
this->prependmods = this->tableData->Item(selected).primarylist; |
| 901 |
this->appendmods = this->tableData->Item(selected).secondarylist; |
| 902 |
|
| 903 |
if ( !this->prependmods.IsEmpty() ) { |
| 904 |
wxStringTokenizer prependtokens(this->prependmods, _T(","), wxTOKEN_STRTOK); // no empty tokens |
| 905 |
while ( prependtokens.HasMoreTokens() ) { |
| 906 |
if ( !modline.IsEmpty() ) { |
| 907 |
modline += _T(","); |
| 908 |
} |
| 909 |
modline += prependtokens.GetNextToken().Trim(true).Trim(false); |
| 910 |
} |
| 911 |
} |
| 912 |
|
| 913 |
wxCHECK_RET( !shortname.IsEmpty(), _T("Mod shortname is empty!")); |
| 914 |
if ( !modline.IsEmpty() ) { |
| 915 |
modline += _T(","); |
| 916 |
} |
| 917 |
if ( selected != 0 ) { |
| 918 |
// put current mods name into the list unless it is (No mod) |
| 919 |
modline += shortname; |
| 920 |
} |
| 921 |
|
| 922 |
if ( !this->appendmods.IsEmpty() ) { |
| 923 |
wxStringTokenizer appendtokens(this->appendmods, _T(","), wxTOKEN_STRTOK); |
| 924 |
while ( appendtokens.HasMoreTokens() ) { |
| 925 |
if ( !modline.IsEmpty() ) { |
| 926 |
modline += _T(","); |
| 927 |
} |
| 928 |
modline += appendtokens.GetNextToken().Trim(true).Trim(false); |
| 929 |
} |
| 930 |
} |
| 931 |
|
| 932 |
wxLogDebug(_T("New modline is %s"), modline.c_str()); |
| 933 |
|
| 934 |
ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_TC_CURRENT_MODLINE, modline); |
| 935 |
ProMan::GetProfileManager()->ProfileWrite(PRO_CFG_TC_CURRENT_MOD, shortname); |
| 936 |
|
| 937 |
TCManager::GenerateTCActiveModChanged(); |
| 938 |
this->Refresh(); |
| 939 |
} |
| 940 |
|
| 941 |
void ModList::OnInfoMod(wxCommandEvent &WXUNUSED(event)) { |
| 942 |
int selected = this->GetSelection(); |
| 943 |
wxCHECK_RET(selected != wxNOT_FOUND, _T("Do not have a valid selection.")); |
| 944 |
new ModInfoDialog(new ModItem(this->tableData->Item(selected)), this); |
| 945 |
} |
| 946 |
|
| 947 |
void ModList::OnTCSkinChanged(wxCommandEvent &WXUNUSED(event)) { |
| 948 |
Refresh(); |
| 949 |
} |
| 950 |
|
| 951 |
// comparison is case-insensitive, and mod names containing spaces are preserved |
| 952 |
bool ModList::isADependency(const wxString &mod, const wxString& modlist) { |
| 953 |
wxCHECK_MSG(!mod.IsEmpty(), false, _T("isADependency() called with empty mod!")); |
| 954 |
wxCHECK_MSG(!modlist.IsEmpty(), false, _T("isADependency() called with empty modlist!")); |
| 955 |
|
| 956 |
wxString normalizedModName(mod); |
| 957 |
normalizedModName.Trim(true).Trim(false).MakeLower(); |
| 958 |
|
| 959 |
wxStringTokenizer tokens(modlist, _T(","), wxTOKEN_STRTOK); |
| 960 |
while ( tokens.HasMoreTokens() ) { |
| 961 |
if ( tokens.GetNextToken().Trim(true).Trim(false).Lower() == normalizedModName ) { |
| 962 |
return true; |
| 963 |
} |
| 964 |
} |
| 965 |
return false; |
| 966 |
} |
| 967 |
|
| 968 |
|
| 969 |
bool ModList::isAnAppendMod(const wxString &mod) const { |
| 970 |
if ( this->appendmods.IsEmpty() ) return false; // no append mods, mod cannot be one |
| 971 |
return ModList::isADependency(mod, this->appendmods); |
| 972 |
} |
| 973 |
|
| 974 |
bool ModList::isAPrependMod(const wxString &mod) const { |
| 975 |
if ( this->prependmods.IsEmpty() ) return false; // no prepend mods, mod cannot be one |
| 976 |
return ModList::isADependency(mod, this->prependmods); |
| 977 |
} |
| 978 |
|
| 979 |
bool ModList::isCurrentSelectionAnAppendMod(const wxString &mod) const { |
| 980 |
int selection = this->GetSelection(); |
| 981 |
if ( selection == wxNOT_FOUND |
| 982 |
|| this->tableData->Item(selection).secondarylist.IsEmpty()) { |
| 983 |
return false; |
| 984 |
} |
| 985 |
return ModList::isADependency(mod, this->tableData->Item(selection).secondarylist); |
| 986 |
} |
| 987 |
|
| 988 |
bool ModList::isCurrentSelectionAPrependMod(const wxString &mod) const { |
| 989 |
int selection = this->GetSelection(); |
| 990 |
if ( selection == wxNOT_FOUND |
| 991 |
|| this->tableData->Item(selection).primarylist.IsEmpty()) { |
| 992 |
return false; |
| 993 |
} |
| 994 |
return ModList::isADependency(mod, this->tableData->Item(selection).primarylist); |
| 995 |
} |
| 996 |
|
| 997 |
|
| 998 |
BEGIN_EVENT_TABLE(ModList, wxVListBox) |
| 999 |
EVT_LISTBOX(ID_MODLISTBOX, ModList::OnSelectionChange) |
| 1000 |
EVT_BUTTON(ID_MODLISTBOX_ACTIVATE_BUTTON, ModList::OnActivateMod) |
| 1001 |
EVT_BUTTON(ID_MODLISTBOX_INFO_BUTTON, ModList::OnInfoMod) |
| 1002 |
END_EVENT_TABLE() |
| 1003 |
|
| 1004 |
/////////////////////////////////////////////////////////////////////////////// |
| 1005 |
// Flagsets |
| 1006 |
/** \class FlagSetItem |
| 1007 |
Structure used to store the name, notes, and the flagset itself. Pointer's that |
| 1008 |
are not NULL when structure is destroyed will be deleted by the structure. */ |
| 1009 |
/** Constructor. Only makes sure that the members are nulled. Does nothing |
| 1010 |
else.*/ |
| 1011 |
FlagSetItem::FlagSetItem() { |
| 1012 |
} |
| 1013 |
|
| 1014 |
/** Destructor. Deletes any non NULL pointers that are contained in the |
| 1015 |
structure. */ |
| 1016 |
FlagSetItem::~FlagSetItem() { |
| 1017 |
} |
| 1018 |
|
| 1019 |
#include <wx/arrimpl.cpp> |
| 1020 |
WX_DEFINE_OBJARRAY(FlagSets); |
| 1021 |
|
| 1022 |
#ifdef MOD_TEXT_LOCALIZATION // mod text localization is not supported for now |
| 1023 |
/////////////////////////////////////////////////////////////////////////////// |
| 1024 |
// I18nData |
| 1025 |
/** \class I18nItem |
| 1026 |
Structure to store the translation of the supported translatable strings |
| 1027 |
(modname and infotext). Structure will delete the non-null pointers it |
| 1028 |
contains at the structures time of destruction. */ |
| 1029 |
/** Constructor. Only NULL's the member variables. */ |
| 1030 |
I18nItem::I18nItem() { |
| 1031 |
this->modname = NULL; |
| 1032 |
this->infotext = NULL; |
| 1033 |
} |
| 1034 |
|
| 1035 |
/** Destructor. Deletes any non-null member variables. */ |
| 1036 |
I18nItem::~I18nItem() { |
| 1037 |
if ( this->modname ) { |
| 1038 |
delete this->modname; |
| 1039 |
} |
| 1040 |
if ( this->infotext ) { |
| 1041 |
delete this->infotext; |
| 1042 |
} |
| 1043 |
} |
| 1044 |
/** The supported langauges. */ |
| 1045 |
const wxString __SupportedLanguages[] = { |
| 1046 |
_T("French"), |
| 1047 |
_T("Romanian"), |
| 1048 |
_T("German"), |
| 1049 |
_T("Polish"), |
| 1050 |
}; |
| 1051 |
/** Languages that are supported by the launcher and thus will search for |
| 1052 |
translations for in mod.ini's. */ |
| 1053 |
wxSortedArrayString SupportedLanguages = wxArrayString(sizeof(__SupportedLanguages)/sizeof(wxString), __SupportedLanguages); |
| 1054 |
#endif |
| 1055 |
|
| 1056 |
//#include <wx/impl.cpp> |
| 1057 |
//WX_DEFINE_OBJARRAY(I18nData); |
| 1058 |
|
| 1059 |
/////////////////////////////////////////////////////////////////////////////// |
| 1060 |
// ModGridTable::ModItem |
| 1061 |
/** \struct ModGridTable::ModItem |
| 1062 |
Structure that holds all of the information for a single line in the mod table. |
| 1063 |
*/ |
| 1064 |
/** Constructor.*/ |
| 1065 |
ModItem::ModItem() { |
| 1066 |
warn = false; |
| 1067 |
|
| 1068 |
this->flagsets = NULL; |
| 1069 |
#ifdef MOD_TEXT_LOCALIZATION // mod text localization is not supported for now |
| 1070 |
this->i18n = NULL; |
| 1071 |
#endif |
| 1072 |
|
| 1073 |
this->infoTextPanel = new InfoText(this); |
| 1074 |
this->modImagePanel = new ModImage(this); |
| 1075 |
this->modNamePanel = new ModName(this); |
| 1076 |
|
| 1077 |
} |
| 1078 |
|
| 1079 |
/** Destructor. Deletes all memory pointed to by non NULL internal pointers. */ |
| 1080 |
ModItem::~ModItem() { |
| 1081 |
if (this->flagsets != NULL) delete this->flagsets; |
| 1082 |
#ifdef MOD_TEXT_LOCALIZATION // mod text localization is not supported for now |
| 1083 |
if (this->i18n != NULL) { |
| 1084 |
I18nData::iterator i18niter = this->i18n->begin(); |
| 1085 |
while (i18niter != this->i18n->end()) { |
| 1086 |
delete i18niter->second; |
| 1087 |
i18niter++; |
| 1088 |
} |
| 1089 |
delete this->i18n; |
| 1090 |
} |
| 1091 |
#endif |
| 1092 |
if (this->infoTextPanel != NULL) delete this->infoTextPanel; |
| 1093 |
if (this->modImagePanel != NULL) delete this->modImagePanel; |
| 1094 |
if (this->modNamePanel != NULL) delete this->modNamePanel; |
| 1095 |
} |
| 1096 |
|
| 1097 |
void ModItem::Draw(wxDC &dc, const wxRect &rect, bool selected, wxSizer* mainSizer, wxSizer* buttons, wxStaticBitmap* warn) { |
| 1098 |
wxRect titlerect = rect; |
| 1099 |
titlerect.width = 150; |
| 1100 |
|
| 1101 |
wxRect imgrect = rect; |
| 1102 |
imgrect.width = SkinSystem::ModListImageWidth; |
| 1103 |
imgrect.x = titlerect.width; |
| 1104 |
|
| 1105 |
wxRect infotextrect = rect; |
| 1106 |
// The 5 is to keep the text away from the image. |
| 1107 |
infotextrect.x = titlerect.width + imgrect.width + 5; |
| 1108 |
infotextrect.width = rect.width - infotextrect.x; |
| 1109 |
|
| 1110 |
wxFont titlefont = SkinSystem::GetSkinSystem()->GetFont(); |
| 1111 |
titlefont.SetPointSize(titlefont.GetPointSize() + 2); |
| 1112 |
titlefont.SetWeight(wxFONTWEIGHT_BOLD); |
| 1113 |
dc.SetFont(titlefont); |
| 1114 |
this->modNamePanel->Draw(dc, titlerect); |
| 1115 |
dc.SetFont(SkinSystem::GetSkinSystem()->GetFont()); |
| 1116 |
this->modImagePanel->Draw(dc, imgrect); |
| 1117 |
|
| 1118 |
if ( selected ) { /* If I am selected do not have info panel draw because |
| 1119 |
I am going to put the buttons over the info text. */ |
| 1120 |
buttons->Show(true); |
| 1121 |
if ( this->warn) { |
| 1122 |
warn->Show(true); |
| 1123 |
} else if ( !this->warn) { |
| 1124 |
warn->Show(false); |
| 1125 |
} |
| 1126 |
mainSizer->SetDimension(infotextrect.x, infotextrect.y, |
| 1127 |
infotextrect.width, infotextrect.height); |
| 1128 |
} else { |
| 1129 |
this->infoTextPanel->Draw(dc, infotextrect); |
| 1130 |
} |
| 1131 |
} |
| 1132 |
|
| 1133 |
#include <wx/arrimpl.cpp> |
| 1134 |
WX_DEFINE_OBJARRAY(ModItemArray); |
| 1135 |
|
| 1136 |
/////////////////////////////////////////// |
| 1137 |
/** \class ModItem::InfoText |
| 1138 |
Extends wxPanel so that it can draw the info text to the correct size in the list |
| 1139 |
*/ |
| 1140 |
/** Constructor. Sets up stuff. */ |
| 1141 |
ModItem::InfoText::InfoText(ModItem *myData) { |
| 1142 |
this->myData = myData; |
| 1143 |
} |
| 1144 |
|
| 1145 |
void ModItem::InfoText::Draw(wxDC &dc, const wxRect &rect) { |
| 1146 |
if ( !this->myData->infotext.IsEmpty() ) { |
| 1147 |
// to keep "\n" from appearing in the mod list info text |
| 1148 |
wxString escapedInfoText(this->myData->infotext); |
| 1149 |
escapedInfoText.Replace(_T("\\n"), _T(" ")); |
| 1150 |
|
| 1151 |
wxStringTokenizer tokens(escapedInfoText); |
| 1152 |
ArrayOfWords words; |
| 1153 |
words.Alloc(tokens.CountTokens()); |
| 1154 |
|
| 1155 |
FillArrayOfWordsFromTokens(tokens, dc, NULL, words); |
| 1156 |
|
| 1157 |
const int maxwidth = rect.width; |
| 1158 |
int currentx = rect.x, currenty = rect.y; |
| 1159 |
|
| 1160 |
wxSize spaceSize = dc.GetTextExtent(_T(" ")); |
| 1161 |
int currentwidth = 0; |
| 1162 |
wxString string; |
| 1163 |
for( size_t i = 0; i < words.Count(); i++) { |
| 1164 |
if ( currentwidth + words[i].size.x + spaceSize.x > maxwidth ) { |
| 1165 |
dc.DrawText(string, currentx, currenty); |
| 1166 |
|
| 1167 |
string.Empty(); |
| 1168 |
currentwidth = 0; |
| 1169 |
|
| 1170 |
currenty += words[i].size.y; |
| 1171 |
if (currenty + words[i].size.y> rect.y + rect.height) { |
| 1172 |
break; |
| 1173 |
} |
| 1174 |
} else { |
| 1175 |
if (!(string.IsEmpty())) { // prevent leading space in info text |
| 1176 |
string.append(_T(" ")); |
| 1177 |
} |
| 1178 |
} |
| 1179 |
string.append(words[i].word); |
| 1180 |
currentwidth += words[i].size.x + spaceSize.x; |
| 1181 |
} |
| 1182 |
if ( !string.IsEmpty()) { |
| 1183 |
dc.DrawText(string, currentx, currenty); |
| 1184 |
} |
| 1185 |
} |
| 1186 |
} |
| 1187 |
|
| 1188 |
/////////////////////////////////////////// |
| 1189 |
/** \class ModItem::ModName |
| 1190 |
Extends wxPanel so that it can draw the mod's name to the correct size in the list |
| 1191 |
or the mod's short name. |
| 1192 |
*/ |
| 1193 |
/** Constructor. Sets up stuff. */ |
| 1194 |
ModItem::ModName::ModName(ModItem *myData) { |
| 1195 |
this->myData = myData; |
| 1196 |
} |
| 1197 |
|
| 1198 |
void ModItem::ModName::Draw(wxDC &dc, const wxRect &rect) { |
| 1199 |
wxString name; |
| 1200 |
|
| 1201 |
if ( !this->myData->name.IsEmpty() ) { |
| 1202 |
name = this->myData->name; |
| 1203 |
} else { |
| 1204 |
name = this->myData->shortname; |
| 1205 |
} |
| 1206 |
|
| 1207 |
wxCoord width, height; |
| 1208 |
wxFont testFont(dc.GetFont()); /* font to use to compensate for |
| 1209 |
GetTextExtent's inabliity to handle |
| 1210 |
bold font.*/ |
| 1211 |
testFont.SetPointSize(testFont.GetPointSize() + 2); |
| 1212 |
dc.GetMultiLineTextExtent(name, &width, &height, NULL, &testFont); |
| 1213 |
|
| 1214 |
if ( width > rect.width ) { |
| 1215 |
// too wide need to wrap if possible. |
| 1216 |
ArrayOfWords titleWords; |
| 1217 |
wxStringTokenizer tokens(name); |
| 1218 |
ArrayOfWords words; |
| 1219 |
words.Alloc(tokens.CountTokens()); |
| 1220 |
|
| 1221 |
FillArrayOfWordsFromTokens(tokens, dc, &testFont, words); |
| 1222 |
|
| 1223 |
const int maxwidth = rect.width; |
| 1224 |
int currentx = rect.x, currenty = rect.y; |
| 1225 |
|
| 1226 |
wxCoord spaceX, spaceY; |
| 1227 |
dc.GetTextExtent(_T(" "), &spaceX, &spaceY, NULL, NULL, &testFont); |
| 1228 |
int currentwidth = 0; |
| 1229 |
wxString string; |
| 1230 |
for( size_t i = 0; i < words.Count(); i++) { |
| 1231 |
if ( currentwidth + words[i].size.x + spaceX > maxwidth ) { |
| 1232 |
wxCoord tempX, tempY; |
| 1233 |
dc.GetTextExtent(string, &tempX, &tempY, NULL, NULL, &testFont); |
| 1234 |
|
| 1235 |
Words* temp = new Words(); |
| 1236 |
temp->size.SetWidth(tempX); |
| 1237 |
temp->size.SetHeight(tempY); |
| 1238 |
temp->word = string; |
| 1239 |
titleWords.Add(temp); |
| 1240 |
|
| 1241 |
string.Empty(); |
| 1242 |
currentwidth = 0; |
| 1243 |
|
| 1244 |
currenty += words[i].size.y; |
| 1245 |
if (currenty + words[i].size.y > rect.y + rect.height) { |
| 1246 |
break; |
| 1247 |
} |
| 1248 |
} else if ( string.size() > 0 ) { |
| 1249 |
string.append(_T(" ")); |
| 1250 |
} |
| 1251 |
string.append(words[i].word); |
| 1252 |
currentwidth += words[i].size.x + spaceX; |
| 1253 |
} |
| 1254 |
wxCoord tempX, tempY; |
| 1255 |
dc.GetTextExtent(string, &tempX, &tempY, NULL, NULL, &testFont); |
| 1256 |
|
| 1257 |
Words* temp = new Words(); |
| 1258 |
temp->size.SetWidth(tempX); |
| 1259 |
temp->size.SetHeight(tempY); |
| 1260 |
temp->word = string; |
| 1261 |
titleWords.Add(temp); |
| 1262 |
|
| 1263 |
// draw the words properly centered |
| 1264 |
|
| 1265 |
// Find the hight of all of the lines of text |
| 1266 |
int totalHeight = 0; |
| 1267 |
for( size_t i = 0; i < titleWords.Count(); i++ ) { |
| 1268 |
totalHeight += titleWords[i].size.y; |
| 1269 |
} |
| 1270 |
|
| 1271 |
int currentHeightOffset = 0; |
| 1272 |
for( size_t i = 0; i < titleWords.Count(); i++ ) { |
| 1273 |
dc.DrawText(titleWords[i].word, |
| 1274 |
rect.x + rect.width/2 - titleWords[i].size.x/2, |
| 1275 |
rect.y + rect.height/2 - titleWords[i].size.y/2 + currentHeightOffset - totalHeight/2); |
| 1276 |
currentHeightOffset += titleWords[i].size.y; |
| 1277 |
} |
| 1278 |
|
| 1279 |
} else { |
| 1280 |
dc.DrawText(name, |
| 1281 |
rect.x + rect.width/2 - width/2, |
| 1282 |
rect.y + rect.height/2 - height/2); |
| 1283 |
} |
| 1284 |
} |
| 1285 |
|
| 1286 |
/////////////////////////////////////////// |
| 1287 |
/** \class ModItem::ModImage |
| 1288 |
Draws the Mod's image on the list or degrades smoothly to drawing the text |
| 1289 |
"NO IMAGE". |
| 1290 |
*/ |
| 1291 |
/** Constructor. Sets up stuff. */ |
| 1292 |
ModItem::ModImage::ModImage(ModItem *myData) { |
| 1293 |
this->myData = myData; |
| 1294 |
} |
| 1295 |
|
| 1296 |
void ModItem::ModImage::Draw(wxDC &dc, const wxRect &rect) { |
| 1297 |
if ( this->myData->image182x80.IsOk() ) { |
| 1298 |
dc.DrawBitmap(this->myData->image182x80, rect.x, rect.y); |
| 1299 |
} else if ( this->myData->shortname != NO_MOD ) { |
| 1300 |
dc.DrawBitmap(SkinSystem::GetSkinSystem()->GetSmallModImage(), rect.x, rect.y); |
| 1301 |
} else { |
| 1302 |
dc.DrawRectangle(rect); |
| 1303 |
wxPen pen(dc.GetPen()); |
| 1304 |
pen.SetWidth(1); |
| 1305 |
dc.SetPen(pen); |
| 1306 |
wxString noimg = _("NO IMAGE"); |
| 1307 |
wxSize size = dc.GetTextExtent(noimg); |
| 1308 |
dc.DrawText(noimg, rect.x + rect.width/2 - size.x/2, rect.y + rect.height/2 - size.y/2); |
| 1309 |
} |
| 1310 |
} |
| 1311 |
|
| 1312 |
ModInfoDialog::ModInfoDialog(ModItem* item, wxWindow* parent) { |
| 1313 |
wxASSERT(item != NULL); |
| 1314 |
this->item = item; |
| 1315 |
|
| 1316 |
wxASSERT(!item->name.IsEmpty() || !item->shortname.IsEmpty()); |
| 1317 |
wxString modName = |
| 1318 |
wxString::Format(_T("%s"), |
| 1319 |
item->name.IsEmpty() ? item->shortname.c_str(): item->name.c_str()); |
| 1320 |
wxDialog::Create(parent, wxID_ANY, modName, wxDefaultPosition, wxDefaultSize, wxBORDER_RAISED | wxBORDER_DOUBLE ); |
| 1321 |
this->SetBackgroundColour(wxColour(_T("WHITE"))); |
| 1322 |
|
| 1323 |
wxStaticText* titleBox = |
| 1324 |
new wxStaticText(this, wxID_ANY, modName, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); |
| 1325 |
wxFont titleFont = titleBox->GetFont(); |
| 1326 |
titleFont.SetWeight(wxFONTWEIGHT_BOLD); |
| 1327 |
titleFont.SetPointSize(14); |
| 1328 |
titleBox->SetFont(titleFont); |
| 1329 |
|
| 1330 |
wxString tcPath; |
| 1331 |
ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath, wxEmptyString); |
| 1332 |
wxString modFolderString = |
| 1333 |
wxString::Format(_T("%s%s"), |
| 1334 |
tcPath.c_str(), |
| 1335 |
(item->shortname == NO_MOD) ? wxEmptyString : |
| 1336 |
(wxString(wxFileName::GetPathSeparator()) + item->shortname).c_str()); |
| 1337 |
wxStaticText* modFolderBox = |
| 1338 |
new wxStaticText(this, wxID_ANY, modFolderString, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE); |
| 1339 |
|
| 1340 |
wxPanel* modImage = new ModInfoDialog::ImageDrawer(this); |
| 1341 |
modImage->SetMaxSize(wxSize(SkinSystem::ModInfoDialogImageWidth, SkinSystem::ModInfoDialogImageHeight)); |
| 1342 |
|
| 1343 |
wxHtmlWindow* info = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN); |
| 1344 |
info->SetMinSize(wxSize(SkinSystem::ModInfoDialogImageWidth, 250)); |
| 1345 |
if ( item->infotext.IsEmpty() ) { |
| 1346 |
info->SetPage(DEFAULT_MOD_LAUNCHER_INFO_TEXT); |
| 1347 |
} else { |
| 1348 |
wxString infoText(item->infotext); |
| 1349 |
infoText.Replace(_T("\\n"), _T("<br />")); |
| 1350 |
info->SetPage(infoText); |
| 1351 |
} |
| 1352 |
|
| 1353 |
wxHtmlWindow* links = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN | wxHW_SCROLLBAR_NEVER ); |
| 1354 |
links->SetSize(SkinSystem::ModInfoDialogImageWidth, 40); |
| 1355 |
wxString linksWebsite; |
| 1356 |
if (!item->website.IsEmpty()) { |
| 1357 |
linksWebsite = wxString::Format( |
| 1358 |
wxT_2("<a href='%s'>%s</a> :: "), |
| 1359 |
item->website.c_str(), |
| 1360 |
_("Website")); |
| 1361 |
} |
| 1362 |
wxString linksForum; |
| 1363 |
if (item->forum.IsEmpty()) { |
| 1364 |
// Give the default Missing and Campaigns Forum |
| 1365 |
linksForum = wxString::Format( |
| 1366 |
wxT_2("<a href='%s'>%s</a>"), |
| 1367 |
wxT_2("http://www.hard-light.net/forums/index.php?board=124.0"), |
| 1368 |
_("Forum")); |
| 1369 |
} else { |
| 1370 |
linksForum = wxString::Format( |
| 1371 |
wxT_2("<a href='%s'>%s</a>"), |
| 1372 |
item->forum.c_str(), |
| 1373 |
_("Forum")); |
| 1374 |
} |
| 1375 |
wxString linksBugs; |
| 1376 |
if (!item->bugs.IsEmpty()) { |
| 1377 |
linksBugs = wxString::Format( |
| 1378 |
wxT_2("<a href='%s'>%s</a>"), |
| 1379 |
item->bugs.c_str(), |
| 1380 |
_("Bugs")); |
| 1381 |
} |
| 1382 |
wxString linksSupport; |
| 1383 |
if (!item->support.IsEmpty()) { |
| 1384 |
linksSupport = wxString::Format( |
| 1385 |
wxT_2("<a href='%s'>%s</a>"), |
| 1386 |
item->support.c_str(), |
| 1387 |
_("Support")); |
| 1388 |
} |
| 1389 |
|
| 1390 |
wxString linksContent = wxString::Format( |
| 1391 |
wxT_2("<center>%s%s%s%s%s%s%s</center>"), |
| 1392 |
linksWebsite.c_str(), |
| 1393 |
(item->website.IsEmpty())?wxEmptyString:wxT(" :: "), |
| 1394 |
linksForum.c_str(), |
| 1395 |
(item->bugs.IsEmpty())?wxEmptyString:wxT(" :: "), |
| 1396 |
linksBugs.c_str(), |
| 1397 |
(item->support.IsEmpty())?wxEmptyString:wxT(" :: "), |
| 1398 |
linksSupport.c_str()); |
| 1399 |
links->SetPage(linksContent); |
| 1400 |
links->Connect(wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler(ModInfoDialog::OnLinkClicked)); |
| 1401 |
|
| 1402 |
wxStaticBitmap* warning = NULL; |
| 1403 |
wxHtmlWindow* notesText = NULL; |
| 1404 |
|
| 1405 |
if ( !item->notes.IsEmpty() ) { |
| 1406 |
if ( item->warn ) { |
| 1407 |
warning = new wxStaticBitmap(this, wxID_ANY, SkinSystem::GetSkinSystem()->GetBigWarningIcon()); |
| 1408 |
} |
| 1409 |
notesText = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN); |
| 1410 |
notesText->SetPage(item->notes); |
| 1411 |
notesText->SetMinSize(wxSize(200, 64)); |
| 1412 |
} |
| 1413 |
|
| 1414 |
wxButton* close = new wxButton(this, wxID_ANY, _("Close")); |
| 1415 |
this->SetEscapeId(close->GetId()); |
| 1416 |
|
| 1417 |
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); |
| 1418 |
sizer->Add(titleBox, wxSizerFlags().Centre()); |
| 1419 |
sizer->Add(modFolderBox, wxSizerFlags().Centre()); |
| 1420 |
sizer->Add(modImage, wxSizerFlags().Centre()); |
| 1421 |
sizer->Add(info, wxSizerFlags().Centre()); |
| 1422 |
sizer->Add(links, wxSizerFlags().Centre()); |
| 1423 |
if ( notesText != NULL ) { |
| 1424 |
if ( warning != NULL ) { |
| 1425 |
wxSizer* linkSizer = new wxBoxSizer(wxHORIZONTAL); |
| 1426 |
linkSizer->Add(warning); |
| 1427 |
linkSizer->Add(notesText); |
| 1428 |
sizer->Add(linkSizer, wxSizerFlags().Expand().Centre()); |
| 1429 |
} else { |
| 1430 |
sizer->Add(notesText, wxSizerFlags().Expand().Centre()); |
| 1431 |
} |
| 1432 |
} |
| 1433 |
sizer->Add(close, wxSizerFlags().Centre()); |
| 1434 |
this->SetSizerAndFit(sizer); |
| 1435 |
this->Layout(); |
| 1436 |
this->CentreOnParent(); |
| 1437 |
this->ShowModal(); |
| 1438 |
} |
| 1439 |
|
| 1440 |
void ModInfoDialog::OnLinkClicked(wxHtmlLinkEvent &event) { |
| 1441 |
wxHtmlLinkInfo info = event.GetLinkInfo(); |
| 1442 |
wxString rest; |
| 1443 |
wxLaunchDefaultBrowser(info.GetHref()); |
| 1444 |
} |
| 1445 |
|
| 1446 |
ModInfoDialog::ImageDrawer::ImageDrawer(ModInfoDialog* parent): |
| 1447 |
wxPanel(parent) { |
| 1448 |
this->parent = parent; |
| 1449 |
|
| 1450 |
if (!parent->item->image255x112.IsOk()) { |
| 1451 |
this->SetSize(SkinSystem::ModInfoDialogImageWidth, SkinSystem::ModInfoDialogImageHeight); |
| 1452 |
} else { |
| 1453 |
this->SetSize( |
| 1454 |
parent->item->image255x112.GetWidth(), |
| 1455 |
parent->item->image255x112.GetHeight()); |
| 1456 |
} |
| 1457 |
this->GetEventHandler()->Connect(wxEVT_PAINT, wxPaintEventHandler(ModInfoDialog::ImageDrawer::OnDraw)); |
| 1458 |
} |
| 1459 |
|
| 1460 |
void ModInfoDialog::ImageDrawer::OnDraw(wxPaintEvent &WXUNUSED(event)) { |
| 1461 |
wxPaintDC dc(this); |
| 1462 |
if ( parent->item->image255x112.IsOk() ) { |
| 1463 |
dc.DrawBitmap(parent->item->image255x112, 0, 0); |
| 1464 |
} else if ( parent->item->shortname != NO_MOD ) { |
| 1465 |
dc.DrawBitmap(SkinSystem::GetSkinSystem()->GetModImage(), 0, 0); |
| 1466 |
} else { |
| 1467 |
wxCoord textWidth, textHeight; |
| 1468 |
dc.GetTextExtent(_("NO IMAGE"), &textWidth, &textHeight); |
| 1469 |
|
| 1470 |
wxCoord drawLocationX = SkinSystem::ModInfoDialogImageWidth/2 - textWidth/2; |
| 1471 |
wxCoord drawLocationY = SkinSystem::ModInfoDialogImageHeight/2 - textHeight/2; |
| 1472 |
|
| 1473 |
dc.DrawText(_("NO IMAGE"), drawLocationX, drawLocationY); |
| 1474 |
} |
| 1475 |
} |
| 1476 |
|
| 1477 |
BEGIN_EVENT_TABLE(ModInfoDialog::ImageDrawer, wxPanel) |
| 1478 |
END_EVENT_TABLE() |