extracting ui render function from the ECS components. Adding dynamic component display
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
#include "open_engine/scene/native_scriptable_entity.hpp"
|
||||
#include "open_engine/scene/scene_serializer.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
#include "open_engine/scene/components.hpp"
|
||||
|
||||
#include "open_engine/core/file_dialogs.hpp"
|
||||
#include "open_engine/core/time.hpp"
|
||||
|
||||
@@ -31,20 +31,9 @@ namespace OpenEngine {
|
||||
TagComponent(const TagComponent&) = default;
|
||||
TagComponent(const std::string& tag)
|
||||
: tag(tag) {}
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
char buffer[256];
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
std::strncpy(buffer, tag.c_str(), sizeof(buffer));
|
||||
|
||||
if (ImGui::InputText("##tagEditor", buffer, sizeof(buffer), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)
|
||||
|| (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)))
|
||||
tag = buffer;
|
||||
};
|
||||
};
|
||||
|
||||
struct TransformComponent
|
||||
struct TransformComponent
|
||||
{
|
||||
glm::vec3 translation = { 0.0f, 0.0f, 0.0f };
|
||||
glm::vec3 rotation = { 0.0f, 0.0f, 0.0f };
|
||||
@@ -64,18 +53,9 @@ namespace OpenEngine {
|
||||
|
||||
return transform;
|
||||
};
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
DrawVec3Control("Position", translation);
|
||||
glm::vec3 rotation_comp = glm::degrees(rotation);
|
||||
DrawVec3Control("Rotation", rotation_comp);
|
||||
rotation = glm::radians(rotation_comp);
|
||||
DrawVec3Control("Scale", scale);
|
||||
};
|
||||
};
|
||||
|
||||
struct SpriteRendererComponent
|
||||
struct SpriteRendererComponent
|
||||
{
|
||||
glm::vec4 color{ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
|
||||
@@ -83,14 +63,9 @@ namespace OpenEngine {
|
||||
SpriteRendererComponent(const SpriteRendererComponent&) = default;
|
||||
SpriteRendererComponent(const glm::vec4& color)
|
||||
: color(color) {}
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
ImGui::ColorEdit4("color", glm::value_ptr(color));
|
||||
};
|
||||
};
|
||||
|
||||
struct CameraComponent
|
||||
struct CameraComponent
|
||||
{
|
||||
SceneCamera camera;
|
||||
bool primary = true;
|
||||
@@ -98,65 +73,18 @@ namespace OpenEngine {
|
||||
|
||||
CameraComponent() = default;
|
||||
CameraComponent(const CameraComponent&) = default;
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{
|
||||
ImGui::Checkbox("Is primary", &primary);
|
||||
const char* projection_type_strings[] = {"Perspective", "Orthographic"};
|
||||
const char* current_projection_type = projection_type_strings[(int)camera.GetProjectionType()];
|
||||
|
||||
if (ImGui::BeginCombo("Projection", current_projection_type)) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
bool is_selected = current_projection_type == projection_type_strings[i];
|
||||
if (ImGui::Selectable(projection_type_strings[i], is_selected)) {
|
||||
current_projection_type = projection_type_strings[i];
|
||||
camera.SetProjectionType((SceneCamera::ProjectionType)i);
|
||||
}
|
||||
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
if (camera.GetProjectionType() == SceneCamera::ProjectionType::Perspective) {
|
||||
float fov = camera.GetVerticalFov();
|
||||
if (ImGui::DragFloat("Fov", &fov, 0.1f))
|
||||
camera.SetVerticalFov(fov);
|
||||
|
||||
float near_clip = camera.GetPerspectiveNearClip();
|
||||
if (ImGui::DragFloat("Near clip", &near_clip, 0.1f))
|
||||
camera.SetPerspectiveNearClip(near_clip);
|
||||
|
||||
float far_clip = camera.GetPerspectiveFarClip();
|
||||
if (ImGui::DragFloat("Far clip", &far_clip, 0.1f))
|
||||
camera.SetPerspectiveFarClip(far_clip);
|
||||
}
|
||||
else if (camera.GetProjectionType() == SceneCamera::ProjectionType::Orthographic) {
|
||||
ImGui::Checkbox("Has fixed aspect ratio", &fixed_aspect_ratio);
|
||||
float ortho_size = camera.GetOrthographicSize();
|
||||
if (ImGui::DragFloat("Orthographic size", &ortho_size, 0.1f))
|
||||
camera.SetOrthographicSize(ortho_size);
|
||||
|
||||
float near_clip = camera.GetOrthographicNearClip();
|
||||
if (ImGui::DragFloat("Near clip", &near_clip, 0.1f))
|
||||
camera.SetOrthographicNearClip(near_clip);
|
||||
|
||||
float far_clip = camera.GetOrthographicFarClip();
|
||||
if (ImGui::DragFloat("Far clip", &far_clip, 0.1f))
|
||||
camera.SetOrthographicFarClip(far_clip);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
struct NativeScriptComponent
|
||||
struct NativeScriptComponent
|
||||
{
|
||||
NativeScriptableEntity* instance = nullptr;
|
||||
|
||||
NativeScriptableEntity* (*InstanciateScript)();
|
||||
void (*DestroyInstanceScript)(NativeScriptComponent*);
|
||||
|
||||
void OnImGuiRender(Entity& entity)
|
||||
{};
|
||||
|
||||
template <typename T>
|
||||
void Bind()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user