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

77 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()
: m_context(nullptr)
, m_properties_panel_context(nullptr)
, m_selection_context()
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_properties_panel_context(propertiesPanel)
2022-03-08 21:19:19 +03:30
{
}
void SceneHierarchyPanel::on_user_interface_update()
2022-03-08 21:19:19 +03:30
{
if (m_context)
{
2022-03-08 21:19:19 +03:30
ImGui::Begin("Hierarchy");
for (auto entityID : m_context->m_registry.view<TagComponent>())
{
2025-07-06 14:02:50 +03:30
auto entity = Entity {
static_cast<entt::entity>(entityID),
m_context.get(),
};
2022-03-08 21:19:19 +03:30
2025-07-06 14:02:50 +03:30
const auto &tag = entity.get_component<TagComponent>();
draw_node(entity, tag);
};
}
ImGui::End();
2022-03-08 21:19:19 +03:30
}
void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel)
2022-03-08 21:19:19 +03:30
{
if (propertiesPanel)
m_properties_panel_context = propertiesPanel;
2022-03-08 21:19:19 +03:30
m_context = context;
2022-03-08 21:19:19 +03:30
}
void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label)
2022-03-08 21:19:19 +03:30
{
2025-07-06 14:02:50 +03:30
auto flags = (m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : NULL)
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth;
2022-03-08 21:19:19 +03:30
2025-07-06 14:02:50 +03:30
const auto 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_selection_context = entity;
m_properties_panel_context->set_entity_context(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