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

80 lines
1.7 KiB
C++
Raw Normal View History

2025-07-11 01:16:52 +03:30
#include <ecs/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>
2025-07-11 00:05:48 +03:30
namespace lt {
2025-07-06 15:10:34 +03:30
SceneHierarchyPanel::SceneHierarchyPanel(): m_context(nullptr), m_properties_panel_context(nullptr)
2022-03-08 21:19:19 +03:30
{
}
2025-07-06 15:10:34 +03:30
SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> properties_panel)
: m_context(std::move(context))
, m_properties_panel_context(std::move(properties_panel))
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
}
2025-07-06 15:10:34 +03:30
void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> properties_panel)
2022-03-08 21:19:19 +03:30
{
2025-07-06 15:10:34 +03:30
if (properties_panel)
{
m_properties_panel_context = std::move(properties_panel);
}
2022-03-08 21:19:19 +03:30
2025-07-06 15:10:34 +03:30
m_context = std::move(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 15:10:34 +03:30
auto flags = ImGuiTreeNodeFlags {
// NOLINTNEXTLINE
(m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : ImGuiTreeNodeFlags {})
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth
};
2022-03-08 21:19:19 +03:30
2025-07-06 15:10:34 +03:30
// NOLINTNEXTLINE
2025-07-06 14:02:50 +03:30
const auto expanded = ImGui::TreeNodeEx(
2025-07-06 15:10:34 +03:30
std::bit_cast<void *>(static_cast<uint64_t>(entity)),
2025-07-06 14:02:50 +03:30
flags,
2025-07-06 15:10:34 +03:30
"%s",
2025-07-06 14:02:50 +03:30
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)
{
2025-07-06 15:10:34 +03:30
ImGui::TextUnformatted("TEST_OPENED_TREE!");
2022-03-08 21:19:19 +03:30
ImGui::TreePop();
}
2022-03-08 21:19:19 +03:30
}
2025-07-11 00:05:48 +03:30
} // namespace lt