2026-03-20 17:08:06 +08:00
|
|
|
#include "InspectorPanel.h"
|
|
|
|
|
#include "Managers/SceneManager.h"
|
|
|
|
|
#include "Managers/SelectionManager.h"
|
2026-03-24 20:02:38 +08:00
|
|
|
#include "UI/UI.h"
|
2026-03-20 17:08:06 +08:00
|
|
|
#include <imgui.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
namespace XCEngine {
|
|
|
|
|
namespace Editor {
|
2026-03-20 17:08:06 +08:00
|
|
|
|
|
|
|
|
InspectorPanel::InspectorPanel() : Panel("Inspector") {
|
2026-03-24 18:38:01 +08:00
|
|
|
m_selectionHandlerId = SelectionManager::Get().OnSelectionChanged.Subscribe([this](uint64_t) {
|
2026-03-20 17:08:06 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InspectorPanel::~InspectorPanel() {
|
|
|
|
|
SelectionManager::Get().OnSelectionChanged.Unsubscribe(m_selectionHandlerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InspectorPanel::Render() {
|
|
|
|
|
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
|
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
::XCEngine::Components::GameObject* entity = SelectionManager::Get().GetSelectedEntity();
|
2026-03-20 17:08:06 +08:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
void InspectorPanel::RenderEntity(::XCEngine::Components::GameObject* entity) {
|
2026-03-24 18:38:01 +08:00
|
|
|
ImGui::Text("%s", entity->GetName().c_str());
|
2026-03-20 17:08:06 +08:00
|
|
|
ImGui::Separator();
|
|
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
auto components = entity->GetComponents<::XCEngine::Components::Component>();
|
|
|
|
|
for (auto* component : components) {
|
|
|
|
|
RenderComponent(component);
|
2026-03-20 17:08:06 +08:00
|
|
|
ImGui::Separator();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
void InspectorPanel::RenderComponent(::XCEngine::Components::Component* component) {
|
2026-03-20 17:08:06 +08:00
|
|
|
if (!component) return;
|
|
|
|
|
|
|
|
|
|
const char* name = component->GetName().c_str();
|
|
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
std::string headerId = std::string(name) + "##" + std::to_string(reinterpret_cast<uintptr_t>(component));
|
2026-03-20 17:08:06 +08:00
|
|
|
|
|
|
|
|
if (ImGui::CollapsingHeader(headerId.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
|
|
|
|
|
ImGui::Indent(10.0f);
|
|
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
if (auto* transform = dynamic_cast<::XCEngine::Components::TransformComponent*>(component)) {
|
|
|
|
|
::XCEngine::Math::Vector3 position = transform->GetLocalPosition();
|
|
|
|
|
::XCEngine::Math::Vector3 rotation = transform->GetLocalEulerAngles();
|
|
|
|
|
::XCEngine::Math::Vector3 scale = transform->GetLocalScale();
|
2026-03-20 17:08:06 +08:00
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
if (UI::DrawVec3("Position", position, 0.0f, 80.0f, 0.1f)) {
|
2026-03-24 18:38:01 +08:00
|
|
|
transform->SetLocalPosition(position);
|
|
|
|
|
}
|
2026-03-20 17:08:06 +08:00
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
if (UI::DrawVec3("Rotation", rotation, 0.0f, 80.0f, 1.0f)) {
|
2026-03-24 18:38:01 +08:00
|
|
|
transform->SetLocalEulerAngles(rotation);
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
if (UI::DrawVec3("Scale", scale, 1.0f, 80.0f, 0.1f)) {
|
2026-03-24 18:38:01 +08:00
|
|
|
transform->SetLocalScale(scale);
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::Unindent(10.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
}
|
2026-03-24 20:02:38 +08:00
|
|
|
}
|