diff --git a/editor/AGENTS.md b/editor/AGENTS.md index d29b4212..9d2fe536 100644 --- a/editor/AGENTS.md +++ b/editor/AGENTS.md @@ -74,6 +74,10 @@ Rules: - the old shared `EditorPanelServices` dependency bag is gone. Workspace and utility panels now receive explicit bindings or panel-local contexts; do not recreate a catch-all mutable panel service bundle under a new name +- `EditorFrameServices` remains a window/content orchestration boundary. It must + not be passed through the workspace-panel seam as a generic dependency source; + workspace panels should receive explicit panel-local bindings or typed + callbacks instead ## Working Rules @@ -82,6 +86,9 @@ Rules: - keep panel dependencies explicit. If a panel needs more data or actions, add a narrow panel-local context or binding instead of routing everything through a generic shared services struct +- do not reintroduce `void*` plus callback-function panel hooks for scene-open + or utility-window requests; use typed callbacks or explicit requester + interfaces instead - when changing runtime or document flow, inspect `EditorSession`, `EditorRuntimeCoordinator`, `EditorHostCommandBridge`, the relevant feature, and the matching tests @@ -98,6 +105,7 @@ Rules: - no panel-local shortcut that bypasses the intended runtime owner - no new shared mutable panel-services bag or service-locator style panel dependency bundle +- no `EditorFrameServices` tunneling into workspace-panel update/prepare paths - no scene-open side channel in `EditorProjectRuntime`; project UI must call the panel service request hook - no play-mode path that mutates the editable scene in place or skips diff --git a/editor/app/Bootstrap/Application.cpp b/editor/app/Bootstrap/Application.cpp index 6421682e..1e27af2f 100644 --- a/editor/app/Bootstrap/Application.cpp +++ b/editor/app/Bootstrap/Application.cpp @@ -219,9 +219,21 @@ bool Application::Initialize(HINSTANCE hInstance, int nCmdShow) { m_runtimePaths); m_renderRuntimeFactory = std::make_unique(); - App::EditorWorkspaceShellRuntimeFactory workspaceShellRuntimeFactory = []() { + App::EditorWorkspaceShellRuntimeFactory workspaceShellRuntimeFactory = [this]() { return App::CreateEditorWorkspaceShellRuntime( - App::CreateEditorWorkspacePanelRuntimeSet(), + App::CreateEditorWorkspacePanelRuntimeSet( + m_editorContext->GetSession(), + m_editorContext->GetCommandFocusService(), + m_editorContext->GetProjectRuntime(), + m_editorContext->GetSceneRuntime(), + m_editorContext->GetColorPickerToolState(), + m_systemInteractionHost.get(), + [this](App::EditorUtilityWindowKind kind) { + m_editorContext->RequestOpenUtilityWindow(kind); + }, + [this](const std::filesystem::path& scenePath) { + return m_editorContext->RequestOpenSceneAsset(scenePath); + }), App::CreateEditorIconService(), App::CreateEditorViewportRuntimeServices()); }; diff --git a/editor/app/Composition/EditorContext.cpp b/editor/app/Composition/EditorContext.cpp index e2fddc80..db32edf4 100644 --- a/editor/app/Composition/EditorContext.cpp +++ b/editor/app/Composition/EditorContext.cpp @@ -112,7 +112,8 @@ void EditorContext::AttachTextMeasurer( m_shellServices.textMeasurer = &textMeasurer; } -void EditorContext::SetSystemInteractionHost(System::SystemInteractionService* systemInteractionHost) { +void EditorContext::SetSystemInteractionHost( + ::XCEngine::UI::Editor::System::SystemInteractionService* systemInteractionHost) { m_systemInteractionHost = systemInteractionHost; } @@ -225,11 +226,11 @@ void EditorContext::SyncSessionFromCommandFocusService() { ResolveEditorActionRoute(m_session.activePanelId)); } -System::SystemInteractionService* EditorContext::GetSystemInteractionHost() { +::XCEngine::UI::Editor::System::SystemInteractionService* EditorContext::GetSystemInteractionHost() { return m_systemInteractionHost; } -const System::SystemInteractionService* EditorContext::GetSystemInteractionHost() const { +const ::XCEngine::UI::Editor::System::SystemInteractionService* EditorContext::GetSystemInteractionHost() const { return m_systemInteractionHost; } diff --git a/editor/app/Composition/EditorContext.h b/editor/app/Composition/EditorContext.h index 3adcf34b..ddd8a40c 100644 --- a/editor/app/Composition/EditorContext.h +++ b/editor/app/Composition/EditorContext.h @@ -39,7 +39,8 @@ public: const EditorRuntimePaths& runtimePaths, EditorSceneBackendFactory& sceneBackendFactory); void AttachTextMeasurer(const UIEditorTextMeasurer& textMeasurer) override; - void SetSystemInteractionHost(System::SystemInteractionService* systemInteractionHost); + void SetSystemInteractionHost( + ::XCEngine::UI::Editor::System::SystemInteractionService* systemInteractionHost); void BindEditCommandRoutes( EditorEditCommandRoute* hierarchyRoute, EditorEditCommandRoute* projectRoute, @@ -56,8 +57,8 @@ public: EditorColorPickerToolState& GetColorPickerToolState() override; const EditorColorPickerToolState& GetColorPickerToolState() const override; void RequestOpenUtilityWindow(EditorUtilityWindowKind kind) override; - System::SystemInteractionService* GetSystemInteractionHost() override; - const System::SystemInteractionService* GetSystemInteractionHost() const override; + ::XCEngine::UI::Editor::System::SystemInteractionService* GetSystemInteractionHost() override; + const ::XCEngine::UI::Editor::System::SystemInteractionService* GetSystemInteractionHost() const override; const UIEditorTextMeasurer* GetTextMeasurer() const override; bool RequestOpenSceneAsset(const std::filesystem::path& scenePath) override; void SyncSessionFromWorkspace( @@ -112,7 +113,7 @@ private: EditorColorPickerToolState m_colorPickerToolState = {}; EditorUtilityWindowRequestState m_utilityWindowRequestState = {}; EditorHostCommandBridge m_hostCommandBridge = {}; - System::SystemInteractionService* m_systemInteractionHost = nullptr; + ::XCEngine::UI::Editor::System::SystemInteractionService* m_systemInteractionHost = nullptr; bool m_valid = false; std::string m_validationMessage = {}; std::string m_lastStatus = {}; diff --git a/editor/app/Composition/EditorShellHostedPanelCoordinator.cpp b/editor/app/Composition/EditorShellHostedPanelCoordinator.cpp index 7bdbaf8e..ff51f970 100644 --- a/editor/app/Composition/EditorShellHostedPanelCoordinator.cpp +++ b/editor/app/Composition/EditorShellHostedPanelCoordinator.cpp @@ -21,7 +21,6 @@ void EditorShellHostedPanelCoordinator::Update( shellOwnsHostedContentPointerStream); const EditorWorkspacePanelUpdateContext updateContext{ - .frameServices = context.frameServices, .shellFrame = context.shellFrame, .shellInteractionState = context.shellInteractionState, .hostedContentEvents = hostedContentEvents, diff --git a/editor/app/Composition/EditorShellSessionCoordinator.cpp b/editor/app/Composition/EditorShellSessionCoordinator.cpp index a399e13d..52dc8221 100644 --- a/editor/app/Composition/EditorShellSessionCoordinator.cpp +++ b/editor/app/Composition/EditorShellSessionCoordinator.cpp @@ -6,9 +6,7 @@ namespace XCEngine::UI::Editor::App { UIEditorShellInteractionDefinition EditorShellSessionCoordinator::PrepareShellDefinition( const EditorShellSessionCoordinatorContext& context) const { - context.workspacePanels.PrepareForShellDefinition( - context.frameServices, - context.workspaceController); + context.workspacePanels.PrepareForShellDefinition(context.workspaceController); context.frameServices.BindEditCommandRoutes( context.workspacePanels.FindCommandRoute(EditorActionRoute::Hierarchy), context.workspacePanels.FindCommandRoute(EditorActionRoute::Project), diff --git a/editor/app/Core/Windowing/EditorFrameServices.h b/editor/app/Core/Windowing/EditorFrameServices.h index 3e8b5309..c7c742d8 100644 --- a/editor/app/Core/Windowing/EditorFrameServices.h +++ b/editor/app/Core/Windowing/EditorFrameServices.h @@ -57,8 +57,8 @@ public: virtual const EditorSceneRuntime& GetSceneRuntime() const = 0; virtual EditorColorPickerToolState& GetColorPickerToolState() = 0; virtual const EditorColorPickerToolState& GetColorPickerToolState() const = 0; - virtual System::SystemInteractionService* GetSystemInteractionHost() = 0; - virtual const System::SystemInteractionService* GetSystemInteractionHost() const = 0; + virtual ::XCEngine::UI::Editor::System::SystemInteractionService* GetSystemInteractionHost() = 0; + virtual const ::XCEngine::UI::Editor::System::SystemInteractionService* GetSystemInteractionHost() const = 0; virtual const UIEditorTextMeasurer* GetTextMeasurer() const = 0; virtual void RequestOpenUtilityWindow(EditorUtilityWindowKind kind) = 0; virtual bool RequestOpenSceneAsset(const std::filesystem::path& scenePath) = 0; diff --git a/editor/app/Core/WorkspacePanels/EditorWorkspacePanelRuntime.cpp b/editor/app/Core/WorkspacePanels/EditorWorkspacePanelRuntime.cpp index c556a0cb..52df68ff 100644 --- a/editor/app/Core/WorkspacePanels/EditorWorkspacePanelRuntime.cpp +++ b/editor/app/Core/WorkspacePanels/EditorWorkspacePanelRuntime.cpp @@ -51,10 +51,9 @@ void EditorWorkspacePanelRuntimeSet::ResetInteractionState() { } void EditorWorkspacePanelRuntimeSet::PrepareForShellDefinition( - EditorFrameServices& frameServices, UIEditorWorkspaceController& workspaceController) { for (const std::unique_ptr& panel : m_panels) { - panel->PrepareForShellDefinition(frameServices, workspaceController); + panel->PrepareForShellDefinition(workspaceController); } } diff --git a/editor/app/Core/WorkspacePanels/EditorWorkspacePanelRuntime.h b/editor/app/Core/WorkspacePanels/EditorWorkspacePanelRuntime.h index ee6c04d3..5a54af70 100644 --- a/editor/app/Core/WorkspacePanels/EditorWorkspacePanelRuntime.h +++ b/editor/app/Core/WorkspacePanels/EditorWorkspacePanelRuntime.h @@ -5,6 +5,7 @@ #include "Environment/EditorRuntimePaths.h" #include "Viewport/EditorViewportRuntimeServices.h" #include "State/EditorSession.h" +#include "State/EditorColorPickerToolState.h" #include #include @@ -14,6 +15,7 @@ #include #include +#include #include #include #include @@ -26,9 +28,24 @@ struct UIInputEvent; } // namespace XCEngine::UI +namespace XCEngine::UI::Editor::System { + +class SystemInteractionService; + +} // namespace XCEngine::UI::Editor::System + namespace XCEngine::UI::Editor::App { -class EditorFrameServices; +class EditorCommandFocusService; +class EditorEditCommandRoute; +class EditorProjectRuntime; +class EditorSceneRuntime; +enum class EditorUtilityWindowKind : std::uint8_t; + +using RequestOpenSceneAssetCallback = + std::function; +using RequestOpenUtilityWindowCallback = + std::function; enum class EditorWorkspacePanelCursorKind : std::uint8_t { Arrow = 0, @@ -56,7 +73,6 @@ struct EditorWorkspacePanelInitializationContext { struct EditorWorkspacePanelShutdownContext {}; struct EditorWorkspacePanelUpdateContext { - EditorFrameServices& frameServices; UIEditorShellInteractionFrame& shellFrame; UIEditorShellInteractionState& shellInteractionState; const std::vector<::XCEngine::UI::UIInputEvent>& hostedContentEvents; @@ -73,12 +89,7 @@ public: virtual void Initialize(const EditorWorkspacePanelInitializationContext&) {} virtual void Shutdown(const EditorWorkspacePanelShutdownContext&) {} virtual void ResetInteractionState() {} - virtual void PrepareForShellDefinition( - EditorFrameServices& frameServices, - UIEditorWorkspaceController& workspaceController) { - (void)frameServices; - (void)workspaceController; - } + virtual void PrepareForShellDefinition(UIEditorWorkspaceController&) {} virtual EditorWorkspacePanelUpdatePhase GetUpdatePhase() const { return EditorWorkspacePanelUpdatePhase::Main; } @@ -113,9 +124,7 @@ public: void Initialize(const EditorWorkspacePanelInitializationContext& context); void Shutdown(const EditorWorkspacePanelShutdownContext& context); void ResetInteractionState(); - void PrepareForShellDefinition( - EditorFrameServices& frameServices, - UIEditorWorkspaceController& workspaceController); + void PrepareForShellDefinition(UIEditorWorkspaceController& workspaceController); void UpdatePhase( const EditorWorkspacePanelUpdateContext& context, EditorWorkspacePanelUpdatePhase phase); diff --git a/editor/app/Features/EditorWorkspacePanelRegistry.cpp b/editor/app/Features/EditorWorkspacePanelRegistry.cpp index 8b929c2d..b3258097 100644 --- a/editor/app/Features/EditorWorkspacePanelRegistry.cpp +++ b/editor/app/Features/EditorWorkspacePanelRegistry.cpp @@ -9,13 +9,12 @@ #include "Scene/SceneEditCommandRoute.h" #include "Scene/SceneViewportFeature.h" #include "Product/EditorProductManifest.h" -#include "Windowing/EditorFrameServices.h" #include -#include #include #include +#include namespace XCEngine::UI::Editor::App { @@ -28,22 +27,6 @@ constexpr int kProjectUpdatePriority = 20; constexpr int kInspectorUpdatePriority = 30; constexpr int kConsoleUpdatePriority = 40; -void RequestUtilityWindowFromFrameServices( - void* requester, - EditorUtilityWindowKind kind) { - auto* frameServices = static_cast(requester); - if (frameServices != nullptr) { - frameServices->RequestOpenUtilityWindow(kind); - } -} - -bool RequestSceneAssetFromFrameServices( - void* requester, - const std::filesystem::path& scenePath) { - auto* frameServices = static_cast(requester); - return frameServices != nullptr && frameServices->RequestOpenSceneAsset(scenePath); -} - const UIEditorHostedPanelDispatchEntry& ResolveHostedPanelDispatchEntry( const UIEditorHostedPanelDispatchFrame& dispatchFrame, std::string_view panelId) { @@ -183,6 +166,9 @@ std::string DescribeHierarchyPanelEvent(const HierarchyPanel::Event& event) { class ConsoleWorkspacePanel final : public EditorWorkspacePanel { public: + explicit ConsoleWorkspacePanel(const EditorSession& session) + : m_session(session) {} + std::string_view GetPanelId() const override { return kConsolePanelId; } @@ -205,7 +191,7 @@ public: void Update(const EditorWorkspacePanelUpdateContext& context) override { m_panel.Update( - context.frameServices.GetSession(), + m_session, ResolveHostedPanelDispatchEntry( context.shellFrame.hostedPanelDispatchFrame, GetPanelId())); @@ -216,11 +202,18 @@ public: } private: + const EditorSession& m_session; ConsolePanel m_panel = {}; }; class HierarchyWorkspacePanel final : public EditorWorkspacePanel { public: + HierarchyWorkspacePanel( + EditorSceneRuntime& sceneRuntime, + EditorCommandFocusService& commandFocusService) + : m_sceneRuntime(sceneRuntime) + , m_commandFocusService(commandFocusService) {} + std::string_view GetPanelId() const override { return kHierarchyPanelId; } @@ -247,11 +240,9 @@ public: m_panel.ResetInteractionState(); } - void PrepareForShellDefinition( - EditorFrameServices& frameServices, - UIEditorWorkspaceController&) override { - m_panel.SetSceneRuntime(&frameServices.GetSceneRuntime()); - m_panel.SetCommandFocusService(&frameServices.GetCommandFocusService()); + void PrepareForShellDefinition(UIEditorWorkspaceController&) override { + m_panel.SetSceneRuntime(&m_sceneRuntime); + m_panel.SetCommandFocusService(&m_commandFocusService); } void Update(const EditorWorkspacePanelUpdateContext& context) override { @@ -287,11 +278,27 @@ public: } private: + EditorSceneRuntime& m_sceneRuntime; + EditorCommandFocusService& m_commandFocusService; HierarchyPanel m_panel = {}; }; class InspectorWorkspacePanel final : public EditorWorkspacePanel { public: + InspectorWorkspacePanel( + const EditorSession& session, + EditorCommandFocusService& commandFocusService, + EditorProjectRuntime& projectRuntime, + EditorSceneRuntime& sceneRuntime, + EditorColorPickerToolState& colorPickerToolState, + RequestOpenUtilityWindowCallback requestOpenUtilityWindow) + : m_session(session) + , m_commandFocusService(commandFocusService) + , m_projectRuntime(projectRuntime) + , m_sceneRuntime(sceneRuntime) + , m_colorPickerToolState(colorPickerToolState) + , m_requestOpenUtilityWindow(std::move(requestOpenUtilityWindow)) {} + std::string_view GetPanelId() const override { return kInspectorPanelId; } @@ -309,15 +316,14 @@ public: } void Update(const EditorWorkspacePanelUpdateContext& context) override { - m_panel.SetCommandFocusService(&context.frameServices.GetCommandFocusService()); + m_panel.SetCommandFocusService(&m_commandFocusService); InspectorPanelContext panelContext{ - .session = context.frameServices.GetSession(), - .projectRuntime = context.frameServices.GetProjectRuntime(), - .sceneRuntime = context.frameServices.GetSceneRuntime(), - .colorPickerToolState = context.frameServices.GetColorPickerToolState(), - .textMeasurer = context.frameServices.GetTextMeasurer(), - .utilityWindowRequester = &context.frameServices, - .requestUtilityWindow = RequestUtilityWindowFromFrameServices, + .session = m_session, + .projectRuntime = m_projectRuntime, + .sceneRuntime = m_sceneRuntime, + .colorPickerToolState = m_colorPickerToolState, + .textMeasurer = m_textMeasurer, + .requestOpenUtilityWindow = m_requestOpenUtilityWindow, }; m_panel.Update( panelContext, @@ -331,16 +337,37 @@ public: m_panel.Append(drawList); } + void Initialize(const EditorWorkspacePanelInitializationContext& context) override { + m_textMeasurer = &context.textMeasurer; + } + EditorEditCommandRoute* GetEditCommandRoute() override { return &m_panel; } private: + const EditorSession& m_session; + EditorCommandFocusService& m_commandFocusService; + EditorProjectRuntime& m_projectRuntime; + EditorSceneRuntime& m_sceneRuntime; + EditorColorPickerToolState& m_colorPickerToolState; + RequestOpenUtilityWindowCallback m_requestOpenUtilityWindow = {}; + const UIEditorTextMeasurer* m_textMeasurer = nullptr; InspectorPanel m_panel = {}; }; class ProjectWorkspacePanel final : public EditorWorkspacePanel { public: + ProjectWorkspacePanel( + EditorProjectRuntime& projectRuntime, + EditorCommandFocusService& commandFocusService, + ::XCEngine::UI::Editor::System::SystemInteractionService* systemInteractionHost, + RequestOpenSceneAssetCallback requestOpenSceneAsset) + : m_projectRuntime(projectRuntime) + , m_commandFocusService(commandFocusService) + , m_systemInteractionHost(systemInteractionHost) + , m_requestOpenSceneAsset(std::move(requestOpenSceneAsset)) {} + std::string_view GetPanelId() const override { return kProjectPanelId; } @@ -367,12 +394,10 @@ public: } void Update(const EditorWorkspacePanelUpdateContext& context) override { - m_panel.SetProjectRuntime(&context.frameServices.GetProjectRuntime()); - m_panel.SetCommandFocusService(&context.frameServices.GetCommandFocusService()); - m_panel.SetSystemInteractionHost(context.frameServices.GetSystemInteractionHost()); - m_panel.SetSceneAssetOpenRequestHandler( - &context.frameServices, - RequestSceneAssetFromFrameServices); + m_panel.SetProjectRuntime(&m_projectRuntime); + m_panel.SetCommandFocusService(&m_commandFocusService); + m_panel.SetSystemInteractionHost(m_systemInteractionHost); + m_panel.SetSceneAssetOpenRequestHandler(m_requestOpenSceneAsset); m_panel.Update( ResolveHostedPanelDispatchEntry( context.shellFrame.hostedPanelDispatchFrame, @@ -415,11 +440,21 @@ public: } private: + EditorProjectRuntime& m_projectRuntime; + EditorCommandFocusService& m_commandFocusService; + ::XCEngine::UI::Editor::System::SystemInteractionService* m_systemInteractionHost = nullptr; + RequestOpenSceneAssetCallback m_requestOpenSceneAsset = {}; ProjectPanel m_panel = {}; }; class SceneWorkspacePanel final : public EditorWorkspacePanel { public: + SceneWorkspacePanel( + EditorSceneRuntime& sceneRuntime, + EditorCommandFocusService& commandFocusService) + : m_sceneRuntime(sceneRuntime) + , m_commandFocusService(commandFocusService) {} + std::string_view GetPanelId() const override { return kScenePanelId; } @@ -454,17 +489,15 @@ public: m_feature.ResetInteractionState(); } - void PrepareForShellDefinition( - EditorFrameServices& frameServices, - UIEditorWorkspaceController&) override { - m_commandRoute.BindSceneRuntime(&frameServices.GetSceneRuntime()); - m_feature.SetCommandFocusService(&frameServices.GetCommandFocusService()); - m_feature.SyncRenderRequest(frameServices.GetSceneRuntime()); + void PrepareForShellDefinition(UIEditorWorkspaceController&) override { + m_commandRoute.BindSceneRuntime(&m_sceneRuntime); + m_feature.SetCommandFocusService(&m_commandFocusService); + m_feature.SyncRenderRequest(m_sceneRuntime); } void Update(const EditorWorkspacePanelUpdateContext& context) override { m_feature.Update( - context.frameServices.GetSceneRuntime(), + m_sceneRuntime, context.shellInteractionState.workspaceInteractionState.composeState, context.shellFrame.workspaceInteractionFrame.composeFrame); } @@ -478,12 +511,17 @@ public: } private: + EditorSceneRuntime& m_sceneRuntime; + EditorCommandFocusService& m_commandFocusService; SceneViewportFeature m_feature = {}; SceneEditCommandRoute m_commandRoute = {}; }; class GameWorkspacePanel final : public EditorWorkspacePanel { public: + explicit GameWorkspacePanel(EditorCommandFocusService& commandFocusService) + : m_commandFocusService(commandFocusService) {} + std::string_view GetPanelId() const override { return kGamePanelId; } @@ -509,10 +547,8 @@ public: m_feature.ResetInteractionState(); } - void PrepareForShellDefinition( - EditorFrameServices& frameServices, - UIEditorWorkspaceController&) override { - m_feature.SetCommandFocusService(&frameServices.GetCommandFocusService()); + void PrepareForShellDefinition(UIEditorWorkspaceController&) override { + m_feature.SetCommandFocusService(&m_commandFocusService); } void Update(const EditorWorkspacePanelUpdateContext& context) override { @@ -526,24 +562,47 @@ public: } private: + EditorCommandFocusService& m_commandFocusService; GameViewportFeature m_feature = {}; }; std::unique_ptr CreateWorkspacePanelRuntime( - const EditorProductPanelDescriptor& panel) { + const EditorProductPanelDescriptor& panel, + const EditorSession& session, + EditorCommandFocusService& commandFocusService, + EditorProjectRuntime& projectRuntime, + EditorSceneRuntime& sceneRuntime, + EditorColorPickerToolState& colorPickerToolState, + ::XCEngine::UI::Editor::System::SystemInteractionService* systemInteractionHost, + const RequestOpenUtilityWindowCallback& requestOpenUtilityWindow, + const RequestOpenSceneAssetCallback& requestOpenSceneAsset) { switch (panel.runtimeKind) { case EditorProductPanelRuntimeKind::Console: - return std::make_unique(); + return std::make_unique(session); case EditorProductPanelRuntimeKind::Game: - return std::make_unique(); + return std::make_unique(commandFocusService); case EditorProductPanelRuntimeKind::Hierarchy: - return std::make_unique(); + return std::make_unique( + sceneRuntime, + commandFocusService); case EditorProductPanelRuntimeKind::Inspector: - return std::make_unique(); + return std::make_unique( + session, + commandFocusService, + projectRuntime, + sceneRuntime, + colorPickerToolState, + requestOpenUtilityWindow); case EditorProductPanelRuntimeKind::Project: - return std::make_unique(); + return std::make_unique( + projectRuntime, + commandFocusService, + systemInteractionHost, + requestOpenSceneAsset); case EditorProductPanelRuntimeKind::Scene: - return std::make_unique(); + return std::make_unique( + sceneRuntime, + commandFocusService); case EditorProductPanelRuntimeKind::None: default: return nullptr; @@ -552,11 +611,28 @@ std::unique_ptr CreateWorkspacePanelRuntime( } // namespace -EditorWorkspacePanelRuntimeSet CreateEditorWorkspacePanelRuntimeSet() { +EditorWorkspacePanelRuntimeSet CreateEditorWorkspacePanelRuntimeSet( + const EditorSession& session, + EditorCommandFocusService& commandFocusService, + EditorProjectRuntime& projectRuntime, + EditorSceneRuntime& sceneRuntime, + EditorColorPickerToolState& colorPickerToolState, + ::XCEngine::UI::Editor::System::SystemInteractionService* systemInteractionHost, + RequestOpenUtilityWindowCallback requestOpenUtilityWindow, + RequestOpenSceneAssetCallback requestOpenSceneAsset) { EditorWorkspacePanelRuntimeSet panels = {}; for (const EditorProductPanelDescriptor& panel : GetEditorProductPanels()) { if (std::unique_ptr runtime = - CreateWorkspacePanelRuntime(panel); + CreateWorkspacePanelRuntime( + panel, + session, + commandFocusService, + projectRuntime, + sceneRuntime, + colorPickerToolState, + systemInteractionHost, + requestOpenUtilityWindow, + requestOpenSceneAsset); runtime != nullptr) { panels.AddPanel(std::move(runtime)); } diff --git a/editor/app/Features/EditorWorkspacePanelRegistry.h b/editor/app/Features/EditorWorkspacePanelRegistry.h index 2342471b..dc05511e 100644 --- a/editor/app/Features/EditorWorkspacePanelRegistry.h +++ b/editor/app/Features/EditorWorkspacePanelRegistry.h @@ -4,6 +4,14 @@ namespace XCEngine::UI::Editor::App { -EditorWorkspacePanelRuntimeSet CreateEditorWorkspacePanelRuntimeSet(); +EditorWorkspacePanelRuntimeSet CreateEditorWorkspacePanelRuntimeSet( + const EditorSession& session, + EditorCommandFocusService& commandFocusService, + EditorProjectRuntime& projectRuntime, + EditorSceneRuntime& sceneRuntime, + EditorColorPickerToolState& colorPickerToolState, + ::XCEngine::UI::Editor::System::SystemInteractionService* systemInteractionHost, + RequestOpenUtilityWindowCallback requestOpenUtilityWindow, + RequestOpenSceneAssetCallback requestOpenSceneAsset); } // namespace XCEngine::UI::Editor::App diff --git a/editor/app/Features/Inspector/InspectorPanel.h b/editor/app/Features/Inspector/InspectorPanel.h index 811782ad..36e0ff3b 100644 --- a/editor/app/Features/Inspector/InspectorPanel.h +++ b/editor/app/Features/Inspector/InspectorPanel.h @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -29,19 +30,19 @@ struct EditorSession; enum class EditorUtilityWindowKind : std::uint8_t; struct InspectorPanelContext { - using UtilityWindowRequestFn = void (*)(void*, EditorUtilityWindowKind); + using RequestOpenUtilityWindowCallback = + std::function; const EditorSession& session; EditorProjectRuntime& projectRuntime; EditorSceneRuntime& sceneRuntime; EditorColorPickerToolState& colorPickerToolState; const ::XCEngine::UI::Editor::UIEditorTextMeasurer* textMeasurer = nullptr; - void* utilityWindowRequester = nullptr; - UtilityWindowRequestFn requestUtilityWindow = nullptr; + RequestOpenUtilityWindowCallback requestOpenUtilityWindow = {}; void RequestOpenUtilityWindow(EditorUtilityWindowKind kind) const { - if (requestUtilityWindow != nullptr) { - requestUtilityWindow(utilityWindowRequester, kind); + if (requestOpenUtilityWindow) { + requestOpenUtilityWindow(kind); } } }; diff --git a/editor/app/Features/Project/ProjectPanel.cpp b/editor/app/Features/Project/ProjectPanel.cpp index 8d445110..ce5d4e56 100644 --- a/editor/app/Features/Project/ProjectPanel.cpp +++ b/editor/app/Features/Project/ProjectPanel.cpp @@ -407,10 +407,8 @@ void ProjectPanel::SetSystemInteractionHost( } void ProjectPanel::SetSceneAssetOpenRequestHandler( - void* requester, - SceneAssetOpenRequestFn requestOpenSceneAsset) { - m_sceneAssetOpenRequester = requester; - m_requestOpenSceneAsset = requestOpenSceneAsset; + SceneAssetOpenRequestCallback requestOpenSceneAsset) { + m_requestOpenSceneAsset = std::move(requestOpenSceneAsset); } void ProjectPanel::SetIconService(EditorIconService* icons) { @@ -861,8 +859,8 @@ bool ProjectPanel::NavigateToFolder(std::string_view itemId, EventSource source) } bool ProjectPanel::RequestOpenSceneAsset(const AssetEntry& asset) { - return m_requestOpenSceneAsset != nullptr && - m_requestOpenSceneAsset(m_sceneAssetOpenRequester, asset.absolutePath); + return static_cast(m_requestOpenSceneAsset) && + m_requestOpenSceneAsset(asset.absolutePath); } bool ProjectPanel::OpenProjectItem(std::string_view itemId, EventSource source) { diff --git a/editor/app/Features/Project/ProjectPanel.h b/editor/app/Features/Project/ProjectPanel.h index 1a1300b6..7c124b36 100644 --- a/editor/app/Features/Project/ProjectPanel.h +++ b/editor/app/Features/Project/ProjectPanel.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -81,16 +82,13 @@ public: bool directory = false; }; - using SceneAssetOpenRequestFn = bool (*)( - void*, - const std::filesystem::path&); + using SceneAssetOpenRequestCallback = + std::function; void SetProjectRuntime(EditorProjectRuntime* projectRuntime); void SetCommandFocusService(EditorCommandFocusService* commandFocusService); void SetSystemInteractionHost(System::SystemInteractionService* systemInteractionHost); - void SetSceneAssetOpenRequestHandler( - void* requester, - SceneAssetOpenRequestFn requestOpenSceneAsset); + void SetSceneAssetOpenRequestHandler(SceneAssetOpenRequestCallback requestOpenSceneAsset); void SetIconService(EditorIconService* icons); void SetTextMeasurer(const ::XCEngine::UI::Editor::UIEditorTextMeasurer* textMeasurer); void ResetInteractionState(); @@ -257,8 +255,7 @@ private: EditorProjectRuntime* m_projectRuntime = nullptr; EditorCommandFocusService* m_commandFocusService = nullptr; System::SystemInteractionService* m_systemInteractionHost = nullptr; - void* m_sceneAssetOpenRequester = nullptr; - SceneAssetOpenRequestFn m_requestOpenSceneAsset = nullptr; + SceneAssetOpenRequestCallback m_requestOpenSceneAsset = {}; EditorIconService* m_icons = nullptr; const ::XCEngine::UI::Editor::UIEditorTextMeasurer* m_textMeasurer = nullptr; std::vector m_windowTreeItems = {};