feat(Window): Added Log window
This commit is contained in:
parent
b87efe5a4e
commit
ecac78c493
37
BigBaseV2/src/backend/looped/self/window_log.cpp
Normal file
37
BigBaseV2/src/backend/looped/self/window_log.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "gui/window.hpp"
|
||||||
|
#include "gui/window/main/tabs.hpp"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "renderer.hpp"
|
||||||
|
#include "logger.hpp"
|
||||||
|
|
||||||
|
namespace big
|
||||||
|
{
|
||||||
|
static size_t iLastLogCount = 0;
|
||||||
|
void window::log()
|
||||||
|
{
|
||||||
|
ImGui::SetNextWindowSize({ 500, 250 }, ImGuiCond_FirstUseEver);
|
||||||
|
ImGui::SetNextWindowPos({ 50, 50 }, ImGuiCond_FirstUseEver);
|
||||||
|
if (g.window.log && ImGui::Begin("Log"))
|
||||||
|
{
|
||||||
|
ImGui::PushFont(g_renderer->m_monospace_font);
|
||||||
|
|
||||||
|
std::lock_guard lock(g_logger->m_mutex);
|
||||||
|
auto msgs = g_logger->get_messages();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < msgs.second; i++)
|
||||||
|
{
|
||||||
|
ImGui::TextUnformatted(msgs.first[i].get());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iLastLogCount != msgs.second)
|
||||||
|
{
|
||||||
|
iLastLogCount = msgs.second;
|
||||||
|
ImGui::SetScrollHereY(1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopFont();
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,6 +28,7 @@ struct globals {
|
|||||||
|
|
||||||
struct window {
|
struct window {
|
||||||
bool main = true;
|
bool main = true;
|
||||||
|
bool log = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
self self{};
|
self self{};
|
||||||
|
@ -7,6 +7,8 @@ namespace big
|
|||||||
{
|
{
|
||||||
window::top_bar();
|
window::top_bar();
|
||||||
|
|
||||||
|
window::log();
|
||||||
|
|
||||||
window::main();
|
window::main();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ namespace big
|
|||||||
class window {
|
class window {
|
||||||
public:
|
public:
|
||||||
static void top_bar();
|
static void top_bar();
|
||||||
|
static void log();
|
||||||
static void main();
|
static void main();
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ namespace big
|
|||||||
void window::main()
|
void window::main()
|
||||||
{
|
{
|
||||||
ImGui::SetNextWindowSize({ 800, 840 }, ImGuiCond_FirstUseEver);
|
ImGui::SetNextWindowSize({ 800, 840 }, ImGuiCond_FirstUseEver);
|
||||||
if (g.window.main && ImGui::Begin("Yimura's Mod Menu", &g.window.main))
|
if (g.window.main && ImGui::Begin("Yimura's Mod Menu"))
|
||||||
{
|
{
|
||||||
ImGui::BeginTabBar("tabbar");
|
ImGui::BeginTabBar("tabbar");
|
||||||
tab_main::tab_self();
|
tab_main::tab_self();
|
||||||
@ -15,7 +15,8 @@ namespace big
|
|||||||
tab_main::tab_vehicle();
|
tab_main::tab_vehicle();
|
||||||
tab_main::tab_weapons();
|
tab_main::tab_weapons();
|
||||||
ImGui::EndTabBar();
|
ImGui::EndTabBar();
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
}
|
}
|
||||||
ImGui::End();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -53,7 +53,8 @@ namespace big
|
|||||||
|
|
||||||
if (ImGui::BeginMenu("Windows"))
|
if (ImGui::BeginMenu("Windows"))
|
||||||
{
|
{
|
||||||
ImGui::MenuItem("Main Window", nullptr, &g.window.main);
|
ImGui::MenuItem("Main", nullptr, &g.window.main);
|
||||||
|
ImGui::MenuItem("Logs", nullptr, &g.window.log);
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
@ -62,12 +63,7 @@ namespace big
|
|||||||
{
|
{
|
||||||
if (ImGui::MenuItem("Unload Menu (may crash)"))
|
if (ImGui::MenuItem("Unload Menu (may crash)"))
|
||||||
{
|
{
|
||||||
QUEUE_JOB_BEGIN_CLAUSE(&)
|
g_running = false;
|
||||||
{
|
|
||||||
g_running = false;
|
|
||||||
|
|
||||||
notify::above_map("Thanks for using Yim's Mod Menu");
|
|
||||||
}QUEUE_JOB_END_CLAUSE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::MenuItem("Rage Quit (hard crash)"))
|
if (ImGui::MenuItem("Rage Quit (hard crash)"))
|
||||||
|
@ -53,17 +53,6 @@ namespace big
|
|||||||
explicit logger() :
|
explicit logger() :
|
||||||
m_file_path(std::getenv("appdata")),
|
m_file_path(std::getenv("appdata")),
|
||||||
m_worker(g3::LogWorker::createLogWorker())
|
m_worker(g3::LogWorker::createLogWorker())
|
||||||
{
|
|
||||||
if ((m_did_console_exist = AttachConsole(GetCurrentProcessId())) == false)
|
|
||||||
AllocConsole();
|
|
||||||
|
|
||||||
if ((m_console_handle = GetStdHandle(STD_OUTPUT_HANDLE)) != nullptr)
|
|
||||||
{
|
|
||||||
SetConsoleTitleA("Yim's Mod Menu");
|
|
||||||
SetConsoleOutputCP(CP_UTF8);
|
|
||||||
|
|
||||||
m_console_out.open("CONOUT$", std::ios_base::out | std::ios_base::app);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_file_path /= "BigBaseV2";
|
m_file_path /= "BigBaseV2";
|
||||||
std::filesystem::path m_backup_path = m_file_path;
|
std::filesystem::path m_backup_path = m_file_path;
|
||||||
@ -130,6 +119,13 @@ namespace big
|
|||||||
g_logger = nullptr;
|
g_logger = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<std::unique_ptr<char[]>*, std::size_t> get_messages()
|
||||||
|
{
|
||||||
|
return std::make_pair(m_messages.data(), m_messages.size());
|
||||||
|
}
|
||||||
|
std::vector<std::unique_ptr<char[]>> m_messages;
|
||||||
|
std::mutex m_mutex;
|
||||||
|
|
||||||
struct log_sink
|
struct log_sink
|
||||||
{
|
{
|
||||||
std::map<std::string, log_color> log_colors = {
|
std::map<std::string, log_color> log_colors = {
|
||||||
@ -151,8 +147,17 @@ namespace big
|
|||||||
|
|
||||||
if (!(level_value & FLAG_NO_CONSOLE))
|
if (!(level_value & FLAG_NO_CONSOLE))
|
||||||
{
|
{
|
||||||
SetConsoleTextAttribute(g_logger->m_console_handle, static_cast<std::uint16_t>(log_colors[log_message._level.text]));
|
std::lock_guard lock(g_logger->m_mutex);
|
||||||
g_logger->m_console_out << log_message.toString(is_raw ? format_raw : format_console) << std::flush;
|
|
||||||
|
const std::string msg = log_message.toString(is_raw ? format_raw : format_console);
|
||||||
|
|
||||||
|
std::size_t size = msg.size() + 1;
|
||||||
|
auto message = std::make_unique<char[]>(size);
|
||||||
|
std::uninitialized_fill_n(message.get(), size, '\0');
|
||||||
|
strcpy(message.get(), msg.c_str());
|
||||||
|
g_logger->m_messages.push_back(
|
||||||
|
std::move(message)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(level_value & FLAG_NO_DISK))
|
if (!(level_value & FLAG_NO_DISK))
|
||||||
|
Reference in New Issue
Block a user