editor: centralize product panel manifest

This commit is contained in:
2026-04-28 04:33:44 +08:00
parent ea765b9481
commit 8c66cdac07
12 changed files with 574 additions and 136 deletions

View File

@@ -5,6 +5,7 @@
#include <vector>
#include <utility>
#include "Panels/EditorPanelIds.h"
#include "Product/EditorProductManifest.h"
#include <XCEngine/Input/InputTypes.h>
#include "Assets/EditorIconService.h"
@@ -134,6 +135,10 @@ UIEditorCommandDescriptor BuildWorkspaceCommand(
return command;
}
std::string BuildPanelActivationCommandId(std::string_view panelId) {
return std::string("view.activate_") + std::string(panelId);
}
UIShortcutBinding BuildBinding(
std::string commandId,
std::int32_t keyCode,
@@ -187,38 +192,16 @@ UIEditorCommandRegistry BuildEditorCommandRegistry() {
BuildWorkspaceCommand(
"view.reset_layout",
"Reset Layout",
UIEditorWorkspaceCommandKind::ResetWorkspace),
BuildWorkspaceCommand(
"view.activate_hierarchy",
"Hierarchy",
UIEditorWorkspaceCommandKind::ActivatePanel,
std::string(kHierarchyPanelId)),
BuildWorkspaceCommand(
"view.activate_scene",
"Scene",
UIEditorWorkspaceCommandKind::ActivatePanel,
std::string(kScenePanelId)),
BuildWorkspaceCommand(
"view.activate_game",
"Game",
UIEditorWorkspaceCommandKind::ActivatePanel,
std::string(kGamePanelId)),
BuildWorkspaceCommand(
"view.activate_inspector",
"Inspector",
UIEditorWorkspaceCommandKind::ActivatePanel,
std::string(kInspectorPanelId)),
BuildWorkspaceCommand(
"view.activate_console",
"Console",
UIEditorWorkspaceCommandKind::ActivatePanel,
std::string(kConsolePanelId)),
BuildWorkspaceCommand(
"view.activate_project",
"Project",
UIEditorWorkspaceCommandKind::ActivatePanel,
std::string(kProjectPanelId))
UIEditorWorkspaceCommandKind::ResetWorkspace)
};
for (const EditorProductPanelDescriptor& panel : GetEditorProductPanels()) {
registry.commands.push_back(
BuildWorkspaceCommand(
BuildPanelActivationCommandId(panel.panelId),
std::string(panel.defaultTitle),
UIEditorWorkspaceCommandKind::ActivatePanel,
std::string(panel.panelId)));
}
return registry;
}
@@ -250,39 +233,22 @@ namespace XCEngine::UI::Editor::App {
namespace {
UIEditorPanelDescriptor BuildHostedContentPanelDescriptor(
std::string_view panelId,
std::string_view title,
bool placeholder,
bool canHide,
bool canClose) {
UIEditorPanelDescriptor BuildProductPanelDescriptor(
const EditorProductPanelDescriptor& productPanel) {
UIEditorPanelDescriptor descriptor = {};
descriptor.panelId = std::string(panelId);
descriptor.defaultTitle = std::string(title);
descriptor.presentationKind = UIEditorPanelPresentationKind::HostedContent;
descriptor.placeholder = placeholder;
descriptor.canHide = canHide;
descriptor.canClose = canClose;
return descriptor;
}
UIEditorPanelDescriptor BuildViewportPanelDescriptor(
std::string_view panelId,
std::string_view title,
bool canHide,
bool canClose,
bool showTopBar,
bool showBottomBar) {
UIEditorPanelDescriptor descriptor = {};
descriptor.panelId = std::string(panelId);
descriptor.defaultTitle = std::string(title);
descriptor.presentationKind = UIEditorPanelPresentationKind::ViewportShell;
descriptor.placeholder = false;
descriptor.canHide = canHide;
descriptor.canClose = canClose;
descriptor.viewportShellSpec.chrome.title = descriptor.defaultTitle;
descriptor.viewportShellSpec.chrome.showTopBar = showTopBar;
descriptor.viewportShellSpec.chrome.showBottomBar = showBottomBar;
descriptor.panelId = std::string(productPanel.panelId);
descriptor.defaultTitle = std::string(productPanel.defaultTitle);
descriptor.presentationKind = productPanel.presentationKind;
descriptor.placeholder = productPanel.placeholder;
descriptor.canHide = productPanel.canHide;
descriptor.canClose = productPanel.canClose;
if (descriptor.presentationKind == UIEditorPanelPresentationKind::ViewportShell) {
descriptor.viewportShellSpec.chrome.title = descriptor.defaultTitle;
descriptor.viewportShellSpec.chrome.showTopBar =
productPanel.showViewportTopBar;
descriptor.viewportShellSpec.chrome.showBottomBar =
productPanel.showViewportBottomBar;
}
return descriptor;
}
@@ -303,14 +269,9 @@ const UIEditorPanelDescriptor& RequirePanelDescriptor(
UIEditorPanelRegistry BuildEditorPanelRegistry() {
UIEditorPanelRegistry registry = {};
registry.panels = {
BuildHostedContentPanelDescriptor(kHierarchyPanelId, kHierarchyPanelTitle, true, false, false),
BuildViewportPanelDescriptor(kScenePanelId, kScenePanelTitle, false, false, false, false),
BuildViewportPanelDescriptor(kGamePanelId, kGamePanelTitle, false, false, false, false),
BuildHostedContentPanelDescriptor(kInspectorPanelId, kInspectorPanelTitle, true, false, false),
BuildHostedContentPanelDescriptor(kConsolePanelId, kConsolePanelTitle, true, false, false),
BuildHostedContentPanelDescriptor(kProjectPanelId, kProjectPanelTitle, false, false, false)
};
for (const EditorProductPanelDescriptor& panel : GetEditorProductPanels()) {
registry.panels.push_back(BuildProductPanelDescriptor(panel));
}
return registry;
}
@@ -498,30 +459,20 @@ UIEditorMenuModel BuildEditorMenuModel() {
BuildCommandItem("scripts-rebuild", "Rebuild Script Assemblies", "scripts.rebuild")
};
UIEditorMenuCheckedStateBinding hierarchyActive = {
UIEditorMenuCheckedStateSource::PanelActive,
std::string(kHierarchyPanelId)
};
UIEditorMenuCheckedStateBinding sceneActive = {
UIEditorMenuCheckedStateSource::PanelActive,
std::string(kScenePanelId)
};
UIEditorMenuCheckedStateBinding gameActive = {
UIEditorMenuCheckedStateSource::PanelActive,
std::string(kGamePanelId)
};
UIEditorMenuCheckedStateBinding inspectorActive = {
UIEditorMenuCheckedStateSource::PanelActive,
std::string(kInspectorPanelId)
};
UIEditorMenuCheckedStateBinding consoleActive = {
UIEditorMenuCheckedStateSource::PanelActive,
std::string(kConsolePanelId)
};
UIEditorMenuCheckedStateBinding projectActive = {
UIEditorMenuCheckedStateSource::PanelActive,
std::string(kProjectPanelId)
};
std::vector<UIEditorMenuItemDescriptor> panelMenuItems = {};
panelMenuItems.reserve(GetEditorProductPanels().size());
for (const EditorProductPanelDescriptor& panel : GetEditorProductPanels()) {
UIEditorMenuCheckedStateBinding activeBinding = {
UIEditorMenuCheckedStateSource::PanelActive,
std::string(panel.panelId)
};
panelMenuItems.push_back(
BuildCommandItem(
std::string("view-panel-") + std::string(panel.panelId),
std::string(panel.defaultTitle),
BuildPanelActivationCommandId(panel.panelId),
std::move(activeBinding)));
}
UIEditorMenuDescriptor viewMenu = {};
viewMenu.menuId = "view";
@@ -532,14 +483,7 @@ UIEditorMenuModel BuildEditorMenuModel() {
BuildSubmenuItem(
"view-panels",
"Panels",
{
BuildCommandItem("view-panel-hierarchy", "Hierarchy", "view.activate_hierarchy", hierarchyActive),
BuildCommandItem("view-panel-scene", "Scene", "view.activate_scene", sceneActive),
BuildCommandItem("view-panel-game", "Game", "view.activate_game", gameActive),
BuildCommandItem("view-panel-inspector", "Inspector", "view.activate_inspector", inspectorActive),
BuildCommandItem("view-panel-console", "Console", "view.activate_console", consoleActive),
BuildCommandItem("view-panel-project", "Project", "view.activate_project", projectActive)
})
std::move(panelMenuItems))
};
UIEditorMenuDescriptor helpMenu = {};