From 5cb693e834053025158d8e33699452c47bd34f96 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 14 Feb 2022 01:39:25 +0100 Subject: [PATCH] fix: handle DTR node removals when reloading plugins (fixes #759) --- Dalamud/Game/Gui/Dtr/DtrBar.cs | 22 +++++++++++++++------- Dalamud/Plugin/Internal/PluginManager.cs | 6 +++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Dalamud/Game/Gui/Dtr/DtrBar.cs b/Dalamud/Game/Gui/Dtr/DtrBar.cs index 406cc48d2..9fcf0de6e 100644 --- a/Dalamud/Game/Gui/Dtr/DtrBar.cs +++ b/Dalamud/Game/Gui/Dtr/DtrBar.cs @@ -74,6 +74,19 @@ namespace Dalamud.Game.Gui.Dtr Service.Get().Update -= this.Update; } + /// + /// Remove nodes marked as "should be removed" from the bar. + /// + internal void HandleRemovedNodes() + { + foreach (var data in this.entries.Where(d => d.ShouldBeRemoved)) + { + this.RemoveNode(data.TextNode); + } + + this.entries.RemoveAll(d => d.ShouldBeRemoved); + } + /// /// Check whether an entry with the specified title exists. /// @@ -123,12 +136,7 @@ namespace Dalamud.Game.Gui.Dtr var dtr = GetDtr(); if (dtr == null) return; - foreach (var data in this.entries.Where(d => d.ShouldBeRemoved)) - { - this.RemoveNode(data.TextNode); - } - - this.entries.RemoveAll(d => d.ShouldBeRemoved); + this.HandleRemovedNodes(); // The collision node on the DTR element is always the width of its content if (dtr->UldManager.NodeList == null) return; @@ -206,7 +214,7 @@ namespace Dalamud.Game.Gui.Dtr var dtr = GetDtr(); if (dtr == null || dtr->RootNode == null) return false; - for (int i = 0; i < dtr->UldManager.NodeListCount; i++) + for (var i = 0; i < dtr->UldManager.NodeListCount; i++) { if (dtr->UldManager.NodeList[i]->NodeID > 1000) return true; diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index dc751c448..e1ac35d11 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Linq; -using System.Net.Http; using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -14,6 +13,7 @@ using CheapLoc; using Dalamud.Configuration; using Dalamud.Configuration.Internal; using Dalamud.Game.Gui; +using Dalamud.Game.Gui.Dtr; using Dalamud.Game.Text; using Dalamud.Logging.Internal; using Dalamud.Plugin.Internal.Exceptions; @@ -790,6 +790,10 @@ namespace Dalamud.Plugin.Internal } } + // We need to handle removed DTR nodes here, as otherwise, plugins will not be able to re-add their bar entries after updates. + var dtr = Service.Get(); + dtr.HandleRemovedNodes(); + try { await this.InstallPluginAsync(metadata.UpdateManifest, metadata.UseTesting, PluginLoadReason.Update);