GUI loading error popup

Also added fireParticles option
master
krzys-h 2015-08-06 18:19:01 +02:00
parent b9bd075903
commit dc9e2d2e8b
8 changed files with 85 additions and 38 deletions

View File

@ -159,6 +159,9 @@ msgstr ""
msgid "LOADING" msgid "LOADING"
msgstr "" msgstr ""
msgid "OK"
msgstr ""
msgid "Keyword help(\\key cbot;)" msgid "Keyword help(\\key cbot;)"
msgstr "" msgstr ""
@ -240,9 +243,6 @@ msgstr ""
msgid "Recorder" msgid "Recorder"
msgstr "" msgstr ""
msgid "OK"
msgstr ""
msgid "Cancel" msgid "Cancel"
msgstr "" msgstr ""

View File

@ -110,6 +110,7 @@ void InitializeRestext()
stringsText[RT_DIALOG_YES] = TR("Yes"); stringsText[RT_DIALOG_YES] = TR("Yes");
stringsText[RT_DIALOG_NO] = TR("No"); stringsText[RT_DIALOG_NO] = TR("No");
stringsText[RT_DIALOG_LOADING] = TR("LOADING"); stringsText[RT_DIALOG_LOADING] = TR("LOADING");
stringsText[RT_DIALOG_OK] = TR("OK");
stringsText[RT_STUDIO_LISTTT] = TR("Keyword help(\\key cbot;)"); stringsText[RT_STUDIO_LISTTT] = TR("Keyword help(\\key cbot;)");
stringsText[RT_STUDIO_COMPOK] = TR("Compilation ok (0 errors)"); stringsText[RT_STUDIO_COMPOK] = TR("Compilation ok (0 errors)");

View File

@ -106,6 +106,7 @@ enum ResTextType
RT_DIALOG_YES = 107, RT_DIALOG_YES = 107,
RT_DIALOG_NO = 108, RT_DIALOG_NO = 108,
RT_DIALOG_LOADING = 109, RT_DIALOG_LOADING = 109,
RT_DIALOG_OK = 110,
RT_STUDIO_LISTTT = 120, RT_STUDIO_LISTTT = 120,
RT_STUDIO_COMPOK = 121, RT_STUDIO_COMPOK = 121,

View File

@ -509,15 +509,8 @@ void CRobotMain::ChangePhase(Phase phase)
m_fixScene = false; m_fixScene = false;
} }
if (m_phase == PHASE_MAIN_MENU)
{
m_engine->DeleteTexture("generic.png");
}
if (m_phase == PHASE_SIMUL) if (m_phase == PHASE_SIMUL)
{ {
m_engine->DeleteTexture("interface.png");
m_app->SetLowCPU(false); // high CPU for simulation m_app->SetLowCPU(false); // high CPU for simulation
bool loading = !m_sceneReadPath.empty(); bool loading = !m_sceneReadPath.empty();
@ -541,9 +534,7 @@ void CRobotMain::ChangePhase(Phase phase)
} }
catch (const std::runtime_error& e) catch (const std::runtime_error& e)
{ {
GetLogger()->Error("An error occured while trying to load a level\n"); LevelLoadingError("An error occured while trying to load a level scene", e);
GetLogger()->Error("%s\n", e.what());
ChangePhase(PHASE_MAIN_MENU);
} }
} }
@ -586,9 +577,7 @@ void CRobotMain::ChangePhase(Phase phase)
} }
catch (const std::runtime_error& e) catch (const std::runtime_error& e)
{ {
GetLogger()->Error("An error occured while trying to load win scene\n"); LevelLoadingError("An error occured while trying to load win scene", e);
GetLogger()->Error("%s\n", e.what());
ChangePhase(PHASE_LEVEL_LIST);
} }
} }
} }
@ -618,9 +607,7 @@ void CRobotMain::ChangePhase(Phase phase)
} }
catch (const std::runtime_error& e) catch (const std::runtime_error& e)
{ {
GetLogger()->Error("An error occured while trying to load lost scene\n"); LevelLoadingError("An error occured while trying to load lost scene", e);
GetLogger()->Error("%s\n", e.what());
ChangePhase(PHASE_LEVEL_LIST);
} }
} }
} }
@ -963,7 +950,7 @@ bool CRobotMain::ProcessEvent(Event &event)
break; break;
case EVENT_OBJECT_DELETE: case EVENT_OBJECT_DELETE:
m_ui->GetDialog()->StartQuestion(RT_DIALOG_DELOBJ, true, false, [&]() { m_ui->GetDialog()->StartQuestion(RT_DIALOG_DELOBJ, true, false, false, [&]() {
DeleteObject(); DeleteObject();
}); });
break; break;
@ -2744,8 +2731,7 @@ void CRobotMain::ScenePerso()
} }
catch (const std::runtime_error& e) catch (const std::runtime_error& e)
{ {
GetLogger()->Error("An error occured while trying to load apperance scene\n"); LevelLoadingError("An error occured while trying to load apperance scene", e, PHASE_PLAYER_SELECT);
GetLogger()->Error("%s\n", e.what());
} }
m_engine->SetDrawWorld(false); // does not draw anything on the interface m_engine->SetDrawWorld(false); // does not draw anything on the interface
@ -3879,6 +3865,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_eventQueue->AddEvent(Event(EVENT_QUIT)); m_eventQueue->AddEvent(Event(EVENT_QUIT));
} }
void CRobotMain::LevelLoadingError(const std::string& error, const std::runtime_error& exception, Phase exitPhase)
{
GetLogger()->Error("%s\n", error.c_str());
GetLogger()->Error("%s\n", exception.what());
ChangePhase(exitPhase);
m_ui->GetDialog()->StartInformation("Loading error", error, exception.what(), true, false);
}
//! Creates a directional light //! Creates a directional light
int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color) int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color)
{ {
@ -5308,9 +5302,7 @@ void CRobotMain::ResetCreate()
} }
catch (const std::runtime_error& e) catch (const std::runtime_error& e)
{ {
GetLogger()->Error("An error occured while trying to reset scene\n"); LevelLoadingError("An error occured while trying to reset scene", e);
GetLogger()->Error("%s\n", e.what());
ChangePhase(PHASE_LEVEL_LIST);
} }
} }

View File

@ -381,6 +381,8 @@ protected:
void CreateScene(bool soluce, bool fixScene, bool resetObject); void CreateScene(bool soluce, bool fixScene, bool resetObject);
void ResetCreate(); void ResetCreate();
void LevelLoadingError(const std::string& error, const std::runtime_error& exception, Phase exitPhase = PHASE_LEVEL_LIST);
Math::Vector LookatPoint(Math::Vector eye, float angleH, float angleV, float length); Math::Vector LookatPoint(Math::Vector eye, float angleH, float angleV, float length);
int CreateLight(Math::Vector direction, Gfx::Color color); int CreateLight(Math::Vector direction, Gfx::Color color);
void HiliteClear(); void HiliteClear();

View File

@ -237,7 +237,7 @@ void CMainDialog::StartPauseMenu()
pb->SetName(name); pb->SetName(name);
} }
void CMainDialog::StartQuestion(const std::string& text, bool warningYes, bool warningNo, DialogCallback yes, DialogCallback no) void CMainDialog::StartQuestion(const std::string& text, bool warningYes, bool warningNo, bool fireParticles, DialogCallback yes, DialogCallback no)
{ {
CWindow* pw; CWindow* pw;
CButton* pb; CButton* pb;
@ -247,7 +247,7 @@ void CMainDialog::StartQuestion(const std::string& text, bool warningYes, bool w
dim.x = 0.7f; dim.x = 0.7f;
dim.y = 0.3f; dim.y = 0.3f;
StartDialog(dim, false); StartDialog(dim, fireParticles);
m_dialogType = DialogType::Question; m_dialogType = DialogType::Question;
m_callbackYes = yes; m_callbackYes = yes;
m_callbackNo = no; m_callbackNo = no;
@ -288,11 +288,55 @@ void CMainDialog::StartQuestion(const std::string& text, bool warningYes, bool w
} }
} }
void CMainDialog::StartQuestion(ResTextType text, bool warningYes, bool warningNo, DialogCallback yes, DialogCallback no) void CMainDialog::StartQuestion(ResTextType text, bool warningYes, bool warningNo, bool fireParticles, DialogCallback yes, DialogCallback no)
{ {
std::string name; std::string name;
GetResource(RES_TEXT, text, name); GetResource(RES_TEXT, text, name);
StartQuestion(name, warningYes, warningNo, yes, no); StartQuestion(name, warningYes, warningNo, fireParticles, yes, no);
}
void CMainDialog::StartInformation(const std::string& title, const std::string& text, const std::string& details, bool warning, bool fireParticles, DialogCallback ok)
{
CWindow* pw;
CButton* pb;
CLabel* pl;
Math::Point pos, dim, ddim;
std::string name;
dim.x = 0.7f;
dim.y = 0.3f;
StartDialog(dim, fireParticles);
m_dialogType = DialogType::Question;
m_callbackYes = ok;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW9));
if ( pw == 0 ) return;
pw->SetName(title);
pos.x = 0.00f;
pos.y = 0.50f;
ddim.x = 1.00f;
ddim.y = 0.05f;
pl = pw->CreateLabel(pos, ddim, -1, EVENT_DIALOG_LABEL, text);
pl->SetFontType(Gfx::FONT_COLOBOT_BOLD);
//TODO: Add \n support in CLabel
pos.y -= ddim.y;
pl = pw->CreateLabel(pos, ddim, -1, EVENT_DIALOG_LABEL1, details);
pl->SetFontSize(10.0f);
pos.x = 0.50f-0.075f;
pos.y = 0.50f-dim.y/2.0f+0.03f;
ddim.x = 0.15f;
ddim.y = 0.06f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_DIALOG_OK);
pb->SetState(STATE_SHADOW);
GetResource(RES_TEXT, RT_DIALOG_OK, name);
pb->SetName(name);
if (warning)
{
pb->SetState(STATE_WARNING);
}
} }
// Beginning of displaying a dialog. // Beginning of displaying a dialog.
@ -364,10 +408,10 @@ void CMainDialog::FrameDialog(float rTime)
ddim = m_dialogDim; ddim = m_dialogDim;
m_dialogTime += rTime; m_dialogTime += rTime;
if ( m_dialogTime < 1.0f ) pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW9));
if ( pw != 0 )
{ {
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW9)); if ( m_dialogTime < 1.0f )
if ( pw != 0 )
{ {
if ( m_dialogTime < 0.50f ) if ( m_dialogTime < 0.50f )
{ {
@ -386,10 +430,9 @@ void CMainDialog::FrameDialog(float rTime)
dpos.x -= ddim.x/2.0f; dpos.x -= ddim.x/2.0f;
dpos.y -= ddim.y/2.0f; dpos.y -= ddim.y/2.0f;
pw->SetPos(dpos);
pw->SetDim(ddim);
} }
pw->SetPos(dpos);
pw->SetDim(ddim);
} }
if ( !m_settings->GetInterfaceGlint() ) return; if ( !m_settings->GetInterfaceGlint() ) return;

View File

@ -51,11 +51,19 @@ public:
typedef std::function<void()> DialogCallback; typedef std::function<void()> DialogCallback;
void StartQuestion(const std::string& text, void StartQuestion(const std::string& text,
bool warningYes, bool warningNo, bool warningYes = false, bool warningNo = false,
bool fireParticles = false,
DialogCallback yes = nullptr, DialogCallback no = nullptr); DialogCallback yes = nullptr, DialogCallback no = nullptr);
void StartQuestion(ResTextType text, void StartQuestion(ResTextType text,
bool warningYes, bool warningNo, bool warningYes = false, bool warningNo = false,
bool fireParticles = false,
DialogCallback yes = nullptr, DialogCallback no = nullptr); DialogCallback yes = nullptr, DialogCallback no = nullptr);
void StartInformation(const std::string& title,
const std::string& text,
const std::string& details,
bool warning = false,
bool fireParticles = false,
DialogCallback ok = nullptr);
void StartPauseMenu(); void StartPauseMenu();
void StopDialog(); void StopDialog();
bool IsDialog(); bool IsDialog();

View File

@ -205,7 +205,7 @@ bool CScreenPlayerSelect::EventProcess(const Event &event)
GetResource(RES_TEXT, RT_DIALOG_DELGAME, name); GetResource(RES_TEXT, RT_DIALOG_DELGAME, name);
gamer = pl->GetItemName(pl->GetSelect()); gamer = pl->GetItemName(pl->GetSelect());
m_dialog->StartQuestion(StrUtils::Format(name.c_str(), gamer), true, false, [&]() { m_dialog->StartQuestion(StrUtils::Format(name.c_str(), gamer), true, false, false, [&]() {
NameDelete(); NameDelete();
}); });
break; break;