diff --git a/Engine/src/Engine/Camera/SceneCamera.h b/Engine/src/Engine/Camera/SceneCamera.h index 72da15a..957fc91 100644 --- a/Engine/src/Engine/Camera/SceneCamera.h +++ b/Engine/src/Engine/Camera/SceneCamera.h @@ -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; } diff --git a/Engine/src/Engine/Graphics/Renderer.h b/Engine/src/Engine/Graphics/Renderer.h index 2fd1b6e..6fd6c67 100644 --- a/Engine/src/Engine/Graphics/Renderer.h +++ b/Engine/src/Engine/Graphics/Renderer.h @@ -69,7 +69,6 @@ namespace Light { private: Renderer(GLFWwindow* windowHandle, Ref sharedContext); - void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint, Ref 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); diff --git a/Engine/src/Engine/Scene/Entity.h b/Engine/src/Engine/Scene/Entity.h index 76b5645..e9779b6 100644 --- a/Engine/src/Engine/Scene/Entity.h +++ b/Engine/src/Engine/Scene/Entity.h @@ -36,6 +36,12 @@ namespace Light { return m_Scene->m_Registry.has(m_Handle); } + template + inline void RemoveComponent() + { + m_Scene->m_Registry.remove(m_Handle); + } + inline bool IsValid() const { return m_Handle != entt::null && m_Scene != nullptr; } operator uint32_t() { return (uint32_t)m_Handle; } diff --git a/Engine/src/Platform/OS/Windows/wWindow.cpp b/Engine/src/Platform/OS/Windows/wWindow.cpp index 3f2c553..6ba9b85 100644 --- a/Engine/src/Platform/OS/Windows/wWindow.cpp +++ b/Engine/src/Platform/OS/Windows/wWindow.cpp @@ -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'"); } diff --git a/Mirror/src/MirrorLayer.h b/Mirror/src/MirrorLayer.h index 9f0e12c..ea7dd5c 100644 --- a/Mirror/src/MirrorLayer.h +++ b/Mirror/src/MirrorLayer.h @@ -3,7 +3,6 @@ #include "Panels/SceneHierarchyPanel.h" #include "Panels/PropertiesPanel.h" - #include namespace Light { diff --git a/Mirror/src/Panels/PropertiesPanel.cpp b/Mirror/src/Panels/PropertiesPanel.cpp index ed7b72a..94edba6 100644 --- a/Mirror/src/Panels/PropertiesPanel.cpp +++ b/Mirror/src/Panels/PropertiesPanel.cpp @@ -2,6 +2,8 @@ #include "Scene/Components.h" +#include "Utility/ResourceManager.h" + #include #include @@ -9,62 +11,48 @@ #include namespace Light { - + void PropertiesPanel::OnUserInterfaceUpdate() { ImGui::Begin("Properties"); - if(m_EntityContext.IsValid()) + if (m_EntityContext.IsValid()) { - if(m_EntityContext.HasComponent()) + if (m_EntityContext.HasComponent()) { auto& tagComponent = m_EntityContext.GetComponent(); 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()) + DrawComponent("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(); - - DrawVec3Control("Translation", transform.translation); - - ImGui::TreePop(); - } - } - - if (m_EntityContext.HasComponent()) + DrawComponent("SpriteRenderer Component", m_EntityContext, [&](auto& spriteRendererComponent) { - if (ImGui::TreeNodeEx((void*)typeid(SpriteRendererComponent).hash_code(), ImGuiTreeNodeFlags_DefaultOpen, "Sprite")) - { - auto& spriteRenderer = m_EntityContext.GetComponent(); - ImGui::ColorEdit4("Color", &spriteRenderer.tint[0]); + ImGui::ColorEdit4("Color", &spriteRendererComponent.tint[0]); + }); - ImGui::TreePop(); - } - } - if(m_EntityContext.HasComponent()) + DrawComponent("Camera Component", m_EntityContext, [&](auto& cameraComponent) { - auto& cameraComp = m_EntityContext.GetComponent(); - 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() ? ImGuiSelectableFlags_Disabled : NULL)) + m_EntityContext.AddComponent(Light::ResourceManager::GetTexture("awesomeface")); + + if (ImGui::Selectable("Camera", false, m_EntityContext.HasComponent() ? ImGuiSelectableFlags_Disabled : NULL)) + m_EntityContext.AddComponent(); + + 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 + void PropertiesPanel::DrawComponent(const std::string& name, Entity entity, UIFunction userInterfaceFunction) + { + if (!entity.HasComponent()) + return; + + auto& component = entity.GetComponent(); + + 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(); + + ImGui::EndPopup(); + } + + userInterfaceFunction(component); + ImGui::TreePop(); + + } + } + } \ No newline at end of file diff --git a/Mirror/src/Panels/PropertiesPanel.h b/Mirror/src/Panels/PropertiesPanel.h index 4aa8a6e..e51963b 100644 --- a/Mirror/src/Panels/PropertiesPanel.h +++ b/Mirror/src/Panels/PropertiesPanel.h @@ -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 + void DrawComponent(const std::string& name, Entity entity, UIFunction function); }; + } \ No newline at end of file