70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
#include <engine/scene/components.hpp>
|
|
#include <entt/entt.hpp>
|
|
#include <imgui.h>
|
|
#include <mirror/panel/properties.hpp>
|
|
#include <mirror/panel/scene_hierarchy.hpp>
|
|
|
|
namespace Light {
|
|
|
|
SceneHierarchyPanel::SceneHierarchyPanel()
|
|
: m_context(nullptr)
|
|
, m_properties_panel_context(nullptr)
|
|
, m_selection_context()
|
|
{
|
|
}
|
|
|
|
SceneHierarchyPanel::
|
|
SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
|
|
: m_context(context)
|
|
, m_properties_panel_context(propertiesPanel)
|
|
{
|
|
}
|
|
|
|
void SceneHierarchyPanel::OnUserInterfaceUpdate()
|
|
{
|
|
if (m_context)
|
|
{
|
|
ImGui::Begin("Hierarchy");
|
|
|
|
for (auto entityID : m_context->m_registry.view<TagComponent>())
|
|
{
|
|
Entity entity(static_cast<entt::entity>(entityID), m_context.get());
|
|
const std::string &tag = entity.GetComponent<TagComponent>();
|
|
|
|
DrawNode(entity, tag);
|
|
};
|
|
}
|
|
|
|
ImGui::End();
|
|
}
|
|
|
|
void SceneHierarchyPanel::
|
|
SetContext(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
|
|
{
|
|
if (propertiesPanel)
|
|
m_properties_panel_context = propertiesPanel;
|
|
|
|
m_context = context;
|
|
}
|
|
|
|
void SceneHierarchyPanel::DrawNode(Entity entity, const std::string &label)
|
|
{
|
|
ImGuiTreeNodeFlags flags = (m_selection_context == 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_selection_context = entity;
|
|
m_properties_panel_context->SetEntityContext(entity);
|
|
}
|
|
|
|
if (expanded)
|
|
{
|
|
ImGui::Text("TEST_OPENED_TREE!");
|
|
ImGui::TreePop();
|
|
}
|
|
}
|
|
|
|
} // namespace Light
|