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 {
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
2021-07-31 11:03:31 +04: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
|
|
|
{
|
|
|
|
}
|
2021-07-31 11:03:31 +04:30
|
|
|
|
2022-03-08 21:19:19 +03:30
|
|
|
void SceneHierarchyPanel::OnUserInterfaceUpdate()
|
|
|
|
{
|
|
|
|
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 11:33:43 +03:30
|
|
|
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);
|
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-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;
|
|
|
|
}
|
2021-08-01 16:55:26 +04:30
|
|
|
|
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);
|
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
|
|
|
{
|
2022-03-08 21:19:19 +03:30
|
|
|
ImGui::Text("TEST_OPENED_TREE!");
|
|
|
|
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
|