diff --git a/include/Engine/Editor/EditorSystem.h b/include/Engine/Editor/EditorSystem.h index 949795ff..92e237d1 100644 --- a/include/Engine/Editor/EditorSystem.h +++ b/include/Engine/Editor/EditorSystem.h @@ -2,6 +2,8 @@ #include #include "../Core/System.h" #include "../Core/EMousePress.h" +#include "../Core/ConfigFile.h" +#include "../Input/EInputCommand.h" #include "../Rendering/EPicking.h" #include "../Rendering/RenderQueueFactory.h" @@ -13,12 +15,16 @@ public: virtual void Update(World* world, double dt) override; private: + bool m_Enabled; + bool m_Visible; std::vector m_PickingQueue; EntityID m_Widget = 0; EntityID m_Selection = 0; EntityID m_LastSelection = 0; glm::vec3 m_Position; + EventRelay m_EInputCommand; + bool OnInputCommand(const Events::InputCommand& e); EventRelay m_EMousePress; bool OnMousePress(const Events::MousePress& e); EventRelay m_EPicking; diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 80b41bf9..a56ba79c 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -5,12 +5,25 @@ EditorSystem::EditorSystem(EventBroker* eventBroker) : ImpureSystem(eventBroker) { + auto config = ResourceManager::Load("Config.ini"); + m_Enabled = config->Get("Debug.EditorEnabled", false); + m_Visible = m_Enabled; + + if (!m_Enabled) { + return; + } + + EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &EditorSystem::OnInputCommand); EVENT_SUBSCRIBE_MEMBER(m_EMousePress, &EditorSystem::OnMousePress); EVENT_SUBSCRIBE_MEMBER(m_EPicking, &EditorSystem::OnPicking); } void EditorSystem::Update(World* world, double dt) { + if (!m_Enabled) { + return; + } + if (m_Widget == 0) { m_Widget = world->CreateEntity(); world->AttachComponent(m_Widget, "Transform"); @@ -22,6 +35,8 @@ void EditorSystem::Update(World* world, double dt) } + auto& widgetModel = world->GetComponent(m_Widget, "Model"); + widgetModel["Visible"] = m_Visible; if (m_Selection != 0) { if (world->HasComponent(m_Selection, "Transform")) { glm::vec3 pos = RenderQueueFactory::AbsolutePosition(world, m_Selection); @@ -30,11 +45,24 @@ void EditorSystem::Update(World* world, double dt) } else { m_Selection = 0; } - } + } + + if (!m_Visible) { + return; + } drawUI(world, dt); } + +bool EditorSystem::OnInputCommand(const Events::InputCommand& e) +{ + if (e.Command == "ToggleEditor" && e.Value > 0) { + m_Visible = !m_Visible; + } + return true; +} + bool EditorSystem::OnMousePress(const Events::MousePress& e) { if (e.Button == GLFW_MOUSE_BUTTON_RIGHT) { @@ -146,7 +174,6 @@ void EditorSystem::drawUI(World* world, double dt) val = tempVal; } } else { - //ImGui::InputFloat3(field.c_str(), glm::value_ptr(val)); ImGui::DragFloat3(field.c_str(), glm::value_ptr(val), 0.1f, std::numeric_limits::lowest(), std::numeric_limits::max()); } } else if (type == "Color") { @@ -165,6 +192,9 @@ void EditorSystem::drawUI(World* world, double dt) if (ImGui::InputFloat(field.c_str(), &tempVal, 0.01f, 1.f)) { component.SetProperty(field, static_cast(tempVal)); } + } else if (type == "bool") { + auto& val = component.Property(field); + ImGui::Checkbox(field.c_str(), &val); } } }