using System.Numerics; using Dalamud.Bindings.ImGui; using Dalamud.Interface.GameFonts; using Dalamud.Plugin; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using KamiLib.Classes; using KamiLib.CommandManager; using KamiLib.Window; using Mappy.Controllers; using Mappy.Data; using Mappy.Windows; namespace Mappy; public sealed class MappyPlugin : IDalamudPlugin { private static bool _minimapPushedPadding; public MappyPlugin(IDalamudPluginInterface pluginInterface) { pluginInterface.Create(); System.LargeAxisFontHandle = Service.PluginInterface.UiBuilder.FontAtlas.NewGameFontHandle(new GameFontStyle { SizePt = 72.0f, FamilyAndSize = GameFontFamilyAndSize.Axis36, Italic = true, BaseSkewStrength = 16f, }); System.SystemConfig = SystemConfig.Load(); System.IconConfig = IconConfig.Load(); System.FlagConfig = FlagConfig.Load(); System.Teleporter = new Teleporter(Service.PluginInterface); System.CommandManager = new CommandManager(Service.PluginInterface, "hsmappy"); System.MapRenderer = new MapRenderer.MapRenderer(); System.ConfigWindow = new ConfigurationWindow(); System.MapWindow = new MapWindow(); System.MinimapWindow = new MinimapWindow(); // Push zero padding before window system draw so the first window (minimap) gets it. Service.PluginInterface.UiBuilder.Draw += SetMinimapZeroPadding; System.WindowManager = new WindowManager(Service.PluginInterface); Service.PluginInterface.UiBuilder.Draw += PopMinimapPadding; // Minimap is added first so it's drawn first and receives the zero padding. System.WindowManager.AddWindow(System.MinimapWindow, WindowFlags.RequireLoggedIn); System.WindowManager.AddWindow(System.ConfigWindow, WindowFlags.IsConfigWindow | WindowFlags.RequireLoggedIn); System.WindowManager.AddWindow(System.MapWindow, WindowFlags.RequireLoggedIn); if (System.SystemConfig.ShowMinimap) System.MinimapWindow.UnCollapseOrShow(); // PopMinimapPadding already registered above (after WindowManager) System.FlagController = new FlagController(); System.AreaMapController = new AddonAreaMapController(); System.IntegrationsController = new IntegrationsController(); Service.PluginInterface.UiBuilder.OpenMainUi += OpenMapWindow; System.CommandManager.RegisterCommand(new ToggleCommandHandler { BaseActivationPath = "/fatelist", EnableDelegate = _ => System.WindowManager.OpenOrCreateUnique(WindowFlags.OpenImmediately | WindowFlags.RequireLoggedIn), DisableDelegate = _ => System.WindowManager.GetWindow()?.Close(), ToggleDelegate = _ => System.WindowManager.GetWindow()?.UnCollapseOrToggle(), }); System.CommandManager.RegisterCommand(new ToggleCommandHandler { BaseActivationPath = "/questlist", EnableDelegate = _ => System.WindowManager.OpenOrCreateUnique(WindowFlags.OpenImmediately | WindowFlags.RequireLoggedIn), DisableDelegate = _ => System.WindowManager.GetWindow()?.Close(), ToggleDelegate = _ => System.WindowManager.GetWindow()?.UnCollapseOrToggle(), }); System.CommandManager.RegisterCommand(new ToggleCommandHandler { BaseActivationPath = "/flaglist", EnableDelegate = _ => System.WindowManager.OpenOrCreateUnique(WindowFlags.OpenImmediately | WindowFlags.RequireLoggedIn), DisableDelegate = _ => System.WindowManager.GetWindow()?.Close(), ToggleDelegate = _ => System.WindowManager.GetWindow()?.UnCollapseOrToggle(), }); } private unsafe void OpenMapWindow() => AgentMap.Instance()->Show(); /// /// Called first each frame so the first window (minimap) gets zero padding when visible. /// private static void SetMinimapZeroPadding() { if (System.SystemConfig.ShowMinimap && IntegrationsController.ShouldShowMinimap()) { ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, new Vector2(0f, 0f)); _minimapPushedPadding = true; } } /// /// Called after window system draw to pop the padding we pushed (keeps style stack balanced). /// private static void PopMinimapPadding() { if (_minimapPushedPadding) { ImGui.PopStyleVar(); _minimapPushedPadding = false; } } public void Dispose() { Service.PluginInterface.UiBuilder.Draw -= SetMinimapZeroPadding; Service.PluginInterface.UiBuilder.Draw -= PopMinimapPadding; System.MapWindow.OnClose(); System.WindowManager.Dispose(); System.IntegrationsController.Dispose(); System.AreaMapController.Dispose(); System.FlagController.Dispose(); System.MapRenderer.Dispose(); Service.PluginInterface.UiBuilder.OpenMainUi -= OpenMapWindow; } }