How to create a/add to inventory context menu

From ESOUI Wiki

Revision as of 20:55, 25 March 2020 by Baertram (Talk | contribs)
Jump to: navigation, search

Explanation

The inventory context menu (right click on an inventory row to show it) contains some pre-defined actions that could be taken with an inventory item.
You might have the need to add some enties of your addon to rhis context menu.
There is an easy way to do this: The library LibCustomMenu.

Please see description of the library LibCustomMenu on this wbesite if you want to use the library to register and use the context menu
[1]

The library provides functions to register a context menu:

LibCustomMenu:RegisterContextMenu(func, category)

The function "func" needs to have the following format:

local function func(inventorySlot, slotActions)
  --Exampole code to determine the bagId, slotIndex an itemLink of the current inventoryRow (inventorySlot)
    local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
    local itemLink = GetItemLink(bagId, slotIndex)
end

The library also provides other fucntions to respect the keybinds and the determination of the action slots in the context menu.
Use the following functions to add a new entry to the ZO_Menu contextmenu:

function AddCustomMenuItem(mytext, myfunction, itemType, myfont, normalColor, highlightColor, itemYPad)

Please check the library description for a full list of the parameters and what they control.

You can also add a checkbox here if you like to, like this:

local index = AddCustomMenuItem("CheckBox", function() <your callback> end, MENU_ADD_OPTION_CHECKBOX)
if needToCheckIt then
    ZO_CheckButton_SetChecked(ZO_Menu.items[index].checkbox)
end


You can also define a submenu like this and add it to the context menu:

local entries = {
  {
    label = "Test 1",
    callback = function() d("Test 1") end,
  },
  {
    label = "Test 2",
    callback = function() d("Test 2") end,
    disabled = function(rootMenu, childControl) return true end,
  }
}
AddCustomSubMenuItem("Sub Menu", entries)

Examples

Please read the library description for examples! [2]

Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox