#include "HierarchyPanelSupport.h" namespace XCEngine::UI::Editor::App { using namespace HierarchyPanelSupport; void HierarchyPanel::Initialize() { m_model = HierarchyModel::BuildDefault(); RebuildItems(); } void HierarchyPanel::SetBuiltInIcons(const BuiltInIcons* icons) { m_icons = icons; RebuildItems(); } void HierarchyPanel::ResetInteractionState() { m_treeInteractionState = {}; m_treeFrame = {}; m_dragState = {}; ResetTransientState(); } const UIEditorPanelContentHostPanelState* HierarchyPanel::FindMountedHierarchyPanel( const UIEditorPanelContentHostFrame& contentHostFrame) const { for (const UIEditorPanelContentHostPanelState& panelState : contentHostFrame.panelStates) { if (panelState.panelId == kHierarchyPanelId && panelState.mounted) { return &panelState; } } return nullptr; } void HierarchyPanel::ResetTransientState() { m_frameEvents.clear(); m_dragState.requestPointerCapture = false; m_dragState.requestPointerRelease = false; } void HierarchyPanel::RebuildItems() { const auto icon = ResolveGameObjectIcon(m_icons); const std::string previousSelection = m_selection.HasSelection() ? m_selection.GetSelectedId() : std::string(); m_treeItems = m_model.BuildTreeItems(icon); m_expansion.Expand("player"); m_expansion.Expand("environment"); m_expansion.Expand("props"); if (!previousSelection.empty() && m_model.ContainsNode(previousSelection)) { m_selection.SetSelection(previousSelection); return; } if (!m_treeItems.empty()) { m_selection.SetSelection(m_treeItems.front().itemId); } } void HierarchyPanel::EmitSelectionEvent() { if (!m_selection.HasSelection()) { return; } const HierarchyNode* node = m_model.FindNode(m_selection.GetSelectedId()); if (node == nullptr) { return; } Event event = {}; event.kind = EventKind::SelectionChanged; event.itemId = node->nodeId; event.label = node->label; m_frameEvents.push_back(std::move(event)); } void HierarchyPanel::EmitReparentEvent( EventKind kind, std::string itemId, std::string targetItemId) { Event event = {}; event.kind = kind; event.itemId = std::move(itemId); event.targetItemId = std::move(targetItemId); if (const HierarchyNode* node = m_model.FindNode(event.itemId); node != nullptr) { event.label = node->label; } m_frameEvents.push_back(std::move(event)); } bool HierarchyPanel::WantsHostPointerCapture() const { return m_dragState.requestPointerCapture; } bool HierarchyPanel::WantsHostPointerRelease() const { return m_dragState.requestPointerRelease; } bool HierarchyPanel::HasActivePointerCapture() const { return m_dragState.dragging; } const std::vector& HierarchyPanel::GetFrameEvents() const { return m_frameEvents; } } // namespace XCEngine::UI::Editor::App