fix(context): store agent for later use

This commit is contained in:
Anna 2021-04-30 15:22:49 -04:00
parent 35e76ad570
commit 71e746ee67
2 changed files with 20 additions and 6 deletions

View File

@ -269,6 +269,13 @@ namespace XivCommon.Functions.ContextMenu {
// remove any NormalContextMenuItems that may have been added - these will crash the game // remove any NormalContextMenuItems that may have been added - these will crash the game
args.Items.RemoveAll(item => item is NormalContextMenuItem); 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); this.Items.AddRange(args.Items);
} else { } else {
var info = GetAgentInfo(agent); 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 // remove any InventoryContextMenuItems that may have been added - these will crash the game
args.Items.RemoveAll(item => item is InventoryContextMenuItem); 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); this.Items.AddRange(args.Items);
} }
@ -371,13 +385,12 @@ namespace XivCommon.Functions.ContextMenu {
switch (item) { switch (item) {
// a custom item is being clicked // a custom item is being clicked
case NormalContextMenuItem custom: { case NormalContextMenuItem custom: {
var (_, agent) = this.GetContextMenuAgent();
var addonName = this.GetParentAddonName(addon); var addonName = this.GetParentAddonName(addon);
var info = GetAgentInfo(agent); var info = GetAgentInfo(custom.Agent);
var args = new ContextMenuItemSelectedArgs( var args = new ContextMenuItemSelectedArgs(
addon, addon,
agent, custom.Agent,
addonName, addonName,
info.actorId, info.actorId,
info.contentIdLower, info.contentIdLower,
@ -394,13 +407,12 @@ namespace XivCommon.Functions.ContextMenu {
break; break;
} }
case InventoryContextMenuItem custom: { case InventoryContextMenuItem custom: {
var (_, agent) = this.GetContextMenuAgent();
var addonName = this.GetParentAddonName(addon); var addonName = this.GetParentAddonName(addon);
var info = GetInventoryAgentInfo(agent); var info = GetInventoryAgentInfo(custom.Agent);
var args = new InventoryContextMenuItemSelectedArgs( var args = new InventoryContextMenuItemSelectedArgs(
addon, addon,
agent, custom.Agent,
addonName, addonName,
info.itemId, info.itemId,
info.itemAmount, info.itemAmount,

View File

@ -6,6 +6,8 @@ namespace XivCommon.Functions.ContextMenu {
/// </summary> /// </summary>
public abstract class CustomContextMenuItem<T> : BaseContextMenuItem public abstract class CustomContextMenuItem<T> : BaseContextMenuItem
where T : Delegate { where T : Delegate {
internal IntPtr Agent { get; set; }
/// <summary> /// <summary>
/// The name of the context item to be shown for English clients. /// The name of the context item to be shown for English clients.
/// </summary> /// </summary>