OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4MapFolderData Class Reference

#include <C4StartupScenSelDlg.h>

Public Member Functions

 C4MapFolderData ()=default
 
 ~C4MapFolderData ()
 
void Clear ()
 
bool Load (C4Group &hGroup, C4ScenarioListLoader::Folder *pScenLoaderFolder)
 
void CompileFunc (StdCompiler *pComp)
 
void CreateGUIElements (C4StartupScenSelDlg *pMainDlg, C4GUI::Window &rContainer)
 
void ResetSelection ()
 
C4GUI::TextWindowGetSelectionInfoBox () const
 
C4ScenarioListLoader::EntryGetSelectedEntry () const
 

Protected Member Functions

void OnButtonScenario (C4GUI::Control *pEl)
 

Friends

class C4StartupScenSelDlg
 

Detailed Description

Definition at line 277 of file C4StartupScenSelDlg.h.

Constructor & Destructor Documentation

C4MapFolderData::C4MapFolderData ( )
default
C4MapFolderData::~C4MapFolderData ( )
inline

Definition at line 349 of file C4StartupScenSelDlg.h.

References Clear().

349 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

void C4MapFolderData::Clear ( )

Definition at line 91 of file C4StartupScenSelDlg.cpp.

References C4FacetSurface::Clear(), and C4Rect::Set().

Referenced by Load(), and ~C4MapFolderData().

92 {
93  fCoordinatesAdjusted = false;
94  fctBackgroundPicture.Clear();
95  pScenarioFolder = nullptr;
96  pSelectedEntry = nullptr;
97  pSelectionInfoBox = nullptr;
98  rcScenInfoArea.Set(0,0,0,0);
99  MinResX=MinResY=0;
100  fUseFullscreenMap=false;
101  int i;
102  for (i=0; i<iScenCount; ++i) delete ppScenList[i];
103  iScenCount=0;
104  delete [] ppScenList; ppScenList=nullptr;
105  for (i=0; i<iAccessGfxCount; ++i) delete ppAccessGfxList[i];
106  iAccessGfxCount=0;
107  delete [] ppAccessGfxList; ppAccessGfxList=nullptr;
108  pMainDlg = nullptr;
109 }
void Set(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt)
Definition: C4Rect.cpp:86
void Clear()
Definition: C4FacetEx.h:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MapFolderData::CompileFunc ( StdCompiler pComp)

Definition at line 184 of file C4StartupScenSelDlg.cpp.

References StdCompiler::isDeserializer(), mkArrayAdaptMap(), mkNamingAdapt(), mkNamingCountAdapt(), mkPtrAdaptNoNull(), and StdCompiler::Value().

185 {
186  // core values
187  pComp->Value(mkNamingAdapt( rcScenInfoArea, "ScenInfoArea", C4Rect(0,0,0,0)));
188  pComp->Value(mkNamingAdapt( MinResX, "MinResX", 0));
189  pComp->Value(mkNamingAdapt( MinResY, "MinResY", 0));
190  pComp->Value(mkNamingAdapt( fUseFullscreenMap,"FullscreenBG", false));
191  // compile scenario list
192  int32_t iOldScenCount = iScenCount;
193  pComp->Value(mkNamingCountAdapt(iScenCount, "Scenario"));
194  if (pComp->isDeserializer())
195  {
196  while (iOldScenCount--) delete ppScenList[iOldScenCount];
197  delete [] ppScenList;
198  if (iScenCount)
199  {
200  ppScenList = new Scenario *[iScenCount];
201  memset(ppScenList, 0, sizeof(Scenario *)*iScenCount);
202  }
203  else
204  ppScenList = nullptr;
205  }
206  if (iScenCount)
207  {
208  mkPtrAdaptNoNull(*ppScenList);
209  pComp->Value(mkNamingAdapt(mkArrayAdaptMap(ppScenList, iScenCount, mkPtrAdaptNoNull<Scenario>), "Scenario"));
210  }
211  // compile access gfx list
212  int32_t iOldAccesGfxCount = iAccessGfxCount;
213  pComp->Value(mkNamingCountAdapt(iAccessGfxCount, "AccessGfx"));
214  if (pComp->isDeserializer())
215  {
216  while (iOldAccesGfxCount--) delete ppAccessGfxList[iOldAccesGfxCount];
217  delete [] ppAccessGfxList;
218  if (iAccessGfxCount)
219  {
220  ppAccessGfxList = new AccessGfx *[iAccessGfxCount];
221  memset(ppAccessGfxList, 0, sizeof(AccessGfx *)*iAccessGfxCount);
222  }
223  else
224  ppAccessGfxList = nullptr;
225  }
226  if (iAccessGfxCount)
227  {
228  mkPtrAdaptNoNull(*ppAccessGfxList);
229  pComp->Value(mkNamingAdapt(mkArrayAdaptMap(ppAccessGfxList, iAccessGfxCount, mkPtrAdaptNoNull<AccessGfx>), "AccessGfx"));
230  }
231 }
StdNamingCountAdapt< int_t > mkNamingCountAdapt(int_t &iCount, const char *szName)
Definition: StdAdaptors.h:976
Definition: C4Rect.h:27
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:606
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
StdArrayAdapt< T, M > mkArrayAdaptMap(T *pArray, int iSize, M &&map)
Definition: StdAdaptors.h:313

Here is the call graph for this function:

void C4MapFolderData::CreateGUIElements ( C4StartupScenSelDlg pMainDlg,
C4GUI::Window rContainer 
)

Definition at line 300 of file C4StartupScenSelDlg.cpp.

References C4GUI::Container::AddElement(), C4StartupScenSel_TitleOverlayMargin, C4StartupScenSel_TitlePictureHgt, C4StartupScenSel_TitlePicturePadding, C4StartupScenSel_TitlePictureWdt, C4GUI::Element::ClientPos2ScreenPos(), Config, FormatString(), C4Config::General, C4Startup::Get(), C4StartupGraphics::GetBlackFontByHeight(), C4GUI::Element::GetBounds(), C4GUI::Window::GetClientRect(), C4GUI::Container::GetFirst(), C4GraphicsResource::GetFontByHeight(), C4Startup::Graphics, GraphicsResource, LoadResStr(), C4ConfigGeneral::MissionAccess, C4StartupScenSelDlg::OnButtonScenario(), C4StartupScenSelDlg::SetBackground(), C4GUI::TextWindow::SetDecoration(), SIsModule(), C4Rect::x, and C4Rect::y.

301 {
302  this->pMainDlg = pMainDlg;
303  // convert all coordinates to match the container sizes
304  // do this only once; assume container won't change between loads
305  if (!fCoordinatesAdjusted)
306  {
307  if (!fUseFullscreenMap)
308  ConvertFacet2ScreenCoord(rContainer.GetClientRect(), true);
309  else
310  {
311  C4Rect rcMapRect = pMainDlg->GetBounds();
312  rContainer.ClientPos2ScreenPos(rcMapRect.x, rcMapRect.y);
313  ConvertFacet2ScreenCoord(rcMapRect, false);
314  }
315  }
316  // empty any previous stuff in container
317  while (rContainer.GetFirst()) delete rContainer.GetFirst();
318  // create background image
319  if (!fUseFullscreenMap)
320  rContainer.AddElement(new MapPic(rcfBG, fctBackgroundPicture));
321  else
322  {
323  pMainDlg->SetBackground(&fctBackgroundPicture);
324  }
325  // create mission access overlays
326  int i;
327  for (i=0; i<iAccessGfxCount; ++i)
328  {
329  AccessGfx *pGfx = ppAccessGfxList[i];
330  const char *szPassword = pGfx->sPassword.getData();
331  if (!szPassword || !*szPassword || SIsModule(Config.General.MissionAccess, szPassword))
332  {
333  // ACCESS TO GFX GRANTED: draw it
334  rContainer.AddElement(new MapPic(pGfx->rcfOverlayPos, pGfx->fctOverlay));
335  }
336  }
337  // create buttons for scenarios
338  C4GUI::Button *pBtnFirst = nullptr;
339  for (i=0; i<iScenCount; ++i)
340  {
341  Scenario *pScen = ppScenList[i];
342  if (pScen->pScenEntry && !pScen->pScenEntry->HasMissionAccess())
343  {
344  // no access to this scenario: Do not create a button at all; not even base image. The scenario is "invisible".
345  }
346  else
347  {
349  (pScen->fctBase, pScen->fctOverlay, pScen->rcfOverlayPos, 0, pMainDlg, &C4StartupScenSelDlg::OnButtonScenario);
350  ppScenList[i]->pBtn = pBtn;
351  if (pScen->pScenEntry)
352  pBtn->SetToolTip(FormatString(LoadResStr("IDS_MSG_MAP_STARTSCEN"), pScen->pScenEntry->GetName().getData()).getData());
353  if (pScen->sTitle.getLength()>0)
354  {
355  pBtn->SetText(pScen->sTitle.getData());
356  pBtn->SetTextColors(pScen->dwTitleInactClr, pScen->dwTitleActClr);
357  pBtn->SetTextPos(pScen->iTitleOffX, pScen->iTitleOffY, pScen->byTitleAlign);
358  CStdFont *pUseFont; float fFontZoom=1.0f;
359  if (pScen->fTitleBookFont)
360  pUseFont = &(C4Startup::Get()->Graphics.GetBlackFontByHeight(pScen->iTitleFontSize, &fFontZoom));
361  else
362  pUseFont = &(::GraphicsResource.GetFontByHeight(pScen->iTitleFontSize, &fFontZoom));
363  if (Inside<float>(fFontZoom, 0.8f, 1.25f)) fFontZoom = 1.0f; // some tolerance for font zoom
364  pBtn->SetTextFont(pUseFont, fFontZoom);
365  }
366  rContainer.AddElement(pBtn);
367  if (!pBtnFirst) pBtnFirst = pBtn;
368  }
369  }
370  // create scenario info listbox
371  pSelectionInfoBox = new C4GUI::TextWindow(rcScenInfoArea,
373  C4StartupScenSel_TitlePicturePadding, 100, 4096, nullptr, true, &C4Startup::Get()->Graphics.fctScenSelTitleOverlay, C4StartupScenSel_TitleOverlayMargin);
374  pSelectionInfoBox->SetDecoration(false, false, &C4Startup::Get()->Graphics.sfctBookScroll, true);
375  rContainer.AddElement(pSelectionInfoBox);
376 }
const int32_t C4StartupScenSel_TitlePictureWdt
C4Config Config
Definition: C4Config.cpp:833
void SetDecoration(bool fDrawBG, bool fDrawFrame, ScrollBarFacets *pToGfx, bool fAutoScroll)
Definition: C4Gui.h:1752
char MissionAccess[CFG_MaxString+1]
Definition: C4Config.h:45
C4ConfigGeneral General
Definition: C4Config.h:251
CStdFont & GetFontByHeight(int32_t iHgt, float *pfZoom=nullptr)
void SetBackground(C4Facet *pNewBG)
Definition: C4Rect.h:27
void AddElement(Element *pChild)
bool SIsModule(const char *szList, const char *szString, int *ipIndex, bool fCaseSensitive)
Definition: Standard.cpp:541
C4GraphicsResource GraphicsResource
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
const int32_t C4StartupScenSel_TitlePictureHgt
const int32_t C4StartupScenSel_TitleOverlayMargin
int32_t y
Definition: C4Rect.h:30
Element * GetFirst()
Definition: C4Gui.h:829
void OnButtonScenario(C4GUI::Control *pEl)
C4Rect & GetClientRect() override
Definition: C4Gui.h:864
const int32_t C4StartupScenSel_TitlePicturePadding
C4Rect & GetBounds()
Definition: C4Gui.h:445
int32_t x
Definition: C4Rect.h:30
void ClientPos2ScreenPos(int32_t &riX, int32_t &riY)
Definition: C4Gui.cpp:231
static C4Startup * Get()
Definition: C4Startup.h:133
CStdFont & GetBlackFontByHeight(int32_t iHgt, float *pfZoom)
Definition: C4Startup.cpp:96
C4StartupGraphics Graphics
Definition: C4Startup.h:100
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

