重构UI架构:分离数据模型和显示逻辑
- 新增 Core 模块:GameObject、LogEntry、AssetItem 数据模型 - 新增 Managers 模块:SceneManager、LogSystem、ProjectManager - Panel 层只负责显示,不再持有数据 - 解耦 HierarchyPanel 和 InspectorPanel 之间的直接依赖
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include "InspectorPanel.h"
|
||||
#include "Managers/SceneManager.h"
|
||||
#include "Core/GameObject.h"
|
||||
#include <imgui.h>
|
||||
|
||||
namespace UI {
|
||||
@@ -8,18 +10,22 @@ InspectorPanel::InspectorPanel() : Panel("Inspector") {}
|
||||
void InspectorPanel::Render() {
|
||||
ImGui::Begin(m_name.c_str(), &m_isOpen, ImGuiWindowFlags_None);
|
||||
|
||||
GameObject* selected = nullptr;
|
||||
if (m_hierarchyPanel) {
|
||||
selected = m_hierarchyPanel->GetSelectedObject();
|
||||
}
|
||||
GameObject* selected = SceneManager::Get().GetSelectedObject();
|
||||
|
||||
if (selected) {
|
||||
ImGui::Text("%s", selected->name.c_str());
|
||||
ImGui::Separator();
|
||||
|
||||
RenderTransformSection();
|
||||
ImGui::Separator();
|
||||
RenderMeshRendererSection();
|
||||
auto transform = selected->GetComponent<TransformComponent>();
|
||||
if (transform) {
|
||||
RenderTransformSection(transform);
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
auto meshRenderer = selected->GetComponent<MeshRendererComponent>();
|
||||
if (meshRenderer) {
|
||||
RenderMeshRendererSection(meshRenderer);
|
||||
}
|
||||
} else {
|
||||
ImGui::Text("No object selected");
|
||||
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Select an object in Hierarchy");
|
||||
@@ -28,44 +34,42 @@ void InspectorPanel::Render() {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void InspectorPanel::RenderTransformSection() {
|
||||
void InspectorPanel::RenderTransformSection(TransformComponent* transform) {
|
||||
if (ImGui::CollapsingHeader("Transform", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::Indent(10.0f);
|
||||
|
||||
ImGui::Text("Position");
|
||||
ImGui::SameLine(80);
|
||||
ImGui::SetNextItemWidth(180);
|
||||
ImGui::DragFloat3("##Position", m_position, 0.1f);
|
||||
ImGui::DragFloat3("##Position", transform->position, 0.1f);
|
||||
|
||||
ImGui::Text("Rotation");
|
||||
ImGui::SameLine(80);
|
||||
ImGui::SetNextItemWidth(180);
|
||||
ImGui::DragFloat3("##Rotation", m_rotation, 1.0f);
|
||||
ImGui::DragFloat3("##Rotation", transform->rotation, 1.0f);
|
||||
|
||||
ImGui::Text("Scale");
|
||||
ImGui::SameLine(80);
|
||||
ImGui::SetNextItemWidth(180);
|
||||
ImGui::DragFloat3("##Scale", m_scale, 0.1f);
|
||||
ImGui::DragFloat3("##Scale", transform->scale, 0.1f);
|
||||
|
||||
ImGui::Unindent(10.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void InspectorPanel::RenderMeshRendererSection() {
|
||||
void InspectorPanel::RenderMeshRendererSection(MeshRendererComponent* meshRenderer) {
|
||||
if (ImGui::CollapsingHeader("Mesh Renderer", ImGuiTreeNodeFlags_DefaultOpen)) {
|
||||
ImGui::Indent(10.0f);
|
||||
|
||||
ImGui::Text("Material");
|
||||
ImGui::SameLine(80);
|
||||
ImGui::SetNextItemWidth(180);
|
||||
static char materialName[64] = "Default-Material";
|
||||
ImGui::InputText("##Material", materialName, sizeof(materialName));
|
||||
ImGui::InputText("##Material", meshRenderer->materialName.data(), meshRenderer->materialName.capacity());
|
||||
|
||||
ImGui::Text("Mesh");
|
||||
ImGui::SameLine(80);
|
||||
ImGui::SetNextItemWidth(180);
|
||||
static char meshName[64] = "Cube Mesh";
|
||||
ImGui::InputText("##Mesh", meshName, sizeof(meshName));
|
||||
ImGui::InputText("##Mesh", meshRenderer->meshName.data(), meshRenderer->meshName.capacity());
|
||||
|
||||
ImGui::Unindent(10.0f);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user