添加ui_editor编辑器模块初始代码
This commit is contained in:
70
ui_editor/src/panels/ConsolePanel.cpp
Normal file
70
ui_editor/src/panels/ConsolePanel.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "ConsolePanel.h"
|
||||
#include "Managers/LogSystem.h"
|
||||
#include "Core/LogEntry.h"
|
||||
#include <imgui.h>
|
||||
|
||||
namespace UI {
|
||||
|
||||
ConsolePanel::ConsolePanel() : Panel("Console") {
|
||||
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(), nullptr, ImGuiWindowFlags_None);
|
||||
|
||||
if (ImGui::Button("Clear")) {
|
||||
LogSystem::Get().Clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Info")) {
|
||||
LogSystem::Get().AddLog(LogEntry::Level::Info, "Test info message");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Warn")) {
|
||||
LogSystem::Get().AddLog(LogEntry::Level::Warning, "Test warning message");
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Error")) {
|
||||
LogSystem::Get().AddLog(LogEntry::Level::Error, "Test error message");
|
||||
}
|
||||
|
||||
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) {
|
||||
case LogEntry::Level::Info:
|
||||
color = ImVec4(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
prefix = "[Info] ";
|
||||
break;
|
||||
case LogEntry::Level::Warning:
|
||||
color = ImVec4(1.0f, 0.8f, 0.0f, 1.0f);
|
||||
prefix = "[Warn] ";
|
||||
break;
|
||||
case LogEntry::Level::Error:
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user