OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScenarioListLoader::Scenario Class Reference

#include <C4StartupScenSelDlg.h>

Inheritance diagram for C4ScenarioListLoader::Scenario:
[legend]
Collaboration diagram for C4ScenarioListLoader::Scenario:
[legend]

Public Member Functions

 Scenario (class C4ScenarioListLoader *pLoader, class Folder *pParent)
 
virtual ~Scenario ()
 
virtual bool LoadCustom (C4Group &rGrp, bool fNameLoaded, bool fIconLoaded)
 
virtual bool LoadCustomPre (C4Group &rGrp)
 
virtual bool Start ()
 
virtual bool CanOpen (StdStrBuf &sError)
 
virtual bool IsGrayed ()
 
virtual bool IsHidden ()
 
virtual bool HasMissionAccess () const
 
virtual StdStrBuf GetOpenText ()
 
virtual StdStrBuf GetOpenTooltip ()
 
const C4ScenarioGetC4S () const
 
virtual bool GetAchievement (int32_t idx, C4Facet *out_facet, const char **out_description)
 
virtual StdStrBuf GetTypeName ()
 
virtual const char * GetDefaultExtension ()
 
virtual C4ScenarioParameterDefsGetParameterDefs ()
 
virtual C4ScenarioParametersGetParameters ()
 
virtual bool IsScenario ()
 
bool Load (C4Group *pFromGrp, const StdStrBuf *psFilename, bool fLoadEx)
 
virtual FolderGetIsFolder ()
 
const StdStrBufGetName () const
 
const StdStrBufGetEntryFilename () const
 
const StdStrBufGetVersion () const
 
const StdStrBufGetAuthor () const
 
const C4FacetGetIconFacet () const
 
const C4FacetGetTitlePicture () const
 
const StdStrBufGetDesc () const
 
int GetIconIndex ()
 
int GetDifficulty ()
 
int GetFolderIndex ()
 
EntryGetNext () const
 
class FolderGetParent () const
 
virtual bool HasUnregisteredAccess () const
 
virtual bool SetTitleInGroup (C4Group &rGrp, const char *szNewTitle)
 
bool RenameTo (const char *szNewName)
 

Static Public Member Functions

static EntryCreateEntryForFile (const StdStrBuf &sFilename, C4ScenarioListLoader *pLoader, Folder *pParent)
 

Protected Attributes

class C4ScenarioListLoaderpLoader
 
EntrypNext
 
class FolderpParent
 
StdCopyStrBuf sName
 
StdCopyStrBuf sFilename
 
StdCopyStrBuf sDesc
 
StdCopyStrBuf sVersion
 
StdCopyStrBuf sAuthor
 
C4FacetSurface fctIcon
 
C4FacetSurface fctTitle
 
bool fBaseLoaded
 
bool fExLoaded
 
int iIconIndex
 
int iDifficulty
 
int iFolderIndex
 

Detailed Description

Definition at line 111 of file C4StartupScenSelDlg.h.

Constructor & Destructor Documentation

C4ScenarioListLoader::Scenario::Scenario ( class C4ScenarioListLoader pLoader,
class Folder pParent 
)
inline

Definition at line 124 of file C4StartupScenSelDlg.h.

124 : Entry(pLoader, pParent), fNoMissionAccess(false), nAchievements(0), iMinPlrCount(0) {}
Entry(class C4ScenarioListLoader *pLoader, class Folder *pParent)
class C4ScenarioListLoader * pLoader
class Folder * pParent
virtual C4ScenarioListLoader::Scenario::~Scenario ( )
inlinevirtual

Definition at line 125 of file C4StartupScenSelDlg.h.

125 {}

Member Function Documentation

bool C4ScenarioListLoader::Scenario::CanOpen ( StdStrBuf sError)
virtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 764 of file C4StartupScenSelDlg.cpp.

References Config, StdStrBuf::Copy(), StdStrBuf::Format(), C4Config::General, C4StartupScenSelDlg::IsNetworkStart(), LoadResStr(), C4ConfigGeneral::Participants, C4StartupScenSelDlg::pInstance, and SModuleCount().

