128 lines
3.4 KiB
C#
128 lines
3.4 KiB
C#
using System.Numerics;
|
|
using ImGuiNET;
|
|
using Raylib_cs;
|
|
using rlImGui_cs;
|
|
using SzGui.Windows;
|
|
|
|
namespace SzGui;
|
|
|
|
public class SzApp
|
|
{
|
|
public static readonly SzApp AppInstance = new();
|
|
private SzApp() { }
|
|
|
|
private List<SzGuiWindowBase> _activeWindows = new();
|
|
|
|
public void ActivateWindow(SzGuiWindowBase window)
|
|
{
|
|
if (_activeWindows.Any(w => w.GetType() == window.GetType()))
|
|
{
|
|
ImGui.SetWindowFocus(window.WindowName);
|
|
return;
|
|
}
|
|
|
|
_activeWindows.Add(window);
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
ApplicationSettings.LoadSettings();
|
|
|
|
Raylib.SetConfigFlags(ConfigFlags.Msaa4xHint | ConfigFlags.VSyncHint | ConfigFlags.ResizableWindow);
|
|
Raylib.InitWindow(1280, 800, "SessionZero");
|
|
|
|
rlImGui.Setup(true, true);
|
|
ImGui.GetIO().ConfigWindowsMoveFromTitleBarOnly = true;
|
|
|
|
if (ApplicationSettings.GetSettingValue<bool>("ShowStartup")) ActivateWindow(new StartupWindow());
|
|
|
|
while (!Raylib.WindowShouldClose())
|
|
{
|
|
Raylib.BeginDrawing();
|
|
Raylib.ClearBackground(Color.Gray);
|
|
rlImGui.Begin();
|
|
|
|
ImGui.PushStyleColor(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 0));
|
|
ImGui.DockSpaceOverViewport(0);
|
|
ImGui.PopStyleColor();
|
|
|
|
HandleShortcuts();
|
|
DrawImGui();
|
|
|
|
rlImGui.End();
|
|
Raylib.EndDrawing();
|
|
}
|
|
|
|
rlImGui.Shutdown();
|
|
Raylib.CloseWindow();
|
|
}
|
|
|
|
private void HandleShortcuts()
|
|
{
|
|
var io = ImGui.GetIO();
|
|
|
|
if (io is { KeyCtrl: true, KeyAlt: true } && ImGui.IsKeyPressed(ImGuiKey.S))
|
|
{
|
|
ActivateWindow(new SettingsWindow());
|
|
}
|
|
|
|
if (io is { KeyCtrl: true, KeyAlt: true } && ImGui.IsKeyPressed(ImGuiKey.Q))
|
|
{
|
|
Raylib.CloseWindow();
|
|
}
|
|
}
|
|
|
|
private void UpdateImGuiTheme()
|
|
{
|
|
var c = ApplicationSettings.GetSettingValue<Color>("BackgroundColor");
|
|
Vector4 styleColor = new Vector4(c.R / 255f, c.G / 255f, c.B / 255f, 1.0f);
|
|
ImGui.GetStyle().Colors[(int)ImGuiCol.WindowBg] = styleColor;
|
|
}
|
|
|
|
private void DrawImGui()
|
|
{
|
|
DrawGlobalMenuBar();
|
|
|
|
for (int i = _activeWindows.Count - 1; i >= 0; i--)
|
|
{
|
|
_activeWindows[i].Draw();
|
|
if (!_activeWindows[i].IsOpen) _activeWindows.RemoveAt(i);
|
|
}
|
|
}
|
|
|
|
private void DrawGlobalMenuBar()
|
|
{
|
|
if (ImGui.BeginMainMenuBar())
|
|
{
|
|
if (ImGui.BeginMenu("File"))
|
|
{
|
|
if (ImGui.MenuItem("Exit", "Ctrl+Alt+Q")) Raylib.CloseWindow();
|
|
ImGui.EndMenu();
|
|
}
|
|
|
|
if (ImGui.BeginMenu("Edit"))
|
|
{
|
|
if (ImGui.MenuItem("Settings", "Ctrl+Alt+S"))
|
|
{
|
|
ActivateWindow(new SettingsWindow());
|
|
}
|
|
ImGui.EndMenu();
|
|
}
|
|
|
|
if (ImGui.BeginMenu("View"))
|
|
{
|
|
if (ImGui.MenuItem("Start window"))
|
|
{
|
|
ActivateWindow(new StartupWindow());
|
|
}
|
|
ImGui.EndMenu();
|
|
}
|
|
|
|
if (ImGui.MenuItem("Library")) ActivateWindow(new SzLibraryWindow());
|
|
|
|
ImGui.EndMainMenuBar();
|
|
}
|
|
}
|
|
|
|
}
|