Make HierarchyPanel use EventBus for selection changes
- Subscribe to SelectionChangedEvent via EventBus in OnAttach - Unsubscribe in destructor - Added m_selectionHandlerId and m_needsRefresh members - HierarchyPanel now properly receives selection change notifications
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "HierarchyPanel.h"
|
||||
#include "Core/IEditorContext.h"
|
||||
#include "Core/ISceneManager.h"
|
||||
#include "Core/ISelectionManager.h"
|
||||
#include "Core/EditorEvents.h"
|
||||
#include "Core/EventBus.h"
|
||||
#include <XCEngine/Core/Math/Vector3.h>
|
||||
#include <XCEngine/Core/Math/Quaternion.h>
|
||||
#include <imgui.h>
|
||||
@@ -13,11 +16,24 @@ HierarchyPanel::HierarchyPanel() : Panel("Hierarchy") {
|
||||
}
|
||||
|
||||
HierarchyPanel::~HierarchyPanel() {
|
||||
if (m_context) {
|
||||
m_context->GetEventBus().Unsubscribe<SelectionChangedEvent>(m_selectionHandlerId);
|
||||
}
|
||||
}
|
||||
|
||||
void HierarchyPanel::OnAttach() {
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
sceneManager.CreateDemoScene();
|
||||
|
||||
m_selectionHandlerId = m_context->GetEventBus().Subscribe<SelectionChangedEvent>(
|
||||
[this](const SelectionChangedEvent& event) {
|
||||
OnSelectionChanged(event);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void HierarchyPanel::OnSelectionChanged(const SelectionChangedEvent& event) {
|
||||
m_needsRefresh = true;
|
||||
}
|
||||
|
||||
void HierarchyPanel::Render() {
|
||||
|
||||
Reference in New Issue
Block a user