Quantcast
Download
(14 Kb)
Download
Updated: 08/13/18 11:17 AM
Pictures
File Info
Compatibility:
Wolfhunter (4.1)
Summerset (4.0)
Updated:08/13/18 11:17 AM
Created:07/11/15 10:51 AM
Monthly downloads:2,116
Total downloads:6,404
Favorites:37
MD5:
4.1
LibCustomMenu  Popular! (More than 5000 hits)
Version: 6.6
by: votan [More]
Info
This library is not intended as stand-alone. It is for addon developers, because it requires additional changes in the addon source anyway.

Description
This library is written to overcome one way to get the "Access a private function XYZ from insecure code". But beginning with version 2.0, it does additional provide a new feature: sub menus.
Beginning with version 3.0, it does additional provide a new feature: divider.

Background
Controls, created from add-on code (as part of code path) are marked as "insecure/compromissed".
Functions, which have no problem with been called from "insecure" controls, are still working perfectly.
Like those of add-ons or Show On Map, Link in Chat or Get Help.
But "secured" functions like UseItem, InitiateDestroy, PickupInventoryItem raising the error message from above.
Once you hook AddMenuItem ALL controls created for the context-menu are "insecure".

Prior to ESO 2.0.13 if an add-on offers a full custom context-menu (no built-in menu entries) and this context-menu is shown first after (re-)load UI the first menu item controls are insecure. A crash of "Use" in the inventory afterwards was guaranteed.
Starting with ESO 2.0.13 ZOS preallocates 10 "secure" menu items. See here.
But this just reduces the chance of running into that problem, it does not fix it.
Currently the number of preallocated controls is 30. Running into this problem with AddMenuItem is real rare, but inventory action slots still don't like custom menu entries.

To avoid the error message, the controls of built-in menu items and add-on menu items must be strictly separated. That's what AddCustomMenuItem of this library does. It uses an own pool of controls, which look exactly the same. Sounds strange, but works.

I don't use private functions. Why should I use this lib?
It's not you, who uses private functions. It is built-in code, which re-uses controls indirectly created by your add-on in AddMenuItem.

I want to use this lib, so what to do?
After you have included the lib in your add-on manifest (.txt) do a text search for the global function AddMenuItem (not any :AddMenuItem of other objects) and replace it with AddCustomMenuItem.
Be careful with a simple "Replace All" over all files! You probably replace the AddMenuItem of LibCustomMenu itself

Version 1.0
This version was intended as proof of concept, but was successfully used in Beartram's FCO Item Saver, Circonian's FilterIt and my Fish Fillet.

Version 2.0
In order to have more value than avoiding a rare, just annoying "bug", sirinsidiator suggested and provided proof of concept code for sub menu items.
A big thank to sirinsidiator!
I finalized it and here we are.

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

Fully compatible with AddMenuItem.
mytext: string, required. Caption of menu item.
myfunction: function(), required. Called if clicked.
itemType: int, optional. MENU_ADD_OPTION_LABEL or MENU_ADD_OPTION_CHECKBOX. Default MENU_ADD_OPTION_LABEL.
myfont: string, optional.
normalColor: ZO_ColorDef, optional. Color of unselected item.
highlightColor: ZO_ColorDef, optional. Color of selected/hovered item.
itemYPad: int, optional. y-padding between items.


function AddCustomSubMenuItem(mytext, entries, myfont, normalColor, highlightColor, itemYPad)

mytext: string, required. Caption of menu item.
entries: table of sub items or callback returning table of sub items, required.
myfont: string, optional.
normalColor: ZO_ColorDef, optional. Color of unselected/normal sub item.
highlightColor: ZO_ColorDef, optional. Color of selected/hovered sub item.
itemYPad: int, optional. y-padding between sub items.

sub item:
label: string or function(rootMenu, childControl), required.
callback: function(), required.
disabled: boolean or function(rootMenu, childControl), optional. Default false. if true, sub item is visible, but gray and not clickable.
visible: boolean or function(rootMenu, childControl), optional. Default true.

example 1:
Lua Code:
  1. local entries = {
  2.   {
  3.     label = "Test 1",
  4.     callback = function() d("Test 1") end,
  5.   },
  6.   {
  7.     label = "Test 2",
  8.     callback = function() d("Test 2") end,
  9.     disabled = function(rootMenu, childControl) return true end,
  10.   }
  11. }
  12. ClearMenu()
  13. AddCustomSubMenuItem("Sub Menu", entries)
  14. ShowMenu()

example 2:
Lua Code:
  1. local function GetEntries(rootMenu)
  2. d("run")
  3. return {
  4.   {
  5.     label = function() return GetTimeStamp() end,
  6.     callback = function() d("Test 1") end,
  7.   },
  8.   {
  9.     label = "Test 2",
  10.     callback = function() d("Test 2") end,
  11.     disabled = function(rootMenu, childControl) return true end,
  12.   }
  13. }
  14. end
  15. ClearMenu()
  16. AddCustomSubMenuItem("Sub Menu", GetEntries)
  17. ShowMenu()
If you have Notebook or ZAM Notebook, you could copy&paste the scripts from above and execute them.

API 3.0
In addition to API 2.0:
Allow divider by setting member label to a static "-". Suggested by Beartram.

example:
Lua Code:
  1. local entries = {
  2.   {
  3.     label = "Test 1",
  4.     callback = function() d("Test 1") end,
  5.   },
  6.   {
  7.     label = "-",
  8.   },
  9.   {
  10.     label = "Test 2",
  11.     callback = function() d("Test 2") end,
  12.     disabled = function(rootMenu, childControl) return true end,
  13.   }
  14. }
  15. ClearMenu()
  16. AddCustomSubMenuItem("Sub Menu", entries)
  17. ShowMenu()

API 4.1
In addition to API 3.0:
actionSlots:AddCustomSlotAction(actionStringId, actionCallback, actionType, visibilityFunction, options)

for example while hooking ZO_InventorySlot_DiscoverSlotActionsFromActionList(inventorySlot, slotActions)
for example within the callback of API 6.0. See below.

API 5.0
In addition to API 4.1+:
New entry properties itemType and checked.
itemType = MENU_ADD_OPTION_LABEL (default) or MENU_ADD_OPTION_CHECKBOX for a checkbox
checked = false/true or function() return state end
The initial checked state than opening the sub menu.

example:
Lua Code:
  1. local myState = true
  2.     local entries = {
  3.       {
  4.         label = "Test 1",
  5.         callback = function(state) myState = state df("Test 1: %s", tostring(myState)) end,
  6.         checked = function() return myState end,
  7.         itemType = MENU_ADD_OPTION_CHECKBOX,
  8.       },
  9.       {
  10.         label = "Test 1b",
  11.         callback = function() d("Test 1b") end,
  12.         itemType = MENU_ADD_OPTION_LABEL,
  13.       },
  14.       {
  15.         label = "-",
  16.       },
  17.       {
  18.         label = "Test 2",
  19.         callback = function() d("Test 2") end,
  20.         disabled = function(rootMenu, childControl) return true end,
  21.       }
  22.     }
  23.     ClearMenu()
  24.     AddCustomSubMenuItem("Sub Menu", entries)
  25.     ShowMenu()

API 6.2
In addition to API 5+:
Added callbacks, you can register to, to hook into inventory slot context menu. You don't need to reinvent the hook and are able to control the position of your entry/entries more granular.

category
lib.CATEGORY_EARLY
lib.CATEGORY_PRIMARY
lib.CATEGORY_SECONDARY
lib.CATEGORY_TERTIARY
lib.CATEGORY_QUATERNARY
lib.CATEGORY_LATE

CATEGORY_EARLY is before the first built-in menu entry.
CATEGORY_PRIMARY is after the first built-in menu entry. And so on.
CATEGORY_LATE is after built-in menu and default.

lib:RegisterContextMenu(func, category)
Register to the context menu of the inventory mouse right click.

lib:RegisterKeyStripEnter(func, category)
Register to the inventory mouse hover used to update the keybind buttons at the bottom.

func: callback function to be called.
Signature:
Lua Code:
  1. local function func(inventorySlot, slotActions)
  2. end

category: optional. defaults to CATEGORY_LATE.

lib:RegisterKeyStripExit(func)
Register to the inventory mouse hover used to update the keybind buttons at the bottom, if the mouse exits an inventory slot.

func: callback function to be called.
Signature:
Lua Code:
  1. local function func()
  2. end

example:
Lua Code:
  1. ZO_CreateStringId("SI_BINDING_NAME_SHOW_POPUP", "Show in Popup")
  2. local function AddItem(inventorySlot, slotActions)
  3.   local valid = ZO_Inventory_GetBagAndIndex(inventorySlot)
  4.   if not valid then return end
  5.   slotActions:AddCustomSlotAction(SI_BINDING_NAME_SHOW_POPUP, function()
  6.     local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
  7.     local itemLink = GetItemLink(bagId, slotIndex)
  8.     ZO_PopupTooltip_SetLink(itemLink)
  9.   end , "")
  10. end
  11.  
  12. local menu = LibStub("LibCustomMenu")
  13. menu:RegisterContextMenu(AddItem, menu.CATEGORY_PRIMARY)

example 2:
Lua Code:
  1. local function AddItem(inventorySlot, slotActions)
  2.   local bagId, slotIndex = ZO_Inventory_GetBagAndIndex(inventorySlot)
  3.   if not CanItemBePlayerLocked(bagId, slotIndex) then return end
  4.   local locked = IsItemPlayerLocked(bagId, slotIndex)
  5.  
  6.   slotActions:AddCustomSlotAction(locked and SI_ITEM_ACTION_UNMARK_AS_LOCKED or SI_ITEM_ACTION_MARK_AS_LOCKED, function()
  7.     SetItemIsPlayerLocked(bagId, slotIndex, not locked)
  8.   end, "keybind2")
  9.   -- you can use: "primary", "secondary", "keybind1", "keybind2"
  10. end
  11.  
  12. local menu = LibStub("LibCustomMenu")
  13. --menu:RegisterContextMenu(AddItem, menu.CATEGORY_PRIMARY)
  14. menu:RegisterKeyStripEnter(AddItem, menu.CATEGORY_LATE)
Not really practical, because it hides the built-in keybind.
But you could use the callback just to be notified aswell.
version 6.6:
- Update to API 100024 "Wolfhunter".
- New library load structure.

version 6.5: Fix for PTS.

version 6.4: Fixed compatibility with other addons hooking the context-menu. Like Craft Bag Extended.

version 6.3:
- Improve compabitility with AGS.

version 6.2:
- Handle inventory context menu and key strip menu. Take 2.


version 6.1:
- Fixed a conflict with CraftBagExtended.

version 6:
- Handle inventory context menu and key strip menu.


version 5:
- Supporting checkboxes in submenus.
- Fixed Divider menu item.

version 4.3:
- Update for "Horns of the Reach".

version 4.2.0:
- Fixed rare timing issue closing menu while mouse is over sub-menu.
- APIVersion update to 100017.

version 4.1.1:
- APIVersion update to 100014.

version 4.1:
- Added ZO_InventorySlotActions:AddCustomSlotAction. (Requested by merlight)
- APIVersion update to 100013.

version 4: * Working with Orsinium. Just the manifest APIVersion must be updated
- Fixed issue: main menu not closing if sub-menu used outside inventory. Thanks to circonian.

version 3:
- New menu item type: Divider. A static text "-" will be displayed as a divider. You can use <lib>.DIVIDER for better readability.

version 2:
- New global function AddCustomSubMenuItem

version 1:
- New global function AddCustomMenuItem as a replacement for AddMenuItem.
Optional Files (0)


Archived Files (13)
File Name
Version
Size
Author
Date
6.5
8kB
votan
04/22/18 05:21 AM
6.4
7kB
votan
04/16/18 11:45 AM
6.3
7kB
votan
03/03/18 10:58 AM
6.2
8kB
votan
02/02/18 12:35 AM
5
7kB
votan
01/27/18 03:11 PM
5
7kB
votan
08/15/17 12:34 PM
4.3
6kB
votan
07/15/17 01:00 PM
4.2.0
6kB
votan
10/12/16 12:56 PM
4.1.1
6kB
votan
03/07/16 12:13 PM
4.1.0
6kB
votan
11/22/15 02:24 PM
4.0.0
6kB
votan
08/06/15 10:48 AM
3.0.0
6kB
votan
07/25/15 05:36 AM
2.0.0
5kB
votan
07/11/15 10:51 AM


Post A Reply Comment Options
Unread 06/02/18, 04:37 AM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 458
File comments: 1015
Uploads: 26
We are working on that already. Did you use the lastest version of AGS and did it happen again?
__________________
@votan73 (EU - megaserver)
Report comment to moderator  
Reply With Quote
Unread 06/02/18, 03:33 AM  
RavenMind
 
RavenMind's Avatar

Forum posts: 0
File comments: 270
Uploads: 0
This error seems to be occurring with some frequency among users of Awesome Guild Store. Looks like that thread is starting to fill up. I'll keep an eye on it there. Thanks!
Report comment to moderator  
Reply With Quote
Unread 05/30/18, 03:21 AM  
RavenMind
 
RavenMind's Avatar

Forum posts: 0
File comments: 270
Uploads: 0
Originally Posted by votan
Do you have Advanced Filter and use the drop-down to filter items?
I do have Advanced Filters but I don't use the dropdown menu.
Report comment to moderator  
Reply With Quote
Unread 05/30/18, 02:55 AM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 458
File comments: 1015
Uploads: 26
Originally Posted by RavenMind
It occurs when double clicking an item to withdraw/deposit, and a second of this type of error occurs when using the keyboard to do the same. When that happens, neither keyboard nor mouse will work & I have to reloadUI (which seems to "fix" it for a while.
Do you have Advanced Filter and use the drop-down to filter items?
__________________
@votan73 (EU - megaserver)
Report comment to moderator  
Reply With Quote
Unread 05/30/18, 02:15 AM  
RavenMind
 
RavenMind's Avatar

Forum posts: 0
File comments: 270
Uploads: 0
Hi Votan. I'm still quite often getting the following error at banks:
Code:
EsoUI/Ingame/Inventory/InventorySlot.lua:697: Attempt to access a private function 'PickupInventoryItem' from insecure code. The callstack became untrusted 3 stack frame(s) from the top.
stack traceback:
	EsoUI/Ingame/Inventory/InventorySlot.lua:697: in function 'TryBankItem'
	EsoUI/Ingame/Inventory/InventorySlot.lua:1516: in function 'INDEX_ACTION_CALLBACK'
	EsoUI/Ingame/Inventory/InventorySlotActions.lua:96: in function 'ZO_InventorySlotActions:DoPrimaryAction'
	EsoUI/Ingame/Inventory/ItemSlotActionController.lua:30: in function 'callback'
	EsoUI/Libraries/ZO_KeybindStrip/ZO_KeybindStrip.lua:645: in function 'ZO_KeybindStrip:TryHandlingKeybindDown'
	(tail call): ?
	(tail call): ?
It occurs when double clicking an item to withdraw/deposit, and a second of this type of error occurs when using the keyboard to do the same. When that happens, neither keyboard nor mouse will work & I have to reloadUI (which seems to "fix" it for a while.
I've updated all my addons to use this latest version of LibCustomMenu (as well as LibAddonMenu). I don't understand scripting very well, but I gather that this problem is one that this Lib tries to address. Do you think this error is occurring because of something with the lib, or the improper use of the lib by other authors? Not sure who to try to contact to let them know that this is a problem. Thanks!
Report comment to moderator  
Reply With Quote
Unread 04/27/18, 12:03 AM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 458
File comments: 1015
Uploads: 26
Originally Posted by silvereyes
Originally Posted by votan
As @silvereyes released 6.5, it is the current version, but 6.4 is not out-dated.
Sorry about that. I kinda forgot that libstub would overwrite *everyone's* LCM with the latest version, not just in my addons. Didn't mean to force 6.5 out of beta.

I reaaaaaally don't like it when nobody can use PTS inventory because of my addons throwing permissions errors. Guess I kinda panicked.

Btw, thanks for the API changes regarding hooks. I plan to rewrite my hooking stuff in CraftBagExtended to use it.
Hey, no worries
Imagine how it felt that "your"(=mine) lib causing trouble for everybody on PTS
__________________
@votan73 (EU - megaserver)
Report comment to moderator  
Reply With Quote
Unread 04/26/18, 11:40 PM  
silvereyes
 
silvereyes's Avatar
AddOn Author - Click to view AddOns

Forum posts: 51
File comments: 162
Uploads: 11
Originally Posted by votan
As @silvereyes released 6.5, it is the current version, but 6.4 is not out-dated.
Sorry about that. I kinda forgot that libstub would overwrite *everyone's* LCM with the latest version, not just in my addons. Didn't mean to force 6.5 out of beta.

I reaaaaaally don't like it when nobody can use PTS inventory because of my addons throwing permissions errors. Guess I kinda panicked.

Btw, thanks for the API changes regarding hooks. I plan to rewrite my hooking stuff in CraftBagExtended to use it.
Report comment to moderator  
Reply With Quote
Unread 04/26/18, 06:10 PM  
RavenMind
 
RavenMind's Avatar

Forum posts: 0
File comments: 270
Uploads: 0
Originally Posted by votan
Everything 6.4+ is ok.

To make it more clear: 6.4 is working on live and did not work in the first week of PTS. This required to make 6.5. But ZOS reverted their changes. So, now 6.4 would work on PTS again. But 6.5 is also working for live and PTS. As @silvereyes released 6.5, it is the current version, but 6.4 is not out-dated.
Thank you for the clarification!!
Report comment to moderator  
Reply With Quote
Unread 04/26/18, 02:01 PM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 458
File comments: 1015
Uploads: 26
Originally Posted by Anceane
Originally Posted by votan
Originally Posted by RavenMind
Is it possible to just copy the current LibCustomMenu.lua into other addons' \lib\LibCustomMenu\ folders to get them up to date? I'm still seeing some very popular addons running very out of date versions.
Thanks!
yes. 6.4 is ok. The changes of 6.5 were made for PTS. And ZOS was so kind to revert their changes.
Does this means that 6.4 is the only good version ? lol just lost after i saw you updating to 6.5 in fisherman :P
Everything 6.4+ is ok.

To make it more clear: 6.4 is working on live and did not work in the first week of PTS. This required to make 6.5. But ZOS reverted their changes. So, now 6.4 would work on PTS again. But 6.5 is also working for live and PTS. As @silvereyes released 6.5, it is the current version, but 6.4 is not out-dated.
__________________
@votan73 (EU - megaserver)
Last edited by votan : 04/26/18 at 02:55 PM.
Report comment to moderator  
Reply With Quote
Unread 04/26/18, 01:33 PM  
Anceane
 
Anceane's Avatar

Forum posts: 166
File comments: 620
Uploads: 0
Originally Posted by votan
Originally Posted by RavenMind
Is it possible to just copy the current LibCustomMenu.lua into other addons' \lib\LibCustomMenu\ folders to get them up to date? I'm still seeing some very popular addons running very out of date versions.
Thanks!
yes. 6.4 is ok. The changes of 6.5 were made for PTS. And ZOS was so kind to revert their changes.
Does this means that 6.4 is the only good version ? lol just lost after i saw you updating to 6.5 in fisherman :P
__________________
Report comment to moderator  
Reply With Quote
Unread 04/26/18, 12:21 AM  
RavenMind
 
RavenMind's Avatar

Forum posts: 0
File comments: 270
Uploads: 0
Originally Posted by votan
yes. 6.4 is ok. The changes of 6.5 were made for PTS. And ZOS was so kind to revert their changes.
That would explain some things! Thanks very much, I appreciate all the work you put in to your addons & the lib!
Report comment to moderator  
Reply With Quote
Unread 04/25/18, 10:51 AM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 458
File comments: 1015
Uploads: 26
Originally Posted by RavenMind
Is it possible to just copy the current LibCustomMenu.lua into other addons' \lib\LibCustomMenu\ folders to get them up to date? I'm still seeing some very popular addons running very out of date versions.
Thanks!
yes. 6.4 is ok. The changes of 6.5 were made for PTS. And ZOS was so kind to revert their changes.
__________________
@votan73 (EU - megaserver)
Report comment to moderator  
Reply With Quote
Unread 04/25/18, 01:07 AM  
RavenMind
 
RavenMind's Avatar

Forum posts: 0
File comments: 270
Uploads: 0
Is it possible to just copy the current LibCustomMenu.lua into other addons' \lib\LibCustomMenu\ folders to get them up to date? I'm still seeing some very popular addons running very out of date versions.
Thanks!
Report comment to moderator  
Reply With Quote
Unread 01/27/18, 01:45 PM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 458
File comments: 1015
Uploads: 26
Forget it. Reverted back to rev 5. The conflict is unsolved and gets worse.

Found a conflict with CraftBagExtended. If you have downloaded rev6, please use rev6.1.
__________________
@votan73 (EU - megaserver)
Last edited by votan : 01/27/18 at 06:05 PM.
Report comment to moderator  
Reply With Quote
Unread 07/13/17, 10:49 AM  
votan
 
votan's Avatar
AddOn Author - Click to view AddOns

Forum posts: 458
File comments: 1015
Uploads: 26
Originally Posted by Shinni
On pts this line causes problems:
https://github.com/esoui/esoui/blob/...menus.lua#L278
To fix it, your custom controls need to have a nameLabel field:
https://github.com/esoui/esoui/blob/...menus.lua#L273
I fixed it locally by adding
control.nameLabel = label
after every line of the form:
local label = wm:CreateControlFromVirtual("$(parent)Name", control, [...]
Okay. Thanks
__________________
@votan73 (EU - megaserver)
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: