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

#include <C4StartupScenSelDlg.h>

Public Member Functions

 C4MapFolderData ()
 
 ~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 278 of file C4StartupScenSelDlg.h.

Constructor & Destructor Documentation

C4MapFolderData::C4MapFolderData ( )
inline

Definition at line 349 of file C4StartupScenSelDlg.h.

349 : fCoordinatesAdjusted(false), ppScenList(nullptr), iScenCount(0), ppAccessGfxList(nullptr), iAccessGfxCount(0), pMainDlg(nullptr) {}
C4MapFolderData::~C4MapFolderData ( )
inline

Definition at line 350 of file C4StartupScenSelDlg.h.

References Clear().

350 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

void C4MapFolderData::Clear ( )

Definition at line 95 of file C4StartupScenSelDlg.cpp.

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

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

96 {
97  fCoordinatesAdjusted = false;
98  fctBackgroundPicture.Clear();
99  pScenarioFolder = nullptr;
100  pSelectedEntry = nullptr;
101  pSelectionInfoBox = nullptr;
102  rcScenInfoArea.Set(0,0,0,0);
103  MinResX=MinResY=0;
104  fUseFullscreenMap=false;
105  int i;
106  for (i=0; i<iScenCount; ++i) delete ppScenList[i];
107  iScenCount=0;
108  delete [] ppScenList; ppScenList=nullptr;
109  for (i=0; i<iAccessGfxCount; ++i) delete ppAccessGfxList[i];
110  iAccessGfxCount=0;
111  delete [] ppAccessGfxList; ppAccessGfxList=nullptr;
112  pMainDlg = nullptr;
113 }
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 188 of file C4StartupScenSelDlg.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 304 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.

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

Here is the call graph for this function:

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

Definition at line 370 of file C4StartupScenSelDlg.h.

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

Definition at line 369 of file C4StartupScenSelDlg.h.

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

Definition at line 115 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.

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

Here is the call graph for this function:

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

Definition at line 382 of file C4StartupScenSelDlg.cpp.

Referenced by C4StartupScenSelDlg::OnButtonScenario().

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

Here is the caller graph for this function:

void C4MapFolderData::ResetSelection ( )

Definition at line 394 of file C4StartupScenSelDlg.cpp.

Referenced by C4StartupScenSelDlg::DeselectAll().

395 {
396  pSelectedEntry = nullptr;
397 }

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4StartupScenSelDlg
friend

Definition at line 360 of file C4StartupScenSelDlg.h.


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