diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenuItem.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenuItem.cs index 31a9f9119..c286ac4bb 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenuItem.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenuItem.cs @@ -19,9 +19,9 @@ namespace Dalamud.Game.Gui.ContextMenus } /// - /// Gets or sets the name of the item. + /// Gets the name of the item. /// - public SeString Name { get; set; } + public SeString Name { get; internal set; } /// /// Gets or sets a value indicating whether or not the item is enabled. When enabled, an item is selectable. diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenuOpenedArgs.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenuOpenedArgs.cs index 66043c814..35ce0e398 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenuOpenedArgs.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenuOpenedArgs.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; +using Dalamud.Game.Text.SeStringHandling; using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI.Agent; @@ -59,5 +60,22 @@ namespace Dalamud.Game.Gui.ContextMenus /// Gets the item context associated with the context menu. /// public InventoryItemContext? InventoryItemContext { get; init; } + + /// + /// Append a custom context menu item to this context menu. + /// + /// The name of the item. + /// The action to be executed once selected. + public void AddCustomItem(SeString name, CustomContextMenuItemSelectedDelegate selected) => + this.Items.Add(new CustomContextMenuItem(name, selected)); + + /// + /// Append a custom submenu to this context menu. + /// Note that these cannot be nested, and will be ignored if they are. + /// + /// The name of the submenu. + /// The action to be executed once opened. + public void AddCustomSubMenu(SeString name, ContextMenuOpenedDelegate opened) => + this.Items.Add(new OpenSubContextMenuItem(name, opened)); } } diff --git a/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/ContextMenuAgingStep.cs b/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/ContextMenuAgingStep.cs index 675b21087..3752a09f5 100644 --- a/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/ContextMenuAgingStep.cs +++ b/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/ContextMenuAgingStep.cs @@ -154,30 +154,30 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps switch (this.currentSubStep) { case SubStep.TestSubMenu: - args.Items.Add(new OpenSubContextMenuItem("Aging Submenu", openedArgs => + args.AddCustomSubMenu("Aging Submenu", openedArgs => { - openedArgs.Items.Add(new CustomContextMenuItem("Submenu Item 1", args => + openedArgs.AddCustomItem("Submenu Item 1", _ => { this.multipleTriggerOne = true; - })); + }); - openedArgs.Items.Add(new CustomContextMenuItem("Submenu Item 2", args => + openedArgs.AddCustomItem("Submenu Item 2", _ => { this.multipleTriggerTwo = true; - })); - })); + }); + }); return; case SubStep.TestMultiple: - args.Items.Insert(0, new CustomContextMenuItem("Aging Item 1", args => + args.AddCustomItem("Aging Item 1", _ => { this.multipleTriggerOne = true; - })); + }); - args.Items.Add(new CustomContextMenuItem("Aging Item 2", args => + args.AddCustomItem("Aging Item 2", _ => { this.multipleTriggerTwo = true; - })); + }); return; case SubStep.Finish: @@ -190,13 +190,13 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps if (this.currentSubStep != SubStep.TestItem) return; - args.Items.Add(new CustomContextMenuItem("Aging Item", selectedArgs => + args.AddCustomItem("Aging Item", _ => { this.clickedItemId = args.InventoryItemContext!.Id; this.clickedItemHq = args.InventoryItemContext!.IsHighQuality; this.clickedItemCount = args.InventoryItemContext!.Count; Log.Warning("Clicked item: {Id} hq:{Hq} count:{Count}", this.clickedItemId, this.clickedItemHq, this.clickedItemCount); - })); + }); break; case null: @@ -214,7 +214,7 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps if (this.currentSubStep != SubStep.TestGameObject || args.GameObjectContext == null || args.GameObjectContext.Name.IsNullOrEmpty()) return; - args.Items.Add(new CustomContextMenuItem("Aging Character", selectedArgs => + args.AddCustomItem("Aging Character", _ => { this.clickedPlayerName = args.GameObjectContext.Name!; this.clickedPlayerWorld = args.GameObjectContext.WorldId; @@ -222,7 +222,7 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps this.clickedPlayerId = args.GameObjectContext.Id; Log.Warning("Clicked player: {Name} world:{World} cid:{Cid} id:{Id}", this.clickedPlayerName, this.clickedPlayerWorld, this.clickedPlayerCid, this.clickedPlayerId); - })); + }); break; }