C4ScenarioListLoader::Entry* C4MapFolderData::GetSelectedEntry ( ) const
inline

Definition at line 369 of file C4StartupScenSelDlg.h.

369 { return pSelectedEntry; }
C4GUI::TextWindow* C4MapFolderData::GetSelectionInfoBox ( ) const
inline

Definition at line 368 of file C4StartupScenSelDlg.h.

368 { return pSelectionInfoBox; }
bool C4MapFolderData::Load ( C4Group hGroup,
C4ScenarioListLoader::Folder pScenLoaderFolder 
)

Definition at line 111 of file C4StartupScenSelDlg.cpp.

References C4Draw::Blit(), C4CFN_MapFolderBG, C4CFN_MapFolderData, C4CFN_ScriptStringTbl, C4FCT_Full, Clear(), Config, C4FacetSurface::Create(), DebugLogF(), C4ScenarioListLoader::Folder::FindEntryByName(), C4Config::General, C4Group::GetName(), C4GUI::GetScreenHgt(), C4GUI::GetScreenWdt(), C4Facet::Hgt, C4ConfigGeneral::LanguageEx, C4FacetSurface::Load(), C4Language::LoadComponentHost(), C4Group::LoadEntryString(), mkNamingAdapt(), pDraw, C4LangStringTable::ReplaceStrings(), C4Surface::SavePNG(), C4Facet::Surface, C4Surface::Wdt, and C4Facet::Wdt.

112 {
113  // clear previous
114  Clear();
115  // load localization info
116  C4LangStringTable LangTable;
117  bool fHasLangTable = C4Language::LoadComponentHost(&LangTable, hGroup, C4CFN_ScriptStringTbl, Config.General.LanguageEx);
118  // load core data
119  StdStrBuf Buf;
120  if (!hGroup.LoadEntryString(C4CFN_MapFolderData, &Buf)) return false;
121  if (fHasLangTable) LangTable.ReplaceStrings(Buf);
122  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(mkNamingAdapt(*this, "FolderMap"), Buf, C4CFN_MapFolderData)) return false;
123  // check resolution requirement
124  if (MinResX && MinResX>C4GUI::GetScreenWdt()) return false;
125  if (MinResY && MinResY>C4GUI::GetScreenHgt()) return false;
126  // load images
127  if (!fctBackgroundPicture.Load(hGroup, C4CFN_MapFolderBG, C4FCT_Full, C4FCT_Full, false, 0))
128  {
129  DebugLogF(R"(C4MapFolderData::Load(%s): Could not load background graphic "%s")", hGroup.GetName(), C4CFN_MapFolderBG);
130  return false;
131  }
132  int i;
133  for (i=0; i<iScenCount; ++i)
134  {
135  // init scenario entry stuff
136  Scenario *pScen = ppScenList[i];
137  pScen->pScenEntry = pScenLoaderFolder->FindEntryByName(pScen->sFilename.getData());
138  pScen->pBtn = nullptr;
139  pScen->sTitle.Replace("TITLE", pScen->pScenEntry ? pScen->pScenEntry->GetName().getData() : "<c ff0000>ERROR</c>" /* scenario not loaded; title cannot be referenced */);
140  // developer image dump
141  if (pScen->fImgDump)
142  {
143  C4FacetSurface fctDump; bool fSuccess=false;
144  if (fctDump.Create(pScen->rcOverlayPos.Wdt, pScen->rcOverlayPos.Hgt, C4FCT_Full, C4FCT_Full))
145  {
146  pDraw->Blit(fctBackgroundPicture.Surface,
147  (float) pScen->rcOverlayPos.x, (float) pScen->rcOverlayPos.y,
148  (float) pScen->rcOverlayPos.Wdt, (float) pScen->rcOverlayPos.Hgt,
149  fctDump.Surface,
150  0, 0,
151  fctDump.Wdt, fctDump.Hgt);
152  fSuccess = fctDump.Surface->SavePNG(pScen->sBaseImage.getData(), true, false, false);
153  }
154  if (!fSuccess)
155  DebugLogF(R"(C4MapFolderData::Load(%s): Could not dump graphic "%s")", hGroup.GetName(), pScen->sBaseImage.getData());
156  continue;
157  }
158  // load images
159  if (pScen->sBaseImage.getLength()>0) if (!pScen->fctBase.Load(hGroup, pScen->sBaseImage.getData(), C4FCT_Full, C4FCT_Full, false, 0))
160  {
161  DebugLogF(R"(C4MapFolderData::Load(%s): Could not load base graphic "%s")", hGroup.GetName(), pScen->sBaseImage.getData());
162  return false;
163  }
164  if (pScen->sOverlayImage.getLength()>0) if (!pScen->fctOverlay.Load(hGroup, pScen->sOverlayImage.getData(), C4FCT_Full, C4FCT_Full, false, 0))
165  {
166  DebugLogF(R"(C4MapFolderData::Load(%s): Could not load graphic "%s")", hGroup.GetName(), pScen->sOverlayImage.getData());
167  return false;
168  }
169  }
170  for (i=0; i<iAccessGfxCount; ++i)
171  {
172  AccessGfx *pGfx= ppAccessGfxList[i];
173  if (pGfx->sOverlayImage.getLength()>0) if (!pGfx->fctOverlay.Load(hGroup, pGfx->sOverlayImage.getData(), C4FCT_Full, C4FCT_Full, false, 0))
174  {
175  DebugLogF(R"(C4MapFolderData::Load(%s): Could not load graphic "%s")", hGroup.GetName(), pGfx->sOverlayImage.getData());
176  return false;
177  }
178  }
179  // all loaded
180  pScenarioFolder = pScenLoaderFolder;
181  return true;
182 }
C4Config Config
Definition: C4Config.cpp:833
int Wdt
Definition: C4Surface.h:65
C4ConfigGeneral General
Definition: C4Config.h:251
bool Load(C4Group &hGroup, const char *szName, int iWdt, int iHgt, bool fNoErrIfNotFound, int iFlags)
Definition: C4FacetEx.cpp:78
bool SavePNG(C4Group &hGroup, const char *szFilename, bool fSaveAlpha=true, bool fSaveOverlayOnly=false)
int32_t GetScreenWdt()
Definition: C4Gui.h:2821
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
#define C4CFN_ScriptStringTbl
Definition: C4Components.h:68
static bool LoadComponentHost(C4ComponentHost *host, C4Group &hGroup, const char *szFilename, const char *szLanguage)
Definition: C4Language.cpp:232
#define C4CFN_MapFolderBG
Definition: C4Components.h:136
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:278
const char * GetName() const
Definition: C4Group.cpp:1845
C4Draw * pDraw
Definition: C4Draw.cpp:42
void ReplaceStrings(StdStrBuf &rBuf)
char LanguageEx[CFG_MaxString+1]
Definition: C4Config.h:37
int32_t GetScreenHgt()
Definition: C4Gui.h:2822
bool Blit(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:301
#define C4CFN_MapFolderData
Definition: C4Components.h:135
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
float Hgt
Definition: C4Facet.h:118
bool Create(int iWdt, int iHgt, int iWdt2=C4FCT_Full, int iHgt2=C4FCT_Full)
Definition: C4FacetEx.cpp:54
C4Surface * Surface
Definition: C4Facet.h:117
const int C4FCT_Full
Definition: C4FacetEx.h:26
Entry * FindEntryByName(const char *szFilename) const
float Wdt
Definition: C4Facet.h:118

Here is the call graph for this function:

void C4MapFolderData::OnButtonScenario ( C4GUI::Control pEl)
protected

Definition at line 378 of file C4StartupScenSelDlg.cpp.

Referenced by C4StartupScenSelDlg::OnButtonScenario().

379 {
380  // get associated scenario entry
381  int i;
382  for (i=0; i<iScenCount; ++i)
383  if (pEl == ppScenList[i]->pBtn)
384  break;
385  if (i == iScenCount) return;
386  // select the associated entry
387  pSelectedEntry = ppScenList[i]->pScenEntry;
388 }

Here is the caller graph for this function:

void C4MapFolderData::ResetSelection ( )

Definition at line 390 of file C4StartupScenSelDlg.cpp.

Referenced by C4StartupScenSelDlg::DeselectAll().

391 {
392  pSelectedEntry = nullptr;
393 }

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4StartupScenSelDlg
friend

Definition at line 359 of file C4StartupScenSelDlg.h.


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