PropertiesPanel
- Added PropertiesPanel
This commit is contained in:
parent
0c8b26360a
commit
54c195dae0
8 changed files with 7122 additions and 38219 deletions
44953
Dependencies/entt/entt.hpp
vendored
44953
Dependencies/entt/entt.hpp
vendored
File diff suppressed because it is too large
Load diff
|
@ -19,17 +19,25 @@ namespace Light {
|
||||||
~Entity();
|
~Entity();
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
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)...);
|
return m_Scene->m_Registry.emplace<T>(m_Handle, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& GetComponent()
|
inline T& GetComponent()
|
||||||
{
|
{
|
||||||
return m_Scene->m_Registry.get<T>(m_Handle);
|
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; }
|
operator uint32_t() { return (uint32_t)m_Handle; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ Collapsed=1
|
||||||
[Window][Dear ImGui Demo]
|
[Window][Dear ImGui Demo]
|
||||||
Pos=86,24
|
Pos=86,24
|
||||||
Size=247,278
|
Size=247,278
|
||||||
Collapsed=1
|
Collapsed=0
|
||||||
|
|
||||||
[Window][GameView]
|
[Window][GameView]
|
||||||
Pos=203,64
|
Pos=203,64
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include <LightEngine.h>
|
#include <LightEngine.h>
|
||||||
|
|
||||||
#include "Panels/SceneHierarchyPanel.h"
|
#include "Panels/SceneHierarchyPanel.h"
|
||||||
|
#include "Panels/PropertiesPanel.h"
|
||||||
|
|
||||||
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
@ -17,7 +19,8 @@ namespace Light {
|
||||||
Ref<Framebuffer> m_Framebuffer;
|
Ref<Framebuffer> m_Framebuffer;
|
||||||
|
|
||||||
Ref<Scene> m_Scene;
|
Ref<Scene> m_Scene;
|
||||||
SceneHierarchyPanel m_SceneHierarchyPanel;
|
Ref<SceneHierarchyPanel> m_SceneHierarchyPanel;
|
||||||
|
Ref<PropertiesPanel> m_PropertiesPanel;
|
||||||
|
|
||||||
Entity m_CameraEntity;
|
Entity m_CameraEntity;
|
||||||
Entity m_NativeScriptEntity;
|
Entity m_NativeScriptEntity;
|
||||||
|
@ -58,7 +61,6 @@ namespace Light {
|
||||||
private:
|
private:
|
||||||
void OnUpdate(float deltaTime)
|
void OnUpdate(float deltaTime)
|
||||||
{
|
{
|
||||||
LT_CLIENT_TRACE("NativeScript on update {}", deltaTime);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
m_NativeScriptEntity.AddComponent<NativeScriptComponent>().Bind<SampleNativeScript>();
|
m_NativeScriptEntity.AddComponent<NativeScriptComponent>().Bind<SampleNativeScript>();
|
||||||
|
@ -66,7 +68,9 @@ namespace Light {
|
||||||
|
|
||||||
// create native scripts
|
// create native scripts
|
||||||
m_Scene->OnCreate();
|
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
|
void OnUpdate(float deltaTime) override
|
||||||
|
@ -124,7 +128,8 @@ namespace Light {
|
||||||
|
|
||||||
ImGui::End();
|
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 "SceneHierarchyPanel.h"
|
||||||
|
|
||||||
|
#include "PropertiesPanel.h"
|
||||||
|
|
||||||
#include "Scene/Components.h"
|
#include "Scene/Components.h"
|
||||||
|
|
||||||
#include <entt.hpp>
|
#include <entt.hpp>
|
||||||
|
@ -8,22 +10,27 @@
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context)
|
SceneHierarchyPanel::SceneHierarchyPanel()
|
||||||
: m_Context(context)
|
: 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()
|
void SceneHierarchyPanel::OnUserInterfaceUpdate()
|
||||||
|
{
|
||||||
|
if(m_Context)
|
||||||
{
|
{
|
||||||
ImGui::Begin("Hierarchy");
|
ImGui::Begin("Hierarchy");
|
||||||
|
|
||||||
m_Context->m_Registry.
|
m_Context->m_Registry.
|
||||||
each([&](auto& entityID)
|
each([&](auto entityID)
|
||||||
{
|
{
|
||||||
Entity entity(entityID, m_Context.get());
|
Entity entity(entityID, m_Context.get());
|
||||||
const std::string& tag = entity.GetComponent<TagComponent>();
|
const std::string& tag = entity.GetComponent<TagComponent>();
|
||||||
|
@ -33,6 +40,15 @@ namespace Light {
|
||||||
|
|
||||||
ImGui::End();
|
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)
|
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());
|
bool expanded = ImGui::TreeNodeEx((void*)(uint64_t)(uint32_t)(entity), flags, label.c_str());
|
||||||
|
|
||||||
if (ImGui::IsItemClicked())
|
if (ImGui::IsItemClicked())
|
||||||
|
{
|
||||||
m_SelectionContext = entity;
|
m_SelectionContext = entity;
|
||||||
|
m_PropertiesPanelContext->SetEntityContext(entity);
|
||||||
|
}
|
||||||
|
|
||||||
if(expanded)
|
if(expanded)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,20 +9,23 @@
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
class PropertiesPanel;
|
||||||
|
|
||||||
class SceneHierarchyPanel : public Panel
|
class SceneHierarchyPanel : public Panel
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Ref<Scene> m_Context;
|
Ref<Scene> m_Context;
|
||||||
|
Ref<PropertiesPanel> m_PropertiesPanelContext;
|
||||||
Entity m_SelectionContext;
|
Entity m_SelectionContext;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SceneHierarchyPanel() = default;
|
SceneHierarchyPanel();
|
||||||
SceneHierarchyPanel(Ref<Scene> context);
|
SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel = nullptr);
|
||||||
|
|
||||||
void SetContext(Ref<Scene> context);
|
|
||||||
|
|
||||||
void OnUserInterfaceUpdate();
|
void OnUserInterfaceUpdate();
|
||||||
|
|
||||||
|
void SetContext(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DrawNode(Entity entity, const std::string& label);
|
void DrawNode(Entity entity, const std::string& label);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue