OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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_PlrSel, 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)
 
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 C4StartupAboutDlg
 
class C4StartupPlrSelDlg
 

Detailed Description

Definition at line 93 of file C4Startup.h.

Member Enumeration Documentation

Enumerator
SDID_Main 
SDID_ScenSel 
SDID_ScenSelNetwork 
SDID_NetJoin 
SDID_Options 
SDID_About 
SDID_PlrSel 
SDID_Back 

Definition at line 102 of file C4Startup.h.

Constructor & Destructor Documentation

C4Startup::C4Startup ( )

Definition at line 125 of file C4Startup.cpp.

Referenced by EnsureLoaded().

125  : fInStartup(false), pLastDlg(nullptr), pCurrDlg(nullptr)
126 {
127  // must be single!
128  assert(!pInstance);
129  pInstance = this;
130 }

Here is the caller graph for this function:

C4Startup::~C4Startup ( )

Definition at line 132 of file C4Startup.cpp.

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

Member Function Documentation

void C4Startup::CloseStartup ( )
static

Definition at line 282 of file C4Startup.cpp.

References DontStartup().

Referenced by C4Application::GameTick().

283 {
284  if (pInstance) pInstance->DontStartup();
285 }
void DontStartup()
Definition: C4Startup.cpp:260

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Startup::DontStartup ( )
protected

Definition at line 260 of file C4Startup.cpp.

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

Referenced by CloseStartup().

261 {
262  // check whether startup was aborted
263  delete pLastDlg; pLastDlg = nullptr;
264  if (pCurrDlg)
265  {
266  // deinit last shown dlg
267  if (pCurrDlg->IsShown())
268  {
269  pCurrDlg->Close(true);
270  }
271  delete pCurrDlg;
272  pCurrDlg = nullptr;
273  }
274 
275  // now no more in startup!
276  fInStartup = false;
277 
278  // after startup: cleanup
279  ::pGUI->CloseAllDialogs(true);
280 }
void Close(bool fOK)
bool IsShown()
Definition: C4Gui.h:2147
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
void CloseAllDialogs(bool fWithOK)
Definition: C4Gui.cpp:707

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Startup::DoStartup ( )
protected

Definition at line 221 of file C4Startup.cpp.

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().

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

Here is the call graph for this function:

Here is the caller graph for this function:

C4Startup * C4Startup::EnsureLoaded ( )
static

Definition at line 287 of file C4Startup.cpp.

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

Referenced by InitStartup().

288 {
289  // create and load startup data if not done yet
290  assert(::pGUI);
291  if (!pInstance)
292  {
293  Game.SetInitProgress(36.0f);
294  C4Startup *pStartup = new C4Startup();
295  Game.SetInitProgress(37.0f);
296  // load startup specific gfx
297  if (!pStartup->Graphics.Init())
298  { LogFatal(LoadResStr("IDS_ERR_NOGFXSYS")); delete pStartup; return nullptr; }
299  }
300  return pInstance;
301 }
void SetInitProgress(float fToProgress)
Definition: C4Game.cpp:3389
C4Game Game
Definition: C4Globals.cpp:52
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:230
C4StartupGraphics Graphics
Definition: C4Startup.h:100

Here is the call graph for this function:

Here is the caller graph for this function:

static C4Startup* C4Startup::Get ( )
inlinestatic

Definition at line 133 of file C4Startup.h.

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

133 { assert(pInstance); return pInstance; }

Here is the caller graph for this function:

void C4Startup::InitStartup ( )
static

Definition at line 309 of file C4Startup.cpp.

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

Referenced by C4Application::PreInit().

310 {
311  // ensure gfx are loaded
312  C4Startup *pStartup = EnsureLoaded();
313  if (!pStartup)
314  {
315  Application.Quit();
316  return;
317  }
318  // exec it
319  pStartup->DoStartup();
320 }
virtual void Quit()
void DoStartup()
Definition: C4Startup.cpp:221
static C4Startup * EnsureLoaded()
Definition: C4Startup.cpp:287
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Startup::OnKeyboardLayoutChanged ( )

Definition at line 350 of file C4Startup.cpp.

References C4StartupDlg::OnKeyboardLayoutChanged().

Referenced by C4Application::OnKeyboardLayoutChanged().

351 {
352  // forward message to current dialog
353  if (pCurrDlg) pCurrDlg->OnKeyboardLayoutChanged();
354 }
virtual void OnKeyboardLayoutChanged()
Definition: C4Startup.h:89

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Startup::OnLeagueOptionChanged ( )

Definition at line 356 of file C4Startup.cpp.

References C4StartupDlg::OnLeagueOptionChanged().

Referenced by C4GameOptionButtons::OnBtnLeague().

357 {
358  // forward message to current dialog
359  if (pCurrDlg) pCurrDlg->OnLeagueOptionChanged();
360 }
virtual void OnLeagueOptionChanged()
Definition: C4Startup.h:90

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Startup::SetStartScreen ( const char *  szScreen)
static

Definition at line 322 of file C4Startup.cpp.

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

Referenced by C4Application::ParseCommandLine().

323 {
324  sSubDialog.Clear();
325  // set dialog ID to be shown to specified value
326  if (SEqualNoCase(szScreen, "main"))
327  eLastDlgID = SDID_Main;
328  if (SEqualNoCase(szScreen, "scen"))
329  eLastDlgID = SDID_ScenSel;
330  if (SEqualNoCase(szScreen, "netscen"))
331  eLastDlgID = SDID_ScenSelNetwork;
332  else if (SEqualNoCase(szScreen, "net"))
333  eLastDlgID = SDID_NetJoin;
334  else if (SEqualNoCase(szScreen, "options"))
335  eLastDlgID = SDID_Options;
336  else if (SEqual2NoCase(szScreen, "options-"))
337  {
338  eLastDlgID = SDID_Options;
339  // subscreen of options
340  sSubDialog.Copy(szScreen+8);
341  }
342  else if (SEqualNoCase(szScreen, "plrsel"))
343  eLastDlgID = SDID_PlrSel;
344  else if (SEqualNoCase(szScreen, "about"))
345  eLastDlgID = SDID_About;
346  else return false;
347  return true;
348 }
void Clear()
Definition: StdBuf.h:474
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:177
bool SEqual2NoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:190
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 139 of file C4Startup.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Startup::Unload ( )
static

Definition at line 303 of file C4Startup.cpp.

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

304 {
305  // make sure startup data is destroyed
306  if (pInstance) { delete pInstance; pInstance=nullptr; }
307 }

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4StartupAboutDlg
friend

Definition at line 121 of file C4Startup.h.

Referenced by SwitchDialog().

friend class C4StartupMainDlg
friend

Definition at line 117 of file C4Startup.h.

Referenced by SwitchDialog().

friend class C4StartupNetDlg
friend

Definition at line 118 of file C4Startup.h.

Referenced by SwitchDialog().

friend class C4StartupOptionsDlg
friend

Definition at line 120 of file C4Startup.h.

Referenced by SwitchDialog().

friend class C4StartupPlrSelDlg
friend

Definition at line 122 of file C4Startup.h.

Referenced by SwitchDialog().

friend class C4StartupScenSelDlg
friend

Definition at line 119 of file C4Startup.h.

Referenced by SwitchDialog().

Member Data Documentation


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