2022-03-08 21:19:19 +03:30
|
|
|
#include "SceneHierarchyPanel.hpp"
|
2021-07-31 11:03:31 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
#include "PropertiesPanel.hpp"
|
|
|
|
#include "Scene/Components.hpp"
|
2021-07-31 11:03:31 +04:30
|
|
|
|
2021-09-09 19:46:02 +04:30
|
|
|
#include <entt/entt.hpp>
|
2021-07-31 11:03:31 +04:30
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
namespace Light {
|
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
SceneHierarchyPanel::SceneHierarchyPanel()
|
|
|
|
: m_Context(nullptr), m_PropertiesPanelContext(nullptr), m_SelectionContext()
|
|
|
|
{
|
|
|
|
}
|
2021-07-31 11:03:31 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
|
|
|
|
: m_Context(context), m_PropertiesPanelContext(propertiesPanel)
|
|
|
|
{
|
|
|
|
}
|
2021-07-31 11:03:31 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneHierarchyPanel::OnUserInterfaceUpdate()
|
|
|
|
{
|
|
|
|
if (m_Context)
|
2021-07-31 11:03:31 +04:30
|
|
|
{
|
2022-03-08 21:19:19 +03:30
|
|
|
ImGui::Begin("Hierarchy");
|
|
|
|
|
|
|
|
m_Context->m_Registry.each([&](auto entityID) {
|
|
|
|
Entity entity(entityID, m_Context.get());
|
|
|
|
const std::string& tag = entity.GetComponent<TagComponent>();
|
|
|
|
|
|
|
|
DrawNode(entity, tag);
|
|
|
|
});
|
|
|
|
|
|
|
|
ImGui::End();
|
2021-08-01 16:55:26 +04:30
|
|
|
}
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-08-01 16:55:26 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneHierarchyPanel::SetContext(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
|
|
|
|
{
|
|
|
|
if (propertiesPanel)
|
|
|
|
m_PropertiesPanelContext = propertiesPanel;
|
|
|
|
|
|
|
|
m_Context = context;
|
|
|
|
}
|
2021-08-01 16:55:26 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneHierarchyPanel::DrawNode(Entity entity, const std::string& label)
|
|
|
|
{
|
|
|
|
ImGuiTreeNodeFlags flags = (m_SelectionContext == entity ? ImGuiTreeNodeFlags_Selected : NULL) |
|
|
|
|
ImGuiTreeNodeFlags_OpenOnArrow |
|
|
|
|
ImGuiTreeNodeFlags_SpanFullWidth;
|
|
|
|
|
|
|
|
bool expanded = ImGui::TreeNodeEx((void*)(uint64_t)(uint32_t)(entity), flags, label.c_str());
|
|
|
|
|
|
|
|
if (ImGui::IsItemClicked())
|
|
|
|
{
|
|
|
|
m_SelectionContext = entity;
|
|
|
|
m_PropertiesPanelContext->SetEntityContext(entity);
|
2021-07-31 11:03:31 +04:30
|
|
|
}
|
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
if (expanded)
|
2021-07-31 11:03:31 +04:30
|
|
|
{
|
2022-03-08 21:19:19 +03:30
|
|
|
ImGui::Text("TEST_OPENED_TREE!");
|
|
|
|
ImGui::TreePop();
|
2021-07-31 11:03:31 +04:30
|
|
|
}
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-07-31 11:03:31 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
} // namespace Light
|