2026-03-20 17:08:06 +08:00
|
|
|
#include "ConsolePanel.h"
|
|
|
|
|
#include "Managers/LogSystem.h"
|
|
|
|
|
#include "Core/LogEntry.h"
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
|
|
|
|
|
namespace UI {
|
|
|
|
|
|
|
|
|
|
ConsolePanel::ConsolePanel() : Panel("Console") {
|
2026-03-20 17:28:06 +08:00
|
|
|
LogSystem::Get().AddLog(XCEngine::Debug::LogLevel::Info, "Engine initialized successfully");
|
|
|
|
|
LogSystem::Get().AddLog(XCEngine::Debug::LogLevel::Info, "Loading default scene...");
|
|
|
|
|
LogSystem::Get().AddLog(XCEngine::Debug::LogLevel::Warning, "Missing material on object 'Cube'");
|
|
|
|
|
LogSystem::Get().AddLog(XCEngine::Debug::LogLevel::Error, "Failed to load texture: 'Assets/Textures/missing.png'");
|
|
|
|
|
LogSystem::Get().AddLog(XCEngine::Debug::LogLevel::Info, "Scene loaded successfully");
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConsolePanel::Render() {
|
|
|
|
|
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
|
|
|
|
|
|
|
|
|
if (ImGui::Button("Clear")) {
|
|
|
|
|
LogSystem::Get().Clear();
|
|
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("Info")) {
|
2026-03-20 17:28:06 +08:00
|
|
|
LogSystem::Get().AddLog(XCEngine::Debug::LogLevel::Info, "Test info message");
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("Warn")) {
|
2026-03-20 17:28:06 +08:00
|
|
|
LogSystem::Get().AddLog(XCEngine::Debug::LogLevel::Warning, "Test warning message");
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
if (ImGui::Button("Error")) {
|
2026-03-20 17:28:06 +08:00
|
|
|
LogSystem::Get().AddLog(XCEngine::Debug::LogLevel::Error, "Test error message");
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
ImGui::BeginChild("LogScroll", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
|
|
|
|
|
|
|
|
|
for (const auto& log : LogSystem::Get().GetLogs()) {
|
|
|
|
|
ImVec4 color;
|
|
|
|
|
const char* prefix;
|
|
|
|
|
|
|
|
|
|
switch (log.level) {
|
2026-03-20 17:28:06 +08:00
|
|
|
case XCEngine::Debug::LogLevel::Info:
|
2026-03-20 17:08:06 +08:00
|
|
|
color = ImVec4(0.7f, 0.7f, 0.7f, 1.0f);
|
|
|
|
|
prefix = "[Info] ";
|
|
|
|
|
break;
|
2026-03-20 17:28:06 +08:00
|
|
|
case XCEngine::Debug::LogLevel::Warning:
|
2026-03-20 17:08:06 +08:00
|
|
|
color = ImVec4(1.0f, 0.8f, 0.0f, 1.0f);
|
|
|
|
|
prefix = "[Warn] ";
|
|
|
|
|
break;
|
2026-03-20 17:28:06 +08:00
|
|
|
case XCEngine::Debug::LogLevel::Error:
|
2026-03-20 17:08:06 +08:00
|
|
|
color = ImVec4(1.0f, 0.3f, 0.3f, 1.0f);
|
|
|
|
|
prefix = "[Error]";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::TextColored(color, "%s%s", prefix, log.message.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_scrollToBottom) {
|
|
|
|
|
ImGui::SetScrollHereY(1.0f);
|
|
|
|
|
m_scrollToBottom = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|