OpenClonk
C4Startup Class Reference

#include <C4Startup.h>

Collaboration diagram for C4Startup:
[legend]

Public Types

enum  DialogID {
  SDID_Main =0 , SDID_ScenSel , SDID_ScenSelNetwork , SDID_NetJoin ,
  SDID_Options , SDID_About , SDID_Legal , SDID_PlrSel ,
  SDID_Mods , SDID_Back
}
 

Public Member Functions

 C4Startup ()
 
 ~C4Startup ()
 
void OnKeyboardLayoutChanged ()
 
void OnLeagueOptionChanged ()
 

Static Public Member Functions

static C4StartupEnsureLoaded ()
 
static void Unload ()
 
static void InitStartup ()
 
static void CloseStartup ()
 
static bool SetStartScreen (const char *szScreen, const char *szSubDialog=nullptr)
 
static C4StartupGet ()
 

Public Attributes

C4StartupGraphics Graphics
 

Protected Member Functions

void DoStartup ()
 
void DontStartup ()
 
class C4StartupDlgSwitchDialog (DialogID eToDlg, bool fFade=true, const char *szSubDialog=nullptr)
 

Friends

class C4StartupMainDlg
 
class C4StartupNetDlg
 
class C4StartupScenSelDlg
 
class C4StartupOptionsDlg
 
class C4StartupModsDlg
 
class C4StartupAboutDlg
 
class C4StartupLegalDlg
 
class C4StartupPlrSelDlg
 

Detailed Description

Definition at line 105 of file C4Startup.h.

Member Enumeration Documentation

◆ DialogID

Enumerator
SDID_Main 
SDID_ScenSel 
SDID_ScenSelNetwork 
SDID_NetJoin 
SDID_Options 
SDID_About 
SDID_Legal 
SDID_PlrSel 
SDID_Mods 
SDID_Back 

Definition at line 114 of file C4Startup.h.

Constructor & Destructor Documentation

◆ C4Startup()

C4Startup::C4Startup ( )

Definition at line 125 of file C4Startup.cpp.

126 {
127  // must be single!
128  assert(!pInstance);
129  pInstance = this;
130 }

Referenced by EnsureLoaded().

Here is the caller graph for this function:

◆ ~C4Startup()

C4Startup::~C4Startup ( )

Definition at line 132 of file C4Startup.cpp.

133 {
134  pInstance = nullptr;
135  delete pLastDlg;
136  delete pCurrDlg;
137 }

Member Function Documentation

◆ CloseStartup()

void C4Startup::CloseStartup ( )
static

Definition at line 292 of file C4Startup.cpp.

293 {
294  if (pInstance) pInstance->DontStartup();
295 }
void DontStartup()
Definition: C4Startup.cpp:270

References DontStartup().

Referenced by C4Application::GameTick().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DontStartup()

void C4Startup::DontStartup ( )
protected

Definition at line 270 of file C4Startup.cpp.

271 {
272  // check whether startup was aborted
273  delete pLastDlg; pLastDlg = nullptr;
274  if (pCurrDlg)
275  {
276  // deinit last shown dlg
277  if (pCurrDlg->IsShown())
278  {
279  pCurrDlg->Close(true);
280  }
281  delete pCurrDlg;
282  pCurrDlg = nullptr;
283  }
284 
285  // now no more in startup!
286  fInStartup = false;
287 
288  // after startup: cleanup
289  ::pGUI->CloseAllDialogs(true);
290 }
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
void Close(bool fOK)
bool IsShown()
Definition: C4Gui.h:2148
void CloseAllDialogs(bool fWithOK)
Definition: C4Gui.cpp:704

References C4GUI::Dialog::Close(), C4GUI::Screen::CloseAllDialogs(), C4GUI::Dialog::IsShown(), and pGUI.

Referenced by CloseStartup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoStartup()

void C4Startup::DoStartup ( )
protected

Definition at line 231 of file C4Startup.cpp.

