#include "Inspector.h" #include "../TransformVec3.h" void Inspector::Draw() { if (selected.isValid()) { AddComponentDropDown(); ShowComponents(); } } void AddComponent(YoggieEngine::Entity selected , int i) { switch (i) { case 0: selected.AddComponent(); break; case 1: selected.AddComponent(); break; case 2: selected.AddComponent(); break; case 3: selected.AddComponent(); default: break; } } void Inspector::AddComponentDropDown() { static char* names[] = { "Script Component", "Camera Component", "Light Component", "Render3D"}; if (ImGui::Button("Add Component")) ImGui::OpenPopup("Component picker"); ImGui::SameLine(); if (ImGui::BeginPopup("Component picker")) { for (int i = 0; i < IM_ARRAYSIZE(names); i++) { if (ImGui::MenuItem(names[i])) AddComponent(selected, i); } ImGui::EndPopup(); } ImGui::NewLine(); } void Inspector::ShowComponents() { auto component = selected.GetComponent(); ImGui::InputText("Name:", (char*)component.name.c_str(), component.name.size() * sizeof(char), ImGuiInputTextFlags_ReadOnly); if (selected.HasComponent()) { auto& transform = selected.GetComponent(); if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) { /* ImGui::DragFloat3("Position", glm::value_ptr(transform.Position), 0.1f); ImGui::DragFloat3("Rotation", glm::value_ptr(transform.Rotation), 0.1f); ImGui::DragFloat3("Scale", glm::value_ptr(transform.Scale), 0.1f, 0.0f); */ auto something = glm::value_ptr(transform.Position); ImGuiExtension::TransformVec3("Position", transform.Position); ImGuiExtension::TransformVec3("Rotation", transform.Rotation); ImGuiExtension::TransformVec3("Scale", transform.Scale); } if (selected.HasComponent()) { ImGui::Text("Has relation"); } } if (selected.HasComponent()) { auto& render3d = selected.GetComponent(); const char* AssetNames[]{ "Asset1" , "Asset2" }; if (ImGui::CollapsingHeader("Render3D", ImGuiTreeNodeFlags_DefaultOpen)) { if (ImGui::Button("Select Renderable Asset")) ImGui::OpenPopup("Renderable_list_popup"); ImGui::SameLine(); ImGui::TextUnformatted(render3d.mesh.elements.empty() ? "" : "ASSET_GUID_OR_ID"); if (ImGui::BeginPopup("Renderable_list_popup")) { ImGui::Text("None"); ImGui::Separator(); for (int i = 0; i < IM_ARRAYSIZE(AssetNames); i++) { if(ImGui::Selectable(AssetNames[i])) { } } ImGui::EndPopup(); } ImGui::ColorEdit3("Colour", glm::value_ptr(render3d.color)); ImGui::Checkbox("Use static rendering:", &render3d.isStatic); } } static bool deferred = true; if (selected.HasComponent()) { auto& light = selected.GetComponent(); if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::ColorEdit3("Colour", glm::value_ptr(light.Color)); ImGui::Checkbox("Deferred", &deferred); } } if (selected.HasComponent ()) { auto& camera = selected.GetComponent(); if (ImGui::CollapsingHeader("Camera")) { ImGui::DragFloat3("Position:", glm::value_ptr(camera.Position), 0.01f); ImGui::DragFloat3("Rotation:", glm::value_ptr(camera.Rotation), 0.01f); } } if (selected.HasComponent()) { auto& rigibody = selected.GetComponent(); if (ImGui::CollapsingHeader("RigidBody")) { } } if (selected.HasComponent()) { const char* AssetNames[]{ "Script 1" , "Script 2" }; if (ImGui::CollapsingHeader("Script", ImGuiTreeNodeFlags_Leaf)) { if (ImGui::Button("Select Renderable Asset")) ImGui::OpenPopup("Scripts_list_popup"); if (ImGui::BeginPopup("Scripts_list_popup")) { ImGui::Text("None"); ImGui::Separator(); for (int i = 0; i < IM_ARRAYSIZE(AssetNames); i++) { if (ImGui::Selectable(AssetNames[i])) { } } ImGui::EndPopup(); } ImGui::SameLine(); std::string scriptAssetId = ""; ImGui::InputText("asset", scriptAssetId.data(), scriptAssetId.length(), ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_AutoSelectAll); } } } void ComponentView(const std::string& componentName, voidFunction func) { ImGuiWindowFlags_ window_flags = ImGuiWindowFlags_None; ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f); ImGui::BeginChild(componentName.c_str()); func(); ImGui::EndChild(); ImGui::PopStyleVar(); }