Quantcast Add item link context menu entry - ESOUI
Thread Tools Display Modes
03/25/20, 07:32 AM   #1
Keldor
 
Keldor's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 60
Add item link context menu entry

Hello everybody,

is there any way to add a menu entry to the item link context menu like in chat?

For the inventory item context menu I used the following line but I was not able to find any hook for the item link context menu.

Lua Code:
  1. ZO_PreHook("ZO_InventorySlot_ShowContextMenu", ESOFarmBuddy.OnInventoryContextMenu)


Keldor
__________________
ESO-Database.com | Character- and Guild Database [EN/DE] (System Status)
ESO-Skillfactory.com | ESO Build planer [EN/DE/FR]
ESO-LFG.com | The ESO Looking for Group Tool [EN/DE/FR]
  Reply With Quote
03/25/20, 08:43 AM   #2
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,864
For inventory context menus PLEASE PLEASE PLEASE use LibCustomMenu (https://www.esoui.com/downloads/info...ustomMenu.html) to assure it does not throw any security related errors anymore and all other addons work properly!
And do not prehook any context menu stuff but use the RegisterContextMenu functions of the librray! See the lib documentation for further details please, search at teh description for "lib:RegisterContextMenu".

Edit:
Benefit is also that the lib will provide some functions like register a context menu for normal right click and for right click + mopdifier key (alt, shift, ctrl).
Other addons already use their own ways toa chieve this like FCOItemSaver does with SHIFT+RIGHT click. This will make them all work properly together and NOT show any contextmenus where they are not wanted to be shown (e.g. clicked right+shift = show a 2nd context menu and not the normal one -> Your prehook would destroy this or show the normal context menu entries then as well).



For the chat it's posible as well, and you also should use AddCustomMenuEntry of LibCustomMenu here. Let me find an example from my WishList addon e.g.

Lua Code:
  1. local function linkContextMenu(link, button, _, _, linkType, ...)
  2.     if button == MOUSE_BUTTON_INDEX_RIGHT and linkType == ITEM_LINK_TYPE then
  3.        local itemType = GetItemLinkItemType(link)
  4.        ...
  5.        AddCustomMenuEntry(...)
  6.     end
  7. end
  8.  
  9.  
  10.     --Link handler (for right clicking an item in chat, etc.)
  11.     LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_MOUSE_UP_EVENT, linkContextMenu)

Last edited by Baertram : 03/25/20 at 08:49 AM.
  Reply With Quote
03/25/20, 09:12 AM   #3
Keldor
 
Keldor's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 60
Thanks Baertram for pointing this out. It's my first time creating an addon with an UI
There are so many tricks to learn that you can't even know at first

I've rewritten the PreHook part to use LibCustomMenu for Farm Buddy. I'll try your posted snippet later, thanks!

Keldor
__________________
ESO-Database.com | Character- and Guild Database [EN/DE] (System Status)
ESO-Skillfactory.com | ESO Build planer [EN/DE/FR]
ESO-LFG.com | The ESO Looking for Group Tool [EN/DE/FR]
  Reply With Quote
03/26/20, 05:39 AM   #4
Keldor
 
Keldor's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 60
Thanks Baertram, your snippet works well. I looked at your WishList AddOn and my code looks like this.
Is there something here that also needs to be addressed or is the code okay?

Lua Code:
  1. function ESOFarmBuddy.LinkContextMenu(link, button, _, _, linkType, ...)
  2.     if button == MOUSE_BUTTON_INDEX_RIGHT and linkType == ITEM_LINK_TYPE then
  3.         zo_callLater(
  4.             function()
  5.                 AddCustomMenuItem(GetString(ESOFB_MENU_TRACK), function() ESOFarmBuddy.TrackItemFromLink(link) end, MENU_ADD_OPTION_LABEL)
  6.                 ShowMenu()
  7.             end
  8.         , 4)
  9.     end
  10. end
  11.  
  12. LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_MOUSE_UP_EVENT, ESOFarmBuddy.LinkContextMenu)

Another question: Is there any way to add a context menu entry to auction house result items?

Keldor
__________________
ESO-Database.com | Character- and Guild Database [EN/DE] (System Status)
ESO-Skillfactory.com | ESO Build planer [EN/DE/FR]
ESO-LFG.com | The ESO Looking for Group Tool [EN/DE/FR]

Last edited by Keldor : 03/26/20 at 06:28 AM.
  Reply With Quote
03/26/20, 08:38 AM   #5
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,864
You could even try to skip the zo_callLater function at all, not sure if this will make a difference there.
I think I had added it to assure it will add the the menu entries after the exisitng ones, as the callback function fires as the link_handler MouseUp fores.
But I think the ZOs code will be run first and then the other link handler callback functions (not sure about this though!)

