#include "Commands/SceneCommands.h" #include "EditorLayer.h" #include "Layout/DockLayoutController.h" #include "panels/MenuBar.h" #include "panels/HierarchyPanel.h" #include "panels/SceneViewPanel.h" #include "panels/GameViewPanel.h" #include "panels/InspectorPanel.h" #include "panels/ConsolePanel.h" #include "panels/ProjectPanel.h" #include "Core/IEditorContext.h" #include "Core/EditorContext.h" #include "Core/IUndoManager.h" #include #include namespace XCEngine { namespace Editor { namespace { std::string BuildFallbackScenePath(const IEditorContext& context) { return (std::filesystem::path(context.GetProjectPath()) / "Assets" / "Scenes" / "Main.xc").string(); } } // namespace EditorLayer::EditorLayer() : Layer("Editor") {} void EditorLayer::SetContext(std::shared_ptr context) { m_context = context; } void EditorLayer::onAttach() { if (!m_context) { m_context = std::make_shared(); } m_panels.Clear(); m_panels.SetContext(m_context.get()); m_panels.Emplace(); m_panels.Emplace(); m_panels.Emplace(); m_panels.Emplace(); m_panels.Emplace(); m_panels.Emplace(); m_projectPanel = &m_panels.Emplace(); m_dockLayoutController = std::make_unique(); m_projectPanel->Initialize(m_context->GetProjectPath()); Commands::LoadStartupScene(*m_context); m_dockLayoutController->Attach(*m_context); m_panels.AttachAll(); } void EditorLayer::onDetach() { if (m_context) { Commands::SaveDirtySceneWithFallback(*m_context, BuildFallbackScenePath(*m_context)); } if (m_dockLayoutController) { m_dockLayoutController->Detach(); } m_panels.DetachAll(); m_panels.Clear(); m_projectPanel = nullptr; } void EditorLayer::onUpdate(float dt) { m_panels.UpdateAll(dt); } void EditorLayer::onEvent(void* event) { m_panels.DispatchEvent(event); } void EditorLayer::onImGuiRender() { m_dockLayoutController->RenderDockspace(); m_panels.RenderAll(); } } }