using System; using System.Collections.Generic; using System.Linq; using Dalamud.Interface.Windowing; using KamiLib.ChatCommands; namespace KamiLib.Windows; public class WindowManager : IDisposable { private readonly WindowSystem windowSystem; private readonly List windows = new(); public WindowManager() { windowSystem = new WindowSystem(KamiCommon.PluginName); windows.ForEach(window => windowSystem.AddWindow(window)); Service.PluginInterface.UiBuilder.Draw += DrawUI; Service.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUI; } public void Dispose() { Service.PluginInterface.UiBuilder.Draw -= DrawUI; Service.PluginInterface.UiBuilder.OpenConfigUi -= DrawConfigUI; windowSystem.RemoveAllWindows(); } public void AddWindow(Window newWindow) { if (windowSystem.Windows.All(w => w.WindowName != newWindow.WindowName)) { windows.Add(newWindow); windowSystem.AddWindow(newWindow); } } public void AddConfigurationWindow(T configWindow) where T : Window { windows.Add(configWindow); windowSystem.AddWindow(configWindow); KamiCommon.CommandManager.AddCommand(new OpenWindowCommand(null, false, "Configuration")); KamiCommon.CommandManager.AddCommand(new OpenWindowCommand("silent", true, "Configuration")); } public void RemoveWindow(Window window) { windows.Remove(window); windowSystem.RemoveWindow(window); } public IReadOnlyCollection GetWindows() => windows; public T? GetWindowOfType() => windows.OfType().FirstOrDefault(); private void DrawUI() => windowSystem.Draw(); private void DrawConfigUI() => KamiCommon.CommandManager.OnCommand($"{KamiCommon.PluginName}", "silent"); }