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>
|
2021-07-31 11:03:31 +04:30
|
|
|
#include <imgui.h>
|
2025-07-05 13:28:41 +03:30
|
|
|
#include <mirror/panel/properties.hpp>
|
|
|
|
#include <mirror/panel/scene_hierarchy.hpp>
|
2021-07-31 11:03:31 +04:30
|
|
|
|
|
|
|
namespace Light {
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
2021-07-31 11:03:31 +04: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
|
|
|
{
|
|
|
|
}
|
2021-07-31 11:03:31 +04:30
|
|
|
|
2025-07-05 15:36:53 +03:30
|
|
|
void SceneHierarchyPanel::on_user_interface_update()
|
2022-03-08 21:19:19 +03:30
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
if (m_context)
|
2021-07-31 11:03:31 +04:30
|
|
|
{
|
2022-03-08 21:19:19 +03:30
|
|
|
ImGui::Begin("Hierarchy");
|
|
|
|
|
2025-07-05 14:23:01 +03:30
|
|
|
for (auto entityID : m_context->m_registry.view<TagComponent>())
|
2025-07-05 11:33:43 +03:30
|
|
|
{
|
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>();
|
2025-07-05 15:36:53 +03:30
|
|
|
draw_node(entity, tag);
|
2025-07-05 11:33:43 +03:30
|
|
|
};
|
2021-08-01 16:55:26 +04:30
|
|
|
}
|
2025-07-05 11:33:43 +03:30
|
|
|
|
|
|
|
ImGui::End();
|
2022-03-08 21:19:19 +03:30
|
|
|
}
|
2021-08-01 16:55:26 +04: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
|
|
|
}
|
2021-08-01 16:55:26 +04:30
|
|
|
|
2025-07-05 15:36:53 +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())
|
|
|
|
{
|
2025-07-05 14:23:01 +03:30
|
|
|
m_selection_context = entity;
|
2025-07-05 15:36:53 +03:30
|
|
|
m_properties_panel_context->set_entity_context(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
|
|
|
{
|
2025-07-06 15:10:34 +03:30
|
|
|
ImGui::TextUnformatted("TEST_OPENED_TREE!");
|
2022-03-08 21:19:19 +03:30
|
|
|
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
|