Migrate InspectorPanel to use IEditorContext and EventBus
- Replace SelectionManager::Get() singleton with m_context->GetSelectionManager() - Use EventBus for selection change events instead of direct subscription - Store entity ID (uint64_t) instead of GameObject* pointer - Resolve entity ID to GameObject* via SceneManager::GetEntity() - Remove direct includes of SelectionManager.h
This commit is contained in:
@@ -474,6 +474,12 @@ private:
|
|||||||
- `editor/src/Core/IEditorContext.h` - 编辑器上下文接口
|
- `editor/src/Core/IEditorContext.h` - 编辑器上下文接口
|
||||||
- `editor/src/Core/EditorContextImpl.h` - 编辑器上下文实现
|
- `editor/src/Core/EditorContextImpl.h` - 编辑器上下文实现
|
||||||
|
|
||||||
|
**2026-03-25 更新**:
|
||||||
|
- `editor/src/panels/HierarchyPanel.h/cpp` - 已迁移至 IEditorContext
|
||||||
|
- `editor/src/panels/InspectorPanel.h/cpp` - 已迁移至 IEditorContext + EventBus
|
||||||
|
- 移除了所有 Panel 中的 `SelectionManager::Get()` 和 `EditorSceneManager::Get()` 单例调用
|
||||||
|
- SceneManager::RenameEntity 实现已添加
|
||||||
|
|
||||||
### 阶段二:核心功能(第 3-4 周)
|
### 阶段二:核心功能(第 3-4 周)
|
||||||
|
|
||||||
| 任务 | 依赖 | 状态 |
|
| 任务 | 依赖 | 状态 |
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "InspectorPanel.h"
|
#include "InspectorPanel.h"
|
||||||
|
#include "Core/EditorContextImpl.h"
|
||||||
#include "Managers/SceneManager.h"
|
#include "Managers/SceneManager.h"
|
||||||
#include "Managers/SelectionManager.h"
|
|
||||||
#include "UI/UI.h"
|
#include "UI/UI.h"
|
||||||
#include <XCEngine/Debug/Logger.h>
|
#include <XCEngine/Debug/Logger.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@@ -11,23 +11,40 @@ namespace Editor {
|
|||||||
|
|
||||||
InspectorPanel::InspectorPanel() : Panel("Inspector") {
|
InspectorPanel::InspectorPanel() : Panel("Inspector") {
|
||||||
Debug::Logger::Get().Debug(Debug::LogCategory::General, "InspectorPanel constructed");
|
Debug::Logger::Get().Debug(Debug::LogCategory::General, "InspectorPanel constructed");
|
||||||
m_selectionHandlerId = SelectionManager::Get().OnSelectionChanged.Subscribe([this](uint64_t) {
|
|
||||||
m_selectedGameObject = SelectionManager::Get().GetSelectedEntity();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InspectorPanel::~InspectorPanel() {
|
InspectorPanel::~InspectorPanel() {
|
||||||
SelectionManager::Get().OnSelectionChanged.Unsubscribe(m_selectionHandlerId);
|
if (m_context) {
|
||||||
|
m_context->GetEventBus().Unsubscribe<SelectionChangedEvent>(m_selectionHandlerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InspectorPanel::OnSelectionChanged(const SelectionChangedEvent& event) {
|
||||||
|
m_selectedEntityId = event.primarySelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectorPanel::Render() {
|
void InspectorPanel::Render() {
|
||||||
Debug::Logger::Get().Debug(Debug::LogCategory::General, "InspectorPanel::Render START");
|
Debug::Logger::Get().Debug(Debug::LogCategory::General, "InspectorPanel::Render START");
|
||||||
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
||||||
|
|
||||||
m_selectedGameObject = SelectionManager::Get().GetSelectedEntity();
|
if (!m_selectionHandlerId && m_context) {
|
||||||
|
m_selectionHandlerId = m_context->GetEventBus().Subscribe<SelectionChangedEvent>(
|
||||||
|
[this](const SelectionChangedEvent& event) {
|
||||||
|
OnSelectionChanged(event);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_selectedGameObject) {
|
m_selectedEntityId = m_context->GetSelectionManager().GetSelectedEntity();
|
||||||
RenderGameObject(m_selectedGameObject);
|
|
||||||
|
if (m_selectedEntityId) {
|
||||||
|
auto* sceneManager = static_cast<SceneManager*>(m_context->GetSceneManager());
|
||||||
|
auto* gameObject = sceneManager->GetEntity(m_selectedEntityId);
|
||||||
|
if (gameObject) {
|
||||||
|
RenderGameObject(gameObject);
|
||||||
|
} else {
|
||||||
|
ImGui::Text("Object not found");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("No object selected");
|
ImGui::Text("No object selected");
|
||||||
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Select an object in Hierarchy");
|
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Select an object in Hierarchy");
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Panel.h"
|
#include "Panel.h"
|
||||||
#include <XCEngine/Components/GameObject.h>
|
|
||||||
#include <XCEngine/Components/TransformComponent.h>
|
#include <XCEngine/Components/TransformComponent.h>
|
||||||
|
|
||||||
namespace XCEngine {
|
namespace XCEngine {
|
||||||
@@ -19,9 +18,10 @@ private:
|
|||||||
void RenderAddComponentPopup(::XCEngine::Components::GameObject* gameObject);
|
void RenderAddComponentPopup(::XCEngine::Components::GameObject* gameObject);
|
||||||
void RenderComponent(::XCEngine::Components::Component* component, ::XCEngine::Components::GameObject* gameObject);
|
void RenderComponent(::XCEngine::Components::Component* component, ::XCEngine::Components::GameObject* gameObject);
|
||||||
void RemoveComponentByType(::XCEngine::Components::Component* component, ::XCEngine::Components::GameObject* gameObject);
|
void RemoveComponentByType(::XCEngine::Components::Component* component, ::XCEngine::Components::GameObject* gameObject);
|
||||||
|
void OnSelectionChanged(const struct SelectionChangedEvent& event);
|
||||||
|
|
||||||
uint64_t m_selectionHandlerId = 0;
|
uint64_t m_selectionHandlerId = 0;
|
||||||
::XCEngine::Components::GameObject* m_selectedGameObject = nullptr;
|
uint64_t m_selectedEntityId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user