From f51a51c5476f30a0e51724c8d816f358132d43a0 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Mon, 25 Nov 2024 18:24:46 +0100 Subject: [PATCH] Fix when context menu appears when right-clicking satisfaction NPC menus --- .../Controller/ContextMenuController.cs | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Questionable/Controller/ContextMenuController.cs b/Questionable/Controller/ContextMenuController.cs index fca77dd8..45230c5f 100644 --- a/Questionable/Controller/ContextMenuController.cs +++ b/Questionable/Controller/ContextMenuController.cs @@ -4,8 +4,10 @@ using Dalamud.Game.Gui.ContextMenu; using Dalamud.Game.Text; using Dalamud.Plugin.Services; using FFXIVClientStructs.FFXIV.Client.Game; +using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using LLib.GameData; +using LLib.GameUI; using Microsoft.Extensions.Logging; using Questionable.Data; using Questionable.Functions; @@ -59,10 +61,17 @@ internal sealed class ContextMenuController : IDisposable private void MenuOpened(IMenuOpenedArgs args) { - uint itemId = (uint)_gameGui.HoveredItem; - if (itemId == 0) + // no clue why this isn't the actual name, but here we are + if (args.AddonName != null) return; + uint itemId = GetHoveredSatisfactionSupplyItemId(); + if (itemId == 0) + { + _logger.LogTrace("Ignoring context menu, no item hovered"); + return; + } + if (itemId > 1_000_000) itemId -= 1_000_000; @@ -74,6 +83,25 @@ internal sealed class ContextMenuController : IDisposable AddContextMenuEntry(args, itemId, npcId, EExtendedClassJob.Miner, "Mine"); AddContextMenuEntry(args, itemId, npcId, EExtendedClassJob.Botanist, "Harvest"); } + else + _logger.LogDebug("No custom delivery NPC found for item {ItemId}.", itemId); + } + + private unsafe uint GetHoveredSatisfactionSupplyItemId() + { + AgentSatisfactionSupply* agent = AgentSatisfactionSupply.Instance(); + if (agent == null || !agent->IsAgentActive()) + return 0; + + + if (_gameGui.TryGetAddonByName("SatisfactionSupply", out AddonSatisfactionSupply* addon) && + LAddon.IsAddonReady(&addon->AtkUnitBase) && + addon->HoveredElementIndex is >= 0 and <= 2) + { + return agent->Items[addon->HoveredElementIndex].Id; + } + + return 0; } private void AddContextMenuEntry(IMenuOpenedArgs args, uint itemId, uint npcId, EExtendedClassJob extendedClassJob, @@ -86,7 +114,7 @@ internal sealed class ContextMenuController : IDisposable if (!_gatheringData.TryGetGatheringPointId(itemId, classJob, out _)) { - _logger.LogInformation("No gathering point found for current job."); + _logger.LogInformation("No gathering point found for {ClassJob}.", classJob); return; }