From dc9e2d2e8b7cda9dd4fe3091dd1ecaa80b575b15 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Thu, 6 Aug 2015 18:19:01 +0200 Subject: [PATCH] GUI loading error popup Also added fireParticles option --- po/colobot.pot | 6 +-- src/common/restext.cpp | 1 + src/common/restext.h | 1 + src/object/robotmain.cpp | 36 ++++++--------- src/object/robotmain.h | 2 + src/ui/maindialog.cpp | 63 ++++++++++++++++++++++---- src/ui/maindialog.h | 12 ++++- src/ui/screen/screen_player_select.cpp | 2 +- 8 files changed, 85 insertions(+), 38 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index 7a8c1e0e..9dddaae3 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -159,6 +159,9 @@ msgstr "" msgid "LOADING" msgstr "" +msgid "OK" +msgstr "" + msgid "Keyword help(\\key cbot;)" msgstr "" @@ -240,9 +243,6 @@ msgstr "" msgid "Recorder" msgstr "" -msgid "OK" -msgstr "" - msgid "Cancel" msgstr "" diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 7b1346c6..92e43993 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -110,6 +110,7 @@ void InitializeRestext() stringsText[RT_DIALOG_YES] = TR("Yes"); stringsText[RT_DIALOG_NO] = TR("No"); stringsText[RT_DIALOG_LOADING] = TR("LOADING"); + stringsText[RT_DIALOG_OK] = TR("OK"); stringsText[RT_STUDIO_LISTTT] = TR("Keyword help(\\key cbot;)"); stringsText[RT_STUDIO_COMPOK] = TR("Compilation ok (0 errors)"); diff --git a/src/common/restext.h b/src/common/restext.h index 654e3baf..ea7ec1b9 100644 --- a/src/common/restext.h +++ b/src/common/restext.h @@ -106,6 +106,7 @@ enum ResTextType RT_DIALOG_YES = 107, RT_DIALOG_NO = 108, RT_DIALOG_LOADING = 109, + RT_DIALOG_OK = 110, RT_STUDIO_LISTTT = 120, RT_STUDIO_COMPOK = 121, diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index c324db09..232b1622 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -509,15 +509,8 @@ void CRobotMain::ChangePhase(Phase phase) m_fixScene = false; } - if (m_phase == PHASE_MAIN_MENU) - { - m_engine->DeleteTexture("generic.png"); - } - if (m_phase == PHASE_SIMUL) { - m_engine->DeleteTexture("interface.png"); - m_app->SetLowCPU(false); // high CPU for simulation bool loading = !m_sceneReadPath.empty(); @@ -541,9 +534,7 @@ void CRobotMain::ChangePhase(Phase phase) } catch (const std::runtime_error& e) { - GetLogger()->Error("An error occured while trying to load a level\n"); - GetLogger()->Error("%s\n", e.what()); - ChangePhase(PHASE_MAIN_MENU); + LevelLoadingError("An error occured while trying to load a level scene", e); } } @@ -586,9 +577,7 @@ void CRobotMain::ChangePhase(Phase phase) } catch (const std::runtime_error& e) { - GetLogger()->Error("An error occured while trying to load win scene\n"); - GetLogger()->Error("%s\n", e.what()); - ChangePhase(PHASE_LEVEL_LIST); + LevelLoadingError("An error occured while trying to load win scene", e); } } } @@ -618,9 +607,7 @@ void CRobotMain::ChangePhase(Phase phase) } catch (const std::runtime_error& e) { - GetLogger()->Error("An error occured while trying to load lost scene\n"); - GetLogger()->Error("%s\n", e.what()); - ChangePhase(PHASE_LEVEL_LIST); + LevelLoadingError("An error occured while trying to load lost scene", e); } } } @@ -963,7 +950,7 @@ bool CRobotMain::ProcessEvent(Event &event) break; case EVENT_OBJECT_DELETE: - m_ui->GetDialog()->StartQuestion(RT_DIALOG_DELOBJ, true, false, [&]() { + m_ui->GetDialog()->StartQuestion(RT_DIALOG_DELOBJ, true, false, false, [&]() { DeleteObject(); }); break; @@ -2744,8 +2731,7 @@ void CRobotMain::ScenePerso() } catch (const std::runtime_error& e) { - GetLogger()->Error("An error occured while trying to load apperance scene\n"); - GetLogger()->Error("%s\n", e.what()); + LevelLoadingError("An error occured while trying to load apperance scene", e, PHASE_PLAYER_SELECT); } 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)); } +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 int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color) { @@ -5308,9 +5302,7 @@ void CRobotMain::ResetCreate() } catch (const std::runtime_error& e) { - GetLogger()->Error("An error occured while trying to reset scene\n"); - GetLogger()->Error("%s\n", e.what()); - ChangePhase(PHASE_LEVEL_LIST); + LevelLoadingError("An error occured while trying to reset scene", e); } } diff --git a/src/object/robotmain.h b/src/object/robotmain.h index de432438..4e8c2c41 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -381,6 +381,8 @@ protected: void CreateScene(bool soluce, bool fixScene, bool resetObject); 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); int CreateLight(Math::Vector direction, Gfx::Color color); void HiliteClear(); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index a7df5603..7797a089 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -237,7 +237,7 @@ void CMainDialog::StartPauseMenu() 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; CButton* pb; @@ -247,7 +247,7 @@ void CMainDialog::StartQuestion(const std::string& text, bool warningYes, bool w dim.x = 0.7f; dim.y = 0.3f; - StartDialog(dim, false); + StartDialog(dim, fireParticles); m_dialogType = DialogType::Question; m_callbackYes = yes; 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; 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(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. @@ -364,10 +408,10 @@ void CMainDialog::FrameDialog(float rTime) ddim = m_dialogDim; m_dialogTime += rTime; - if ( m_dialogTime < 1.0f ) + pw = static_cast(m_interface->SearchControl(EVENT_WINDOW9)); + if ( pw != 0 ) { - pw = static_cast(m_interface->SearchControl(EVENT_WINDOW9)); - if ( pw != 0 ) + if ( m_dialogTime < 1.0f ) { if ( m_dialogTime < 0.50f ) { @@ -386,10 +430,9 @@ void CMainDialog::FrameDialog(float rTime) dpos.x -= ddim.x/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; diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h index 30be77c2..f48adcb2 100644 --- a/src/ui/maindialog.h +++ b/src/ui/maindialog.h @@ -51,11 +51,19 @@ public: typedef std::function DialogCallback; 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); void StartQuestion(ResTextType text, - bool warningYes, bool warningNo, + bool warningYes = false, bool warningNo = false, + bool fireParticles = false, 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 StopDialog(); bool IsDialog(); diff --git a/src/ui/screen/screen_player_select.cpp b/src/ui/screen/screen_player_select.cpp index 4a9cb4c7..05340a60 100644 --- a/src/ui/screen/screen_player_select.cpp +++ b/src/ui/screen/screen_player_select.cpp @@ -205,7 +205,7 @@ bool CScreenPlayerSelect::EventProcess(const Event &event) GetResource(RES_TEXT, RT_DIALOG_DELGAME, name); 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(); }); break;