Improved editor pause logic. Editor now pauses when it's enabled and makes sure UI is up to date with the current state.
This commit is contained in:
@@ -98,6 +98,7 @@ private:
|
|||||||
std::set<std::string> m_ModalsToOpen;
|
std::set<std::string> m_ModalsToOpen;
|
||||||
std::map<std::string, boost::any> m_ModalData;
|
std::map<std::string, boost::any> m_ModalData;
|
||||||
std::string m_DroppedFile = "";
|
std::string m_DroppedFile = "";
|
||||||
|
bool m_Paused = false;
|
||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
OnEntitySelectedCallback_t m_OnEntitySelected = nullptr;
|
OnEntitySelectedCallback_t m_OnEntitySelected = nullptr;
|
||||||
@@ -116,6 +117,10 @@ private:
|
|||||||
bool OnKeyDown(const Events::KeyDown& e);
|
bool OnKeyDown(const Events::KeyDown& e);
|
||||||
EventRelay<EditorGUI, Events::FileDropped> m_EFileDropped;
|
EventRelay<EditorGUI, Events::FileDropped> m_EFileDropped;
|
||||||
bool OnFileDropped(const Events::FileDropped& e);
|
bool OnFileDropped(const Events::FileDropped& e);
|
||||||
|
EventRelay<EditorGUI, Events::Pause> m_EPause;
|
||||||
|
bool OnPause(const Events::Pause& e);
|
||||||
|
EventRelay<EditorGUI, Events::Resume> m_EResume;
|
||||||
|
bool OnResume(const Events::Resume& e);
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
boost::filesystem::path fileOpenDialog();
|
boost::filesystem::path fileOpenDialog();
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ EditorGUI::EditorGUI(World* world, EventBroker* eventBroker)
|
|||||||
{
|
{
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &EditorGUI::OnKeyDown);
|
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &EditorGUI::OnKeyDown);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EFileDropped, &EditorGUI::OnFileDropped);
|
EVENT_SUBSCRIBE_MEMBER(m_EFileDropped, &EditorGUI::OnFileDropped);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EPause, &EditorGUI::OnPause);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EResume, &EditorGUI::OnResume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorGUI::Draw()
|
void EditorGUI::Draw()
|
||||||
@@ -58,19 +60,17 @@ void EditorGUI::drawTools()
|
|||||||
// Play button
|
// Play button
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
static bool paused = false;
|
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;
|
Events::Resume e;
|
||||||
e.World = m_World;
|
e.World = m_World;
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
paused = false;
|
|
||||||
}
|
}
|
||||||
// Pause button
|
// Pause button
|
||||||
ImGui::SameLine();
|
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;
|
Events::Pause e;
|
||||||
e.World = m_World;
|
e.World = m_World;
|
||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
paused = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
@@ -596,6 +596,22 @@ bool EditorGUI::OnFileDropped(const Events::FileDropped& e)
|
|||||||
return true;
|
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()
|
boost::filesystem::path EditorGUI::fileOpenDialog()
|
||||||
{
|
{
|
||||||
namespace bfs = boost::filesystem;
|
namespace bfs = boost::filesystem;
|
||||||
|
|||||||
@@ -93,6 +93,11 @@ void EditorSystem::Enable()
|
|||||||
(glm::vec3&)m_EditorCamera["Transform"]["Position"] = Transform::AbsolutePosition(m_ActualCamera);
|
(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;
|
m_Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user