重构UI架构:分离数据模型和显示逻辑

- 新增 Core 模块:GameObject、LogEntry、AssetItem 数据模型
- 新增 Managers 模块:SceneManager、LogSystem、ProjectManager
- Panel 层只负责显示,不再持有数据
- 解耦 HierarchyPanel 和 InspectorPanel 之间的直接依赖
This commit is contained in:
2026-03-12 16:13:34 +08:00
parent 7d3e3b464d
commit a2f3db8718
19 changed files with 306 additions and 137 deletions

View File

@@ -1,40 +1,42 @@
#include "ConsolePanel.h"
#include "Managers/LogSystem.h"
#include "Core/LogEntry.h"
#include <imgui.h>
namespace UI {
ConsolePanel::ConsolePanel() : Panel("Console") {
m_logs.push_back({LogEntry::Level::Info, "Engine initialized successfully"});
m_logs.push_back({LogEntry::Level::Info, "Loading default scene..."});
m_logs.push_back({LogEntry::Level::Warning, "Missing material on object 'Cube'"});
m_logs.push_back({LogEntry::Level::Error, "Failed to load texture: 'Assets/Textures/missing.png'"});
m_logs.push_back({LogEntry::Level::Info, "Scene loaded successfully"});
LogSystem::Get().AddLog(LogEntry::Level::Info, "Engine initialized successfully");
LogSystem::Get().AddLog(LogEntry::Level::Info, "Loading default scene...");
LogSystem::Get().AddLog(LogEntry::Level::Warning, "Missing material on object 'Cube'");
LogSystem::Get().AddLog(LogEntry::Level::Error, "Failed to load texture: 'Assets/Textures/missing.png'");
LogSystem::Get().AddLog(LogEntry::Level::Info, "Scene loaded successfully");
}
void ConsolePanel::Render() {
ImGui::Begin(m_name.c_str(), &m_isOpen, ImGuiWindowFlags_None);
if (ImGui::Button("Clear")) {
Clear();
LogSystem::Get().Clear();
}
ImGui::SameLine();
if (ImGui::Button("Info")) {
AddLog(LogEntry::Level::Info, "Test info message");
LogSystem::Get().AddLog(LogEntry::Level::Info, "Test info message");
}
ImGui::SameLine();
if (ImGui::Button("Warn")) {
AddLog(LogEntry::Level::Warning, "Test warning message");
LogSystem::Get().AddLog(LogEntry::Level::Warning, "Test warning message");
}
ImGui::SameLine();
if (ImGui::Button("Error")) {
AddLog(LogEntry::Level::Error, "Test error message");
LogSystem::Get().AddLog(LogEntry::Level::Error, "Test error message");
}
ImGui::Separator();
ImGui::BeginChild("LogScroll", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
for (const auto& log : m_logs) {
for (const auto& log : LogSystem::Get().GetLogs()) {
ImVec4 color;
const char* prefix;
@@ -65,13 +67,4 @@ void ConsolePanel::Render() {
ImGui::End();
}
void ConsolePanel::AddLog(LogEntry::Level level, const std::string& message) {
m_logs.push_back({level, message});
m_scrollToBottom = true;
}
void ConsolePanel::Clear() {
m_logs.clear();
}
}