2026-03-26 21:18:33 +08:00
|
|
|
#include "Commands/SceneCommands.h"
|
2026-03-25 01:23:08 +08:00
|
|
|
#include "EditorLayer.h"
|
2026-03-26 21:18:33 +08:00
|
|
|
#include "Layout/DockLayoutController.h"
|
2026-03-25 01:23:08 +08:00
|
|
|
#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"
|
2026-03-25 15:35:00 +08:00
|
|
|
#include "Core/IEditorContext.h"
|
2026-03-25 16:20:21 +08:00
|
|
|
#include "Core/EditorContext.h"
|
2026-03-26 01:59:14 +08:00
|
|
|
#include "Core/IUndoManager.h"
|
2026-03-26 01:26:26 +08:00
|
|
|
#include <filesystem>
|
2026-03-25 01:23:08 +08:00
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
|
|
namespace XCEngine {
|
|
|
|
|
namespace Editor {
|
|
|
|
|
|
2026-03-26 21:18:33 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
std::string BuildFallbackScenePath(const IEditorContext& context) {
|
|
|
|
|
return (std::filesystem::path(context.GetProjectPath()) / "Assets" / "Scenes" / "Main.xc").string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2026-03-25 01:23:08 +08:00
|
|
|
EditorLayer::EditorLayer() : Layer("Editor") {}
|
|
|
|
|
|
2026-03-25 15:35:00 +08:00
|
|
|
void EditorLayer::SetContext(std::shared_ptr<IEditorContext> context) {
|
|
|
|
|
m_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 01:23:08 +08:00
|
|
|
void EditorLayer::onAttach() {
|
2026-03-25 15:35:00 +08:00
|
|
|
if (!m_context) {
|
2026-03-25 16:20:21 +08:00
|
|
|
m_context = std::make_shared<EditorContext>();
|
2026-03-25 15:35:00 +08:00
|
|
|
}
|
2026-03-26 21:18:33 +08:00
|
|
|
|
|
|
|
|
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>();
|
|
|
|
|
|
2026-03-26 01:26:26 +08:00
|
|
|
m_projectPanel->Initialize(m_context->GetProjectPath());
|
2026-03-26 21:18:33 +08:00
|
|
|
Commands::LoadStartupScene(*m_context);
|
|
|
|
|
m_dockLayoutController->Attach(*m_context);
|
|
|
|
|
m_panels.AttachAll();
|
2026-03-25 01:23:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorLayer::onDetach() {
|
2026-03-26 21:18:33 +08:00
|
|
|
if (m_context) {
|
|
|
|
|
Commands::SaveDirtySceneWithFallback(*m_context, BuildFallbackScenePath(*m_context));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_dockLayoutController) {
|
|
|
|
|
m_dockLayoutController->Detach();
|
2026-03-26 01:26:26 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 21:18:33 +08:00
|
|
|
m_panels.DetachAll();
|
|
|
|
|
m_panels.Clear();
|
|
|
|
|
m_projectPanel = nullptr;
|
2026-03-25 01:23:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorLayer::onUpdate(float dt) {
|
2026-03-26 21:18:33 +08:00
|
|
|
m_panels.UpdateAll(dt);
|
2026-03-25 01:23:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorLayer::onEvent(void* event) {
|
2026-03-26 21:18:33 +08:00
|
|
|
m_panels.DispatchEvent(event);
|
2026-03-25 01:23:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EditorLayer::onImGuiRender() {
|
2026-03-26 21:18:33 +08:00
|
|
|
m_dockLayoutController->RenderDockspace();
|
|
|
|
|
m_panels.RenderAll();
|
2026-03-25 01:23:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|