mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-30 04:13:40 +01:00
IContextMenu Tweaks and Cleanup (#1753)
* Tweaks and cleanup * Fix backwards logic
This commit is contained in:
parent
e075a26ff7
commit
e32fc00277
4 changed files with 53 additions and 28 deletions
|
|
@ -47,14 +47,14 @@ internal sealed unsafe class ContextMenu : IInternalDisposableService, IContextM
|
|||
this.addonContextMenuOnMenuSelectedHook.Enable();
|
||||
}
|
||||
|
||||
private unsafe delegate ushort RaptureAtkModuleOpenAddonByAgentDelegate(RaptureAtkModule* module, byte* addonName, AtkUnitBase* addon, int valueCount, AtkValue* values, AgentInterface* agent, nint a7, ushort parentAddonId);
|
||||
private delegate ushort RaptureAtkModuleOpenAddonByAgentDelegate(RaptureAtkModule* module, byte* addonName, AtkUnitBase* addon, int valueCount, AtkValue* values, AgentInterface* agent, nint a7, ushort parentAddonId);
|
||||
|
||||
private unsafe delegate bool AddonContextMenuOnMenuSelectedDelegate(AddonContextMenu* addon, int selectedIdx, byte a3);
|
||||
private delegate bool AddonContextMenuOnMenuSelectedDelegate(AddonContextMenu* addon, int selectedIdx, byte a3);
|
||||
|
||||
private unsafe delegate ushort RaptureAtkModuleOpenAddonDelegate(RaptureAtkModule* a1, uint addonNameId, uint valueCount, AtkValue* values, AgentInterface* parentAgent, ulong unk, ushort parentAddonId, int unk2);
|
||||
private delegate ushort RaptureAtkModuleOpenAddonDelegate(RaptureAtkModule* a1, uint addonNameId, uint valueCount, AtkValue* values, AgentInterface* parentAgent, ulong unk, ushort parentAddonId, int unk2);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public event IContextMenu.OnMenuOpenedDelegate OnMenuOpened;
|
||||
public event IContextMenu.OnMenuOpenedDelegate? OnMenuOpened;
|
||||
|
||||
private Dictionary<ContextMenuType, List<MenuItem>> MenuItems { get; } = new();
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ internal sealed unsafe class ContextMenu : IInternalDisposableService, IContextM
|
|||
|
||||
private void SetupGenericMenu(int headerCount, int sizeHeaderIdx, int returnHeaderIdx, int submenuHeaderIdx, IReadOnlyList<MenuItem> items, ref int valueCount, ref AtkValue* values)
|
||||
{
|
||||
var itemsWithIdx = items.Select((item, idx) => (item, idx)).OrderBy(i => i.item.Priority);
|
||||
var itemsWithIdx = items.Select((item, idx) => (item, idx)).OrderBy(i => i.item.Priority).ToArray();
|
||||
var prefixItems = itemsWithIdx.Where(i => i.item.Priority < 0).ToArray();
|
||||
var suffixItems = itemsWithIdx.Where(i => i.item.Priority >= 0).ToArray();
|
||||
|
||||
|
|
@ -268,10 +268,10 @@ internal sealed unsafe class ContextMenu : IInternalDisposableService, IContextM
|
|||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (!item.Prefix.HasValue)
|
||||
if (!item.Prefix.HasValue && !item.UseDefaultPrefix)
|
||||
{
|
||||
item.PrefixChar = 'D';
|
||||
item.PrefixColor = 539;
|
||||
item.PrefixChar = MenuItem.DalamudDefaultPrefix.ToIconChar();
|
||||
item.PrefixColor = MenuItem.DalamudDefaultPrefixColor;
|
||||
Log.Warning($"Menu item \"{item.Name}\" has no prefix, defaulting to Dalamud's. Menu items outside of a submenu must have a prefix.");
|
||||
}
|
||||
}
|
||||
|
|
@ -378,13 +378,13 @@ internal sealed unsafe class ContextMenu : IInternalDisposableService, IContextM
|
|||
{
|
||||
// The in game menu actually supports 32 items, but the last item can't have a visible submenu arrow.
|
||||
// As such, we'll only work with 31 items.
|
||||
const int MaxMenuItems = 31;
|
||||
if (items.Count + nativeMenuSize > MaxMenuItems)
|
||||
const int maxMenuItems = 31;
|
||||
if (items.Count + nativeMenuSize > maxMenuItems)
|
||||
{
|
||||
Log.Warning($"Menu size exceeds {MaxMenuItems} items, truncating.");
|
||||
Log.Warning($"Menu size exceeds {maxMenuItems} items, truncating.");
|
||||
var orderedItems = items.OrderBy(i => i.Priority).ToArray();
|
||||
var newItems = orderedItems[..(MaxMenuItems - nativeMenuSize - 1)];
|
||||
var submenuItems = orderedItems[(MaxMenuItems - nativeMenuSize - 1)..];
|
||||
var newItems = orderedItems[..(maxMenuItems - nativeMenuSize - 1)];
|
||||
var submenuItems = orderedItems[(maxMenuItems - nativeMenuSize - 1)..];
|
||||
return newItems.Append(new MenuItem
|
||||
{
|
||||
Prefix = SeIconChar.BoxedLetterD,
|
||||
|
|
@ -450,7 +450,6 @@ internal sealed unsafe class ContextMenu : IInternalDisposableService, IContextM
|
|||
if (callbackId < 0)
|
||||
{
|
||||
selectedIdx = -callbackId - 1;
|
||||
goto original;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -461,17 +460,17 @@ internal sealed unsafe class ContextMenu : IInternalDisposableService, IContextM
|
|||
{
|
||||
if (item.OnClicked == null)
|
||||
throw new InvalidOperationException("Item has no OnClicked handler");
|
||||
item.OnClicked.InvokeSafely(new(
|
||||
(name, items) =>
|
||||
item.OnClicked.InvokeSafely(new MenuItemClickedArgs(
|
||||
(name, submenuItems) =>
|
||||
{
|
||||
short x, y;
|
||||
addon->AtkUnitBase.GetPosition(&x, &y);
|
||||
this.OpenSubmenu(name ?? item.Name, items, x, y);
|
||||
this.OpenSubmenu(name ?? item.Name, submenuItems, x, y);
|
||||
openedSubmenu = true;
|
||||
},
|
||||
this.SelectedParentAddon,
|
||||
this.SelectedAgent,
|
||||
this.SelectedMenuType.Value,
|
||||
this.SelectedMenuType ?? default,
|
||||
this.SelectedEventInterfaces));
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
@ -479,14 +478,14 @@ internal sealed unsafe class ContextMenu : IInternalDisposableService, IContextM
|
|||
Log.Error(e, "Error while handling context menu click");
|
||||
}
|
||||
|
||||
// Close with clicky sound
|
||||
// Close with click sound
|
||||
if (!openedSubmenu)
|
||||
addon->AtkUnitBase.FireCallbackInt(-2);
|
||||
return false;
|
||||
}
|
||||
|
||||
original:
|
||||
// Eventually handled by inventorycontext here: 14022BBD0 (6.51)
|
||||
// Eventually handled by inventory context here: 14022BBD0 (6.51)
|
||||
return this.addonContextMenuOnMenuSelectedHook.Original(addon, selectedIdx, a3);
|
||||
}
|
||||
}
|
||||
|
|
@ -511,7 +510,7 @@ internal class ContextMenuPluginScoped : IInternalDisposableService, IContextMen
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public event IContextMenu.OnMenuOpenedDelegate OnMenuOpened;
|
||||
public event IContextMenu.OnMenuOpenedDelegate? OnMenuOpened;
|
||||
|
||||
private Dictionary<ContextMenuType, List<MenuItem>> MenuItems { get; } = new();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue