feat(new_editor): wire project, inspector, and viewport runtime

This commit is contained in:
2026-04-19 00:03:25 +08:00
parent 8257403036
commit a57b322bc7
168 changed files with 14829 additions and 2507 deletions

View File

@@ -14,6 +14,26 @@ namespace XCEngine::UI::Editor::App {
namespace {
std::string_view DescribeProjectItemKind(ProjectBrowserModel::ItemKind kind) {
switch (kind) {
case ProjectBrowserModel::ItemKind::Folder:
return "Folder";
case ProjectBrowserModel::ItemKind::Scene:
return "Scene";
case ProjectBrowserModel::ItemKind::Model:
return "Model";
case ProjectBrowserModel::ItemKind::Material:
return "Material";
case ProjectBrowserModel::ItemKind::Texture:
return "Texture";
case ProjectBrowserModel::ItemKind::Script:
return "Script";
case ProjectBrowserModel::ItemKind::File:
default:
return "File";
}
}
std::string DescribeProjectPanelEvent(const ProjectPanel::Event& event) {
std::ostringstream stream = {};
switch (event.kind) {
@@ -58,6 +78,12 @@ std::string DescribeProjectPanelEvent(const ProjectPanel::Event& event) {
case ProjectPanel::EventSource::GridSecondary:
stream << "GridSecondary";
break;
case ProjectPanel::EventSource::GridDrag:
stream << "GridDrag";
break;
case ProjectPanel::EventSource::Command:
stream << "Command";
break;
case ProjectPanel::EventSource::Background:
stream << "Background";
break;
@@ -73,6 +99,9 @@ std::string DescribeProjectPanelEvent(const ProjectPanel::Event& event) {
if (!event.displayName.empty()) {
stream << " label=" << event.displayName;
}
if (!event.itemId.empty()) {
stream << " kind=" << DescribeProjectItemKind(event.itemKind);
}
return stream.str();
}
@@ -109,75 +138,26 @@ std::string DescribeHierarchyPanelEvent(const HierarchyPanel::Event& event) {
return stream.str();
}
void ApplyHierarchySelection(
EditorContext& context,
const HierarchyPanel::Event& event) {
if (event.kind != HierarchyPanel::EventKind::SelectionChanged) {
return;
}
const EditorSceneRuntime& sceneRuntime = context.GetSceneRuntime();
if (!sceneRuntime.HasSceneSelection()) {
if (context.GetSession().selection.kind == EditorSelectionKind::HierarchyNode) {
context.ClearSelection();
}
return;
}
EditorSelectionState selection = {};
selection.kind = EditorSelectionKind::HierarchyNode;
selection.itemId = sceneRuntime.GetSelectedItemId();
selection.displayName = sceneRuntime.GetSelectedDisplayName().empty()
? selection.itemId
: sceneRuntime.GetSelectedDisplayName();
context.SetSelection(std::move(selection));
}
void ApplyProjectSelection(
EditorContext& context,
const ProjectPanel::Event& event) {
switch (event.kind) {
case ProjectPanel::EventKind::AssetSelected: {
EditorSelectionState selection = {};
selection.kind = EditorSelectionKind::ProjectItem;
selection.itemId = event.itemId;
selection.displayName = event.displayName.empty() ? event.itemId : event.displayName;
selection.absolutePath = event.absolutePath;
selection.directory = event.directory;
context.SetSelection(std::move(selection));
return;
}
case ProjectPanel::EventKind::AssetSelectionCleared:
case ProjectPanel::EventKind::FolderNavigated:
if (context.GetSession().selection.kind == EditorSelectionKind::ProjectItem) {
context.ClearSelection();
}
return;
case ProjectPanel::EventKind::AssetOpened:
case ProjectPanel::EventKind::RenameRequested:
case ProjectPanel::EventKind::ContextMenuRequested:
case ProjectPanel::EventKind::None:
default:
return;
}
}
} // namespace
std::vector<WorkspaceTraceEntry> SyncWorkspaceEvents(
EditorContext& context,
const EditorShellRuntime& runtime) {
std::vector<WorkspaceTraceEntry> entries = {};
context.SyncSessionFromProjectRuntime();
if (const std::optional<std::filesystem::path> scenePath =
context.GetProjectRuntime().ConsumePendingSceneOpenPath();
scenePath.has_value()) {
context.GetSceneRuntime().OpenSceneAsset(scenePath.value());
}
for (const HierarchyPanel::Event& event : runtime.GetHierarchyPanelEvents()) {
ApplyHierarchySelection(context, event);
const std::string message = DescribeHierarchyPanelEvent(event);
context.SetStatus("Hierarchy", message);
entries.push_back(WorkspaceTraceEntry{ std::string(kHierarchyPanelId), std::move(message) });
}
for (const ProjectPanel::Event& event : runtime.GetProjectPanelEvents()) {
ApplyProjectSelection(context, event);
const std::string message = DescribeProjectPanelEvent(event);
context.SetStatus("Project", message);
entries.push_back(WorkspaceTraceEntry{ std::string(kProjectPanelId), std::move(message) });