feat(ContextMenu): add convenience methods to ContextMenuOpenedArgs

This commit is contained in:
goaaats 2022-01-29 15:45:36 +01:00
parent 6131c3efa1
commit d88e0bcf54
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 34 additions and 16 deletions

View file

@ -19,9 +19,9 @@ namespace Dalamud.Game.Gui.ContextMenus
} }
/// <summary> /// <summary>
/// Gets or sets the name of the item. /// Gets the name of the item.
/// </summary> /// </summary>
public SeString Name { get; set; } public SeString Name { get; internal set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether or not the item is enabled. When enabled, an item is selectable. /// Gets or sets a value indicating whether or not the item is enabled. When enabled, an item is selectable.

View file

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Dalamud.Game.Text.SeStringHandling;
using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Client.UI.Agent;
@ -59,5 +60,22 @@ namespace Dalamud.Game.Gui.ContextMenus
/// Gets the item context associated with the context menu. /// Gets the item context associated with the context menu.
/// </summary> /// </summary>
public InventoryItemContext? InventoryItemContext { get; init; } public InventoryItemContext? InventoryItemContext { get; init; }
/// <summary>
/// Append a custom context menu item to this context menu.
/// </summary>
/// <param name="name">The name of the item.</param>
/// <param name="selected">The action to be executed once selected.</param>
public void AddCustomItem(SeString name, CustomContextMenuItemSelectedDelegate selected) =>
this.Items.Add(new CustomContextMenuItem(name, selected));
/// <summary>
/// Append a custom submenu to this context menu.
/// Note that these cannot be nested, and will be ignored if they are.
/// </summary>
/// <param name="name">The name of the submenu.</param>
/// <param name="opened">The action to be executed once opened.</param>
public void AddCustomSubMenu(SeString name, ContextMenuOpenedDelegate opened) =>
this.Items.Add(new OpenSubContextMenuItem(name, opened));
} }
} }

View file

@ -154,30 +154,30 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
switch (this.currentSubStep) switch (this.currentSubStep)
{ {
case SubStep.TestSubMenu: 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; this.multipleTriggerOne = true;
})); });
openedArgs.Items.Add(new CustomContextMenuItem("Submenu Item 2", args => openedArgs.AddCustomItem("Submenu Item 2", _ =>
{ {
this.multipleTriggerTwo = true; this.multipleTriggerTwo = true;
})); });
})); });
return; return;
case SubStep.TestMultiple: case SubStep.TestMultiple:
args.Items.Insert(0, new CustomContextMenuItem("Aging Item 1", args => args.AddCustomItem("Aging Item 1", _ =>
{ {
this.multipleTriggerOne = true; this.multipleTriggerOne = true;
})); });
args.Items.Add(new CustomContextMenuItem("Aging Item 2", args => args.AddCustomItem("Aging Item 2", _ =>
{ {
this.multipleTriggerTwo = true; this.multipleTriggerTwo = true;
})); });
return; return;
case SubStep.Finish: case SubStep.Finish:
@ -190,13 +190,13 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
if (this.currentSubStep != SubStep.TestItem) if (this.currentSubStep != SubStep.TestItem)
return; return;
args.Items.Add(new CustomContextMenuItem("Aging Item", selectedArgs => args.AddCustomItem("Aging Item", _ =>
{ {
this.clickedItemId = args.InventoryItemContext!.Id; this.clickedItemId = args.InventoryItemContext!.Id;
this.clickedItemHq = args.InventoryItemContext!.IsHighQuality; this.clickedItemHq = args.InventoryItemContext!.IsHighQuality;
this.clickedItemCount = args.InventoryItemContext!.Count; this.clickedItemCount = args.InventoryItemContext!.Count;
Log.Warning("Clicked item: {Id} hq:{Hq} count:{Count}", this.clickedItemId, this.clickedItemHq, this.clickedItemCount); Log.Warning("Clicked item: {Id} hq:{Hq} count:{Count}", this.clickedItemId, this.clickedItemHq, this.clickedItemCount);
})); });
break; break;
case null: 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()) if (this.currentSubStep != SubStep.TestGameObject || args.GameObjectContext == null || args.GameObjectContext.Name.IsNullOrEmpty())
return; return;
args.Items.Add(new CustomContextMenuItem("Aging Character", selectedArgs => args.AddCustomItem("Aging Character", _ =>
{ {
this.clickedPlayerName = args.GameObjectContext.Name!; this.clickedPlayerName = args.GameObjectContext.Name!;
this.clickedPlayerWorld = args.GameObjectContext.WorldId; this.clickedPlayerWorld = args.GameObjectContext.WorldId;
@ -222,7 +222,7 @@ namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps
this.clickedPlayerId = args.GameObjectContext.Id; this.clickedPlayerId = args.GameObjectContext.Id;
Log.Warning("Clicked player: {Name} world:{World} cid:{Cid} id:{Id}", this.clickedPlayerName, this.clickedPlayerWorld, this.clickedPlayerCid, this.clickedPlayerId); Log.Warning("Clicked player: {Name} world:{World} cid:{Cid} id:{Id}", this.clickedPlayerName, this.clickedPlayerWorld, this.clickedPlayerCid, this.clickedPlayerId);
})); });
break; break;
} }