232 {
233  assert(!fInStartup);
234  assert(::pGUI);
235  // now in startup!
236  fInStartup = true;
237  fLastDlgWasBack = false;
238 
240 
241  // clear any previous
242  if (pLastDlg) { delete pLastDlg; pLastDlg = nullptr; }
243  if (pCurrDlg) { delete pCurrDlg; pCurrDlg = nullptr; }
244 
245  // start with the last dlg that was shown - at first startup main dialog
246  SwitchDialog(eLastDlgID, true, sSubDialog.getData());
247 
248  // show error dlg if restart
250  {
251  Game.fQuitWithError = false;
252  // preferred: Show fatal error
253  const char *szErr = GetFatalError();
254  if (szErr)
255  {
256  ::pGUI->ShowMessage(szErr, LoadResStr("IDS_DLG_LOG"), C4GUI::Ico_Error);
257  }
258  else
259  {
260  // fallback to showing complete log
261  StdStrBuf sLastLog;
263  if (!sLastLog.isNull())
264  ::pGUI->ShowRemoveDlg(new C4GUI::InfoDialog(LoadResStr("IDS_DLG_LOG"), 10, sLastLog));
265  }
266  ResetFatalError();
267  }
268 }
C4Game Game
Definition: C4Globals.cpp:52
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
void ResetFatalError()
Definition: C4Log.cpp:252
bool GetLogSection(size_t iStart, size_t iLength, StdStrBuf &rsOut)
Definition: C4Log.cpp:304
const char * GetFatalError()
Definition: C4Log.cpp:257
bool ShowRemoveDlg(Dialog *pDlg)
bool ShowMessage(const char *szMessage, const char *szCaption, Icons icoIcon, int32_t *piConfigDontShowAgainSetting=nullptr)
size_t StartupLogPos
Definition: C4Game.h:142
size_t QuitLogPos
Definition: C4Game.h:142
bool fQuitWithError
Definition: C4Game.h:143
class C4StartupDlg * SwitchDialog(DialogID eToDlg, bool fFade=true, const char *szSubDialog=nullptr)
Definition: C4Startup.cpp:139
const char * getData() const
Definition: StdBuf.h:442
bool isNull() const
Definition: StdBuf.h:441
@ Ico_Error
Definition: C4Gui.h:652

References C4GraphicsSystem::EnableLoaderDrawing(), C4Game::fQuitWithError, Game, StdStrBuf::getData(), GetFatalError(), GetLogSection(), GraphicsSystem, C4GUI::Ico_Error, StdStrBuf::isNull(), LoadResStr(), pGUI, C4Game::QuitLogPos, ResetFatalError(), C4GUI::Screen::ShowMessage(), C4GUI::Screen::ShowRemoveDlg(), C4Game::StartupLogPos, and SwitchDialog().

Referenced by InitStartup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnsureLoaded()

C4Startup * C4Startup::EnsureLoaded ( )
static

Definition at line 297 of file C4Startup.cpp.

298 {
299  // create and load startup data if not done yet
300  assert(::pGUI);
301  if (!pInstance)
302  {
303  Game.SetInitProgress(36.0f);
304  C4Startup *pStartup = new C4Startup();
305  Game.SetInitProgress(37.0f);
306  // load startup specific gfx
307  if (!pStartup->Graphics.Init())
308  { LogFatal(LoadResStr("IDS_ERR_NOGFXSYS")); delete pStartup; return nullptr; }
309  }
310  return pInstance;
311 }
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:239
void SetInitProgress(float to_progress)
Definition: C4Game.cpp:4207
C4StartupGraphics Graphics
Definition: C4Startup.h:112

References C4Startup(), Game, Graphics, C4StartupGraphics::Init(), LoadResStr(), LogFatal(), pGUI, and C4Game::SetInitProgress().

Referenced by InitStartup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get()

static C4Startup* C4Startup::Get ( )
inlinestatic

Definition at line 147 of file C4Startup.h.

147 { assert(pInstance); return pInstance; }

