mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Merge pull request #2448 from Haselnussbomber/dtr-removenode-exception-fix
Fix KeyNotFoundException in DtrBar.RemoveNode
This commit is contained in:
commit
dc9ff0a54c
1 changed files with 35 additions and 26 deletions
|
|
@ -257,7 +257,7 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
|
||||||
/// <param name="toRemove">The resources to remove.</param>
|
/// <param name="toRemove">The resources to remove.</param>
|
||||||
internal void RemoveEntry(DtrBarEntry toRemove)
|
internal void RemoveEntry(DtrBarEntry toRemove)
|
||||||
{
|
{
|
||||||
this.RemoveNode(toRemove.TextNode);
|
this.RemoveNode(toRemove);
|
||||||
|
|
||||||
if (toRemove.Storage != null)
|
if (toRemove.Storage != null)
|
||||||
{
|
{
|
||||||
|
|
@ -378,12 +378,12 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
|
||||||
|
|
||||||
var isHide = !data.Shown || data.UserHidden;
|
var isHide = !data.Shown || data.UserHidden;
|
||||||
var node = data.TextNode;
|
var node = data.TextNode;
|
||||||
var nodeHidden = !node->AtkResNode.IsVisible();
|
var nodeHidden = !node->IsVisible();
|
||||||
|
|
||||||
if (!isHide)
|
if (!isHide)
|
||||||
{
|
{
|
||||||
if (nodeHidden)
|
if (nodeHidden)
|
||||||
node->AtkResNode.ToggleVisibility(true);
|
node->ToggleVisibility(true);
|
||||||
|
|
||||||
if (data is { Added: true, Text: not null, TextNode: not null } && (data.Dirty || nodeHidden))
|
if (data is { Added: true, Text: not null, TextNode: not null } && (data.Dirty || nodeHidden))
|
||||||
{
|
{
|
||||||
|
|
@ -397,27 +397,27 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
|
||||||
|
|
||||||
ushort w = 0, h = 0;
|
ushort w = 0, h = 0;
|
||||||
node->GetTextDrawSize(&w, &h, node->NodeText.StringPtr);
|
node->GetTextDrawSize(&w, &h, node->NodeText.StringPtr);
|
||||||
node->AtkResNode.SetWidth(w);
|
node->SetWidth(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
var elementWidth = data.TextNode->AtkResNode.Width + this.configuration.DtrSpacing;
|
var elementWidth = data.TextNode->Width + this.configuration.DtrSpacing;
|
||||||
|
|
||||||
if (this.configuration.DtrSwapDirection)
|
if (this.configuration.DtrSwapDirection)
|
||||||
{
|
{
|
||||||
data.TextNode->AtkResNode.SetPositionFloat(runningXPos + this.configuration.DtrSpacing, 2);
|
data.TextNode->SetPositionFloat(runningXPos + this.configuration.DtrSpacing, 2);
|
||||||
runningXPos += elementWidth;
|
runningXPos += elementWidth;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
runningXPos -= elementWidth;
|
runningXPos -= elementWidth;
|
||||||
data.TextNode->AtkResNode.SetPositionFloat(runningXPos, 2);
|
data.TextNode->SetPositionFloat(runningXPos, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!nodeHidden)
|
else if (!nodeHidden)
|
||||||
{
|
{
|
||||||
// If we want the node hidden, shift it up, to prevent collision conflicts
|
// If we want the node hidden, shift it up, to prevent collision conflicts
|
||||||
node->AtkResNode.SetYFloat(-collisionNode->Height * dtr->RootNode->ScaleX);
|
node->SetYFloat(-collisionNode->Height * dtr->RootNode->ScaleX);
|
||||||
node->AtkResNode.ToggleVisibility(false);
|
node->ToggleVisibility(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Dirty = false;
|
data.Dirty = false;
|
||||||
|
|
@ -516,8 +516,8 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
|
||||||
|
|
||||||
var node = data.TextNode = this.MakeNode(++this.runningNodeIds);
|
var node = data.TextNode = this.MakeNode(++this.runningNodeIds);
|
||||||
|
|
||||||
this.eventHandles.TryAdd(node->AtkResNode.NodeId, new List<IAddonEventHandle>());
|
this.eventHandles.TryAdd(node->NodeId, new List<IAddonEventHandle>());
|
||||||
this.eventHandles[node->AtkResNode.NodeId].AddRange(new List<IAddonEventHandle>
|
this.eventHandles[node->NodeId].AddRange(new List<IAddonEventHandle>
|
||||||
{
|
{
|
||||||
this.uiEventManager.AddEvent(AddonEventManager.DalamudInternalKey, (nint)dtr, (nint)node, AddonEventType.MouseOver, this.DtrEventHandler),
|
this.uiEventManager.AddEvent(AddonEventManager.DalamudInternalKey, (nint)dtr, (nint)node, AddonEventType.MouseOver, this.DtrEventHandler),
|
||||||
this.uiEventManager.AddEvent(AddonEventManager.DalamudInternalKey, (nint)dtr, (nint)node, AddonEventType.MouseOut, this.DtrEventHandler),
|
this.uiEventManager.AddEvent(AddonEventManager.DalamudInternalKey, (nint)dtr, (nint)node, AddonEventType.MouseOut, this.DtrEventHandler),
|
||||||
|
|
@ -528,8 +528,8 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
|
||||||
while (lastChild->PrevSiblingNode != null) lastChild = lastChild->PrevSiblingNode;
|
while (lastChild->PrevSiblingNode != null) lastChild = lastChild->PrevSiblingNode;
|
||||||
Log.Debug($"Found last sibling: {(ulong)lastChild:X}");
|
Log.Debug($"Found last sibling: {(ulong)lastChild:X}");
|
||||||
lastChild->PrevSiblingNode = (AtkResNode*)node;
|
lastChild->PrevSiblingNode = (AtkResNode*)node;
|
||||||
node->AtkResNode.ParentNode = lastChild->ParentNode;
|
node->ParentNode = lastChild->ParentNode;
|
||||||
node->AtkResNode.NextSiblingNode = lastChild;
|
node->NextSiblingNode = lastChild;
|
||||||
|
|
||||||
dtr->RootNode->ChildCount = (ushort)(dtr->RootNode->ChildCount + 1);
|
dtr->RootNode->ChildCount = (ushort)(dtr->RootNode->ChildCount + 1);
|
||||||
Log.Debug("Set last sibling of DTR and updated child count");
|
Log.Debug("Set last sibling of DTR and updated child count");
|
||||||
|
|
@ -542,22 +542,31 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveNode(AtkTextNode* node)
|
private void RemoveNode(DtrBarEntry data)
|
||||||
{
|
{
|
||||||
var dtr = this.GetDtr();
|
var dtr = this.GetDtr();
|
||||||
|
var node = data.TextNode;
|
||||||
if (dtr == null || dtr->RootNode == null || dtr->UldManager.NodeList == null || node == null) return;
|
if (dtr == null || dtr->RootNode == null || dtr->UldManager.NodeList == null || node == null) return;
|
||||||
|
|
||||||
this.eventHandles[node->AtkResNode.NodeId].ForEach(handle => this.uiEventManager.RemoveEvent(AddonEventManager.DalamudInternalKey, handle));
|
if (this.eventHandles.TryGetValue(node->NodeId, out var eventHandles))
|
||||||
this.eventHandles[node->AtkResNode.NodeId].Clear();
|
{
|
||||||
|
eventHandles.ForEach(handle => this.uiEventManager.RemoveEvent(AddonEventManager.DalamudInternalKey, handle));
|
||||||
|
eventHandles.Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Warning("Could not find AtkResNode with NodeId {nodeId} in eventHandles", node->NodeId);
|
||||||
|
}
|
||||||
|
|
||||||
var tmpPrevNode = node->AtkResNode.PrevSiblingNode;
|
var tmpPrevNode = node->PrevSiblingNode;
|
||||||
var tmpNextNode = node->AtkResNode.NextSiblingNode;
|
var tmpNextNode = node->NextSiblingNode;
|
||||||
|
|
||||||
// if (tmpNextNode != null)
|
// if (tmpNextNode != null)
|
||||||
tmpNextNode->PrevSiblingNode = tmpPrevNode;
|
tmpNextNode->PrevSiblingNode = tmpPrevNode;
|
||||||
if (tmpPrevNode != null)
|
if (tmpPrevNode != null)
|
||||||
tmpPrevNode->NextSiblingNode = tmpNextNode;
|
tmpPrevNode->NextSiblingNode = tmpNextNode;
|
||||||
node->AtkResNode.Destroy(true);
|
node->Destroy(true);
|
||||||
|
data.TextNode = null;
|
||||||
|
|
||||||
dtr->RootNode->ChildCount = (ushort)(dtr->RootNode->ChildCount - 1);
|
dtr->RootNode->ChildCount = (ushort)(dtr->RootNode->ChildCount - 1);
|
||||||
Log.Debug("Set last sibling of DTR and updated child count");
|
Log.Debug("Set last sibling of DTR and updated child count");
|
||||||
|
|
@ -575,13 +584,13 @@ internal sealed unsafe class DtrBar : IInternalDisposableService, IDtrBar
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
newTextNode->AtkResNode.NodeId = nodeId;
|
newTextNode->NodeId = nodeId;
|
||||||
newTextNode->AtkResNode.Type = NodeType.Text;
|
newTextNode->Type = NodeType.Text;
|
||||||
newTextNode->AtkResNode.NodeFlags = NodeFlags.AnchorLeft | NodeFlags.AnchorTop | NodeFlags.Enabled | NodeFlags.RespondToMouse | NodeFlags.HasCollision | NodeFlags.EmitsEvents;
|
newTextNode->NodeFlags = NodeFlags.AnchorLeft | NodeFlags.AnchorTop | NodeFlags.Enabled | NodeFlags.RespondToMouse | NodeFlags.HasCollision | NodeFlags.EmitsEvents;
|
||||||
newTextNode->AtkResNode.DrawFlags = 12;
|
newTextNode->DrawFlags = 12;
|
||||||
newTextNode->AtkResNode.SetWidth(22);
|
newTextNode->SetWidth(22);
|
||||||
newTextNode->AtkResNode.SetHeight(22);
|
newTextNode->SetHeight(22);
|
||||||
newTextNode->AtkResNode.SetPositionFloat(-200, 2);
|
newTextNode->SetPositionFloat(-200, 2);
|
||||||
|
|
||||||
newTextNode->LineSpacing = 12;
|
newTextNode->LineSpacing = 12;
|
||||||
newTextNode->AlignmentFontType = 5;
|
newTextNode->AlignmentFontType = 5;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue