Lots of SzGui work
This commit is contained in:
@@ -2,29 +2,51 @@ 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(new Color(0, 20, 50));
|
||||
Raylib.ClearBackground(Color.Gray);
|
||||
rlImGui.Begin();
|
||||
|
||||
ImGui.PushStyleColor(ImGuiCol.WindowBg, new Vector4(0, 0, 0, 0));
|
||||
ImGui.DockSpaceOverViewport(0);
|
||||
|
||||
// ImGui.ShowDemoWindow();
|
||||
ImGui.ShowStyleEditor();
|
||||
ImGui.PopStyleColor();
|
||||
|
||||
HandleShortcuts();
|
||||
DrawImGui();
|
||||
|
||||
rlImGui.End();
|
||||
@@ -34,13 +56,72 @@ public class SzApp
|
||||
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()
|
||||
{
|
||||
if(ImGui.Begin("SessionZero"))
|
||||
DrawGlobalMenuBar();
|
||||
|
||||
for (int i = _activeWindows.Count - 1; i >= 0; i--)
|
||||
{
|
||||
ImGui.TextUnformatted("Test: " + IconFonts.FontAwesome6.House);
|
||||
_activeWindows[i].Draw();
|
||||
if (!_activeWindows[i].IsOpen) _activeWindows.RemoveAt(i);
|
||||
}
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user