From 71e746ee674cc3907f190f807bd939fbc2d185d2 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 30 Apr 2021 15:22:49 -0400 Subject: [PATCH] fix(context): store agent for later use --- .../Functions/ContextMenu/ContextMenu.cs | 24 ++++++++++++++----- .../ContextMenu/CustomContextMenuItem.cs | 2 ++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/XivCommon/Functions/ContextMenu/ContextMenu.cs b/XivCommon/Functions/ContextMenu/ContextMenu.cs index bc5c0f5..a628cd8 100755 --- a/XivCommon/Functions/ContextMenu/ContextMenu.cs +++ b/XivCommon/Functions/ContextMenu/ContextMenu.cs @@ -269,6 +269,13 @@ namespace XivCommon.Functions.ContextMenu { // remove any NormalContextMenuItems that may have been added - these will crash the game args.Items.RemoveAll(item => item is NormalContextMenuItem); + // set the agent of any remaining custom items + foreach (var item in args.Items) { + if (item is InventoryContextMenuItem custom) { + custom.Agent = agent; + } + } + this.Items.AddRange(args.Items); } else { var info = GetAgentInfo(agent); @@ -294,6 +301,13 @@ namespace XivCommon.Functions.ContextMenu { // remove any InventoryContextMenuItems that may have been added - these will crash the game args.Items.RemoveAll(item => item is InventoryContextMenuItem); + // set the agent of any remaining custom items + foreach (var item in args.Items) { + if (item is NormalContextMenuItem custom) { + custom.Agent = agent; + } + } + this.Items.AddRange(args.Items); } @@ -371,13 +385,12 @@ namespace XivCommon.Functions.ContextMenu { switch (item) { // a custom item is being clicked case NormalContextMenuItem custom: { - var (_, agent) = this.GetContextMenuAgent(); var addonName = this.GetParentAddonName(addon); - var info = GetAgentInfo(agent); + var info = GetAgentInfo(custom.Agent); var args = new ContextMenuItemSelectedArgs( addon, - agent, + custom.Agent, addonName, info.actorId, info.contentIdLower, @@ -394,13 +407,12 @@ namespace XivCommon.Functions.ContextMenu { break; } case InventoryContextMenuItem custom: { - var (_, agent) = this.GetContextMenuAgent(); var addonName = this.GetParentAddonName(addon); - var info = GetInventoryAgentInfo(agent); + var info = GetInventoryAgentInfo(custom.Agent); var args = new InventoryContextMenuItemSelectedArgs( addon, - agent, + custom.Agent, addonName, info.itemId, info.itemAmount, diff --git a/XivCommon/Functions/ContextMenu/CustomContextMenuItem.cs b/XivCommon/Functions/ContextMenu/CustomContextMenuItem.cs index b5fbf8c..e7a7a7d 100755 --- a/XivCommon/Functions/ContextMenu/CustomContextMenuItem.cs +++ b/XivCommon/Functions/ContextMenu/CustomContextMenuItem.cs @@ -6,6 +6,8 @@ namespace XivCommon.Functions.ContextMenu { /// public abstract class CustomContextMenuItem : BaseContextMenuItem where T : Delegate { + internal IntPtr Agent { get; set; } + /// /// The name of the context item to be shown for English clients. ///