Referenced by C4StartupMainDlg::C4StartupMainDlg(), C4StartupModsDlg::C4StartupModsDlg(), C4StartupOptionsDlg::C4StartupOptionsDlg(), C4StartupPlrPropertiesDlg::C4StartupPlrPropertiesDlg(), C4StartupPlrSelDlg::C4StartupPlrSelDlg(), C4StartupScenSelDlg::C4StartupScenSelDlg(), C4StartupNetDlg::CreateGame(), C4MapFolderData::CreateGUIElements(), C4StartupAboutDlg::DoBack(), C4StartupLegalDlg::DoBack(), C4StartupModsDlg::DoBack(), C4StartupNetDlg::DoBack(), C4StartupOptionsDlg::DoBack(), C4StartupPlrSelDlg::DoBack(), C4StartupMainDlg::DrawElement(), C4StartupPlrPropertiesDlg::DrawElement(), C4StartupNetListEntry::Execute(), C4ScenarioListLoader::Entry::Load(), C4ScenarioListLoader::Scenario::LoadCustom(), C4ScenarioListLoader::SubFolder::LoadCustom(), C4ScenarioListLoader::RegularFolder::LoadCustom(), C4StartupModsListEntry::MakeInfoEntry(), C4StartupMainDlg::OnAboutBtn(), C4GameOptionButtons::OnBtnLeague(), C4StartupScenSelDlg::OnClosed(), C4Application::OnKeyboardLayoutChanged(), C4StartupAboutDlg::OnLegalBtn(), C4StartupMainDlg::OnModsBtn(), C4StartupMainDlg::OnNetJoinBtn(), C4StartupMainDlg::OnOptionsBtn(), C4StartupMainDlg::OnPlayerSelectionBtn(), C4StartupMainDlg::OnStartBtn(), C4StartupOptionsDlg::RecreateDialog(), C4StartupScenSelDlg::ScenListItem::ScenListItem(), C4Application::SetGameFont(), C4StartupNetListEntry::SetReference(), C4StartupNetListEntry::SetRefQuery(), and C4StartupPlrSelDlg::PlayerListItem::SetSelectionInfo().

Here is the caller graph for this function:

◆ InitStartup()

void C4Startup::InitStartup ( )
static

Definition at line 319 of file C4Startup.cpp.

320 {
321  // ensure gfx are loaded
322  C4Startup *pStartup = EnsureLoaded();
323  if (!pStartup)
324  {
325  Application.Quit();
326  return;
327  }
328  // exec it
329  pStartup->DoStartup();
330 }
C4Application Application
Definition: C4Globals.cpp:44
void Quit() override
static C4Startup * EnsureLoaded()
Definition: C4Startup.cpp:297
void DoStartup()
Definition: C4Startup.cpp:231

References Application, DoStartup(), EnsureLoaded(), and C4Application::Quit().

Referenced by C4Application::PreInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnKeyboardLayoutChanged()

void C4Startup::OnKeyboardLayoutChanged ( )

Definition at line 365 of file C4Startup.cpp.

366 {
367  // forward message to current dialog
368  if (pCurrDlg) pCurrDlg->OnKeyboardLayoutChanged();
369 }
virtual void OnKeyboardLayoutChanged()
Definition: C4Startup.h:101

References C4StartupDlg::OnKeyboardLayoutChanged().

Referenced by C4Application::OnKeyboardLayoutChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnLeagueOptionChanged()

void C4Startup::OnLeagueOptionChanged ( )

Definition at line 371 of file C4Startup.cpp.

372 {
373  // forward message to current dialog
374  if (pCurrDlg) pCurrDlg->OnLeagueOptionChanged();
375 }
virtual void OnLeagueOptionChanged()
Definition: C4Startup.h:102

References C4StartupDlg::OnLeagueOptionChanged().

Referenced by C4GameOptionButtons::OnBtnLeague().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetStartScreen()

bool C4Startup::SetStartScreen ( const char *  szScreen,
const char *  szSubDialog = nullptr 
)
static

Definition at line 332 of file C4Startup.cpp.

333 {
334  sSubDialog.Clear();
335  if (szSubDialog != nullptr)
336  sSubDialog = szSubDialog;
337 
338  // set dialog ID to be shown to specified value
339  if (SEqualNoCase(szScreen, "main"))
340  eLastDlgID = SDID_Main;
341  if (SEqualNoCase(szScreen, "scen"))
342  eLastDlgID = SDID_ScenSel;
343  if (SEqualNoCase(szScreen, "netscen"))
344  eLastDlgID = SDID_ScenSelNetwork;
345  else if (SEqualNoCase(szScreen, "net"))
346  eLastDlgID = SDID_NetJoin;
347  else if (SEqualNoCase(szScreen, "mods"))
348  eLastDlgID = SDID_Mods;
349  else if (SEqualNoCase(szScreen, "options"))
350  eLastDlgID = SDID_Options;
351  else if (SEqual2NoCase(szScreen, "options-"))
352  {
353  eLastDlgID = SDID_Options;
354  // subscreen of options
355  sSubDialog.Copy(szScreen+8);
356  }
357  else if (SEqualNoCase(szScreen, "plrsel"))
358  eLastDlgID = SDID_PlrSel;
359  else if (SEqualNoCase(szScreen, "about"))
360  eLastDlgID = SDID_About;
361  else return false;
362  return true;
363 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:213
bool SEqual2NoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:226
void Copy()
Definition: StdBuf.h:467
void Clear()
Definition: StdBuf.h:466

References StdStrBuf::Clear(), StdStrBuf::Copy(), SDID_About, SDID_Main, SDID_Mods, SDID_NetJoin, SDID_Options, SDID_PlrSel, SDID_ScenSel, SDID_ScenSelNetwork, SEqual2NoCase(), and SEqualNoCase().

Referenced by C4Application::ParseCommandLine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SwitchDialog()

C4StartupDlg * C4Startup::SwitchDialog ( DialogID  eToDlg,
bool  fFade = true,
const char *  szSubDialog = nullptr 
)
protected

Definition at line 139 of file C4Startup.cpp.

140 {
141 #ifdef USE_CONSOLE
142  return nullptr;
143 #else
144  // can't go back twice, because dialog is not remembered: Always go back to main in this case
145  if (eToDlg == SDID_Back && (fLastDlgWasBack || !pLastDlg)) eToDlg = SDID_Main;
146  fLastDlgWasBack = false;
147  // create new dialog
148  C4StartupDlg *pToDlg = nullptr;
149  switch (eToDlg)
150  {
151  case SDID_Main:
152  pToDlg = new C4StartupMainDlg();
153  break;
154  case SDID_ScenSel:
155  pToDlg = new C4StartupScenSelDlg(false);
156  break;
157  case SDID_ScenSelNetwork:
158  pToDlg = new C4StartupScenSelDlg(true);
159  break;
160  case SDID_NetJoin:
161  pToDlg = new C4StartupNetDlg();
162  break;
163  case SDID_Options:
164  pToDlg = new C4StartupOptionsDlg();
165  break;
166  case SDID_About:
167  pToDlg = new C4StartupAboutDlg();
168  break;
169  case SDID_Legal:
170  pToDlg = new C4StartupLegalDlg();
171  break;
172  case SDID_PlrSel:
173  pToDlg = new C4StartupPlrSelDlg();
174  break;
175  case SDID_Mods:
176  pToDlg = new C4StartupModsDlg();
177  break;
178  case SDID_Back:
179  pToDlg = pLastDlg;
180  fLastDlgWasBack = true;
181  break;
182  };
183  assert(pToDlg);
184  if (!pToDlg) return nullptr;
185  if (pToDlg != pLastDlg)
186  {
187  // remember current position
188  eLastDlgID = eToDlg;
189  // kill any old dialog
190  if (pLastDlg) delete pLastDlg;
191  }
192  // retain current dialog as last, so it can fade out and may be used later
193  if ((pLastDlg = pCurrDlg))
194  {
195  if (fFade)
196  {
197  if (!pLastDlg->IsShown()) pLastDlg->Show(::pGUI, false);
198  pLastDlg->FadeOut(true);
199  }
200  else
201  {
202  delete pLastDlg;
203  pLastDlg = nullptr;
204  }
205  }
206  // Okay; now using this dialog
207  pCurrDlg = pToDlg;
208  // go to dialog subscreen
209  if (szSubDialog) pCurrDlg->SetSubscreen(szSubDialog);
210  // fade in new dlg
211  if (fFade)
212  {
213  if (!pToDlg->FadeIn(::pGUI))
214  {
215  delete pToDlg; pCurrDlg=nullptr;
216  return nullptr;
217  }
218  }
219  else
220  {
221  if (!pToDlg->Show(::pGUI, true))
222  {
223  delete pToDlg; pCurrDlg=nullptr;
224  return nullptr;
225  }
226  }
227  return pToDlg;
228 #endif
229 }
void FadeOut(bool fCloseWithOK)
bool FadeIn(Screen *pOnScreen)
bool Show(Screen *pOnScreen, bool fCB)
virtual bool SetSubscreen(const char *szToScreen)
Definition: C4Startup.h:100
friend class C4StartupLegalDlg
Definition: C4Startup.h:135
friend class C4StartupMainDlg
Definition: C4Startup.h:129
friend class C4StartupModsDlg
Definition: C4Startup.h:133
friend class C4StartupNetDlg
Definition: C4Startup.h:130
friend class C4StartupScenSelDlg
Definition: C4Startup.h:131
friend class C4StartupAboutDlg
Definition: C4Startup.h:134
friend class C4StartupOptionsDlg
Definition: C4Startup.h:132
friend class C4StartupPlrSelDlg
Definition: C4Startup.h:136

References C4StartupAboutDlg, C4StartupLegalDlg, C4StartupMainDlg, C4StartupModsDlg, C4StartupNetDlg, C4StartupOptionsDlg, C4StartupPlrSelDlg, C4StartupScenSelDlg, C4GUI::Dialog::FadeIn(), C4GUI::Dialog::FadeOut(), C4GUI::Dialog::IsShown(), pGUI, SDID_About, SDID_Back, SDID_Legal, SDID_Main, SDID_Mods, SDID_NetJoin, SDID_Options, SDID_PlrSel, SDID_ScenSel, SDID_ScenSelNetwork, C4StartupDlg::SetSubscreen(), and C4GUI::Dialog::Show().

Referenced by C4StartupNetDlg::CreateGame(), C4StartupAboutDlg::DoBack(), C4StartupLegalDlg::DoBack(), C4StartupModsDlg::DoBack(), C4StartupNetDlg::DoBack(), C4StartupOptionsDlg::DoBack(), C4StartupPlrSelDlg::DoBack(), DoStartup(), C4StartupMainDlg::OnAboutBtn(), C4StartupScenSelDlg::OnClosed(), C4StartupAboutDlg::OnLegalBtn(), C4StartupMainDlg::OnModsBtn(), C4StartupMainDlg::OnNetJoinBtn(), C4StartupMainDlg::OnOptionsBtn(), C4StartupMainDlg::OnPlayerSelectionBtn(), C4StartupMainDlg::OnStartBtn(), and C4StartupOptionsDlg::RecreateDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Unload()

void C4Startup::Unload ( )
static

Definition at line 313 of file C4Startup.cpp.

314 {
315  // make sure startup data is destroyed
316  if (pInstance) { delete pInstance; pInstance=nullptr; }
317 }

Referenced by C4Game::Init(), C4Application::Quit(), and C4Game::~C4Game().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4StartupAboutDlg

friend class C4StartupAboutDlg
friend

Definition at line 134 of file C4Startup.h.

Referenced by SwitchDialog().

◆ C4StartupLegalDlg

friend class C4StartupLegalDlg
friend

Definition at line 135 of file C4Startup.h.

Referenced by SwitchDialog().

◆ C4StartupMainDlg

friend class C4StartupMainDlg
friend

Definition at line 129 of file C4Startup.h.

Referenced by SwitchDialog().

◆ C4StartupModsDlg

friend class C4StartupModsDlg
friend

Definition at line 133 of file C4Startup.h.

Referenced by SwitchDialog().

◆ C4StartupNetDlg

friend class C4StartupNetDlg
friend

Definition at line 130 of file C4Startup.h.

Referenced by SwitchDialog().

◆ C4StartupOptionsDlg

friend class C4StartupOptionsDlg
friend

Definition at line 132 of file C4Startup.h.

Referenced by SwitchDialog().

◆ C4StartupPlrSelDlg

friend class C4StartupPlrSelDlg
friend

Definition at line 136 of file C4Startup.h.

Referenced by SwitchDialog().

◆ C4StartupScenSelDlg

friend class C4StartupScenSelDlg
friend

Definition at line 131 of file C4Startup.h.

Referenced by SwitchDialog().

Member Data Documentation

◆ Graphics


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