light/Mirror/src/Panels/SceneHierarchyPanel.cpp

69 lines
1.6 KiB
C++
Raw Normal View History

2022-03-08 21:19:19 +03:30
#include "SceneHierarchyPanel.hpp"
2022-03-08 21:19:19 +03:30
#include "PropertiesPanel.hpp"
#include "Scene/Components.hpp"
2021-09-09 19:46:02 +04:30
#include <entt/entt.hpp>
#include <imgui.h>
namespace Light {
2022-03-08 21:19:19 +03:30
SceneHierarchyPanel::SceneHierarchyPanel()
: m_Context(nullptr), m_PropertiesPanelContext(nullptr), m_SelectionContext()
{
}
2022-03-08 21:19:19 +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
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());
2022-03-08 21:19:19 +03:30
const std::string& tag = entity.GetComponent<TagComponent>();
DrawNode(entity, tag);
};
}
ImGui::End();
2022-03-08 21:19:19 +03:30
}
2022-03-08 21:19:19 +03:30
void SceneHierarchyPanel::SetContext(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
{
if (propertiesPanel)
m_PropertiesPanelContext = propertiesPanel;
m_Context = context;
}
2022-03-08 21:19:19 +03:30
void SceneHierarchyPanel::DrawNode(Entity entity, const std::string& label)
{
ImGuiTreeNodeFlags flags = (m_SelectionContext == entity ? ImGuiTreeNodeFlags_Selected : NULL) |
ImGuiTreeNodeFlags_OpenOnArrow |
ImGuiTreeNodeFlags_SpanFullWidth;
bool expanded = ImGui::TreeNodeEx((void*)(uint64_t)(uint32_t)(entity), flags, label.c_str());
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