Try to remove the zo_callLater and check if it works properly, maybe also add WishList as an addon to test what happens if multiple addons add context menus to the itemlinks in chat items.

For the guild store contextmenus I'd assume this is either added to any guildstore related addon like AwesomeGuildStore already (maybe use Notepad++ -> menu search -> search in files to search the live/AddOns/AwesomeGuildStore folder for AddMenuItem (if you find these tell sirinsidiator to use LibCustomMenu instead please ) or AddCustomMenuItem and see if this is used anywhere as context menu (could be an own created context menu at own controls as well though).

I'll have alook at the esoui src code later if I can find a proper way to add a context menu entry there.

Edit:
TradingHouse should be a normal ZO_Inventory I think.
Try if adding a context menu to normal inventory, like described above with LibCustomMenu:RegisterContextMenu) items will be shown at the trading house search results as well.
You would need to check via e.g. the slotControl of the callback function if you are at the trading house (GetParent or GetOwner or whatever should return something like TRADING_HOUSE then) and maybe only add those entries you need there.

If this does not work, maybe ask Sirinsidiator at the gitter IM.

Edit2:
Could also work:
SecurePostHook ZO_TradingHouse_OnSearchResultClicked(searchResultSlot, button) and check if button = MOUSE_BUTTON_INDEX_RIGHT, then show your context menu on the searchResultSlot.

Right mouse will preview items already so you need to be carefull if your context menu will fail to show because of any preview action taking place etc.
The code used there to check if a preview can take place is:

Lua Code:
  1. local tradingHouseIndex = GetTradingHouseIndexForPreviewFromSlot(searchResultSlot)
  2.         if tradingHouseIndex ~= nil then
  3.         --Preview item
  4.         end

So you only need to check the same in your SecurePostHook and if tradingHouseIndex == nil show your contextmenu instead. This should take care of this.

Last edited by Baertram : 03/26/20 at 08:47 AM.
  Reply With Quote
03/26/20, 09:45 AM   #6
Keldor
 
Keldor's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 60
Hey Baertram,

thanks for the detailed info!
I've tested this without zo_callLater but then the menu entry not appears

For the auction house I've got it woking with this code:
Lua Code:
  1. function ESOFarmBuddy.TradingHouseContextMenu(searchResultSlot, button)
  2.     if button == MOUSE_BUTTON_INDEX_RIGHT then
  3.         local inventorySlot = ZO_InventorySlot_GetInventorySlotComponents(searchResultSlot)
  4.         local tradingHouseIndex = ZO_Inventory_GetSlotIndex(inventorySlot)
  5.         if tradingHouseIndex ~= nil then
  6.             local itemLink = GetTradingHouseSearchResultItemLink(tradingHouseIndex)
  7.  
  8.             zo_callLater(
  9.                     function()
  10.                         AddCustomMenuItem(GetString(ESOFB_MENU_TRACK), function() ESOFarmBuddy.TrackItemFromLink(itemLink) end, MENU_ADD_OPTION_LABEL)
  11.                         ShowMenu()
  12.                     end
  13.             , 4)
  14.         end
  15.     end
  16. end
  17.  
  18. SecurePostHook("ZO_TradingHouse_OnSearchResultClicked", ESOFarmBuddy.TradingHouseContextMenu)

It also works together with your WishList AddOn



Many thanks for your help Baertram I've learned a lot about the UI in ESO.

Keldor
__________________
ESO-Database.com | Character- and Guild Database [EN/DE] (System Status)
ESO-Skillfactory.com | ESO Build planer [EN/DE/FR]
ESO-LFG.com | The ESO Looking for Group Tool [EN/DE/FR]
  Reply With Quote
03/26/20, 10:13 AM   #7
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,864
Does it work properly together with the preview function of the items in teh trading house search results?
As I mentioned the right click is already used for the preview.
The SecurePostHook should assure it will FIRST do the preview and then try to show the contetx menu.

Edit:
But the zo_callLater in the trading house stuff shouldn#t be neede as it is a SecurePOSTHook already.
Please try to remove this and only use your code + ShowMenu(), should be enough.
  Reply With Quote
03/26/20, 10:26 AM   #8
Keldor
 
Keldor's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 60
I've not noticed any issues with the preview in the guild store.

You're right. The zo_callLater is not needed for the SecurePOSTHook. I'll remove it in the next version, thanks!
__________________
ESO-Database.com | Character- and Guild Database [EN/DE] (System Status)
ESO-Skillfactory.com | ESO Build planer [EN/DE/FR]
ESO-LFG.com | The ESO Looking for Group Tool [EN/DE/FR]
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Add item link context menu entry

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off