From 5650bf3ae00789a8196891d64ae4f5c94936b8d3 Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Thu, 25 Jul 2024 00:59:34 +0200 Subject: [PATCH] Properly remove DtrEntries from DtrBarPluginScoped (#1969) fixes #1862 --- Dalamud/Game/Gui/Dtr/DtrBar.cs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Dalamud/Game/Gui/Dtr/DtrBar.cs b/Dalamud/Game/Gui/Dtr/DtrBar.cs index 779dbf7f9..55b2573f0 100644 --- a/Dalamud/Game/Gui/Dtr/DtrBar.cs +++ b/Dalamud/Game/Gui/Dtr/DtrBar.cs @@ -76,6 +76,17 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar this.configuration.QueueSave(); } + /// + /// Event type fired each time a DtrEntry was removed. + /// + /// The title of the bar entry. + internal delegate void DtrEntryRemovedDelegate(string title); + + /// + /// Event fired each time a DtrEntry was removed. + /// + internal event DtrEntryRemovedDelegate? DtrEntryRemoved; + /// public IReadOnlyList Entries => this.entries; @@ -136,6 +147,7 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar if (data.ShouldBeRemoved) { this.RemoveEntry(data); + this.DtrEntryRemoved?.Invoke(data.Title); } } @@ -525,7 +537,6 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar /// Plugin-scoped version of a AddonEventManager service. /// [PluginInterface] - [ServiceManager.ScopedService] #pragma warning disable SA1015 [ResolveVia] @@ -536,13 +547,23 @@ internal class DtrBarPluginScoped : IInternalDisposableService, IDtrBar private readonly DtrBar dtrBarService = Service.Get(); private readonly Dictionary pluginEntries = new(); - + + /// + /// Initializes a new instance of the class. + /// + internal DtrBarPluginScoped() + { + this.dtrBarService.DtrEntryRemoved += this.OnDtrEntryRemoved; + } + /// public IReadOnlyList Entries => this.dtrBarService.Entries; /// void IInternalDisposableService.DisposeService() { + this.dtrBarService.DtrEntryRemoved -= this.OnDtrEntryRemoved; + foreach (var entry in this.pluginEntries) { entry.Value.Remove(); @@ -569,4 +590,9 @@ internal class DtrBarPluginScoped : IInternalDisposableService, IDtrBar this.pluginEntries.Remove(title); } } + + private void OnDtrEntryRemoved(string title) + { + this.pluginEntries.Remove(title); + } }