2026-03-20 17:08:06 +08:00
|
|
|
#include "ConsolePanel.h"
|
2026-03-25 16:13:02 +08:00
|
|
|
#include "Core/EditorConsoleSink.h"
|
|
|
|
|
#include <XCEngine/Debug/Logger.h>
|
2026-03-20 17:08:06 +08:00
|
|
|
#include <imgui.h>
|
|
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
namespace XCEngine {
|
|
|
|
|
namespace Editor {
|
2026-03-20 17:08:06 +08:00
|
|
|
|
|
|
|
|
ConsolePanel::ConsolePanel() : Panel("Console") {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConsolePanel::Render() {
|
|
|
|
|
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
|
|
|
|
|
|
|
|
|
if (ImGui::Button("Clear")) {
|
2026-03-25 16:13:02 +08:00
|
|
|
Debug::EditorConsoleSink::GetInstance()->Clear();
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|
|
|
|
|
ImGui::SameLine();
|
2026-03-25 12:30:05 +08:00
|
|
|
|
2026-03-25 12:56:51 +08:00
|
|
|
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Filter:");
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::Separator();
|
2026-03-25 12:30:05 +08:00
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, m_showInfo ? ImVec4(0.2f, 0.6f, 0.2f, 1.0f) : ImVec4(0.3f, 0.3f, 0.3f, 1.0f));
|
|
|
|
|
if (ImGui::Button("Info")) {
|
|
|
|
|
m_showInfo = !m_showInfo;
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, m_showWarning ? ImVec4(0.8f, 0.6f, 0.0f, 1.0f) : ImVec4(0.3f, 0.3f, 0.3f, 1.0f));
|
|
|
|
|
if (ImGui::Button("Warn")) {
|
|
|
|
|
m_showWarning = !m_showWarning;
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, m_showError ? ImVec4(0.8f, 0.2f, 0.2f, 1.0f) : ImVec4(0.3f, 0.3f, 0.3f, 1.0f));
|
|
|
|
|
if (ImGui::Button("Error")) {
|
|
|
|
|
m_showError = !m_showError;
|
|
|
|
|
}
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
|
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
|
|
ImGui::BeginChild("LogScroll", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
|
|
|
|
|
2026-03-25 16:13:02 +08:00
|
|
|
const auto& logs = Debug::EditorConsoleSink::GetInstance()->GetLogs();
|
2026-03-25 12:30:05 +08:00
|
|
|
size_t logIndex = 0;
|
2026-03-25 16:13:02 +08:00
|
|
|
for (const auto& log : logs) {
|
2026-03-25 12:30:05 +08:00
|
|
|
bool shouldShow = false;
|
|
|
|
|
switch (log.level) {
|
|
|
|
|
case ::XCEngine::Debug::LogLevel::Info:
|
2026-03-25 16:13:02 +08:00
|
|
|
case ::XCEngine::Debug::LogLevel::Verbose:
|
|
|
|
|
case ::XCEngine::Debug::LogLevel::Debug:
|
2026-03-25 12:30:05 +08:00
|
|
|
shouldShow = m_showInfo;
|
|
|
|
|
break;
|
|
|
|
|
case ::XCEngine::Debug::LogLevel::Warning:
|
|
|
|
|
shouldShow = m_showWarning;
|
|
|
|
|
break;
|
|
|
|
|
case ::XCEngine::Debug::LogLevel::Error:
|
2026-03-25 16:13:02 +08:00
|
|
|
case ::XCEngine::Debug::LogLevel::Fatal:
|
2026-03-25 12:30:05 +08:00
|
|
|
shouldShow = m_showError;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!shouldShow) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImVec4 color;
|
|
|
|
|
const char* prefix;
|
|
|
|
|
|
|
|
|
|
switch (log.level) {
|
2026-03-25 16:13:02 +08:00
|
|
|
case ::XCEngine::Debug::LogLevel::Verbose:
|
|
|
|
|
case ::XCEngine::Debug::LogLevel::Debug:
|
2026-03-25 12:30:05 +08:00
|
|
|
case ::XCEngine::Debug::LogLevel::Info:
|
|
|
|
|
color = ImVec4(0.5f, 0.5f, 0.5f, 1.0f);
|
|
|
|
|
prefix = "[INFO] ";
|
|
|
|
|
break;
|
|
|
|
|
case ::XCEngine::Debug::LogLevel::Warning:
|
|
|
|
|
color = ImVec4(1.0f, 0.8f, 0.0f, 1.0f);
|
|
|
|
|
prefix = "[WARN] ";
|
|
|
|
|
break;
|
|
|
|
|
case ::XCEngine::Debug::LogLevel::Error:
|
2026-03-25 16:13:02 +08:00
|
|
|
case ::XCEngine::Debug::LogLevel::Fatal:
|
2026-03-25 12:30:05 +08:00
|
|
|
color = ImVec4(1.0f, 0.3f, 0.3f, 1.0f);
|
|
|
|
|
prefix = "[ERROR]";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::PushID(static_cast<int>(logIndex));
|
|
|
|
|
|
2026-03-25 16:13:02 +08:00
|
|
|
ImGui::TextColored(ImVec4(0.4f, 0.4f, 0.4f, 1.0f), "%s", log.message.CStr());
|
2026-03-25 12:30:05 +08:00
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
2026-03-25 16:13:02 +08:00
|
|
|
std::string fullMessage = std::string(prefix) + log.message.CStr();
|
2026-03-25 12:30:05 +08:00
|
|
|
ImGui::TextColored(color, "%s", fullMessage.c_str());
|
|
|
|
|
|
|
|
|
|
if (ImGui::IsItemClicked()) {
|
|
|
|
|
ImGui::SetClipboardText(fullMessage.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
|
logIndex++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
2026-03-20 17:08:06 +08:00
|
|
|
|
2026-03-24 20:02:38 +08:00
|
|
|
}
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|