ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Chat Context Menu Help (https://www.esoui.com/forums/showthread.php?t=7453)

static_recharge 11/05/17 10:28 AM

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?

Kyoma 11/05/17 10:37 AM

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.

static_recharge 11/05/17 10:41 AM

Quote:

Originally Posted by Kyoma (Post 33096)
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.

static_recharge 11/05/17 01:32 PM

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.

votan 11/05/17 01:34 PM

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

votan 11/05/17 02:53 PM

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 :)

static_recharge 11/05/17 05:40 PM

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?

static_recharge 11/05/17 11:51 PM

This did the trick thank you!


All times are GMT -6. The time now is 01:04 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI