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
|
- ID: 0
|
||||||
Name: Default
|
Name: Default
|
||||||
Components:
|
Components:
|
||||||
Mesh:
|
|
||||||
vao: 1
|
|
||||||
indexCount: 36
|
|
||||||
textureID: 1
|
|
||||||
Transform:
|
Transform:
|
||||||
Position: [0, 2.79999995, -12.6000004]
|
Position: [0, 2.79999995, -12.6000004]
|
||||||
Rotation: [0, 0.5, -20.6000004]
|
Rotation: [0, 0.5, -20.6000004]
|
||||||
Scale: [1, 1, 1]
|
Scale: [1, 1, 1]
|
||||||
|
Mesh:
|
||||||
|
vao: 1
|
||||||
|
indexCount: 36
|
||||||
|
textureID: 1
|
||||||
- ID: 1
|
- ID: 1
|
||||||
Name: New GameObject 1
|
Name: New GameObject 1
|
||||||
Components:
|
Components:
|
||||||
Mesh:
|
|
||||||
vao: 3
|
|
||||||
indexCount: 36
|
|
||||||
textureID: 2
|
|
||||||
Transform:
|
Transform:
|
||||||
Position: [-11.8999996, -2, -21.7999992]
|
Position: [-11.8999996, -2, -21.7999992]
|
||||||
Rotation: [-9, -18.6000004, -28.1000004]
|
Rotation: [-9, -18.6000004, -28.1000004]
|
||||||
Scale: [1, 1, 1]
|
Scale: [1, 1, 1]
|
||||||
|
Mesh:
|
||||||
|
vao: 1
|
||||||
|
indexCount: 36
|
||||||
|
textureID: 2
|
||||||
- ID: 2
|
- ID: 2
|
||||||
Name: New GameObject 2
|
Name: New GameObject 2
|
||||||
Components:
|
Components:
|
||||||
Mesh:
|
|
||||||
vao: 4
|
|
||||||
indexCount: 36
|
|
||||||
textureID: 3
|
|
||||||
Transform:
|
Transform:
|
||||||
Position: [7.80000019, -8.10000038, -20.6000004]
|
Position: [7.80000019, -8.10000038, -20.6000004]
|
||||||
Rotation: [-86.3000031, 0, -66]
|
Rotation: [-86.3000031, 0, -66]
|
||||||
Scale: [1, 1, 1]
|
Scale: [1, 1, 1]
|
||||||
|
Mesh:
|
||||||
|
vao: 1
|
||||||
|
indexCount: 36
|
||||||
|
textureID: 3
|
||||||
- ID: 3
|
- ID: 3
|
||||||
Name: New GameObject 3
|
Name: New GameObject 3
|
||||||
Components:
|
Components:
|
||||||
Mesh:
|
|
||||||
vao: 5
|
|
||||||
indexCount: 36
|
|
||||||
textureID: 4
|
|
||||||
Transform:
|
Transform:
|
||||||
Position: [-1.20000005, -3.4000001, -17.7000008]
|
Position: [-1.20000005, -3.4000001, -17.7000008]
|
||||||
Rotation: [-23.5, 15.8999996, -59.9000015]
|
Rotation: [-23.5, 15.8999996, -59.9000015]
|
||||||
Scale: [1, 1, 1]
|
Scale: [1, 1, 1]
|
||||||
|
Mesh:
|
||||||
|
vao: 1
|
||||||
|
indexCount: 36
|
||||||
|
textureID: 4
|
||||||
- ID: 4
|
- ID: 4
|
||||||
Name: New GameObject 4
|
Name: New GameObject 4
|
||||||
Components:
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [8.10000038, 0.800000012, -12]
|
||||||
|
Rotation: [-17.2999992, -16.1000004, -19.2999992]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 6
|
vao: 1
|
||||||
indexCount: 36
|
indexCount: 36
|
||||||
textureID: 5
|
textureID: 5
|
||||||
|
- ID: 5
|
||||||
|
Name: New GameObject 5
|
||||||
|
Components:
|
||||||
|
Mesh:
|
||||||
|
vao: 4
|
||||||
|
indexCount: 36
|
||||||
|
textureID: 6
|
||||||
Transform:
|
Transform:
|
||||||
Position: [6.80000019, 0.800000012, -12]
|
Position: [-5.9000001, 2.70000005, -11.6000004]
|
||||||
Rotation: [-17.2999992, -16.1000004, -19.2999992]
|
Rotation: [-39.7000008, 0, -33.2000008]
|
||||||
Scale: [1, 1, 1]
|
Scale: [1, 1, 1]
|
@ -83,7 +83,7 @@ void GameObject::Deserialize(const YAML::Node &node)
|
|||||||
transform->Deserialize(compNode);
|
transform->Deserialize(compNode);
|
||||||
AddComponent(transform);
|
AddComponent(transform);
|
||||||
}
|
}
|
||||||
if (compName == MeshComponent::GetStaticName())
|
else if (compName == MeshComponent::GetStaticName())
|
||||||
{
|
{
|
||||||
auto mesh = std::make_shared<MeshComponent>();
|
auto mesh = std::make_shared<MeshComponent>();
|
||||||
mesh->Deserialize(compNode);
|
mesh->Deserialize(compNode);
|
||||||
|
@ -323,13 +323,14 @@ void MyEngine::ShowDockSpace()
|
|||||||
}
|
}
|
||||||
if (ImGui::MenuItem("Save"))
|
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");
|
g_SceneManager.SaveScene(g_GameObjects, "./Default.scene");
|
||||||
|
|
||||||
}
|
}
|
||||||
if (ImGui::MenuItem("Load"))
|
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");
|
g_SceneManager.LoadScene(g_GameObjects, "./Default.scene");
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,27 +5,62 @@
|
|||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <cstdio>
|
#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];
|
char buffer[1024];
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||||
va_end(args);
|
return std::string(buffer);
|
||||||
|
|
||||||
m_Logs.push_back(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");
|
ImGui::Begin("Logger");
|
||||||
|
|
||||||
if (ImGui::Button("Clear"))
|
if (ImGui::Button("Clear")) {
|
||||||
m_Logs.clear();
|
m_Logs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::Separator();
|
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();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,27 @@
|
|||||||
// src/Windows/LoggerWindow.h
|
// src/Windows/LoggerWindow.h
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#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:
|
public:
|
||||||
// Add logs from anywhere
|
|
||||||
void AddLog(const char* fmt, ...);
|
void AddLog(const char* fmt, ...);
|
||||||
|
void AddLog(const char* fmt, std::optional<ImVec4> color, ...);
|
||||||
// Show the ImGui window
|
|
||||||
void Show();
|
void Show();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> m_Logs;
|
std::vector<LogEntry> m_Logs;
|
||||||
|
bool m_ScrollToBottom = false;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user