added color to logger window, and fixed little bug
forgot else if in deserialiser so it would thor random non existant errors
This commit is contained in:
parent
c7f163245a
commit
463e25e87c
@ -2,55 +2,66 @@ Entities:
|
||||
- ID: 0
|
||||
Name: Default
|
||||
Components:
|
||||
Mesh:
|
||||
vao: 1
|
||||
indexCount: 36
|
||||
textureID: 1
|
||||
Transform:
|
||||
Position: [0, 2.79999995, -12.6000004]
|
||||
Rotation: [0, 0.5, -20.6000004]
|
||||
Scale: [1, 1, 1]
|
||||
Mesh:
|
||||
vao: 1
|
||||
indexCount: 36
|
||||
textureID: 1
|
||||
- ID: 1
|
||||
Name: New GameObject 1
|
||||
Components:
|
||||
Mesh:
|
||||
vao: 3
|
||||
indexCount: 36
|
||||
textureID: 2
|
||||
Transform:
|
||||
Position: [-11.8999996, -2, -21.7999992]
|
||||
Rotation: [-9, -18.6000004, -28.1000004]
|
||||
Scale: [1, 1, 1]
|
||||
Mesh:
|
||||
vao: 1
|
||||
indexCount: 36
|
||||
textureID: 2
|
||||
- ID: 2
|
||||
Name: New GameObject 2
|
||||
Components:
|
||||
Mesh:
|
||||
vao: 4
|
||||
indexCount: 36
|
||||
textureID: 3
|
||||
Transform:
|
||||
Position: [7.80000019, -8.10000038, -20.6000004]
|
||||
Rotation: [-86.3000031, 0, -66]
|
||||
Scale: [1, 1, 1]
|
||||
Mesh:
|
||||
vao: 1
|
||||
indexCount: 36
|
||||
textureID: 3
|
||||
- ID: 3
|
||||
Name: New GameObject 3
|
||||
Components:
|
||||
Mesh:
|
||||
vao: 5
|
||||
indexCount: 36
|
||||
textureID: 4
|
||||
Transform:
|
||||
Position: [-1.20000005, -3.4000001, -17.7000008]
|
||||
Rotation: [-23.5, 15.8999996, -59.9000015]
|
||||
Scale: [1, 1, 1]
|
||||
Mesh:
|
||||
vao: 1
|
||||
indexCount: 36
|
||||
textureID: 4
|
||||
- ID: 4
|
||||
Name: New GameObject 4
|
||||
Components:
|
||||
Transform:
|
||||
Position: [8.10000038, 0.800000012, -12]
|
||||
Rotation: [-17.2999992, -16.1000004, -19.2999992]
|
||||
Scale: [1, 1, 1]
|
||||
Mesh:
|
||||
vao: 6
|
||||
vao: 1
|
||||
indexCount: 36
|
||||
textureID: 5
|
||||
- ID: 5
|
||||
Name: New GameObject 5
|
||||
Components:
|
||||
Mesh:
|
||||
vao: 4
|
||||
indexCount: 36
|
||||
textureID: 6
|
||||
Transform:
|
||||
Position: [6.80000019, 0.800000012, -12]
|
||||
Rotation: [-17.2999992, -16.1000004, -19.2999992]
|
||||
Position: [-5.9000001, 2.70000005, -11.6000004]
|
||||
Rotation: [-39.7000008, 0, -33.2000008]
|
||||
Scale: [1, 1, 1]
|
@ -83,7 +83,7 @@ void GameObject::Deserialize(const YAML::Node &node)
|
||||
transform->Deserialize(compNode);
|
||||
AddComponent(transform);
|
||||
}
|
||||
if (compName == MeshComponent::GetStaticName())
|
||||
else if (compName == MeshComponent::GetStaticName())
|
||||
{
|
||||
auto mesh = std::make_shared<MeshComponent>();
|
||||
mesh->Deserialize(compNode);
|
||||
|
@ -323,13 +323,14 @@ void MyEngine::ShowDockSpace()
|
||||
}
|
||||
if (ImGui::MenuItem("Save"))
|
||||
{
|
||||
m_LoggerWindow->AddLog("Saveing Scene");
|
||||
m_LoggerWindow->AddLog("Saveing Scene", ImVec4(0.3f, 1.0f, 0.3f, 1.0f));
|
||||
g_SceneManager.SaveScene(g_GameObjects, "./Default.scene");
|
||||
|
||||
}
|
||||
if (ImGui::MenuItem("Load"))
|
||||
{
|
||||
m_LoggerWindow->AddLog("Loading Scene");
|
||||
m_LoggerWindow->AddLog("Loading Scene", ImVec4(0.3f, 1.0f, 0.3f, 1.0f));
|
||||
|
||||
g_SceneManager.LoadScene(g_GameObjects, "./Default.scene");
|
||||
|
||||
|
||||
|
@ -5,27 +5,62 @@
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
|
||||
void LoggerWindow::AddLog(const char* fmt, ...)
|
||||
{
|
||||
// Helper function to format strings
|
||||
static std::string FormatString(const char* fmt, va_list args) {
|
||||
char buffer[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
m_Logs.push_back(buffer);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
void LoggerWindow::Show()
|
||||
{
|
||||
void LoggerWindow::AddLog(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
std::string formatted = FormatString(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
m_Logs.emplace_back(formatted);
|
||||
m_ScrollToBottom = true;
|
||||
}
|
||||
|
||||
void LoggerWindow::AddLog(const char* fmt, std::optional<ImVec4> color, ...) {
|
||||
va_list args;
|
||||
va_start(args, color);
|
||||
std::string formatted = FormatString(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
m_Logs.emplace_back(formatted, color);
|
||||
m_ScrollToBottom = true;
|
||||
}
|
||||
|
||||
void LoggerWindow::Show() {
|
||||
ImGui::Begin("Logger");
|
||||
|
||||
if (ImGui::Button("Clear"))
|
||||
if (ImGui::Button("Clear")) {
|
||||
m_Logs.clear();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
for (const auto& logLine : m_Logs)
|
||||
ImGui::TextUnformatted(logLine.c_str());
|
||||
|
||||
// Begin a child region to enable scrolling
|
||||
ImGui::BeginChild("LoggerScrollRegion", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||
|
||||
for (const auto& logEntry : m_Logs) {
|
||||
if (logEntry.color.has_value()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, logEntry.color.value());
|
||||
ImGui::TextUnformatted(logEntry.text.c_str());
|
||||
ImGui::PopStyleColor();
|
||||
} else {
|
||||
ImGui::TextUnformatted(logEntry.text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-scroll to bottom if new logs are added
|
||||
if (m_ScrollToBottom) {
|
||||
ImGui::SetScrollHereY(1.0f);
|
||||
m_ScrollToBottom = false;
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
@ -1,18 +1,27 @@
|
||||
// src/Windows/LoggerWindow.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <imgui.h>
|
||||
|
||||
class LoggerWindow
|
||||
{
|
||||
struct LogEntry {
|
||||
std::string text;
|
||||
std::optional<ImVec4> color;
|
||||
|
||||
LogEntry(const std::string& msg, std::optional<ImVec4> col = std::nullopt)
|
||||
: text(msg), color(col) {}
|
||||
};
|
||||
|
||||
class LoggerWindow {
|
||||
public:
|
||||
// Add logs from anywhere
|
||||
void AddLog(const char* fmt, ...);
|
||||
|
||||
// Show the ImGui window
|
||||
void AddLog(const char* fmt, std::optional<ImVec4> color, ...);
|
||||
void Show();
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_Logs;
|
||||
std::vector<LogEntry> m_Logs;
|
||||
bool m_ScrollToBottom = false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user