diff --git a/PositionalGuide/ConfigWindow.cs b/PositionalGuide/ConfigWindow.cs index 51c3242..4aa3df5 100644 --- a/PositionalGuide/ConfigWindow.cs +++ b/PositionalGuide/ConfigWindow.cs @@ -34,6 +34,8 @@ public class ConfigWindow: Window, IDisposable { private bool disposed; private readonly Configuration conf; + public delegate void SettingsUpdate(); + public event SettingsUpdate? OnSettingsUpdate; public ConfigWindow(Plugin core) : base(core.Name, flags) { this.RespectCloseHotkey = true; @@ -313,6 +315,7 @@ public override void Draw() { this.conf.DrawGuides = drawing; this.conf.LineColours = colours; Plugin.Interface.SavePluginConfig(this.conf); + this.OnSettingsUpdate?.Invoke(); } for (int i = 0; i < ptrs.Length; ++i) diff --git a/PositionalGuide/Plugin.cs b/PositionalGuide/Plugin.cs index 6486f30..03c4ed6 100644 --- a/PositionalGuide/Plugin.cs +++ b/PositionalGuide/Plugin.cs @@ -9,6 +9,7 @@ namespace PrincessRTFM.PositionalGuide; using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.ClientState.Objects.Types; +using Dalamud.Game.Gui.Dtr; using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Utility; using Dalamud.Interface.Windowing; @@ -29,6 +30,7 @@ private enum CircleTypes { Target, Outer }; private bool disposed; public string Name { get; } = "Positional Assistant"; + public const string DTRDisplayName = "Guidelines"; [PluginService] public static IGameGui Gui { get; private set; } = null!; [PluginService] public static IChatGui Chat { get; private set; } = null!; @@ -42,12 +44,14 @@ private enum CircleTypes { Target, Outer }; private readonly WindowSystem windowSystem; private readonly ConfigWindow configWindow; + private readonly DtrBarEntry dtrEntry; - public Plugin() { + public Plugin(IDtrBar dtrBar) { this.Config = Interface.GetPluginConfig() as Configuration ?? new(); this.Config.Update(); this.configWindow = new(this); + this.configWindow.OnSettingsUpdate += this.settingsUpdated; this.windowSystem = new(this.GetType().Namespace!); this.windowSystem.AddWindow(this.configWindow); @@ -55,11 +59,26 @@ public Plugin() { HelpMessage = $"Open {this.Name}'s config window", ShowInHelp = true, }); + + this.dtrEntry = dtrBar.Get(this.Name); + this.setDtrText(); + this.dtrEntry.OnClick = this.dtrClickHandler; Interface.UiBuilder.OpenConfigUi += this.toggleConfigUi; Interface.UiBuilder.Draw += this.draw; } + private void settingsUpdated() { + this.setDtrText(); + } + + private void dtrClickHandler() { + this.Config.Enabled = !this.Config.Enabled; + this.setDtrText(); + } + + private void setDtrText() => this.dtrEntry.Text = $"{DTRDisplayName}: {(this.Config.Enabled ? "On" : "Off")}"; + internal void draw() { this.windowSystem.Draw(); @@ -438,6 +457,7 @@ internal void onPluginCommand(string command, string arguments) { return; } + this.settingsUpdated(); Interface.SavePluginConfig(this.Config); } @@ -459,10 +479,12 @@ protected virtual void Dispose(bool disposing) { if (disposing) { Interface.UiBuilder.OpenConfigUi -= this.toggleConfigUi; Interface.UiBuilder.Draw -= this.draw; + this.configWindow.OnSettingsUpdate -= this.settingsUpdated; Commands.RemoveHandler(Command); this.configWindow.Dispose(); + this.dtrEntry.Remove(); } } diff --git a/PositionalGuide/PositionalGuide.csproj b/PositionalGuide/PositionalGuide.csproj index b0b7c20..de6b6c7 100644 --- a/PositionalGuide/PositionalGuide.csproj +++ b/PositionalGuide/PositionalGuide.csproj @@ -2,7 +2,7 @@ PositionalGuide - 4.2.0 + 4.3.0 Provides drawn guidelines to see where you need to stand to hit enemies with positionals Copyleft VariableVixen 2022 https://github.com/PrincessRTFM/PositionalAssistant