Context menu creation / Inventory context menu enhancement - ESOUI
Thread Tools Display Modes
03/25/20, 03:02 PM   #1
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 3,537
Context menu creation / Inventory context menu enhancement

Please read this if you like to add a context menu to your addon or enhance the existing inventory context menu:

It refers to the library "LibCustomMenu".

As this has been used a lot and should not be done anymore to avoid error messages ingame and to make all addons providing context menus (especially at the inventory) work properly together:

Please do NOT use ZO_PreHook on ZO_InventorySlot_ShowContextMenu anymore!

Instead use LibCustomMenu and the function LibCustomMenu:RegisterContextMenu.
And AddCustomMenuItem or AddCustomSubmenuItem for the context menu entries.

Do NOT use and zo_callLater for the menu entries anymore as LibCustomMenu will handle this for you via the parameter "category" of the WIKI mentioned function LibCustomMenu:RegisterContextMenu (for inventory context menus!)
Possible categories can be (Default is LibCustomMenu.CATEGORY_LATE):
From early (at top of the menu) to late (at the bottom of the menu)
See the examples for that function at the libraries description page.

@addon authors still using ZO_PreHook on the inventory context menu functions or keybind functions:
PLEASE change this and use this library properly instead!
Thank you

Note that the info above only relates to the inventory context menus!
Context menus at the chat's player context menu can be still applied using a SecurePostHook to these functions and applying your own callback function.

Hint: Try to change your code from ZO_PreHook and zo_callLater to the nox existing function SecurePostHook! It got ther same parameters like ZO_PreHook but will run your code securely after the menu was build so you do not need to delay your added entries etc.
Lua Code:
  1. local function MyShowPlayerContextMenu(playerName, rawName)
  2.         AddCustomMenuItem(GetString(SI_WHATEVER_TEXT_YOU_NEED), function() d("playerName: " .. tostring(playerName))  end)
  3.         ShowMenu()
  4.     end
  5.     SecurePostHook(SharedChatSystem, "ShowPlayerContextMenu", MyShowPlayerContextMenu)

Itemlink contextmenus in the chat can be applied via:
Lua Code:
  2.     function(link, button, text, color, linkType, ...) end)

Last edited by Baertram : 03/26/20 at 04:32 AM.
  Reply With Quote
03/26/20, 02:43 AM   #2
Keldor's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 87
Hey Baertram, thanks for this detailed post.

It's very helpful for persons like me who worked the first time with the UI.

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]
ESO-Database Game Data API | API for AddOn developers to fetch game related data like Chest positions etc.
  Reply With Quote

ESOUI » Developer Discussions » Tutorials & Other Helpful Info » Context menu creation / Inventory context menu enhancement

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