light/modules/mirror/src/panel/scene_hierarchy.cpp

71 lines
1.7 KiB
C++
Raw Normal View History

2025-07-05 13:28:41 +03:30
#include <engine/scene/components.hpp>
2021-09-09 19:46:02 +04:30
#include <entt/entt.hpp>
#include <imgui.h>
2025-07-05 13:28:41 +03:30
#include <mirror/panel/properties.hpp>
#include <mirror/panel/scene_hierarchy.hpp>
namespace Light {
2022-03-08 21:19:19 +03:30
SceneHierarchyPanel::SceneHierarchyPanel()
2025-07-05 13:28:41 +03:30
: m_Context(nullptr)
, m_PropertiesPanelContext(nullptr)
, m_SelectionContext()
2022-03-08 21:19:19 +03:30
{
}
2025-07-05 13:28:41 +03:30
SceneHierarchyPanel::
SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
: m_Context(context)
, m_PropertiesPanelContext(propertiesPanel)
2022-03-08 21:19:19 +03:30
{
}
2022-03-08 21:19:19 +03:30
void SceneHierarchyPanel::OnUserInterfaceUpdate()
{
if (m_Context)
{
2022-03-08 21:19:19 +03:30
ImGui::Begin("Hierarchy");
for (auto entityID : m_Context->m_Registry.view<TagComponent>())
{
Entity entity(static_cast<entt::entity>(entityID), m_Context.get());
2025-07-05 13:28:41 +03:30
const std::string &tag = entity.GetComponent<TagComponent>();
2022-03-08 21:19:19 +03:30
DrawNode(entity, tag);
};
}
ImGui::End();
2022-03-08 21:19:19 +03:30
}
2025-07-05 13:28:41 +03:30
void SceneHierarchyPanel::
SetContext(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
2022-03-08 21:19:19 +03:30
{
if (propertiesPanel)
m_PropertiesPanelContext = propertiesPanel;
m_Context = context;
}
2025-07-05 13:28:41 +03:30
void SceneHierarchyPanel::DrawNode(Entity entity, const std::string &label)
2022-03-08 21:19:19 +03:30
{
2025-07-05 13:28:41 +03:30
ImGuiTreeNodeFlags flags = (m_SelectionContext == entity ? ImGuiTreeNodeFlags_Selected : NULL)
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth;
2022-03-08 21:19:19 +03:30
2025-07-05 13:28:41 +03:30
bool expanded = ImGui::TreeNodeEx((void *)(uint64_t)(uint32_t)(entity), flags, label.c_str());
2022-03-08 21:19:19 +03:30
if (ImGui::IsItemClicked())
{
m_SelectionContext = entity;
m_PropertiesPanelContext->SetEntityContext(entity);
}
2022-03-08 21:19:19 +03:30
if (expanded)
{
2022-03-08 21:19:19 +03:30
ImGui::Text("TEST_OPENED_TREE!");
ImGui::TreePop();
}
2022-03-08 21:19:19 +03:30
}
2022-03-08 21:19:19 +03:30
} // namespace Light