Thread Tools Display Modes
04/14/14, 01:04 PM   #1
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Event Chaining

Hi,

i try to attach actions to already defined ui event, for example inventory tab clicks, without killing the already assigned actions. I saw a solution inside the InventoryMod (by Cr4x) but it looks cumbersome and may fail once another addon uses its own event storage.

The PreHookHandler, however, is not suitable in this scenario.

lua Code:
  1. -- that kills the default behavior
  2. ZO_PlayerInventoryTabsButton7:SetHandler("OnMouseUp", function() {}))
  Reply With Quote
04/14/14, 01:53 PM   #2
Nogaruk
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 15
To your example, I could be wrong, but I think the problem is you're not giving it anything to do.

-- SetHandler(string handlerName, function functionRef)

When I've used handlers before I haven't had any issues, though, it is possible the ones I've needed didn't already use the event I did. I would think the way you would want to write it though, would be:

Code:
ZO_PlayerInventoryTabsButton7:SetHandler("OnMouseUp", function(self) addonName:SomeFunction() end)
If that still breaks it, you could try seeing if registering into the main mouse event will work. You'll of course have to check against what the mouse was interacting with.

EVENT_GLOBAL_MOUSE_UP (integer button, bool ctrl, bool alt, bool shift, bool command)
I believe it would be:
Code:
EVENT_MANAGER:RegisterForEvent(addonName .. "_OnMouseUp", EVENT_GLOBAL_MOUSE_UP , function(...) self:OnMouseUpHandler(...) end)

function addonName:OnMouseUpHandler(event, button, ctrl, alt, shift, command)
end
Another choice would be to change what event you want to handle. For example you could try:
Code:
ZO_PlayerInventoryTabsButton7:SetHandler("OnClicked", function(self) addonName:SomeFunction() end)
edit: forgot an example

Last edited by Nogaruk : 04/14/14 at 01:58 PM.
  Reply With Quote
04/14/14, 02:12 PM   #3
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Thanks for the examples. The OnMouseUp, kills the default operation, OnClicked is ignored. Maybe there's just something wrong with my event handler assignment:

lua Code:
  1. local function BBS_GetActiveTabs(tabControl)
  2.     local children = {}
  3.     local counter = tabControl:GetNumChildren()
  4.     for i=1, counter do
  5.         local child = tabControl:GetChild(i)
  6.        
  7.         if (child:GetType() == CT_CONTROL) then
  8.             -- add a handler for each control
  9.             -- TODO: add one handler to the parent and handle tab changes
  10.             child:SetHandler("OnClicked", function(self)
  11.                 BBS_SearchBoxOnTextChanged(bbs.editbox)
  12.             end)
  13.             children[i] = child
  14.         end
  15.     end
  16.     return children
  17. end
  Reply With Quote
04/14/14, 02:19 PM   #4
Nogaruk
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 15
I believe the "OnClicked" will only work if it is a CT_BUTTON. Beyond that, you'll probably have to wait for someone more experienced to see this. I have not needed to use handlers that required parameters to be passed along yet, so not sure if there's anything else wrong with that. Otherwise the code looks right.

Edit: also, I'm not sure if the syntax is correct unless you're calling a global function, but it might need addonName or self for

Code:
child:SetHandler("OnClicked", function(self) addonName:BBS_SearchBoxOnTextChanged(bbs.editbox) end)

Last edited by Nogaruk : 04/14/14 at 02:25 PM.
  Reply With Quote
04/14/14, 06:09 PM   #5
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
The EVENT_GLOBAL_MOUSE_UP did the trick, thanks

Anyway, the event chaining problem still ain't solved (at least for me )
  Reply With Quote
04/14/14, 08:56 PM   #6
Kith
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 49
You could try using the ZO built in prehook. As far as I know there is no posthook though so it'll run before the default code does
Lua Code:
  1. ZO_PreHookHandler(ZO_PlayerInventoryTabsButton7, 'OnMouseUp', function(...)
  2.     -- do your stuff here, the ... is the variables passed
  3. end)
  Reply With Quote
04/15/14, 03:38 AM   #7
Cr4x
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
Originally Posted by Wukar View Post
Hi,
... and may fail once another addon uses its own event storage.
Each addon should make sure not to override any existing handlers, wether it is using a event storage or not.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Event Chaining


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