765 {
766  // safety
768  if (!pDlg) return false;
769  // check mission access
770  if (!HasMissionAccess())
771  {
772  sErrOut.Copy(LoadResStr("IDS_PRC_NOMISSIONACCESS"));
773  return false;
774  }
775  // replay
776  if (C4S.Head.Replay)
777  {
778  // replays can currently not be launched in network mode
779  if (pDlg->IsNetworkStart())
780  {
781  sErrOut.Copy(LoadResStr("IDS_PRC_NONETREPLAY"));
782  return false;
783  }
784  }
785  // regular game
786  else
787  {
788  // check player count
789  int32_t iPlrCount = SModuleCount(Config.General.Participants);
790  int32_t iMaxPlrCount = C4S.Head.MaxPlayer;
791  if (C4S.Head.SaveGame)
792  {
793  // Some scenarios have adjusted MaxPlayerCount to 0 after starting to prevent future joins
794  // make sure it's possible to start the savegame anyway
795  iMaxPlrCount = std::max<int32_t>(iMinPlrCount, iMaxPlrCount);
796  }
797  // normal scenarios: At least one player except in network mode, where it is possible to wait for the additional players
798  // Melees need at least two
799  if ((iPlrCount < iMinPlrCount))
800  {
801  if (pDlg->IsNetworkStart())
802  {
803  // network game: Players may yet join in lobby
804  // only issue a warning for too few players (by setting the error but not returning false here)
805  sErrOut.Format(LoadResStr("IDS_MSG_TOOFEWPLAYERSNET"), (int) iMinPlrCount);
806  }
807  else
808  {
809  // for regular games, this is a fatal no-start-cause
810  sErrOut.Format(LoadResStr("IDS_MSG_TOOFEWPLAYERS"), (int) iMinPlrCount);
811  return false;
812  }
813  }
814  // scenarios (both normal and savegame) may also impose a maximum player restriction
815  if (iPlrCount > iMaxPlrCount)
816  {
817  sErrOut.Format(LoadResStr("IDS_MSG_TOOMANYPLAYERS"), (int) C4S.Head.MaxPlayer);
818  return false;
819  }
820  }
821  // Okay, start!
822  return true;
823 }
C4Config Config
Definition: C4Config.cpp:837
C4ConfigGeneral General
Definition: C4Config.h:252
bool Replay
Definition: C4Scenario.h:72
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
bool SaveGame
Definition: C4Scenario.h:71
char Participants[CFG_MaxString+1]
Definition: C4Config.h:39
int32_t MaxPlayer
Definition: C4Scenario.h:70
int SModuleCount(const char *szList)
Definition: Standard.cpp:581
virtual bool HasMissionAccess() const
bool IsNetworkStart() const
C4SHead Head
Definition: C4Scenario.h:230
static C4StartupScenSelDlg * pInstance

Here is the call graph for this function:

C4ScenarioListLoader::Entry * C4ScenarioListLoader::Entry::CreateEntryForFile ( const StdStrBuf sFilename,
C4ScenarioListLoader pLoader,
Folder pParent 
)
staticinherited

Definition at line 548 of file C4StartupScenSelDlg.cpp.

References C4CFN_FolderFiles, C4CFN_ScenarioFiles, DirContainsScenarios(), DirectoryExists(), StdStrBuf::getData(), GetExtension(), and WildcardMatch().

Referenced by C4ScenarioListLoader::SubFolder::DoLoadContents(), and C4ScenarioListLoader::RegularFolder::DoLoadContents().

549 {
550  // determine entry type by file type
551  const char *szFilename = sFilename.getData();
552  if (!szFilename || !*szFilename) return nullptr;
553  if (WildcardMatch(C4CFN_ScenarioFiles, sFilename.getData())) return new Scenario(pLoader, pParent);
554  if (WildcardMatch(C4CFN_FolderFiles, sFilename.getData())) return new SubFolder(pLoader, pParent);
555  // regular, open folder (C4Group-packed folders without extensions are not regarded, because they could contain anything!)
556  const char *szExt = GetExtension(szFilename);
557  if ((!szExt || !*szExt) && DirectoryExists(sFilename.getData()))
558  {
559  // open folders only if they contain a scenario or folder
560  if (DirContainsScenarios(szFilename))
561  return new RegularFolder(pLoader, pParent);
562  }
563  // type not recognized
564  return nullptr;
565 }
const char * getData() const
Definition: StdBuf.h:450
#define C4CFN_FolderFiles
Definition: C4Components.h:175
bool DirContainsScenarios(const char *szDir)
char * GetExtension(char *szFilename)
Definition: StdFile.cpp:131
bool DirectoryExists(const char *szFilename)
Definition: StdFile.cpp:694
bool WildcardMatch(const char *szWildcard, const char *szString)
Definition: StdFile.cpp:384
#define C4CFN_ScenarioFiles
Definition: C4Components.h:174
class Folder * pParent

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScenarioListLoader::Scenario::GetAchievement ( int32_t  idx,
C4Facet out_facet,
const char **  out_description 
)
virtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 748 of file C4StartupScenSelDlg.cpp.

749 {
750  // return true and fill output parameters if player got the indexed achievement
751  if (idx < 0 || idx >= nAchievements) return false;
752  *out_facet = fctAchievements[idx];
753  *out_description = sAchievementDescriptions[idx].getData();
754  return true;
755 }
const char * getData() const
Definition: StdBuf.h:450
const StdStrBuf& C4ScenarioListLoader::Entry::GetAuthor ( ) const
inlineinherited

Definition at line 79 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sAuthor.

79 { return sAuthor; }
StdCopyStrBuf sAuthor
const C4Scenario& C4ScenarioListLoader::Scenario::GetC4S ( ) const
inline

Definition at line 137 of file C4StartupScenSelDlg.h.

Referenced by C4StartupScenSelDlg::StartScenario().

137 { return C4S; } // get scenario core

Here is the caller graph for this function:

virtual const char* C4ScenarioListLoader::Scenario::GetDefaultExtension ( )
inlinevirtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 142 of file C4StartupScenSelDlg.h.

142 { return "ocs"; }
const StdStrBuf& C4ScenarioListLoader::Entry::GetDesc ( ) const
inlineinherited

Definition at line 82 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sDesc.

82 { return sDesc; }
StdCopyStrBuf sDesc
int C4ScenarioListLoader::Entry::GetDifficulty ( )
inlineinherited

Definition at line 84 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::iDifficulty.

Referenced by EntrySortFunc().

Here is the caller graph for this function:

const StdStrBuf& C4ScenarioListLoader::Entry::GetEntryFilename ( ) const
inlineinherited

Definition at line 77 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sFilename.

Referenced by C4StartupScenSelDlg::DeleteConfirm(), C4StartupScenSelDlg::KeyDelete(), and C4StartupScenSelDlg::StartScenario().

77 { return sFilename; }
StdCopyStrBuf sFilename

Here is the caller graph for this function:

int C4ScenarioListLoader::Entry::GetFolderIndex ( )
inlineinherited

Definition at line 85 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::iFolderIndex.

Referenced by EntrySortFunc().

Here is the caller graph for this function:

const C4Facet& C4ScenarioListLoader::Entry::GetIconFacet ( ) const
inlineinherited

Definition at line 80 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::fctIcon.

Referenced by C4StartupScenSelDlg::ScenListItem::ScenListItem().

80 { return fctIcon; }
C4FacetSurface fctIcon

Here is the caller graph for this function:

int C4ScenarioListLoader::Entry::GetIconIndex ( )
inlineinherited

Definition at line 83 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::iIconIndex.

Referenced by EntrySortFunc().

Here is the caller graph for this function:

virtual Folder* C4ScenarioListLoader::Entry::GetIsFolder ( )
inlinevirtualinherited

Reimplemented in C4ScenarioListLoader::Folder.

Definition at line 74 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Folder::ClearChildren(), and EntrySortFunc().

74 { return nullptr; } // return this if this is a folder

Here is the caller graph for this function:

const StdStrBuf& C4ScenarioListLoader::Entry::GetName ( ) const
inlineinherited

Definition at line 76 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sName.

Referenced by EntrySortFunc(), C4StartupScenSelDlg::KeyDelete(), and C4StartupScenSelDlg::ScenListItem::ScenListItem().

76 { return sName; }
StdCopyStrBuf sName

Here is the caller graph for this function:

Entry* C4ScenarioListLoader::Entry::GetNext ( ) const
inlineinherited

Definition at line 86 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::pNext.

Referenced by C4ScenarioListLoader::Folder::FindEntryByName().

86 { return pNext; }
Entry * pNext

Here is the caller graph for this function:

StdStrBuf C4ScenarioListLoader::Scenario::GetOpenText ( )
virtual

Implements C4ScenarioListLoader::Entry.

Definition at line 825 of file C4StartupScenSelDlg.cpp.

References LoadResStr().

826 {
827  return StdCopyStrBuf(LoadResStr("IDS_BTN_STARTGAME"));
828 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83

Here is the call graph for this function:

StdStrBuf C4ScenarioListLoader::Scenario::GetOpenTooltip ( )
virtual

Implements C4ScenarioListLoader::Entry.

Definition at line 830 of file C4StartupScenSelDlg.cpp.

References LoadResStr().

831 {
832  return StdCopyStrBuf(LoadResStr("IDS_DLGTIP_SCENSELNEXT"));
833 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83

Here is the call graph for this function:

virtual C4ScenarioParameterDefs* C4ScenarioListLoader::Scenario::GetParameterDefs ( )
inlinevirtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 144 of file C4StartupScenSelDlg.h.

144 { return &ParameterDefs; }
virtual C4ScenarioParameters* C4ScenarioListLoader::Scenario::GetParameters ( )
inlinevirtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 145 of file C4StartupScenSelDlg.h.

Referenced by C4StartupScenSelDlg::StartScenario().

145 { return &Parameters; }

Here is the caller graph for this function:

class Folder* C4ScenarioListLoader::Entry::GetParent ( ) const
inlineinherited

Definition at line 87 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::pParent.

Referenced by C4ScenarioListLoader::FolderBack().

87 { return pParent; }
class Folder * pParent

Here is the caller graph for this function:

const C4Facet& C4ScenarioListLoader::Entry::GetTitlePicture ( ) const
inlineinherited

Definition at line 81 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::fctTitle.

81 { return fctTitle; }
C4FacetSurface fctTitle
virtual StdStrBuf C4ScenarioListLoader::Scenario::GetTypeName ( )
inlinevirtual

Implements C4ScenarioListLoader::Entry.

Definition at line 140 of file C4StartupScenSelDlg.h.

References LoadResStr().

140 { return StdCopyStrBuf(LoadResStr("IDS_TYPE_SCENARIO"), true); }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83

Here is the call graph for this function:

const StdStrBuf& C4ScenarioListLoader::Entry::GetVersion ( ) const
inlineinherited

Definition at line 78 of file C4StartupScenSelDlg.h.

References C4ScenarioListLoader::Entry::sVersion.

78 { return sVersion; }
StdCopyStrBuf sVersion
virtual bool C4ScenarioListLoader::Scenario::HasMissionAccess ( ) const
inlinevirtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 134 of file C4StartupScenSelDlg.h.

Referenced by IsHidden().

134 { return !fNoMissionAccess; }; // check mission access only

Here is the caller graph for this function:

virtual bool C4ScenarioListLoader::Entry::HasUnregisteredAccess ( ) const
inlinevirtualinherited

Definition at line 97 of file C4StartupScenSelDlg.h.

97 { return false; }
virtual bool C4ScenarioListLoader::Scenario::IsGrayed ( )
inlinevirtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 132 of file C4StartupScenSelDlg.h.

132 { return false; } // additional option for graying out
virtual bool C4ScenarioListLoader::Scenario::IsHidden ( )
inlinevirtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 133 of file C4StartupScenSelDlg.h.

References HasMissionAccess(), C4Scenario::Head, and C4SHead::Secret.

133 { return C4S.Head.Secret && !HasMissionAccess(); } // condition for hiding element completely
virtual bool HasMissionAccess() const
bool Secret
Definition: C4Scenario.h:77
C4SHead Head
Definition: C4Scenario.h:230

Here is the call graph for this function:

virtual bool C4ScenarioListLoader::Scenario::IsScenario ( )
inlinevirtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 147 of file C4StartupScenSelDlg.h.

147 { return true; }
bool C4ScenarioListLoader::Entry::Load ( C4Group pFromGrp,
const StdStrBuf psFilename,
bool  fLoadEx 
)
inherited

Definition at line 435 of file C4StartupScenSelDlg.cpp.

References C4CFN_IconPNG, C4CFN_ScenarioDesc, C4CFN_ScenarioIcon, C4CFN_ScenarioTitle, C4CFN_Title, C4CFN_Version, C4FCT_Full, C4StartupScenSel_DefaultIcon_OldIconBG, C4FacetSurface::Clear(), Config, C4Facet::Draw(), C4StartupGraphics::fctScenSelIcons, C4Group::FindEntry(), C4Config::General, C4Startup::Get(), C4ComponentHost::GetData(), StdStrBuf::getData(), GetFilename(), C4Group::GetFullName(), C4ComponentHost::GetLanguageString(), C4Facet::GetPhase(), C4Surface::GetPixDw(), C4Startup::Graphics, C4Facet::Hgt, C4ConfigGeneral::LanguageEx, C4ComponentHost::Load(), C4FacetSurface::Load(), C4Language::LoadComponentHost(), C4Group::LoadEntryString(), C4Surface::Lock(), C4Group::Open(), C4Group::OpenAsChild(), RemoveExtension(), C4Surface::SetPixDw(), C4Facet::Surface, C4Surface::Unlock(), and C4Facet::Wdt.

Referenced by C4ScenarioListLoader::SubFolder::DoLoadContents(), C4ScenarioListLoader::RegularFolder::DoLoadContents(), and C4ScenarioListLoader::LoadExtended().

436 {
437  // nothing to do if already loaded
438  if (fBaseLoaded && (fExLoaded || !fLoadEx)) return true;
439  C4Group Group;
440  // group specified: Load as child
441  if (pFromGrp)
442  {
443  assert(psFilename);
444  if (!Group.OpenAsChild(pFromGrp, psFilename->getData())) return false;
445  // set FN by complete entry name
446  this->sFilename.Take(Group.GetFullName());
447  }
448  else
449  {
450  // set FN by complete entry name
451  if (psFilename) this->sFilename.Copy(*psFilename);
452  // no parent group: Direct load from filename
453  if (!Group.Open(sFilename.getData())) return false;
454  }
455  // okay; load standard stuff from group
456  bool fNameLoaded=false, fIconLoaded=false;
457  if (fBaseLoaded)
458  {
459  fNameLoaded = fIconLoaded = true;
460  }
461  else
462  {
463  // Set default name as filename without extension
465  char *szBuf = sName.GrabPointer();
466  RemoveExtension(szBuf);
467  sName.Take(szBuf);
468  // load entry specific stuff that's in the front of the group
469  if (!LoadCustomPre(Group))
470  return false;
471  // Load entry name
472  C4ComponentHost DefNames;
475  fNameLoaded = true;
476  // load entry icon
477  if (Group.FindEntry(C4CFN_IconPNG) && fctIcon.Load(Group, C4CFN_IconPNG, C4FCT_Full, C4FCT_Full, false, 0))
478  fIconLoaded = true;
479  else
480  {
481  C4FacetSurface fctTemp;
482  if (Group.FindEntry(C4CFN_ScenarioIcon) && fctTemp.Load(Group, C4CFN_ScenarioIcon, C4FCT_Full, C4FCT_Full, true, 0))
483  {
484  // old style icon: Blit it on a pieace of paper
485  fctTemp.Surface->Lock();
486  for (int y=0; y<fctTemp.Hgt; ++y)
487  for (int x=0; x<fctTemp.Wdt; ++x)
488  {
489  uint32_t dwPix = fctTemp.Surface->GetPixDw(x,y, false);
490  // transparency has some tolerance...
491  if (Inside<uint8_t>(dwPix & 0xff, 0xb8, 0xff))
492  if (Inside<uint8_t>((dwPix>>0x08) & 0xff, 0x00, 0x0f))
493  if (Inside<uint8_t>((dwPix>>0x10) & 0xff, 0xb8, 0xff))
494  fctTemp.Surface->SetPixDw(x,y,0x00ffffff);
495  }
496  fctTemp.Surface->Unlock();
497  int iIconSize = C4Startup::Get()->Graphics.fctScenSelIcons.Hgt;
498  fctIcon.Create(iIconSize, iIconSize, C4FCT_Full, C4FCT_Full);
500  fctTemp.Draw(fctIcon.Surface, (fctIcon.Wdt-fctTemp.Wdt)/2, (fctIcon.Hgt-fctTemp.Hgt)/2);
501  fctTemp.Clear();
502  fIconLoaded = true;
503  }
504  }
505  // load any entryx-type-specific custom data (e.g. fallbacks for scenario title, and icon)
506  if (!LoadCustom(Group, fNameLoaded, fIconLoaded)) return false;
507  fBaseLoaded = true;
508  }
509  // load extended stuff: title picture
510  if (fLoadEx && !fExLoaded)
511  {
512  // load desc
513  C4ComponentHost DefDesc;
515  {
516  sDesc.Copy(DefDesc.GetData());
517  }
518  // load title
520  fExLoaded = true;
521  // load version
523  }
524  // done, success
525  return true;
526 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
C4Config Config
Definition: C4Config.cpp:837
char * GrabPointer()
Definition: StdBuf.h:467
const int32_t C4StartupScenSel_DefaultIcon_OldIconBG
C4ConfigGeneral General
Definition: C4Config.h:252
bool Load(C4Group &hGroup, const char *szName, int iWdt, int iHgt, bool fNoErrIfNotFound, int iFlags)
Definition: C4FacetEx.cpp:78
const char * GetData() const
bool Lock()
Definition: C4Surface.cpp:463
bool Unlock()
Definition: C4Surface.cpp:474
#define C4CFN_Version
Definition: C4Components.h:72
StdCopyStrBuf sDesc
C4FacetID fctScenSelIcons
Definition: C4Startup.h:61
StdCopyStrBuf sName
StdCopyStrBuf sFilename
bool GetLanguageString(const char *szLanguage, StdStrBuf &rTarget)
static bool LoadComponentHost(C4ComponentHost *host, C4Group &hGroup, const char *szFilename, const char *szLanguage)
Definition: C4Language.cpp:235
#define C4CFN_Title
Definition: C4Components.h:82
StdCopyStrBuf sVersion
bool SetPixDw(int iX, int iY, DWORD dwCol)
Definition: C4Surface.cpp:586
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
virtual bool LoadCustom(C4Group &rGrp, bool fNameLoaded, bool fIconLoaded)
void Take(char *pnData)
Definition: StdBuf.h:465
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
Definition: C4Facet.cpp:154
DWORD GetPixDw(int iX, int iY, bool fApplyModulation)
Definition: C4Surface.cpp:501
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:316
C4FacetSurface fctIcon
bool fBaseLoaded
bool fExLoaded
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
#define C4CFN_IconPNG
Definition: C4Components.h:86
float Hgt
Definition: C4Facet.h:120
#define C4CFN_ScenarioDesc
Definition: C4Components.h:88
bool Create(int iWdt, int iHgt, int iWdt2=C4FCT_Full, int iHgt2=C4FCT_Full)
Definition: C4FacetEx.cpp:54
static C4Startup * Get()
Definition: C4Startup.h:133
C4Surface * Surface
Definition: C4Facet.h:119
const int C4FCT_Full
Definition: C4FacetEx.h:26
#define C4CFN_ScenarioIcon
Definition: C4Components.h:85
void Copy()
Definition: StdBuf.h:475
float Wdt
Definition: C4Facet.h:120
C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0)
Definition: C4Facet.cpp:59
C4StartupGraphics Graphics
Definition: C4Startup.h:100
void Clear()
Definition: C4FacetEx.h:44
#define C4CFN_ScenarioTitle
Definition: C4Components.h:84
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false)
Definition: C4Group.cpp:1585
virtual bool LoadCustomPre(C4Group &rGrp)
C4FacetSurface fctTitle

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScenarioListLoader::Scenario::LoadCustom ( C4Group rGrp,
bool  fNameLoaded,
bool  fIconLoaded 
)
virtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 727 of file C4StartupScenSelDlg.cpp.

References C4Startup::Get().

728 {
729  // icon fallback: Standard scenario icon
730  if (!fIconLoaded)
731  {
732  iIconIndex = C4S.Head.Icon;
733  fctIcon.Set(C4Startup::Get()->Graphics.fctScenSelIcons.GetSection(C4S.Head.Icon));
734  }
735  // scenario name fallback to core
736  if (!fNameLoaded)
737  sName = C4S.Head.Title;
738  // difficulty: Set only for regular rounds (not savegame or record) to avoid bogus sorting
739  if (!C4S.Head.SaveGame && !C4S.Head.Replay)
741  else
742  iDifficulty = 0;
743  // minimum required player count
744  iMinPlrCount = C4S.GetMinPlayer();
745  return true;
746 }
int32_t Icon
Definition: C4Scenario.h:68
bool Replay
Definition: C4Scenario.h:72
std::string Title
Definition: C4Scenario.h:64
int32_t GetMinPlayer()
Definition: C4Scenario.cpp:141
void Set(const C4Facet &cpy)
Definition: C4FacetEx.h:46
StdCopyStrBuf sName
int iDifficulty
bool SaveGame
Definition: C4Scenario.h:71
int iIconIndex
C4FacetSurface fctIcon
static C4Startup * Get()
Definition: C4Startup.h:133
int32_t Difficulty
Definition: C4Scenario.h:67
C4SHead Head
Definition: C4Scenario.h:230

Here is the call graph for this function:

bool C4ScenarioListLoader::Scenario::LoadCustomPre ( C4Group rGrp)
virtual

Reimplemented from C4ScenarioListLoader::Entry.

Definition at line 661 of file C4StartupScenSelDlg.cpp.

References C4GraphicsResource::Achievements, C4ScenarioParameters::AddFilename2ID(), C4CFN_Achievements, C4CFN_AnyScriptStringTbl, C4CFN_ScenarioCore, C4CFN_ScenarioParameterDefs, C4CFN_ScriptStringTbl, C4FCT_Full, C4FCT_Height, C4StartupScenSel_MaxAchievements, Config, C4ScenarioParameterDef::Option::Description, DirSep, C4AchievementGraphics::FindByName(), C4Config::General, C4ScenarioParameterDef::GetAchievement(), StdStrBuf::getData(), C4ScenarioParameterDef::GetDefault(), C4Group::GetFullName(), C4ScenarioParameterDef::GetID(), C4ScenarioParameterDef::GetOptionByValue(), C4ScenarioParameterDefs::GetParameterDefByIndex(), GraphicsResource, C4ScenarioParameterDef::IsAchievement(), C4ConfigGeneral::LanguageEx, C4ScenarioListLoader::Load(), C4Language::LoadComponentHost(), C4Group::LoadEntryString(), C4ConfigGeneral::MissionAccess, mkParAdapt(), C4Group::PreCacheEntries(), StdStrBuf::Replace(), C4FacetSurface::Set(), and SIsModule().

662 {
663  // load scenario core first
664  StdStrBuf sFileContents;
665  if (!rGrp.LoadEntryString(C4CFN_ScenarioCore, &sFileContents)) return false;
666  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkParAdapt(C4S, false), sFileContents, (rGrp.GetFullName() + DirSep C4CFN_ScenarioCore).getData()))
667  return false;
668  // Mission access
669  fNoMissionAccess = (!C4S.Head.MissionAccess.empty() && !SIsModule(Config.General.MissionAccess, C4S.Head.MissionAccess.c_str()));
670  // Localized parameter definitions. needed for achievements and parameter input boxes.
671  // Only show them for "real" scenarios
672  if (!C4S.Head.SaveGame && !C4S.Head.Replay)
673  {
674  // Skipping ahead in regular reading list, so keep other entries in memory
677  C4LangStringTable ScenarioLangStringTable;
679  ParameterDefs.Load(rGrp, &ScenarioLangStringTable);
680  // achievement images: Loaded from this entry and parent folder
681  nAchievements = 0;
682  const C4ScenarioParameterDefs *deflists[] = { pParent ? pParent->GetAchievementDefs() : nullptr, &ParameterDefs };
683  for (size_t def_list_idx=0; def_list_idx<2; ++def_list_idx)
684  {
685  const C4ScenarioParameterDefs *deflist = deflists[def_list_idx];
686  if (!deflist) continue;
687  const C4ScenarioParameterDef *def; size_t idx=0;
688  while ((def = deflist->GetParameterDefByIndex(idx++)))
689  {
690  if (def->IsAchievement())
691  {
692  int32_t val = pLoader->GetAchievements().GetValueByID(C4ScenarioParameters::AddFilename2ID(rGrp.GetFullName().getData(), def->GetID()).getData(), def->GetDefault());
693  if (val)
694  {
695  // player has this achievement - find graphics for it
696  const char *achievement_gfx = def->GetAchievement();
697  StdStrBuf sAchievementFilename(C4CFN_Achievements);
698  sAchievementFilename.Replace("*", achievement_gfx);
699  // look in scenario
700  if (!fctAchievements[nAchievements].Load(rGrp, sAchievementFilename.getData(), C4FCT_Height, C4FCT_Full, false, true))
701  {
702  // look in parent folder
703  const C4FacetSurface *fct = nullptr;
704  const C4AchievementGraphics *parent_achv_gfx;
705  if (pParent && (parent_achv_gfx = pParent->GetAchievementGfx())) fct = parent_achv_gfx->FindByName(achievement_gfx);
706  // look in main gfx group file
707  if (!fct) fct = ::GraphicsResource.Achievements.FindByName(achievement_gfx);
708  if (!fct) continue; // achievement graphics not found :(
709  fctAchievements[nAchievements].Set((const C4Facet &)*fct);
710  }
711  // section by achievement index (1-based, since zero means no achievement)
712  if (val>1) fctAchievements[nAchievements].X += fctAchievements[nAchievements].Wdt * (val-1);
713  // description for this achievement is taken from option
714  const C4ScenarioParameterDef::Option *opt = def->GetOptionByValue(val);
715  if (opt) sAchievementDescriptions[nAchievements] = opt->Description;
716  // keep track of achievement count
717  ++nAchievements;
718  if (nAchievements == C4StartupScenSel_MaxAchievements) break;
719  }
720  }
721  }
722  }
723  }
724  return true;
725 }
const char * getData() const
Definition: StdBuf.h:450
bool Load(C4Group &hGroup, class C4LangStringTable *pLang)
const C4ScenarioParameterDef * GetParameterDefByIndex(size_t idx) const
C4Config Config
Definition: C4Config.cpp:837
virtual const C4ScenarioParameterDefs * GetAchievementDefs() const
char MissionAccess[CFG_MaxString+1]
Definition: C4Config.h:46
std::string MissionAccess
Definition: C4Scenario.h:76
C4ConfigGeneral General
Definition: C4Config.h:252
bool Replay
Definition: C4Scenario.h:72
virtual const C4AchievementGraphics * GetAchievementGfx() const
const int C4FCT_Height
Definition: C4FacetEx.h:27
#define C4CFN_ScenarioParameterDefs
Definition: C4Components.h:43
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:511
C4GraphicsResource GraphicsResource
void Set(const C4Facet &cpy)
Definition: C4FacetEx.h:46
static StdStrBuf AddFilename2ID(const char *filename, const char *id)
#define C4CFN_ScriptStringTbl
Definition: C4Components.h:68
static bool LoadComponentHost(C4ComponentHost *host, C4Group &hGroup, const char *szFilename, const char *szLanguage)
Definition: C4Language.cpp:235
bool SaveGame
Definition: C4Scenario.h:71
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
const char * GetID() const
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:38
#define C4CFN_Achievements
Definition: C4Components.h:90
int PreCacheEntries(const char *szSearchPattern, bool cache_previous=false)
Definition: C4Group.cpp:2222
const Option * GetOptionByValue(int32_t val) const
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
#define C4CFN_ScenarioCore
Definition: C4Components.h:42
class C4ScenarioListLoader * pLoader
C4FacetSurface * FindByName(const char *name) const
C4AchievementGraphics Achievements
const char * GetAchievement() const
#define C4CFN_AnyScriptStringTbl
Definition: C4Components.h:69
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:456
bool Load(C4Group *pFromGrp, const StdStrBuf *psFilename, bool fLoadEx)
C4SHead Head
Definition: C4Scenario.h:230
#define DirSep
const int32_t C4StartupScenSel_MaxAchievements
const int C4FCT_Full
Definition: C4FacetEx.h:26
float Wdt
Definition: C4Facet.h:120
float X
Definition: C4Facet.h:120
const C4ScenarioParameters & GetAchievements() const
class Folder * pParent
int32_t GetValueByID(const char *id, int32_t default_value) const

Here is the call graph for this function:

bool C4ScenarioListLoader::Entry::RenameTo ( const char *  szNewName)
inherited

Definition at line 567 of file C4StartupScenSelDlg.cpp.

References _MAX_PATH, C4GUI::MessageDialog::btnOK, C4CFN_Title, C4Group_IsGroup(), C4Group_MoveItem(), C4Group::Close(), C4Group::Delete(), StdStrBuf::Format(), StdStrBuf::getData(), C4Group::GetError(), GetFilename(), C4GUI::Ico_Error, ItemExists(), ItemIdentical(), LoadResStr(), MakeFilenameFromTitle(), C4Group::Open(), pGUI, SAppend(), SCopy(), SEqual(), and C4GUI::Screen::ShowMessageModal().

568 {
569  // change name+filename
570  // some name sanity validation
571  if (!szNewName || !*szNewName) return false;
572  if (SEqual(szNewName, sName.getData())) return true;
573  char fn[_MAX_PATH+1];
574  SCopy(szNewName, fn, _MAX_PATH);
575  // generate new file name
577  if (!*fn) return false;
578  const char *szExt = GetDefaultExtension();
579  if (szExt) { SAppend(".", fn, _MAX_PATH); SAppend(szExt, fn, _MAX_PATH); }
580  char fullfn[_MAX_PATH+1];
581  SCopy(sFilename.getData(), fullfn, _MAX_PATH);
582  char *fullfn_fn = GetFilename(fullfn);
583  SCopy(fn, fullfn_fn, _MAX_PATH - (fullfn_fn - fullfn));
584  StdCopyStrBuf strErr(LoadResStr("IDS_FAIL_RENAME"));
585  // check if a rename is due
586  if (!ItemIdentical(sFilename.getData(), fullfn))
587  {
588  // check for duplicate filename
589  if (ItemExists(fullfn))
590  {
591  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_FILEEXISTS"), fullfn);
593  return false;
594  }
595  // OK; then rename
596  if (!C4Group_MoveItem(sFilename.getData(), fullfn, true))
597  {
598  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_RENAMEFILE"), sFilename.getData(), fullfn);
600  return false;
601  }
602  sFilename.Copy(fullfn);
603  }
604  // update real name in group, if this is a group
605  if (C4Group_IsGroup(fullfn))
606  {
607  C4Group Grp;
608  if (!Grp.Open(fullfn))
609  {
610  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_OPENFILE"), sFilename.getData(), Grp.GetError());
612  return false;
613  }
614  if (!Grp.Delete(C4CFN_Title))
615  {
616  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_DELOLDTITLE"), sFilename.getData(), Grp.GetError());
618  return false;
619  }
620  if (!SetTitleInGroup(Grp, szNewName)) return false;
621  if (!Grp.Close())
622  {
623  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_WRITENEWTITLE"), sFilename.getData(), Grp.GetError());
625  return false;
626  }
627  }
628  // update title
629  sName.Copy(szNewName);
630  // done
631  return true;
632 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:227
bool ItemIdentical(const char *szFilename1, const char *szFilename2)
Definition: StdFile.cpp:865
virtual const char * GetDefaultExtension()
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
bool Delete(const char *szFiles, bool fRecursive=false)
Definition: C4Group.cpp:1334
#define _MAX_PATH
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
StdCopyStrBuf sName
StdCopyStrBuf sFilename
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void MakeFilenameFromTitle(char *szTitle)
Definition: StdFile.cpp:412
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
#define C4CFN_Title
Definition: C4Components.h:82
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
bool C4Group_IsGroup(const char *szFilename)
Definition: C4Group.cpp:94
bool Close()
Definition: C4Group.cpp:755
virtual bool SetTitleInGroup(C4Group &rGrp, const char *szNewTitle)
const char * GetError()
Definition: C4Group.cpp:504
bool C4Group_MoveItem(const char *szSource, const char *szTarget1, bool fNoSort)
Definition: C4Group.cpp:144
bool ItemExists(const char *szItemName)
Definition: StdFile.h:75
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

bool C4ScenarioListLoader::Entry::SetTitleInGroup ( C4Group rGrp,
const char *  szNewTitle 
)
virtualinherited

Definition at line 634 of file C4StartupScenSelDlg.cpp.

References C4Group::Add(), C4GUI::MessageDialog::btnOK, C4CFN_WriteTitle, Config, StdStrBuf::Copy(), StdStrBuf::Format(), C4Config::General, StdStrBuf::getData(), C4Group::GetError(), GetFilename(), StdStrBuf::GrabPointer(), C4GUI::Ico_Error, C4ConfigGeneral::Language, LoadResStr(), pGUI, RemoveExtension(), SEqual(), C4GUI::Screen::ShowMessageModal(), and StdStrBuf::Take().

635 {
636  // default for group files: Create a title text file and set the title in there
637  // no title needed if filename is sufficient - except for scenarios, where a Scenario.txt could overwrite the title
638  if (!IsScenario())
639  {
640  StdStrBuf sNameByFile; sNameByFile.Copy(GetFilename(sFilename.getData()));
641  char *szBuf = sNameByFile.GrabPointer();
642  RemoveExtension(szBuf);
643  sNameByFile.Take(szBuf);
644  if (SEqual(szNewTitle, sNameByFile.getData())) return true;
645  }
646  // okay, make a title
647  StdStrBuf sTitle; sTitle.Format("%s:%s", Config.General.Language, szNewTitle);
648  if (!rGrp.Add(C4CFN_WriteTitle, sTitle, false, true))
649  {
650  StdStrBuf sMsg; sMsg.Format(LoadResStr("IDS_ERR_ERRORADDINGNEWTITLEFORFIL"), sFilename.getData(), rGrp.GetError());
652  return false;
653  }
654  return true;
655 }
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
const char * getData() const
Definition: StdBuf.h:450
#define C4CFN_WriteTitle
Definition: C4Components.h:83
C4Config Config
Definition: C4Config.cpp:837
char * GrabPointer()
Definition: StdBuf.h:467
C4ConfigGeneral General
Definition: C4Config.h:252
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
virtual bool IsScenario()
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
StdCopyStrBuf sFilename
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
bool ShowMessageModal(const char *szMessage, const char *szCaption, DWORD dwButtons, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
void Take(char *pnData)
Definition: StdBuf.h:465
void RemoveExtension(char *szFilename)
Definition: StdFile.cpp:316
char Language[CFG_MaxString+1]
Definition: C4Config.h:37
const char * GetError()
Definition: C4Group.cpp:504
bool Add(const char *szFile, const char *szAddAs)
Definition: C4Group.cpp:1316
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

bool C4ScenarioListLoader::Scenario::Start ( )
virtual

Implements C4ScenarioListLoader::Entry.

Definition at line 757 of file C4StartupScenSelDlg.cpp.

758 {
759  // gogo!
760  if (!(C4StartupScenSelDlg::pInstance)) return false;
761  return (C4StartupScenSelDlg::pInstance)->StartScenario(this);
762 }
static C4StartupScenSelDlg * pInstance

Member Data Documentation

bool C4ScenarioListLoader::Entry::fBaseLoaded
protectedinherited

Definition at line 61 of file C4StartupScenSelDlg.h.

C4FacetSurface C4ScenarioListLoader::Entry::fctIcon
protectedinherited

Definition at line 60 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetIconFacet().

C4FacetSurface C4ScenarioListLoader::Entry::fctTitle
protectedinherited

Definition at line 60 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetTitlePicture().

bool C4ScenarioListLoader::Entry::fExLoaded
protectedinherited

Definition at line 61 of file C4StartupScenSelDlg.h.

int C4ScenarioListLoader::Entry::iDifficulty
protectedinherited
int C4ScenarioListLoader::Entry::iFolderIndex
protectedinherited
int C4ScenarioListLoader::Entry::iIconIndex
protectedinherited
class C4ScenarioListLoader* C4ScenarioListLoader::Entry::pLoader
protectedinherited

Definition at line 52 of file C4StartupScenSelDlg.h.

class Folder* C4ScenarioListLoader::Entry::pParent
protectedinherited

Definition at line 54 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetParent().

StdCopyStrBuf C4ScenarioListLoader::Entry::sAuthor
protectedinherited

Definition at line 59 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetAuthor().

StdCopyStrBuf C4ScenarioListLoader::Entry::sDesc
protectedinherited

Definition at line 59 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetDesc().

StdCopyStrBuf C4ScenarioListLoader::Entry::sFilename
protectedinherited

Definition at line 59 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetEntryFilename().

StdCopyStrBuf C4ScenarioListLoader::Entry::sName
protectedinherited

Definition at line 59 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetName().

StdCopyStrBuf C4ScenarioListLoader::Entry::sVersion
protectedinherited

Definition at line 59 of file C4StartupScenSelDlg.h.

Referenced by C4ScenarioListLoader::Entry::GetVersion().


The documentation for this class was generated from the following files: