Added scene graph UI to Editor

This commit is contained in:
2015-12-13 23:41:00 +01:00
parent 07c4744436
commit 545869e342
2 changed files with 52 additions and 11 deletions
+2
View File
@@ -2,6 +2,7 @@
#include "../Core/System.h" #include "../Core/System.h"
#include "../Core/EMousePress.h" #include "../Core/EMousePress.h"
#include "../Rendering/EPicking.h" #include "../Rendering/EPicking.h"
#include "../Rendering/RenderQueueFactory.h"
class EditorSystem : public ImpureSystem class EditorSystem : public ImpureSystem
{ {
@@ -15,6 +16,7 @@ private:
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;
EventRelay<EditorSystem, Events::MousePress> m_EMousePress; EventRelay<EditorSystem, Events::MousePress> m_EMousePress;
bool OnMousePress(const Events::MousePress& e); bool OnMousePress(const Events::MousePress& e);
+49 -10
View File
@@ -23,10 +23,13 @@ void EditorSystem::Update(World* world, double dt)
} }
if (m_Selection != 0) { if (m_Selection != 0) {
auto selectionTransform = world->GetComponent(m_Selection, "Transform"); if (world->HasComponent(m_Selection, "Transform")) {
auto widgetTransform = world->GetComponent(m_Widget, "Transform"); glm::vec3 pos = RenderQueueFactory::AbsolutePosition(world, m_Selection);
auto widgetTransform = world->GetComponent(m_Widget, "Transform");
widgetTransform["Position"] = (glm::vec3)selectionTransform["Position"]; widgetTransform["Position"] = pos;
} else {
m_Selection = 0;
}
} }
drawUI(world, dt); drawUI(world, dt);
@@ -35,7 +38,7 @@ void EditorSystem::Update(World* world, double dt)
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) {
m_PickingQueue.push_back(glm::vec2(e.X, e.Y)); m_PickingQueue.push_back(glm::vec2((int)e.X, (int)e.Y));
} }
return true; return true;
} }
@@ -53,7 +56,7 @@ bool EditorSystem::OnPicking(const Events::Picking& e)
void EditorSystem::drawUI(World* world, double dt) void EditorSystem::drawUI(World* world, double dt)
{ {
//ImGui::ShowTestWindow(); ImGui::ShowTestWindow();
//ImGui::ShowStyleEditor(); //ImGui::ShowStyleEditor();
if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMainMenuBar()) {
@@ -88,7 +91,7 @@ void EditorSystem::drawUI(World* world, double dt)
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();
} }
if (ImGui::Begin("Properties")) { if (ImGui::Begin("Components")) {
if (m_Selection != 0) { if (m_Selection != 0) {
auto& pools = world->GetComponentPools(); auto& pools = world->GetComponentPools();
@@ -136,11 +139,19 @@ void EditorSystem::drawUI(World* world, double dt)
if (type == "Vector") { if (type == "Vector") {
auto& val = component.Property<glm::vec3>(field); auto& val = component.Property<glm::vec3>(field);
if (field == "Scale") { if (field == "Scale") {
ImGui::DragFloat3(field.c_str(), glm::value_ptr(val), 0.1f, 0.f, 9999.f); ImGui::DragFloat3(field.c_str(), glm::value_ptr(val), 0.1f, 0.f, std::numeric_limits<float>::max());
} else if (field == "Orientation") { } else if (field == "Orientation") {
ImGui::SliderFloat3(field.c_str(), glm::value_ptr(val), 0.f, glm::pi<float>()); glm::vec3 times = val / glm::vec3(glm::pi<float>());
times.x = std::floor(times.x);
times.y = std::floor(times.y);
times.z = std::floor(times.z);
glm::vec3 tempVal = val - (times*glm::pi<float>());
if (ImGui::SliderFloat3(field.c_str(), glm::value_ptr(tempVal), 0.f, glm::pi<float>())) {
val = tempVal;
}
} else { } else {
ImGui::InputFloat3(field.c_str(), glm::value_ptr(val)); //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());
} }
} else if (type == "Color") { } else if (type == "Color") {
auto& val = component.Property<glm::vec4>(field); auto& val = component.Property<glm::vec4>(field);
@@ -166,6 +177,34 @@ void EditorSystem::drawUI(World* world, double dt)
} }
ImGui::End(); ImGui::End();
if (ImGui::Begin("Entitites")) {
auto entityChildren = world->GetEntityChildren();
std::function<void(EntityID)> recurse = [&](EntityID parent) {
auto range = entityChildren.equal_range(parent);
for (auto it = range.first; it != range.second; it++) {
ImGui::SetNextTreeNodeOpened(true, ImGuiSetCond_Once);
if (ImGui::TreeNode((std::string("#") + std::to_string(it->second)).c_str())) {
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(0)) {
m_Selection = it->second;
}
ImGui::SameLine();
if (ImGui::Button("Add")) {
EntityID entity = world->CreateEntity(it->second);
world->AttachComponent(entity, "Transform");
}
ImGui::SameLine();
if (ImGui::Button("Delete")) {
world->DeleteEntity(it->second);
}
recurse(it->second);
ImGui::TreePop();
}
}
};
recurse(0);
}
ImGui::End();
} }
bool EditorSystem::createDeleteButton(std::string componentType) bool EditorSystem::createDeleteButton(std::string componentType)