242 lines
9.7 KiB
C++
242 lines
9.7 KiB
C++
#include "gui/GuiManager.h"
|
|
#include "raylib.h"
|
|
#include <fstream> // Add this to fix the incomplete type error
|
|
#include <string>
|
|
#include <iostream>
|
|
#include "log.h"
|
|
#include "Application.h"
|
|
#include <filesystem> // Add this for cross-platform file handling
|
|
|
|
GuiManager::GuiManager() {}
|
|
|
|
GuiManager::~GuiManager() {}
|
|
|
|
void GuiManager::Initialize(Application *application)
|
|
{
|
|
app = application;
|
|
rlImGuiSetup(true);
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
|
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
|
|
|
SetTheme();
|
|
|
|
logWindow.Initialize(); // Initialize the LogWindow
|
|
log_trace("GuiManager::Initialize - Started");
|
|
}
|
|
|
|
void GuiManager::Render(RenderTexture2D &renderTexture)
|
|
{
|
|
rlImGuiBegin();
|
|
SetupDockspace(renderTexture);
|
|
|
|
RenderErrorBanner();
|
|
RenderNotifications();
|
|
logWindow.Render(showLogWindow); // Render the LogWindow
|
|
|
|
|
|
rlImGuiEnd();
|
|
|
|
ImGui::UpdatePlatformWindows();
|
|
ImGui::RenderPlatformWindowsDefault();
|
|
}
|
|
|
|
void GuiManager::Shutdown()
|
|
{
|
|
rlImGuiShutdown();
|
|
}
|
|
|
|
void GuiManager::SetupDockspace(RenderTexture2D &renderTexture)
|
|
{
|
|
static bool dockspaceOpen = true;
|
|
static bool opt_fullscreen = true;
|
|
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
|
|
|
|
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
|
|
if (opt_fullscreen)
|
|
{
|
|
ImGuiViewport *viewport = ImGui::GetMainViewport();
|
|
ImGui::SetNextWindowPos(viewport->WorkPos);
|
|
ImGui::SetNextWindowSize(viewport->WorkSize);
|
|
ImGui::SetNextWindowViewport(viewport->ID);
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
|
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
|
|
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
|
|
}
|
|
|
|
ImGui::Begin("DockSpaceHost", &dockspaceOpen, window_flags);
|
|
if (opt_fullscreen)
|
|
ImGui::PopStyleVar(2);
|
|
if (ImGui::BeginMenuBar())
|
|
{
|
|
if (ImGui::BeginMenu("Game"))
|
|
{
|
|
if (ImGui::MenuItem("Quit", "Ctrl + Q"))
|
|
{
|
|
// Handle quit here
|
|
app->RequestShutdown();
|
|
}
|
|
ImGui::EndMenu();
|
|
}
|
|
if (ImGui::BeginMenu("View"))
|
|
{
|
|
ImGui::MenuItem("Log Viewer", "Ctrl + L", &showLogWindow);
|
|
ImGui::EndMenu();
|
|
}
|
|
ImGui::EndMenuBar();
|
|
}
|
|
|
|
if (ImGui::GetIO().KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_L))
|
|
{
|
|
showLogWindow = !showLogWindow;
|
|
}
|
|
if (ImGui::GetIO().KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_Q))
|
|
{
|
|
app->Shutdown();
|
|
}
|
|
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
|
|
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
|
|
|
|
// Add a Game Window
|
|
ImGui::Begin("Game Window");
|
|
|
|
// Render Raylib content to the Game Window
|
|
rlImGuiImageRenderTexture(&renderTexture);
|
|
|
|
ImGui::End();
|
|
ImGui::End();
|
|
}
|
|
|
|
void GuiManager::RenderErrorBanner()
|
|
{
|
|
if (!app || !app->HasScriptCompilationError())
|
|
return;
|
|
|
|
ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f));
|
|
ImGui::SetNextWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x, 0.0f));
|
|
ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration |
|
|
ImGuiWindowFlags_NoMove |
|
|
ImGuiWindowFlags_NoSavedSettings;
|
|
ImGui::Begin("PersistentBanner", nullptr, flags);
|
|
ImGui::TextColored(ImVec4(1, 0.4f, 0.4f, 1), ICON_FA_TRIANGLE_EXCLAMATION " Script Compilation Error - running last working version");
|
|
ImGui::End();
|
|
}
|
|
|
|
void GuiManager::RenderNotifications()
|
|
{
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f);
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f);
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.10f, 0.10f, 0.10f, 1.00f));
|
|
|
|
ImGui::RenderNotifications();
|
|
|
|
ImGui::PopStyleVar(2);
|
|
ImGui::PopStyleColor(1);
|
|
}
|
|
void GuiManager::SetTheme()
|
|
{
|
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
|
|
io.Fonts->Clear();
|
|
|
|
// Don't clear; just add new fonts and rebuild
|
|
io.Fonts->AddFontFromFileTTF("fonts/Inter-Regular.ttf", 16); // index 0 (replaces default)
|
|
|
|
// Re-add FontAwesome as merge into default (index 0)
|
|
float iconFontSize = 16.0f * 2.0f / 3.0f;
|
|
static constexpr ImWchar iconsRanges[] = {ICON_MIN_FA, ICON_MAX_16_FA, 0};
|
|
ImFontConfig iconsConfig;
|
|
iconsConfig.MergeMode = true;
|
|
iconsConfig.PixelSnapH = true;
|
|
iconsConfig.GlyphMinAdvanceX = iconFontSize;
|
|
io.Fonts->AddFontFromMemoryCompressedTTF(fa_solid_900_compressed_data,
|
|
fa_solid_900_compressed_size,
|
|
iconFontSize, &iconsConfig, iconsRanges);
|
|
io.Fonts->AddFontFromFileTTF("fonts/JetBrainsMono-Regular.ttf", 16);
|
|
io.Fonts->Build();
|
|
|
|
ImVec4 *colors = ImGui::GetStyle().Colors;
|
|
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
|
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
|
|
colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f);
|
|
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
colors[ImGuiCol_PopupBg] = ImVec4(0.19f, 0.19f, 0.19f, 0.92f);
|
|
colors[ImGuiCol_Border] = ImVec4(0.19f, 0.19f, 0.19f, 0.29f);
|
|
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.24f);
|
|
colors[ImGuiCol_FrameBg] = ImVec4(0.05f, 0.05f, 0.05f, 0.54f);
|
|
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.19f, 0.19f, 0.19f, 0.54f);
|
|
colors[ImGuiCol_FrameBgActive] = ImVec4(0.20f, 0.22f, 0.23f, 1.00f);
|
|
colors[ImGuiCol_TitleBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
|
colors[ImGuiCol_TitleBgActive] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f);
|
|
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
|
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
|
|
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.05f, 0.05f, 0.05f, 0.54f);
|
|
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.34f, 0.34f, 0.34f, 0.54f);
|
|
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.40f, 0.54f);
|
|
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.56f, 0.56f, 0.56f, 0.54f);
|
|
colors[ImGuiCol_CheckMark] = ImVec4(0.33f, 0.67f, 0.86f, 1.00f);
|
|
colors[ImGuiCol_SliderGrab] = ImVec4(0.34f, 0.34f, 0.34f, 0.54f);
|
|
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.56f, 0.56f, 0.56f, 0.54f);
|
|
colors[ImGuiCol_Button] = ImVec4(0.05f, 0.05f, 0.05f, 0.54f);
|
|
colors[ImGuiCol_ButtonHovered] = ImVec4(0.19f, 0.19f, 0.19f, 0.54f);
|
|
colors[ImGuiCol_ButtonActive] = ImVec4(0.20f, 0.22f, 0.23f, 1.00f);
|
|
colors[ImGuiCol_Header] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
|
|
colors[ImGuiCol_HeaderHovered] = ImVec4(0.00f, 0.00f, 0.00f, 0.36f);
|
|
colors[ImGuiCol_HeaderActive] = ImVec4(0.20f, 0.22f, 0.23f, 0.33f);
|
|
colors[ImGuiCol_Separator] = ImVec4(0.28f, 0.28f, 0.28f, 0.29f);
|
|
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.44f, 0.44f, 0.44f, 0.29f);
|
|
colors[ImGuiCol_SeparatorActive] = ImVec4(0.40f, 0.44f, 0.47f, 1.00f);
|
|
colors[ImGuiCol_ResizeGrip] = ImVec4(0.28f, 0.28f, 0.28f, 0.29f);
|
|
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.44f, 0.44f, 0.44f, 0.29f);
|
|
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.40f, 0.44f, 0.47f, 1.00f);
|
|
colors[ImGuiCol_Tab] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
|
|
colors[ImGuiCol_TabHovered] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
|
|
colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.20f, 0.20f, 0.36f);
|
|
colors[ImGuiCol_TabUnfocused] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
|
|
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
|
|
colors[ImGuiCol_DockingPreview] = ImVec4(0.33f, 0.67f, 0.86f, 1.00f);
|
|
colors[ImGuiCol_DockingEmptyBg] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
|
colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
|
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
|
colors[ImGuiCol_PlotHistogram] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
|
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
|
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
|
|
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
|
|
colors[ImGuiCol_TableBorderLight] = ImVec4(0.28f, 0.28f, 0.28f, 0.29f);
|
|
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
|
|
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.20f, 0.22f, 0.23f, 1.00f);
|
|
colors[ImGuiCol_DragDropTarget] = ImVec4(0.33f, 0.67f, 0.86f, 1.00f);
|
|
colors[ImGuiCol_NavHighlight] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
|
|
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 0.00f, 0.00f, 0.70f);
|
|
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(1.00f, 0.00f, 0.00f, 0.20f);
|
|
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(1.00f, 0.00f, 0.00f, 0.35f);
|
|
colors[ImGuiCol_CheckMark] = ImVec4(0.33f, 0.67f, 0.86f, 1.00f);
|
|
|
|
ImGuiStyle &style = ImGui::GetStyle();
|
|
style.WindowPadding = ImVec2(8.00f, 8.00f);
|
|
style.FramePadding = ImVec2(5.00f, 2.00f);
|
|
style.CellPadding = ImVec2(6.00f, 6.00f);
|
|
style.ItemSpacing = ImVec2(6.00f, 6.00f);
|
|
style.ItemInnerSpacing = ImVec2(6.00f, 6.00f);
|
|
style.TouchExtraPadding = ImVec2(0.00f, 0.00f);
|
|
style.IndentSpacing = 25;
|
|
style.ScrollbarSize = 15;
|
|
style.GrabMinSize = 10;
|
|
style.WindowBorderSize = 1;
|
|
style.ChildBorderSize = 1;
|
|
style.PopupBorderSize = 1;
|
|
style.FrameBorderSize = 1;
|
|
style.TabBorderSize = 1;
|
|
style.WindowRounding = 7;
|
|
style.ChildRounding = 4;
|
|
style.FrameRounding = 3;
|
|
style.PopupRounding = 4;
|
|
style.ScrollbarRounding = 9;
|
|
style.GrabRounding = 3;
|
|
style.LogSliderDeadzone = 4;
|
|
style.TabRounding = 4;
|
|
}
|