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:
@@ -1,6 +1,6 @@
|
||||
#include "InspectorPanel.h"
|
||||
#include "Core/EditorContextImpl.h"
|
||||
#include "Managers/SceneManager.h"
|
||||
#include "Managers/SelectionManager.h"
|
||||
#include "UI/UI.h"
|
||||
#include <XCEngine/Debug/Logger.h>
|
||||
#include <imgui.h>
|
||||
@@ -11,23 +11,40 @@ namespace Editor {
|
||||
|
||||
InspectorPanel::InspectorPanel() : Panel("Inspector") {
|
||||
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() {
|
||||
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() {
|
||||
Debug::Logger::Get().Debug(Debug::LogCategory::General, "InspectorPanel::Render START");
|
||||
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) {
|
||||
RenderGameObject(m_selectedGameObject);
|
||||
m_selectedEntityId = m_context->GetSelectionManager().GetSelectedEntity();
|
||||
|
||||
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 {
|
||||
ImGui::Text("No object selected");
|
||||
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Select an object in Hierarchy");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Panel.h"
|
||||
#include <XCEngine/Components/GameObject.h>
|
||||
#include <XCEngine/Components/TransformComponent.h>
|
||||
|
||||
namespace XCEngine {
|
||||
@@ -19,9 +18,10 @@ private:
|
||||
void RenderAddComponentPopup(::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 OnSelectionChanged(const struct SelectionChangedEvent& event);
|
||||
|
||||
uint64_t m_selectionHandlerId = 0;
|
||||
::XCEngine::Components::GameObject* m_selectedGameObject = nullptr;
|
||||
uint64_t m_selectedEntityId = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user