#include "InspectorPanel.h" #include "Managers/SceneManager.h" #include "Managers/SelectionManager.h" #include #include namespace UI { InspectorPanel::InspectorPanel() : Panel("Inspector") { m_selectionHandlerId = SelectionManager::Get().OnSelectionChanged.Subscribe([this](EntityID) { }); } InspectorPanel::~InspectorPanel() { SelectionManager::Get().OnSelectionChanged.Unsubscribe(m_selectionHandlerId); } void InspectorPanel::Render() { ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None); EntityID selectedId = SelectionManager::Get().GetSelectedEntity(); GameObject* entity = SceneManager::Get().GetEntity(selectedId); if (entity) { RenderEntity(entity); } else { ImGui::Text("No object selected"); ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Select an object in Hierarchy"); } ImGui::End(); } void InspectorPanel::RenderEntity(GameObject* entity) { ImGui::Text("%s", entity->name.c_str()); ImGui::Separator(); for (auto& component : entity->components) { RenderComponent(component.get()); ImGui::Separator(); } } void InspectorPanel::RenderComponent(Component* component) { if (!component) return; const char* name = component->GetName().c_str(); std::string headerId = name + std::string("##") + std::to_string(reinterpret_cast(component)); if (ImGui::CollapsingHeader(headerId.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) { ImGui::Indent(10.0f); if (auto* transform = dynamic_cast(component)) { ImGui::Text("Position"); ImGui::SameLine(80); ImGui::SetNextItemWidth(180); ImGui::DragFloat3("##Position", transform->position, 0.1f); ImGui::Text("Rotation"); ImGui::SameLine(80); ImGui::SetNextItemWidth(180); ImGui::DragFloat3("##Rotation", transform->rotation, 1.0f); ImGui::Text("Scale"); ImGui::SameLine(80); ImGui::SetNextItemWidth(180); ImGui::DragFloat3("##Scale", transform->scale, 0.1f); } else if (auto* meshRenderer = dynamic_cast(component)) { char materialBuffer[256] = {}; strncpy_s(materialBuffer, meshRenderer->materialName.c_str(), sizeof(materialBuffer) - 1); ImGui::Text("Material"); ImGui::SameLine(80); ImGui::SetNextItemWidth(180); if (ImGui::InputText("##Material", materialBuffer, sizeof(materialBuffer))) { meshRenderer->materialName = materialBuffer; } char meshBuffer[256] = {}; strncpy_s(meshBuffer, meshRenderer->meshName.c_str(), sizeof(meshBuffer) - 1); ImGui::Text("Mesh"); ImGui::SameLine(80); ImGui::SetNextItemWidth(180); if (ImGui::InputText("##Mesh", meshBuffer, sizeof(meshBuffer))) { meshRenderer->meshName = meshBuffer; } } ImGui::Unindent(10.0f); } } }