Toggle editor with "ToggleEditor" command. Enable editor with "Debug.EnableEditor" config variable.
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
#include <glm/gtx/common.hpp>
|
#include <glm/gtx/common.hpp>
|
||||||
#include "../Core/System.h"
|
#include "../Core/System.h"
|
||||||
#include "../Core/EMousePress.h"
|
#include "../Core/EMousePress.h"
|
||||||
|
#include "../Core/ConfigFile.h"
|
||||||
|
#include "../Input/EInputCommand.h"
|
||||||
#include "../Rendering/EPicking.h"
|
#include "../Rendering/EPicking.h"
|
||||||
#include "../Rendering/RenderQueueFactory.h"
|
#include "../Rendering/RenderQueueFactory.h"
|
||||||
|
|
||||||
@@ -13,12 +15,16 @@ public:
|
|||||||
virtual void Update(World* world, double dt) override;
|
virtual void Update(World* world, double dt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_Enabled;
|
||||||
|
bool m_Visible;
|
||||||
std::vector<glm::vec2> m_PickingQueue;
|
std::vector<glm::vec2> m_PickingQueue;
|
||||||
EntityID m_Widget = 0;
|
EntityID m_Widget = 0;
|
||||||
EntityID m_Selection = 0;
|
EntityID m_Selection = 0;
|
||||||
EntityID m_LastSelection = 0;
|
EntityID m_LastSelection = 0;
|
||||||
glm::vec3 m_Position;
|
glm::vec3 m_Position;
|
||||||
|
|
||||||
|
EventRelay<EditorSystem, Events::InputCommand> m_EInputCommand;
|
||||||
|
bool OnInputCommand(const Events::InputCommand& e);
|
||||||
EventRelay<EditorSystem, Events::MousePress> m_EMousePress;
|
EventRelay<EditorSystem, Events::MousePress> m_EMousePress;
|
||||||
bool OnMousePress(const Events::MousePress& e);
|
bool OnMousePress(const Events::MousePress& e);
|
||||||
EventRelay<EditorSystem, Events::Picking> m_EPicking;
|
EventRelay<EditorSystem, Events::Picking> m_EPicking;
|
||||||
|
|||||||
@@ -5,12 +5,25 @@
|
|||||||
EditorSystem::EditorSystem(EventBroker* eventBroker)
|
EditorSystem::EditorSystem(EventBroker* eventBroker)
|
||||||
: ImpureSystem(eventBroker)
|
: ImpureSystem(eventBroker)
|
||||||
{
|
{
|
||||||
|
auto config = ResourceManager::Load<ConfigFile>("Config.ini");
|
||||||
|
m_Enabled = config->Get<bool>("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_EMousePress, &EditorSystem::OnMousePress);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPicking, &EditorSystem::OnPicking);
|
EVENT_SUBSCRIBE_MEMBER(m_EPicking, &EditorSystem::OnPicking);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorSystem::Update(World* world, double dt)
|
void EditorSystem::Update(World* world, double dt)
|
||||||
{
|
{
|
||||||
|
if (!m_Enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_Widget == 0) {
|
if (m_Widget == 0) {
|
||||||
m_Widget = world->CreateEntity();
|
m_Widget = world->CreateEntity();
|
||||||
world->AttachComponent(m_Widget, "Transform");
|
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 (m_Selection != 0) {
|
||||||
if (world->HasComponent(m_Selection, "Transform")) {
|
if (world->HasComponent(m_Selection, "Transform")) {
|
||||||
glm::vec3 pos = RenderQueueFactory::AbsolutePosition(world, m_Selection);
|
glm::vec3 pos = RenderQueueFactory::AbsolutePosition(world, m_Selection);
|
||||||
@@ -30,11 +45,24 @@ void EditorSystem::Update(World* world, double dt)
|
|||||||
} else {
|
} else {
|
||||||
m_Selection = 0;
|
m_Selection = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!m_Visible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
drawUI(world, dt);
|
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)
|
bool EditorSystem::OnMousePress(const Events::MousePress& e)
|
||||||
{
|
{
|
||||||
if (e.Button == GLFW_MOUSE_BUTTON_RIGHT) {
|
if (e.Button == GLFW_MOUSE_BUTTON_RIGHT) {
|
||||||
@@ -146,7 +174,6 @@ void EditorSystem::drawUI(World* world, double dt)
|
|||||||
val = tempVal;
|
val = tempVal;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//ImGui::InputFloat3(field.c_str(), glm::value_ptr(val));
|
|
||||||
ImGui::DragFloat3(field.c_str(), glm::value_ptr(val), 0.1f, std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max());
|
ImGui::DragFloat3(field.c_str(), glm::value_ptr(val), 0.1f, std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max());
|
||||||
}
|
}
|
||||||
} else if (type == "Color") {
|
} 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)) {
|
if (ImGui::InputFloat(field.c_str(), &tempVal, 0.01f, 1.f)) {
|
||||||
component.SetProperty(field, static_cast<double>(tempVal));
|
component.SetProperty(field, static_cast<double>(tempVal));
|
||||||
}
|
}
|
||||||
|
} else if (type == "bool") {
|
||||||
|
auto& val = component.Property<bool>(field);
|
||||||
|
ImGui::Checkbox(field.c_str(), &val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user