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 123 of file C4Startup.cpp.

Referenced by EnsureLoaded().

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

Here is the caller graph for this function:

C4Startup::~C4Startup ( )

Definition at line 130 of file C4Startup.cpp.

131 {
132  pInstance = nullptr;
133  delete pLastDlg;
134  delete pCurrDlg;
135 }

Member Function Documentation

void C4Startup::CloseStartup ( )
static

Definition at line 280 of file C4Startup.cpp.

References DontStartup().

Referenced by C4Application::GameTick().

281 {
282  if (pInstance) pInstance->DontStartup();
283 }
void DontStartup()
Definition: C4Startup.cpp:258

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Startup::DontStartup ( )
protected

Definition at line 258 of file C4Startup.cpp.

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

Referenced by CloseStartup().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Startup::DoStartup ( )
protected

Definition at line 219 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().

220 {
221  assert(!fInStartup);
222  assert(::pGUI);
223  // now in startup!
224  fInStartup = true;
225  fLastDlgWasBack = false;
226 
228 
229  // clear any previous
230  if (pLastDlg) { delete pLastDlg; pLastDlg = nullptr; }
231  if (pCurrDlg) { delete pCurrDlg; pCurrDlg = nullptr; }
232 
233  // start with the last dlg that was shown - at first startup main dialog
234  SwitchDialog(eLastDlgID, true, sSubDialog.getData());
235 
236  // show error dlg if restart
238  {
239  Game.fQuitWithError = false;
240  // preferred: Show fatal error
241  const char *szErr = GetFatalError();
242  if (szErr)
243  {
244  ::pGUI->ShowMessage(szErr, LoadResStr("IDS_DLG_LOG"), C4GUI::Ico_Error);
245  }
246  else
247  {
248  // fallback to showing complete log
249  StdStrBuf sLastLog;
251  if (!sLastLog.isNull())
252  ::pGUI->ShowRemoveDlg(new C4GUI::InfoDialog(LoadResStr("IDS_DLG_LOG"), 10, sLastLog));
253  }
254  ResetFatalError();
255  }
256 }
const char * getData() const
Definition: StdBuf.h:442
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:141
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
bool fQuitWithError
Definition: C4Game.h:142
class C4StartupDlg * SwitchDialog(DialogID eToDlg, bool fFade=true, const char *szSubDialog=nullptr)
Definition: C4Startup.cpp:137
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:292
size_t QuitLogPos
Definition: C4Game.h:141
const char * GetFatalError()
Definition: C4Log.cpp:245
bool isNull() const
Definition: StdBuf.h:441
void ResetFatalError()
Definition: C4Log.cpp:240

Here is the call graph for this function:

Here is the caller graph for this function:

C4Startup * C4Startup::EnsureLoaded ( )
static

Definition at line 285 of file C4Startup.cpp.

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

Referenced by InitStartup().

286 {
287  // create and load startup data if not done yet
288  assert(::pGUI);
289  if (!pInstance)
290  {
291  Game.SetInitProgress(36.0f);
292  C4Startup *pStartup = new C4Startup();
293  Game.SetInitProgress(37.0f);
294  // load startup specific gfx
295  if (!pStartup->Graphics.Init())
296  { LogFatal(LoadResStr("IDS_ERR_NOGFXSYS")); delete pStartup; return nullptr; }
297  }
298  return pInstance;
299 }
void SetInitProgress(float fToProgress)
Definition: C4Game.cpp:3385
C4Game Game
Definition: C4Globals.cpp:52
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
bool LogFatal(const char *szMessage)
Definition: C4Log.cpp:227
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 307 of file C4Startup.cpp.

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

Referenced by C4Application::PreInit().

308 {
309  // ensure gfx are loaded
310  C4Startup *pStartup = EnsureLoaded();
311  if (!pStartup)
312  {
313  Application.Quit();
314  return;
315  }
316  // exec it
317  pStartup->DoStartup();
318 }
void DoStartup()
Definition: C4Startup.cpp:219
void Quit() override
static C4Startup * EnsureLoaded()
Definition: C4Startup.cpp:285
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 348 of file C4Startup.cpp.

References C4StartupDlg::OnKeyboardLayoutChanged().

Referenced by C4Application::OnKeyboardLayoutChanged().

349 {
350  // forward message to current dialog
351  if (pCurrDlg) pCurrDlg->OnKeyboardLayoutChanged();
352 }
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 354 of file C4Startup.cpp.

References C4StartupDlg::OnLeagueOptionChanged().

Referenced by C4GameOptionButtons::OnBtnLeague().

355 {
356  // forward message to current dialog
357  if (pCurrDlg) pCurrDlg->OnLeagueOptionChanged();
358 }
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 320 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().

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

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

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

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

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

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: