Thread Tools Display Modes
05/09/14, 05:22 PM   #1
BadVolt
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 74
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?
  Reply With Quote
05/10/14, 07:57 AM   #2
BadVolt
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 74
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.


  Reply With Quote
05/10/14, 12:01 PM   #3
Fathis Ules
Thief Guild Master
 
Fathis Ules's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 42
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

Last edited by Fathis Ules : 05/10/14 at 12:06 PM.
  Reply With Quote
05/10/14, 12:58 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
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).
  Reply With Quote
05/10/14, 01:28 PM   #5
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
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).
  Reply With Quote
05/10/14, 02:30 PM   #6
BadVolt
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 74
Thanks Fathis Ules for support!
ShowMenu() done all magic I want to

And removed hacky-code with "callLater" function.
  Reply With Quote
05/17/14, 10:09 AM   #7
thelegendaryof
 
thelegendaryof's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 161
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!

Last edited by thelegendaryof : 05/17/14 at 10:29 AM.
  Reply With Quote
07/02/14, 09:19 AM   #8
Deome
 
Deome's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 29
Thumbs up

Originally Posted by thelegendaryof View Post

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.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Adding items to chat context menu


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