diff --git a/include/Engine/Editor/EditorGUI.h b/include/Engine/Editor/EditorGUI.h index 00c823e9..8bd9bbab 100644 --- a/include/Engine/Editor/EditorGUI.h +++ b/include/Engine/Editor/EditorGUI.h @@ -98,6 +98,7 @@ private: std::set m_ModalsToOpen; std::map m_ModalData; std::string m_DroppedFile = ""; + bool m_Paused = false; // Callbacks OnEntitySelectedCallback_t m_OnEntitySelected = nullptr; @@ -116,6 +117,10 @@ private: bool OnKeyDown(const Events::KeyDown& e); EventRelay m_EFileDropped; bool OnFileDropped(const Events::FileDropped& e); + EventRelay m_EPause; + bool OnPause(const Events::Pause& e); + EventRelay m_EResume; + bool OnResume(const Events::Resume& e); // Utility functions boost::filesystem::path fileOpenDialog(); diff --git a/src/Engine/Editor/EditorGUI.cpp b/src/Engine/Editor/EditorGUI.cpp index c1f1683d..007e845d 100644 --- a/src/Engine/Editor/EditorGUI.cpp +++ b/src/Engine/Editor/EditorGUI.cpp @@ -7,6 +7,8 @@ EditorGUI::EditorGUI(World* world, EventBroker* eventBroker) { EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &EditorGUI::OnKeyDown); EVENT_SUBSCRIBE_MEMBER(m_EFileDropped, &EditorGUI::OnFileDropped); + EVENT_SUBSCRIBE_MEMBER(m_EPause, &EditorGUI::OnPause); + EVENT_SUBSCRIBE_MEMBER(m_EResume, &EditorGUI::OnResume); } void EditorGUI::Draw() @@ -58,19 +60,17 @@ void EditorGUI::drawTools() // Play button ImGui::SameLine(); static bool paused = false; - if (ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Play.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (!paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) { + if (ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Play.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (!m_Paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) { Events::Resume e; e.World = m_World; m_EventBroker->Publish(e); - paused = false; } // Pause button ImGui::SameLine(); - if (ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Pause.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) { + if (ImGui::ImageButton((void*)tryLoadTexture("Textures/Icons/Pause.png"), ImVec2(24, 24), ImVec2(0, 1), ImVec2(1, 0), -1, ImVec4(0, 0, 0, 0), (m_Paused) ? ImVec4(0, 1, 0, 1) : ImVec4(1, 1, 1, 1))) { Events::Pause e; e.World = m_World; m_EventBroker->Publish(e); - paused = true; } ImGui::End(); @@ -596,6 +596,22 @@ bool EditorGUI::OnFileDropped(const Events::FileDropped& e) return true; } +bool EditorGUI::OnPause(const Events::Pause& e) +{ + if (e.World == m_World) { + m_Paused = true; + } + return true; +} + +bool EditorGUI::OnResume(const Events::Resume& e) +{ + if (e.World == m_World) { + m_Paused = false; + } + return true; +} + boost::filesystem::path EditorGUI::fileOpenDialog() { namespace bfs = boost::filesystem; diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 16023b18..83963531 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -93,6 +93,11 @@ void EditorSystem::Enable() (glm::vec3&)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera); } + // Pause the world we're editing + Events::Pause ePause; + ePause.World = m_World; + m_EventBroker->Publish(ePause); + m_Enabled = true; }