DrawComponeent, RemoveComponent
- Added DrawComponent to PropertiesPanel - Added RemoveComponet to Entity - Maintenance
This commit is contained in:
parent
c5cd73737a
commit
b39518c74c
7 changed files with 81 additions and 41 deletions
|
@ -53,7 +53,7 @@ namespace Light {
|
|||
inline float GetOrthographicFarPlane() const { return m_OrthographicSpecification.farPlane; }
|
||||
inline float GetOrthographicNearPlane() const { return m_OrthographicSpecification.nearPlane; }
|
||||
|
||||
inline float GetPerspectiveverticalFOV() const { return m_PerspectiveSpecification.verticalFOV; }
|
||||
inline float GetPerspectiveVerticalFOV() const { return m_PerspectiveSpecification.verticalFOV; }
|
||||
inline float GetPerspectiveFarPlane() const { return m_PerspectiveSpecification.farPlane; }
|
||||
inline float GetPerspectiveNearPlane() const { return m_PerspectiveSpecification.nearPlane; }
|
||||
|
||||
|
|
|
@ -69,7 +69,6 @@ namespace Light {
|
|||
private:
|
||||
Renderer(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext);
|
||||
|
||||
|
||||
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint, Ref<Texture> texture);
|
||||
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint);
|
||||
void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, Ref<Texture> texture);
|
||||
|
|
|
@ -36,6 +36,12 @@ namespace Light {
|
|||
return m_Scene->m_Registry.has<T>(m_Handle);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void RemoveComponent()
|
||||
{
|
||||
m_Scene->m_Registry.remove<T>(m_Handle);
|
||||
}
|
||||
|
||||
inline bool IsValid() const { return m_Handle != entt::null && m_Scene != nullptr; }
|
||||
|
||||
operator uint32_t() { return (uint32_t)m_Handle; }
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace Light {
|
|||
BindGlfwEvents();
|
||||
|
||||
// create graphics context
|
||||
m_GraphicsContext = GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle);
|
||||
m_GraphicsContext = GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle);
|
||||
LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create 'GraphicsContext'");
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "Panels/SceneHierarchyPanel.h"
|
||||
#include "Panels/PropertiesPanel.h"
|
||||
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace Light {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "Scene/Components.h"
|
||||
|
||||
#include "Utility/ResourceManager.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
|
@ -9,62 +11,48 @@
|
|||
#include <imgui_internal.h>
|
||||
|
||||
namespace Light {
|
||||
|
||||
|
||||
void PropertiesPanel::OnUserInterfaceUpdate()
|
||||
{
|
||||
ImGui::Begin("Properties");
|
||||
|
||||
if(m_EntityContext.IsValid())
|
||||
if (m_EntityContext.IsValid())
|
||||
{
|
||||
if(m_EntityContext.HasComponent<TagComponent>())
|
||||
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);
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
if(m_EntityContext.HasComponent<TransformComponent>())
|
||||
DrawComponent<TransformComponent>("Transform Component", m_EntityContext, [&](auto& transformComponent)
|
||||
{
|
||||
DrawVec3Control("Translation", transformComponent.translation);
|
||||
});
|
||||
|
||||
if (ImGui::TreeNodeEx((void*)typeid(TransformComponent).hash_code(), ImGuiTreeNodeFlags_DefaultOpen, "Transform"))
|
||||
{
|
||||
auto& transform = m_EntityContext.GetComponent<TransformComponent>();
|
||||
|
||||
DrawVec3Control("Translation", transform.translation);
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
if (m_EntityContext.HasComponent<SpriteRendererComponent>())
|
||||
DrawComponent<SpriteRendererComponent>("SpriteRenderer Component", m_EntityContext, [&](auto& spriteRendererComponent)
|
||||
{
|
||||
if (ImGui::TreeNodeEx((void*)typeid(SpriteRendererComponent).hash_code(), ImGuiTreeNodeFlags_DefaultOpen, "Sprite"))
|
||||
{
|
||||
auto& spriteRenderer = m_EntityContext.GetComponent<SpriteRendererComponent>();
|
||||
ImGui::ColorEdit4("Color", &spriteRenderer.tint[0]);
|
||||
ImGui::ColorEdit4("Color", &spriteRendererComponent.tint[0]);
|
||||
});
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
if(m_EntityContext.HasComponent<CameraComponent>())
|
||||
DrawComponent<CameraComponent>("Camera Component", m_EntityContext, [&](auto& cameraComponent)
|
||||
{
|
||||
auto& cameraComp = m_EntityContext.GetComponent<CameraComponent>();
|
||||
auto& camera = cameraComp.camera;
|
||||
auto& camera = cameraComponent.camera;
|
||||
|
||||
SceneCamera::ProjectionType projectionType = camera.GetProjectionType();
|
||||
const char* projectionTypesString[] = { "Orthographic", "Perspective" };
|
||||
|
||||
if(ImGui::BeginCombo("ProjectionType", projectionTypesString[(int)projectionType]))
|
||||
if (ImGui::BeginCombo("ProjectionType", projectionTypesString[(int)projectionType]))
|
||||
{
|
||||
for(int i = 0; i < 2; i++)
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
const bool isSelected = (int)projectionType == i;
|
||||
if (ImGui::Selectable(projectionTypesString[i], isSelected))
|
||||
|
@ -80,7 +68,7 @@ namespace Light {
|
|||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
if(projectionType == SceneCamera::ProjectionType::Orthographic)
|
||||
if (projectionType == SceneCamera::ProjectionType::Orthographic)
|
||||
{
|
||||
float orthoSize, nearPlane, farPlane;
|
||||
|
||||
|
@ -88,13 +76,13 @@ namespace Light {
|
|||
nearPlane = camera.GetOrthographicNearPlane();
|
||||
farPlane = camera.GetOrthographicFarPlane();
|
||||
|
||||
if(ImGui::DragFloat("Orthographic Size", &orthoSize))
|
||||
if (ImGui::DragFloat("Orthographic Size", &orthoSize))
|
||||
camera.SetOrthographicSize(orthoSize);
|
||||
|
||||
if (ImGui::DragFloat("Near Plane", &nearPlane))
|
||||
camera.SetOrthographicNearPlane(nearPlane);
|
||||
|
||||
if(ImGui::DragFloat("Far Plane", &farPlane))
|
||||
|
||||
if (ImGui::DragFloat("Far Plane", &farPlane))
|
||||
camera.SetOrthographicFarPlane(farPlane);
|
||||
}
|
||||
|
||||
|
@ -102,7 +90,7 @@ namespace Light {
|
|||
{
|
||||
float verticalFOV, nearPlane, farPlane;
|
||||
|
||||
verticalFOV = glm::degrees(camera.GetPerspectiveverticalFOV());
|
||||
verticalFOV = glm::degrees(camera.GetPerspectiveVerticalFOV());
|
||||
nearPlane = camera.GetPerspectiveNearPlane();
|
||||
farPlane = camera.GetPerspectiveFarPlane();
|
||||
|
||||
|
@ -115,6 +103,22 @@ namespace Light {
|
|||
if (ImGui::DragFloat("Far Plane", &farPlane))
|
||||
camera.SetPerspectiveFarPlane(farPlane);
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
});
|
||||
|
||||
if (ImGui::Button("Add component", ImVec2(ImGui::GetContentRegionAvail().x, 20)))
|
||||
ImGui::OpenPopup("Components");
|
||||
|
||||
if (ImGui::BeginPopup("Components"))
|
||||
{
|
||||
if (ImGui::Selectable("SpriteRenderer", false, m_EntityContext.HasComponent<SpriteRendererComponent>() ? ImGuiSelectableFlags_Disabled : NULL))
|
||||
m_EntityContext.AddComponent<SpriteRendererComponent>(Light::ResourceManager::GetTexture("awesomeface"));
|
||||
|
||||
if (ImGui::Selectable("Camera", false, m_EntityContext.HasComponent<CameraComponent>() ? ImGuiSelectableFlags_Disabled : NULL))
|
||||
m_EntityContext.AddComponent<CameraComponent>();
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,7 +138,7 @@ namespace Light {
|
|||
ImGui::NextColumn();
|
||||
|
||||
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||
|
||||
float lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
||||
ImVec2 buttonSize = { lineHeight + 3.0f, lineHeight };
|
||||
|
@ -151,7 +155,6 @@ namespace Light {
|
|||
ImGui::PopItemWidth();
|
||||
ImGui::SameLine();
|
||||
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.7f, 0.2f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.3f, 0.8f, 0.3f, 1.0f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.2f, 0.7f, 0.2f, 1.0f));
|
||||
|
@ -180,4 +183,33 @@ namespace Light {
|
|||
ImGui::Columns(1);
|
||||
}
|
||||
|
||||
|
||||
template<typename ComponentType, typename UIFunction>
|
||||
void PropertiesPanel::DrawComponent(const std::string& name, Entity entity, UIFunction userInterfaceFunction)
|
||||
{
|
||||
if (!entity.HasComponent<ComponentType>())
|
||||
return;
|
||||
|
||||
auto& component = entity.GetComponent<ComponentType>();
|
||||
|
||||
if (ImGui::TreeNodeEx((void*)typeid(ComponentType).hash_code(), ImGuiTreeNodeFlags_DefaultOpen, name.c_str()))
|
||||
{
|
||||
ImGui::SameLine(ImGui::GetContentRegionAvail().x - 15.0f);
|
||||
if (ImGui::Button("+"))
|
||||
ImGui::OpenPopup("ComponentSettings");
|
||||
|
||||
if (ImGui::BeginPopup("ComponentSettings"))
|
||||
{
|
||||
if (ImGui::Selectable("Remove component"))
|
||||
entity.RemoveComponent<ComponentType>();
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
userInterfaceFunction(component);
|
||||
ImGui::TreePop();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,10 @@ namespace Light {
|
|||
|
||||
private:
|
||||
void DrawVec3Control(const std::string& label, glm::vec3& values, float resetValue = 0.0f, float columnWidth = 100.0f);
|
||||
|
||||
template<typename ComponentType, typename UIFunction>
|
||||
void DrawComponent(const std::string& name, Entity entity, UIFunction function);
|
||||
};
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue