ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Adding items to chat context menu (https://www.esoui.com/forums/showthread.php?t=1448)

BadVolt 05/09/14 05:22 PM

Adding items to chat context menu
 
Hi, guys.
I have a question and hope you can help me.
I want to add additional item to context menu at chat (when you r-click on player name). I found ingame function to do that, but menu is re-created each time player name is clicked.
Lua Code:
  1. AddMenuItem(mytext, myfunction, itemType, myfont, normalColor, highlightColor, itemYPad)

I tried to capture event "OnLinkClicked" for all possible chat windows (stored at "ZO_ChatWindow.container.windows"), but there's a problem. ZO_ChatWindow.container is empty untill someone writes sth to chat, so containers inside can't be hooked before that.

I's stuck. Only some hacky-business is on my mind. So, any ideas how to add own item to ingame menu? :)

BadVolt 05/10/14 07:57 AM

I have some movements with my question.

1st. Register an event to initialize hooking link clicks
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("IRememberYou", EVENT_PLAYER_ACTIVATED, HookChatLink)

2nd. Hooking itself.
Lua Code:
  1. local function HookChatLink()
  2.     for i=1,#ZO_ChatWindow.container.windows do
  3.         ZO_PreHookHandler(ZO_ChatWindow.container.windows[i].buffer,"OnLinkClicked",HookChatLinkClicked)
  4.     end
  5. end

3rd. Function to add item to the end of current list and resise ZO_Menu
Lua Code:
  1. local function HookChatLinkClicked(self, linkData, linkText, button, ctrl, alt, shift, command)
  2.     -- thx Kentarii
  3.     local linkType, _, _ = zo_strsplit(":", linkData)
  4.  
  5.     -- add our menu only to player linktype
  6.  
  7.     if linkType ~= CHARACTER_LINK_TYPE and linkType~=DISPLAY_NAME_LINK_TYPE then return end
  8.  
  9.     -- We want our item added after all items. So, wait untill they are created. Littly hacky, but... :banana:
  10.     zo_callLater(
  11.         function ()
  12.  
  13.             ZO_Menu:SetHeight(ZO_Menu:GetHeight()+22.3125)
  14.  
  15.             AddMenuItem("Rate", YourFunction)
  16.  
  17.         end
  18.     , 1)
  19. end

But now I have another problem... When I move mouse over new item it does not selects properly. It works sometimes, but I can't repeat it manually.



Fathis Ules 05/10/14 12:01 PM

here I hook ZO_ChatSystem_OnLinkClicked, call the original ZO_ChatSystem_OnLinkClicked, then hide the menu, add menu items, and show it again, does the job fine here you can test this in my addon

The only drawback of hooking it is that the menu is flagged unprotected, and even

CallSecureProtected("ShowMenu", nil, 1)
CallSecureProtected("AddMenuItem", COLOR_HAM.."Train as HAM"..COLOR_STOP, function() train(id, false) end)

won't work at all

But anyway it seems only restricting the "Target player" option which is garbage to me , who targets from a ChatWindow today, and anyway this game is not target friendly, huhu

Seerah 05/10/14 12:58 PM

Note that EVENT_PLAYER_ACTIVATED fires for every loading screen. After the event fires the first time and you have done what you need to do, you should unregister for this event (unless there is a reason you need to run your code more than once).

Iyanga 05/10/14 01:28 PM

You can also Unregister the EVENT_ADD_ON_LOADED event in the corresponding handler, saves you some unnecessary calls of the handler (you still need to verify the name though).

BadVolt 05/10/14 02:30 PM

Thanks Fathis Ules for support!
ShowMenu() done all magic I want to :)

And removed hacky-code with "callLater" function.

thelegendaryof 05/17/14 10:09 AM

Lua Code:
  1. local function DERP_OnLinkClicked1(link, button, text, color, linkType, ...)
  2.     -- do your additional stuff
  3.     d("DERP_OnLinkClicked1 on "..tostring(linkType))
  4. end
  5.  
  6. local function DERP_OnLinkClicked2(link, button, text, color, linkType, ...)
  7.     -- do your additional stuff both will be called
  8.     d("DERP_OnLinkClicked2 on "..tostring(linkType))
  9. end
  10.  
  11. LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_CLICKED_EVENT, DERP_OnLinkClicked1)
  12. LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_CLICKED_EVENT, DERP_OnLinkClicked2)

No need to overwrite, hook or detour anything. Both will get called in addition
to the unmodified native code, no matter where you click on the Link.

Cheers! :)

Deome 07/02/14 09:19 AM

Quote:

Originally Posted by thelegendaryof (Post 7928)

No need to overwrite, hook or detour anything. Both will get called in addition
to the unmodified native code, no matter where you click on the Link.

Cheers! :)

I wish I had found this four hours ago. Thank the gods you posted this, I've been pulling my hair out trying to figure out why my PopupTooltips wouldn't give me any link love.


All times are GMT -6. The time now is 06:39 PM.

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