Editor: rework default layout to UE5 arrangement

Panels renamed to UE semantics (docking identity change): Hierarchy ->
Outliner, Inspector -> Details, Asset Browser -> Content Browser.

Default DockBuilder layout now matches UE5 factory layout: Details
docked right (full height), Content Browser docked bottom spanning
left+center, Outliner top-left, Viewport center with Stats as a
side tab.

Legacy imgui.ini (old window names, no new names) is removed once at
Init so the new default rebuilds cleanly; fresh or new-style ini is
untouched.
This commit is contained in:
2026-10-05 00:47:33 +08:00
parent 42757bab36
commit b7d6f53591
5 changed files with 56 additions and 24 deletions
+50 -19
View File
@@ -1,12 +1,14 @@
//
// Editor.cpp:docking 骨架实现。
//
// 布局方案(首帧 DockBuilder 一次,之后 imgui.ini 接管):
// ┌──────────────────────────────┬───────────────┐
// │ Hierarchy │ │
// ├──────────────────────────────┤ Inspector │
// │ Stats │ (28%) │
// └──────────────────────────────┴───────────────┘
// 默认布局 = UE5 出厂布局(首帧 DockBuilder 一次,之后 imgui.ini 接管):
// ┌──────────┬──────────────────────┬───────────┐
// │ Outliner │ │ │
// │ │ Viewport │ Details │
// │ │ (+Stats tab) │ │
// ├──────────┴──────────────────────┤ │
// │ Content Browser(左+中通栏) │ │
// └─────────────────────────────────┴───────────┘
//
#include "Editor.h"
@@ -27,6 +29,7 @@
#include <GLFW/glfw3.h>
#include <filesystem>
#include <fstream>
using namespace Engine; // kDisplayViewport / kDisplayDirect(SceneTypes.h)
@@ -45,6 +48,32 @@ void Editor::Init(const EditorContext& ctx)
m_Viewport = std::make_unique<ViewportPanel>();
m_Stats = std::make_unique<StatsPanel>();
m_AssetBrowser = std::make_unique<AssetBrowserPanel>();
// 旧布局一次性迁移:面板改名(Hierarchy→Outliner / Inspector→Details /
// Asset Browser→Content Browser)= docking 身份全变,旧 imgui.ini 对
// 新窗口名失效(新窗口首启浮动,而默认布局又因 dock node 非空不再
// 重建)。检测"有旧名无新名" → 删 ini 让 UE 默认布局重建一次。
// 此刻 ImGui 首帧 NewFrame 还未读盘(NewFrame 内才 LoadIniSettings),
// 删文件干净无副作用;新式 ini 或无 ini 不动
if (ImGui::GetCurrentContext() && ImGui::GetIO().IniFilename)
{
const char* path = ImGui::GetIO().IniFilename;
std::ifstream file(path);
if (file)
{
const std::string content((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
file.close();
if (content.find("[Window][Hierarchy]") != std::string::npos &&
content.find("[Window][Outliner]") == std::string::npos)
{
std::error_code ec;
std::filesystem::remove(path, ec);
ENGINE_INFO("Editor: legacy imgui.ini removed, "
"UE5 default layout will be rebuilt");
}
}
}
}
// ---- PIE(Play-In-Editor)----
@@ -259,11 +288,11 @@ void Editor::DrawMenuBar()
if (ImGui::BeginMenu("View"))
{
ImGui::MenuItem("Hierarchy", nullptr, &m_ShowHierarchy);
ImGui::MenuItem("Inspector", nullptr, &m_ShowInspector);
ImGui::MenuItem("Outliner", nullptr, &m_ShowHierarchy);
ImGui::MenuItem("Details", nullptr, &m_ShowInspector);
ImGui::MenuItem("Viewport", nullptr, &m_ShowViewport);
ImGui::MenuItem("Stats", nullptr, &m_ShowStats);
ImGui::MenuItem("Asset Browser", nullptr, &m_ShowAssetBrowser);
ImGui::MenuItem("Content Browser", nullptr, &m_ShowAssetBrowser);
ImGui::EndMenu();
}
@@ -284,19 +313,21 @@ void Editor::DrawDockSpace()
ImGui::DockBuilderAddNode(dockspaceId, ImGuiDockNodeFlags_DockSpace);
ImGui::DockBuilderSetNodeSize(dockspaceId, ImGui::GetMainViewport()->Size);
ImGuiID dockLeft = 0, dockRight = 0, dockCenter = 0, dockStats = 0;
ImGui::DockBuilderSplitNode(dockspaceId, ImGuiDir_Left, 0.20f,
&dockLeft, &dockCenter);
ImGui::DockBuilderSplitNode(dockCenter, ImGuiDir_Right, 0.28f,
// UE5 出厂布局:Details 右列通栏 → Content Browser 底部通栏
//(左+中)→ Outliner 左列 → 剩余全给 Viewport(Stats 作其 tab)
ImGuiID dockRight = 0, dockBottom = 0, dockLeft = 0, dockCenter = 0;
ImGui::DockBuilderSplitNode(dockspaceId, ImGuiDir_Right, 0.26f,
&dockRight, &dockCenter);
ImGui::DockBuilderSplitNode(dockLeft, ImGuiDir_Down, 0.38f,
&dockStats, &dockLeft);
ImGui::DockBuilderSplitNode(dockCenter, ImGuiDir_Down, 0.30f,
&dockBottom, &dockCenter);
ImGui::DockBuilderSplitNode(dockCenter, ImGuiDir_Left, 0.22f,
&dockLeft, &dockCenter);
ImGui::DockBuilderDockWindow("Hierarchy", dockLeft);
ImGui::DockBuilderDockWindow("Stats", dockStats);
ImGui::DockBuilderDockWindow("Asset Browser", dockStats);
ImGui::DockBuilderDockWindow("Inspector", dockRight);
ImGui::DockBuilderDockWindow("Outliner", dockLeft);
ImGui::DockBuilderDockWindow("Viewport", dockCenter);
ImGui::DockBuilderDockWindow("Stats", dockCenter); // Viewport 旁 tab
ImGui::DockBuilderDockWindow("Content Browser", dockBottom);
ImGui::DockBuilderDockWindow("Details", dockRight);
ImGui::DockBuilderFinish(dockspaceId);
}