Refactor editor shell host layers

This commit is contained in:
2026-03-26 23:52:05 +08:00
parent f87bc53875
commit 31675e00c8
18 changed files with 738 additions and 518 deletions

View File

@@ -1,30 +1,9 @@
#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 <filesystem>
#include <imgui.h>
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<IEditorContext> context) {
@@ -36,48 +15,25 @@ void EditorLayer::onAttach() {
m_context = std::make_shared<EditorContext>();
}
m_panels.Clear();
m_panels.SetContext(m_context.get());
m_panels.Emplace<MenuBar>();
m_panels.Emplace<HierarchyPanel>();
m_panels.Emplace<SceneViewPanel>();
m_panels.Emplace<GameViewPanel>();
m_panels.Emplace<InspectorPanel>();
m_panels.Emplace<ConsolePanel>();
m_projectPanel = &m_panels.Emplace<ProjectPanel>();
m_dockLayoutController = std::make_unique<DockLayoutController>();
m_projectPanel->Initialize(m_context->GetProjectPath());
Commands::LoadStartupScene(*m_context);
m_dockLayoutController->Attach(*m_context);
m_panels.AttachAll();
m_workspace.Attach(*m_context);
}
void EditorLayer::onDetach() {
if (m_context) {
Commands::SaveDirtySceneWithFallback(*m_context, BuildFallbackScenePath(*m_context));
m_workspace.Detach(*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);
m_workspace.Update(dt);
}
void EditorLayer::onEvent(void* event) {
m_panels.DispatchEvent(event);
m_workspace.DispatchEvent(event);
}
void EditorLayer::onImGuiRender() {
m_dockLayoutController->RenderDockspace();
m_panels.RenderAll();
m_workspace.Render();
}
}