PropertiesPanel
- Added PropertiesPanel
This commit is contained in:
		
							parent
							
								
									0c8b26360a
								
							
						
					
					
						commit
						54c195dae0
					
				
					 8 changed files with 7122 additions and 38219 deletions
				
			
		
							
								
								
									
										45181
									
								
								Dependencies/entt/entt.hpp
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										45181
									
								
								Dependencies/entt/entt.hpp
									
										
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
				
			
			@ -19,17 +19,25 @@ namespace Light {
 | 
			
		|||
		~Entity();
 | 
			
		||||
 | 
			
		||||
		template<typename T, typename... Args>
 | 
			
		||||
		T& AddComponent(Args&&... args)
 | 
			
		||||
		inline T& AddComponent(Args&&... args)
 | 
			
		||||
		{
 | 
			
		||||
			return m_Scene->m_Registry.emplace<T>(m_Handle, std::forward<Args>(args)...);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		template<typename T>
 | 
			
		||||
		T& GetComponent()
 | 
			
		||||
		inline T& GetComponent()
 | 
			
		||||
		{
 | 
			
		||||
			return m_Scene->m_Registry.get<T>(m_Handle);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		template <typename T>
 | 
			
		||||
		inline bool HasComponent()
 | 
			
		||||
		{
 | 
			
		||||
			return m_Scene->m_Registry.has<T>(m_Handle);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		inline bool IsValid() const { return m_Handle != entt::null && m_Scene != nullptr; }
 | 
			
		||||
 | 
			
		||||
		operator uint32_t() { return (uint32_t)m_Handle; }
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,7 +7,7 @@ Collapsed=1
 | 
			
		|||
[Window][Dear ImGui Demo]
 | 
			
		||||
Pos=86,24
 | 
			
		||||
Size=247,278
 | 
			
		||||
Collapsed=1
 | 
			
		||||
Collapsed=0
 | 
			
		||||
 | 
			
		||||
[Window][GameView]
 | 
			
		||||
Pos=203,64
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,8 @@
 | 
			
		|||
#include <LightEngine.h>
 | 
			
		||||
 | 
			
		||||
#include "Panels/SceneHierarchyPanel.h"
 | 
			
		||||
#include "Panels/PropertiesPanel.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <glm/gtc/matrix_transform.hpp>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -17,7 +19,8 @@ namespace Light {
 | 
			
		|||
		Ref<Framebuffer> m_Framebuffer;
 | 
			
		||||
 | 
			
		||||
		Ref<Scene> m_Scene;
 | 
			
		||||
		SceneHierarchyPanel m_SceneHierarchyPanel;
 | 
			
		||||
		Ref<SceneHierarchyPanel> m_SceneHierarchyPanel;
 | 
			
		||||
		Ref<PropertiesPanel> m_PropertiesPanel;
 | 
			
		||||
 | 
			
		||||
		Entity m_CameraEntity;
 | 
			
		||||
		Entity m_NativeScriptEntity;
 | 
			
		||||
| 
						 | 
				
			
			@ -58,7 +61,6 @@ namespace Light {
 | 
			
		|||
			private:
 | 
			
		||||
				void OnUpdate(float deltaTime) 
 | 
			
		||||
				{
 | 
			
		||||
					LT_CLIENT_TRACE("NativeScript on update {}", deltaTime); 
 | 
			
		||||
				}
 | 
			
		||||
			};
 | 
			
		||||
			m_NativeScriptEntity.AddComponent<NativeScriptComponent>().Bind<SampleNativeScript>();
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +68,9 @@ namespace Light {
 | 
			
		|||
 | 
			
		||||
			// create native scripts
 | 
			
		||||
			m_Scene->OnCreate();
 | 
			
		||||
			m_SceneHierarchyPanel.SetContext(m_Scene);
 | 
			
		||||
 | 
			
		||||
			m_PropertiesPanel = CreateRef<PropertiesPanel>();
 | 
			
		||||
			m_SceneHierarchyPanel = CreateRef<SceneHierarchyPanel>(m_Scene, m_PropertiesPanel);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		void OnUpdate(float deltaTime) override
 | 
			
		||||
| 
						 | 
				
			
			@ -124,7 +128,8 @@ namespace Light {
 | 
			
		|||
 | 
			
		||||
			ImGui::End();
 | 
			
		||||
 | 
			
		||||
			m_SceneHierarchyPanel.OnUserInterfaceUpdate();
 | 
			
		||||
			m_SceneHierarchyPanel->OnUserInterfaceUpdate();
 | 
			
		||||
			m_PropertiesPanel->OnUserInterfaceUpdate();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										54
									
								
								Mirror/src/Panels/PropertiesPanel.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								Mirror/src/Panels/PropertiesPanel.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,54 @@
 | 
			
		|||
#include "PropertiesPanel.h"
 | 
			
		||||
 | 
			
		||||
#include "Scene/Components.h"
 | 
			
		||||
 | 
			
		||||
#include <glm/glm.hpp>
 | 
			
		||||
#include <glm/gtc/type_ptr.hpp>
 | 
			
		||||
 | 
			
		||||
#include <imgui.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace Light {
 | 
			
		||||
	
 | 
			
		||||
	void PropertiesPanel::OnUserInterfaceUpdate()
 | 
			
		||||
	{
 | 
			
		||||
		ImGui::Begin("Properties");
 | 
			
		||||
 | 
			
		||||
		if(m_EntityContext.IsValid())
 | 
			
		||||
		{
 | 
			
		||||
			if(m_EntityContext.HasComponent<TagComponent>())
 | 
			
		||||
			{
 | 
			
		||||
				auto& tagComponent = m_EntityContext.GetComponent<TagComponent>();
 | 
			
		||||
 | 
			
		||||
				char buffer[256];
 | 
			
		||||
				memset(buffer, 0, sizeof(buffer));
 | 
			
		||||
				std::strncpy(buffer, tagComponent.tag.c_str(), sizeof(buffer));
 | 
			
		||||
				if (ImGui::InputText("##Tag", buffer, sizeof(buffer)))
 | 
			
		||||
				{
 | 
			
		||||
					LT_ENGINE_TRACE("bruh");
 | 
			
		||||
					tagComponent.tag = std::string(buffer);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if(m_EntityContext.HasComponent<TransformComponent>())
 | 
			
		||||
			{
 | 
			
		||||
 | 
			
		||||
				if (ImGui::TreeNodeEx((void*)typeid(TransformComponent).hash_code(), ImGuiTreeNodeFlags_DefaultOpen, "Transform"))
 | 
			
		||||
				{
 | 
			
		||||
					auto& transformComponent = m_EntityContext.GetComponent<TransformComponent>();
 | 
			
		||||
					ImGui::DragFloat3("Position", glm::value_ptr(transformComponent.transform[3]), 0.5f);
 | 
			
		||||
 | 
			
		||||
					ImGui::TreePop();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		ImGui::End();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void PropertiesPanel::SetEntityContext(Entity entity)
 | 
			
		||||
	{
 | 
			
		||||
		m_EntityContext = entity;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										23
									
								
								Mirror/src/Panels/PropertiesPanel.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Mirror/src/Panels/PropertiesPanel.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include "Panel.h"
 | 
			
		||||
 | 
			
		||||
#include "Scene/Entity.h"
 | 
			
		||||
 | 
			
		||||
namespace Light {
 | 
			
		||||
 | 
			
		||||
	class PropertiesPanel : public Panel
 | 
			
		||||
	{
 | 
			
		||||
	private:
 | 
			
		||||
		Entity m_EntityContext;
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		PropertiesPanel() = default;
 | 
			
		||||
		~PropertiesPanel() = default;
 | 
			
		||||
		
 | 
			
		||||
		void OnUserInterfaceUpdate();
 | 
			
		||||
 | 
			
		||||
		void SetEntityContext(Entity entity);
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,7 @@
 | 
			
		|||
#include "SceneHierarchyPanel.h"
 | 
			
		||||
 | 
			
		||||
#include "PropertiesPanel.h"
 | 
			
		||||
 | 
			
		||||
#include "Scene/Components.h"
 | 
			
		||||
 | 
			
		||||
#include <entt.hpp>
 | 
			
		||||
| 
						 | 
				
			
			@ -8,30 +10,44 @@
 | 
			
		|||
 | 
			
		||||
namespace Light {
 | 
			
		||||
 | 
			
		||||
	SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context)
 | 
			
		||||
		: m_Context(context)
 | 
			
		||||
	SceneHierarchyPanel::SceneHierarchyPanel()
 | 
			
		||||
		: m_Context(nullptr),
 | 
			
		||||
		  m_PropertiesPanelContext(nullptr),
 | 
			
		||||
		  m_SelectionContext()
 | 
			
		||||
	{
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void SceneHierarchyPanel::SetContext(Ref<Scene> context)
 | 
			
		||||
	SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
 | 
			
		||||
		: m_Context(context),
 | 
			
		||||
		  m_PropertiesPanelContext(propertiesPanel)
 | 
			
		||||
	{
 | 
			
		||||
		m_Context = context;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void SceneHierarchyPanel::OnUserInterfaceUpdate()
 | 
			
		||||
	{
 | 
			
		||||
		ImGui::Begin("Hierarchy");
 | 
			
		||||
 | 
			
		||||
		m_Context->m_Registry.
 | 
			
		||||
		each([&](auto& entityID)
 | 
			
		||||
		if(m_Context)
 | 
			
		||||
		{
 | 
			
		||||
			Entity entity(entityID, m_Context.get());
 | 
			
		||||
			const std::string& tag = entity.GetComponent<TagComponent>();
 | 
			
		||||
			ImGui::Begin("Hierarchy");
 | 
			
		||||
 | 
			
		||||
			DrawNode(entity, tag);
 | 
			
		||||
		});
 | 
			
		||||
			m_Context->m_Registry.
 | 
			
		||||
			each([&](auto entityID)
 | 
			
		||||
			{
 | 
			
		||||
				Entity entity(entityID, m_Context.get());
 | 
			
		||||
				const std::string& tag = entity.GetComponent<TagComponent>();
 | 
			
		||||
				
 | 
			
		||||
		ImGui::End();
 | 
			
		||||
				DrawNode(entity, tag);
 | 
			
		||||
			});
 | 
			
		||||
 | 
			
		||||
			ImGui::End();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void SceneHierarchyPanel::SetContext(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
 | 
			
		||||
	{
 | 
			
		||||
		if (propertiesPanel)
 | 
			
		||||
			m_PropertiesPanelContext = propertiesPanel;
 | 
			
		||||
 | 
			
		||||
		m_Context = context;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void SceneHierarchyPanel::DrawNode(Entity entity, const std::string& label)
 | 
			
		||||
| 
						 | 
				
			
			@ -43,7 +59,10 @@ namespace Light {
 | 
			
		|||
		bool expanded = ImGui::TreeNodeEx((void*)(uint64_t)(uint32_t)(entity), flags, label.c_str());
 | 
			
		||||
 | 
			
		||||
		if (ImGui::IsItemClicked())
 | 
			
		||||
		{
 | 
			
		||||
			m_SelectionContext = entity;
 | 
			
		||||
			m_PropertiesPanelContext->SetEntityContext(entity);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(expanded)
 | 
			
		||||
		{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,20 +9,23 @@
 | 
			
		|||
 | 
			
		||||
namespace Light {
 | 
			
		||||
 | 
			
		||||
	class PropertiesPanel;
 | 
			
		||||
 | 
			
		||||
	class SceneHierarchyPanel : public Panel
 | 
			
		||||
	{
 | 
			
		||||
	private:
 | 
			
		||||
		Ref<Scene> m_Context;
 | 
			
		||||
		Ref<PropertiesPanel> m_PropertiesPanelContext;
 | 
			
		||||
		Entity m_SelectionContext;
 | 
			
		||||
 | 
			
		||||
	public:
 | 
			
		||||
		SceneHierarchyPanel() = default;
 | 
			
		||||
		SceneHierarchyPanel(Ref<Scene> context);
 | 
			
		||||
 | 
			
		||||
		void SetContext(Ref<Scene> context);
 | 
			
		||||
		SceneHierarchyPanel();
 | 
			
		||||
		SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel = nullptr);
 | 
			
		||||
 | 
			
		||||
		void OnUserInterfaceUpdate();
 | 
			
		||||
 | 
			
		||||
		void SetContext(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel = nullptr);
 | 
			
		||||
 | 
			
		||||
	private:
 | 
			
		||||
		void DrawNode(Entity entity, const std::string& label);
 | 
			
		||||
	};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue