Quantcast Chat Context Menu Help - ESOUI
Thread Tools Display Modes
11/05/17, 10:28 AM   #1
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
Chat Context Menu Help

I'm trying to add a menu item to the chat context menu for player names. I've looked up how a couple of different addons add menu items to other context menus and think I understand the concept fairly well. Using Zgoo and looking at the source code I've found what I believe to be the proper table and function to prehook. However it doesn't work. When I replace those arguments with ones from other addons that add menu items to the inventory context menu, it works, so I know my function that the prehook is calling works.

Here's the prehook function I think should work but isn't:
Code:
ZO_PreHook(ZO_ChatSystem, "ShowPlayerContextMenu", GH.ContextMenu)
GH.ContextMenu is a function that I have defined directly above the prehook call. When I replace ZO_ChatSystem and "ShowPlayerContextMenu" with "ZO_InventorySlot_DiscoverSlotActionsFromActionList" my menu item gets added no problem to the inventory context menu.

The section of the source code I am looking at is here, line 2077:
http://esodata.uesp.net/current/src/...ystem.lua.html

Also, as an additional question, once this does work how do I retrieve the player's @name that was clicked on for use in my function that the prehook calls?
  Reply With Quote
11/05/17, 10:37 AM   #2
Kyoma
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 48
Hmmm, don't know how ZO_InventorySlot_DiscoverSlotActionsFromActionList populates the context menu but ShowPlayerContextMenu clears the menu when it is called. As such your prehook function is called first, you add the menu item, then it is cleared before the game populates it with the player context. You'll probably want to use zo_callLater with like a 20-50ms delay.
  Reply With Quote
11/05/17, 10:41 AM   #3
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
Originally Posted by Kyoma View Post
Hmmm, don't know how ZO_InventorySlot_DiscoverSlotActionsFromActionList populates the context menu but ShowPlayerContextMenu clears the menu when it is called. As such your prehook function is called first, you add the menu item, then it is cleared before the game populates it with the player context. You'll probably want to use zo_callLater with like a 20-50ms delay.
ZO_InventorySlot_DiscoverSlotActionsFromActionList populates the inventory context menu. As for clearing the menu I never thought about that, thanks! I would really like to do it withouth adding a delay though. Hmm.
  Reply With Quote
11/05/17, 01:32 PM   #4
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
using a delay only partially works. It adds the text to the menu, but it's outside of the menu border at the bottom and is un-clickable. Even if I shrink the delay to 1ms it does this.
  Reply With Quote
11/05/17, 01:34 PM   #5
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 447
You can not simply prehook ShowPlayerContextMenu, because it clears the menu inside. Any prehook menu item will be removed.

You have to look inside that function and find another point to hook in. ESOUI - The Elder Scrolls Online source code
__________________
@votan73 (EU - megaserver)
  Reply With Quote
11/05/17, 02:53 PM   #6
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 447
After taking a look I would suggest:
Lua Code:
  1. local orgShowContextMenu = SharedChatSystem.ShowPlayerContextMenu
  2.     function SharedChatSystem.ShowPlayerContextMenu(...)
  3.         local orgClearMenu = ClearMenu
  4.         local orgShowMenu = ShowMenu
  5.  
  6.         if not ZO_Dialogs_IsShowingDialog() then
  7.             local chat, playerName, rawName = ...
  8.             function ClearMenu(...)
  9.                 ClearMenu = orgClearMenu
  10.                 ClearMenu(...)
  11.                 -- Here: Insert items before
  12.             end
  13.             function ShowMenu(...)
  14.                 ShowMenu = orgShowMenu
  15.                 -- Here: Append items
  16.                 return ShowMenu(...)
  17.             end
  18.         end
  19.         return orgShowContextMenu(...)
  20.     end
But without warranty
__________________
@votan73 (EU - megaserver)
  Reply With Quote
11/05/17, 05:40 PM   #7
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
I appreciate the input! I haven't tried this yet, but I'm curious, how would this react to other addons that do the same thing? I know Shissu's guild tools uses this same method would both of our entries be added to the context menu?
  Reply With Quote
11/05/17, 11:51 PM   #8
static_recharge
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
This did the trick thank you!
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Chat Context Menu Help

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