From f90bb6352049037039acd38f7bced5f0dea81644 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 7 Aug 2015 15:59:05 +0200 Subject: [PATCH] Hide some things in save screenshots Save indicator, mouse cursor, CDisplayText and interface particles --- src/app/app.h | 5 +-- src/graphics/engine/engine.cpp | 16 ++++++++- src/graphics/engine/engine.h | 9 +++++ src/object/robotmain.cpp | 59 ++++++++++++++++++++++++------- src/object/robotmain.h | 6 ++-- src/ui/screen/screen_io.cpp | 5 ++- src/ui/screen/screen_io_write.cpp | 1 - src/ui/screen/screen_loading.cpp | 13 +++---- src/ui/screen/screen_loading.h | 3 -- 9 files changed, 84 insertions(+), 33 deletions(-) diff --git a/src/app/app.h b/src/app/app.h index 4c318a47..315ba034 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -323,6 +323,9 @@ public: //@} bool GetSceneTestMode(); + + //! Renders the image in window + void Render(); protected: //! Creates the window's SDL_Surface @@ -336,8 +339,6 @@ protected: TEST_VIRTUAL Event CreateUpdateEvent(); //! Logs debug data for event void LogEvent(const Event& event); - //! Renders the image in window - void Render(); //! Opens the joystick device bool OpenJoystick(); diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 347fd70e..2d1cd167 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -103,6 +103,7 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils) m_waterAddColor = Color(0.0f, 0.0f, 0.0f, 0.0f); m_render = true; + m_screenshotMode = false; m_shadowVisible = true; m_groundSpotVisible = true; m_dirty = true; @@ -551,6 +552,16 @@ void CEngine::SetRenderEnable(bool enable) m_render = enable; } +void CEngine::SetScreenshotMode(bool screenshotMode) +{ + m_screenshotMode = screenshotMode; +} + +bool CEngine::GetScreenshotMode() +{ + return m_screenshotMode; +} + Math::IntPoint CEngine::GetWindowSize() { return m_size; @@ -3895,7 +3906,10 @@ void CEngine::DrawInterface() m_lastState = -1; SetState(Gfx::ENG_RSTATE_NORMAL); - m_particle->DrawParticle(SH_INTERFACE); // draws the particles of the interface + if (!m_screenshotMode) + { + m_particle->DrawParticle(SH_INTERFACE); // draws the particles of the interface + } // 3D objects drawn in front of interface if (m_drawFront) diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 0d2af074..3e7c36e7 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -684,6 +684,12 @@ public: //! Enables/disables rendering void SetRenderEnable(bool enable); + + //! Management of "screenshot mode" (disables interface particle rendering) + //@{ + void SetScreenshotMode(bool screenshotMode); + bool GetScreenshotMode(); + //@} //! Returns current size of viewport window Math::IntPoint GetWindowSize(); @@ -1326,6 +1332,9 @@ protected: //! Rendering enabled? bool m_render; + //! Screenshot mode? + bool m_screenshotMode; + //! Projection matrix for 3D scene Math::Matrix m_matProj; //! View matrix for 3D scene diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index ea915910..224614ee 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -244,7 +244,6 @@ CRobotMain::CRobotMain() m_autosaveSlots = 3; m_autosaveLast = 0.0f; - m_shotDelay = 0; m_shotSaving = 0; m_cameraPan = 0.0f; @@ -2521,15 +2520,6 @@ bool CRobotMain::EventFrame(const Event &event) } } - if ( m_shotDelay > 0 && !m_ui->GetDialog()->IsDialog() ) - { - m_shotDelay --; - if ( m_shotDelay == 0 ) - { - m_engine->WriteScreenShot(m_shotName); - } - } - m_water->EventProcess(event); m_cloud->EventProcess(event); m_lightning->EventProcess(event); @@ -2661,7 +2651,7 @@ bool CRobotMain::EventFrame(const Event &event) { Math::Point pos, dim; - if (m_shotSaving == 0) + if (m_shotSaving <= 0) { dim.x = 10.0f/640.0f; dim.y = 10.0f/480.0f; @@ -2746,6 +2736,35 @@ bool CRobotMain::EventFrame(const Event &event) return true; } +void CRobotMain::ShowSaveIndicator(bool show) +{ + Ui::CControl* pc = m_interface->SearchControl(EVENT_OBJECT_SAVING); + if (pc != nullptr) + { + Math::Point pos, dim; + + if (!show) + { + dim.x = 10.0f/640.0f; + dim.y = 10.0f/480.0f; + pos.x = -20.0f/640.0f; + pos.y = -20.0f/480.0f; // invisible! + } + else + { + dim.x = 32.0f/640.0f; + dim.y = 32.0f/480.0f; + pos.x = (640.0f-24.0f)/640.0f; + pos.y = (480.0f-24.0f)/480.0f; + + pos.x -= dim.x/2.0f; + pos.y -= dim.y/2.0f; + } + pc->SetPos(pos); + pc->SetDim(dim); + } +} + //! Makes the event for all robots bool CRobotMain::EventObject(const Event &event) { @@ -4962,6 +4981,10 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj) //! Saves the current game bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::string filescreenshot, char *info) { + // Render the indicator to show that we are working + ShowSaveIndicator(true); + m_app->Render(); // update + CLevelParser levelParser(filename); CLevelParserLineUPtr line; @@ -5083,10 +5106,20 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s CBotClass::SaveStaticState(file); fClose(file); - m_shotDelay = 3; - m_shotName = CResourceManager::GetSaveLocation() + "/" + filescreenshot; //TODO: Use PHYSFS? + ShowSaveIndicator(false); // force hide for screenshot + MouseMode oldMouseMode = m_app->GetMouseMode(); + m_app->SetMouseMode(MOUSE_NONE); // disable the mouse + m_displayText->HideText(true); // hide + m_engine->SetScreenshotMode(true); + + m_engine->Render(); // update (but don't show, we're not swapping buffers here!) + m_engine->WriteScreenShot(CResourceManager::GetSaveLocation() + "/" + filescreenshot); //TODO: Use PHYSFS? m_shotSaving++; + m_engine->SetScreenshotMode(false); + m_displayText->HideText(false); + m_app->SetMouseMode(oldMouseMode); + return true; } diff --git a/src/object/robotmain.h b/src/object/robotmain.h index ed307b9e..f9878b14 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -377,6 +377,8 @@ protected: bool EventObject(const Event &event); void InitEye(); + void ShowSaveIndicator(bool show); + void CreateScene(bool soluce, bool fixScene, bool resetObject); void ResetCreate(); @@ -587,9 +589,7 @@ protected: int m_autosaveSlots; float m_autosaveLast; - unsigned int m_shotDelay; - std::string m_shotName; - unsigned int m_shotSaving; + int m_shotSaving; std::deque m_selectionHistory; }; diff --git a/src/ui/screen/screen_io.cpp b/src/ui/screen/screen_io.cpp index de7e79e9..a067df57 100644 --- a/src/ui/screen/screen_io.cpp +++ b/src/ui/screen/screen_io.cpp @@ -222,8 +222,11 @@ void CScreenIO::IOWriteScene() int sel = pl->GetSelect(); if ( sel == -1 ) return; - std::string dir; pe->GetText(info, 100); + + m_interface->DeleteControl(EVENT_WINDOW5); + + std::string dir; if (static_cast(sel) >= m_saveList.size()) { dir = m_main->GetPlayerProfile()->GetSaveFile("save"+clearName(info)); diff --git a/src/ui/screen/screen_io_write.cpp b/src/ui/screen/screen_io_write.cpp index 4dc95b46..33f69ea0 100644 --- a/src/ui/screen/screen_io_write.cpp +++ b/src/ui/screen/screen_io_write.cpp @@ -153,7 +153,6 @@ bool CScreenIOWrite::EventProcess(const Event &event) m_main->ChangePhase(PHASE_SIMUL); m_main->StopSuspend(); IOWriteScene(); - m_interface->DeleteControl(EVENT_WINDOW5); return false; } diff --git a/src/ui/screen/screen_loading.cpp b/src/ui/screen/screen_loading.cpp index f578e73f..5b037d8f 100644 --- a/src/ui/screen/screen_loading.cpp +++ b/src/ui/screen/screen_loading.cpp @@ -31,7 +31,6 @@ namespace Ui { CScreenLoading::CScreenLoading() - : m_loadingCounter(0) { } @@ -79,18 +78,14 @@ void CScreenLoading::CreateInterface() pl->SetTextAlign(Gfx::TEXT_ALIGN_CENTER); SetBackground("textures/interface/interface.png"); - - m_loadingCounter = 1; // enough time to display! } bool CScreenLoading::EventProcess(const Event &event) { - if ( m_loadingCounter == 0 ) - { - m_main->ChangePhase(PHASE_SIMUL); - } - m_loadingCounter --; - return true; + m_app->Render(); // render the frame once before we start loading + m_main->ChangePhase(PHASE_SIMUL); + + return false; } } // namespace Ui diff --git a/src/ui/screen/screen_loading.h b/src/ui/screen/screen_loading.h index 59c2b8bd..e3dddaae 100644 --- a/src/ui/screen/screen_loading.h +++ b/src/ui/screen/screen_loading.h @@ -31,9 +31,6 @@ public: void CreateInterface() override; bool EventProcess(const Event &event) override; - -protected: - int m_loadingCounter; }; } // namespace Ui