2727#include " Lux/Utilities/FileDialogs.h"
2828#include " Lux/Math/Math.h"
2929#include " Panels/TextEditorPanel.h"
30+ #include " Panels/SceneHierarchyPanel.h"
31+ #include " Panels/ContentBrowserPanel.h"
32+ #include " Panels/SceneRendererPanel.h"
3033
3134namespace Lux {
3235
@@ -125,7 +128,9 @@ namespace Lux {
125128 // ///////// Configure Panels ///////////
126129 m_PanelManager = CreateScope<PanelManager>();
127130
128- m_PanelManager->AddPanel <TextEditorPanel>(PanelCategory::View," TextEditorPanel" ," Text Editor" ,true );
131+ m_PanelManager->AddPanel <SceneHierarchyPanel>(PanelCategory::View, SCENE_HIERARCHY_PANEL_ID, " Scene Hierarchy" , true );
132+ m_PanelManager->AddPanel <ContentBrowserPanel>(PanelCategory::View, CONTENT_BROWSER_PANEL_ID, " Content Browser" , true );
133+ m_PanelManager->AddPanel <TextEditorPanel>(PanelCategory::View, " TextEditorPanel" , " Text Editor" , true );
129134
130135 Ref<SceneRendererPanel> sceneRendererPanel = m_PanelManager->AddPanel <SceneRendererPanel>(PanelCategory::View, SCENE_RENDERER_PANEL_ID, " Scene Renderer" , true );
131136
@@ -143,9 +148,6 @@ namespace Lux {
143148 // Light Settings panel
144149 m_PanelManager->AddPanel <LightSettingsPanel>(PanelCategory::View, " LightSettingsPanel" , " Light Settings" , true );
145150
146- // Render statistics panel
147- m_PanelManager->AddPanel <RenderStatsPanel>(PanelCategory::View, " RenderStatsPanel" , " Render Stats" , true );
148-
149151 m_IconPlay = TextureImporter::LoadTexture2D (" Resources/Editor/Viewport/Play.png" );
150152 m_IconPause = TextureImporter::LoadTexture2D (" Resources/Editor/Viewport/Pause.png" );
151153 m_IconSimulate = TextureImporter::LoadTexture2D (" Resources/Editor/Viewport/Simulate.png" );
@@ -171,8 +173,6 @@ namespace Lux {
171173 // Now safe to call - m_Renderer2D is valid.
172174 m_Renderer2D->SetTargetFramebuffer (m_Framebuffer);
173175
174- m_PanelManager->SetSceneContext (m_EditorScene);
175-
176176 EnsureSceneRenderer (m_ActiveScene, m_ViewportSize);
177177 sceneRendererPanel->SetContext (s_SceneRendererState.Renderer );
178178
@@ -187,12 +187,8 @@ namespace Lux {
187187 sceneRendererSpec.ViewportHeight = 720 ;
188188
189189 m_SceneRenderer = Ref<SceneRenderer>::Create (m_ActiveScene, sceneRendererSpec);
190- m_SceneRendererPanel.SetContext (m_SceneRenderer);
191-
192- // FIX: SetContext was never called in OnAttach, so the SceneHierarchyPanel
193- // had a null context on startup. Entities would not appear in the hierarchy
194- // and the Properties panel would never draw any components.
195- m_SceneHierarchyPanel.SetContext (m_EditorScene);
190+ m_PanelManager->SetSceneContext (m_EditorScene);
191+ m_PanelManager->OnProjectChanged (Project::GetActive ());
196192
197193 EnsureSceneRenderer (m_ActiveScene, m_ViewportSize);
198194 if (s_SceneRendererState.Renderer )
@@ -216,7 +212,6 @@ namespace Lux {
216212 m_IconStep.reset ();
217213 m_SquareVA.reset ();
218214 m_FlatColorShader.reset ();
219- m_ContentBrowserPanel.reset ();
220215 s_Font.reset ();
221216 }
222217
@@ -252,7 +247,9 @@ namespace Lux {
252247 m_Renderer2D->ResetStats ();
253248
254249 // Create selection predicate for 3D rendering (highlights selected entity)
255- Entity selectedEntity = m_SceneHierarchyPanel.GetSelectedEntity ();
250+ Entity selectedEntity = {};
251+ if (auto sceneHierarchyPanel = m_PanelManager->GetPanel <SceneHierarchyPanel>(SCENE_HIERARCHY_PANEL_ID))
252+ selectedEntity = sceneHierarchyPanel->GetSelectedEntity ();
256253 auto isEntitySelected = [selectedEntity](Entity entity) -> bool {
257254 return selectedEntity && entity == selectedEntity;
258255 };
@@ -384,14 +381,6 @@ namespace Lux {
384381 ImGui::EndMenuBar ();
385382 }
386383
387- m_SceneHierarchyPanel.OnImGuiRender ();
388-
389- // FIX 3: Guard ContentBrowserPanel - it is only created after a project
390- // is successfully opened via OpenProject(). Calling it unconditionally
391- // when no project is loaded causes a null pointer dereference crash.
392- if (m_ContentBrowserPanel)
393- m_ContentBrowserPanel->OnImGuiRender ();
394-
395384 m_PanelManager->OnImGuiRender ();
396385
397386 // Stats panel
@@ -465,7 +454,9 @@ namespace Lux {
465454 }
466455
467456 // Gizmos
468- Entity selectedEntity = m_SceneHierarchyPanel.GetSelectedEntity ();
457+ Entity selectedEntity = {};
458+ if (auto sceneHierarchyPanel = m_PanelManager->GetPanel <SceneHierarchyPanel>(SCENE_HIERARCHY_PANEL_ID))
459+ selectedEntity = sceneHierarchyPanel->GetSelectedEntity ();
469460 if (selectedEntity && m_GizmoType != -1 )
470461 {
471462 ImGuizmo::SetOrthographic (false );
@@ -673,7 +664,8 @@ namespace Lux {
673664 if (e.GetMouseButton () == MouseButton::Left)
674665 {
675666 if (m_ViewportHovered && !ImGuizmo::IsOver () && !Input::IsKeyPressed (Key::LeftAlt))
676- m_SceneHierarchyPanel.SetSelectedEntity (m_HoveredEntity);
667+ if (auto sceneHierarchyPanel = m_PanelManager->GetPanel <SceneHierarchyPanel>(SCENE_HIERARCHY_PANEL_ID))
668+ sceneHierarchyPanel->SetSelectedEntity (m_HoveredEntity);
677669 }
678670 return false ;
679671 }
@@ -743,7 +735,10 @@ namespace Lux {
743735 }
744736
745737 // Selected entity outline
746- if (Entity selectedEntity = m_SceneHierarchyPanel.GetSelectedEntity ())
738+ Entity selectedEntity = {};
739+ if (auto sceneHierarchyPanel = m_PanelManager->GetPanel <SceneHierarchyPanel>(SCENE_HIERARCHY_PANEL_ID))
740+ selectedEntity = sceneHierarchyPanel->GetSelectedEntity ();
741+ if (selectedEntity)
747742 {
748743 const TransformComponent& transform = selectedEntity.GetComponent <TransformComponent>();
749744 glm::mat4 t = transform.GetTransform ();
@@ -776,7 +771,7 @@ namespace Lux {
776771 AssetHandle startScene = Project::GetActive ()->GetConfig ().StartScene ;
777772 if (startScene)
778773 OpenScene (startScene);
779- m_ContentBrowserPanel = CreateScope<ContentBrowserPanel> (Project::GetActive ());
774+ m_PanelManager-> OnProjectChanged (Project::GetActive ());
780775 }
781776 }
782777
@@ -804,7 +799,7 @@ namespace Lux {
804799 m_EditorScene->OnViewportResize ((uint32_t )m_ViewportSize.x , (uint32_t )m_ViewportSize.y );
805800
806801 m_ActiveScene = m_EditorScene;
807- m_SceneHierarchyPanel. SetContext (m_ActiveScene);
802+ m_PanelManager-> SetSceneContext (m_ActiveScene);
808803 m_EditorScenePath = std::filesystem::path ();
809804
810805 if (m_SceneRenderer)
@@ -838,7 +833,7 @@ namespace Lux {
838833 m_EditorScene->OnViewportResize ((uint32_t )m_ViewportSize.x , (uint32_t )m_ViewportSize.y );
839834
840835 m_ActiveScene = m_EditorScene;
841- m_SceneHierarchyPanel. SetContext (m_EditorScene);
836+ m_PanelManager-> SetSceneContext (m_EditorScene);
842837 m_EditorScenePath = Project::GetActive ()->GetEditorAssetManager ()->GetFilePath (handle);
843838
844839 if (m_SceneRenderer)
@@ -888,7 +883,7 @@ namespace Lux {
888883 m_ActiveScene->OnViewportResize ((uint32_t )m_ViewportSize.x , (uint32_t )m_ViewportSize.y );
889884
890885 m_ActiveScene->OnRuntimeStart ();
891- m_SceneHierarchyPanel. SetContext (m_ActiveScene);
886+ m_PanelManager-> SetSceneContext (m_ActiveScene);
892887
893888 if (m_SceneRenderer)
894889 m_SceneRenderer->SetScene (m_ActiveScene);
@@ -914,7 +909,7 @@ namespace Lux {
914909 m_ActiveScene->OnViewportResize ((uint32_t )m_ViewportSize.x , (uint32_t )m_ViewportSize.y );
915910
916911 m_ActiveScene->OnSimulationStart ();
917- m_SceneHierarchyPanel. SetContext (m_ActiveScene);
912+ m_PanelManager-> SetSceneContext (m_ActiveScene);
918913
919914 if (m_SceneRenderer)
920915 m_SceneRenderer->SetScene (m_ActiveScene);
@@ -938,7 +933,7 @@ namespace Lux {
938933 m_SceneState = SceneState::Edit;
939934 m_ActiveScene = m_EditorScene;
940935
941- m_SceneHierarchyPanel. SetContext (m_ActiveScene);
936+ m_PanelManager-> SetSceneContext (m_ActiveScene);
942937
943938 if (m_SceneRenderer)
944939 m_SceneRenderer->SetScene (m_ActiveScene);
@@ -963,11 +958,15 @@ namespace Lux {
963958 if (m_SceneState != SceneState::Edit)
964959 return ;
965960
966- Entity selectedEntity = m_SceneHierarchyPanel.GetSelectedEntity ();
961+ Entity selectedEntity = {};
962+ Ref<SceneHierarchyPanel> sceneHierarchyPanel = m_PanelManager->GetPanel <SceneHierarchyPanel>(SCENE_HIERARCHY_PANEL_ID);
963+ if (sceneHierarchyPanel)
964+ selectedEntity = sceneHierarchyPanel->GetSelectedEntity ();
967965 if (selectedEntity)
968966 {
969967 Entity newEntity = m_EditorScene->DuplicateEntity (selectedEntity);
970- m_SceneHierarchyPanel.SetSelectedEntity (newEntity);
968+ if (sceneHierarchyPanel)
969+ sceneHierarchyPanel->SetSelectedEntity (newEntity);
971970 }
972971 }
973972}
0 commit comments