Thread Tools Display Modes
04/29/14, 10:34 AM   #1
Keesi
Premium Member
Premium Member
Join Date: Apr 2014
Posts: 2
InformationTooltip Icon... go away

I am working on an addon which will work with the framework which Shinni and several other talented coders have already refined. I am new to writing in lua but I'm drudging through it by trial and error. In a test piece of code I'm working on, I've started with the callback which Shinni used in HarvestMap to create the tooltip. I am wanting to add an Icon to the top left corner of that tooltip. I'm actually not having a problem with that... the problem is that once the icon is there... it's there on all custom map pins. My question is how can I either detect when the InformationTooltip has closed (is there an event I'm missing) or is there some way that I can have it only work for my set of pins? Below is the code snippint I'm using.

Code:
Test.tooltipCreator = {
	creator = function( pin )
	
		if Test.iconControl == nil then
			Test.iconControl = WINDOW_MANAGER:CreateControl("Test_Tooltip_Icon", InformationTooltip, CT_TEXTURE)
		end
		
		InformationTooltip:AddControl(Test.iconControl, 1, true)
		Test.iconControl:SetTexture("Test/Icons/Test.dds")
		Test.iconControl:SetHidden(false)
		Test.iconControl:SetDimensions(64, 64)
		Test.iconControl:ClearAnchors()
		Test.iconControl:SetAnchor(CENTER, InformationTooltip, TOPLEFT, 0, 0)

		for _, name in ipairs(pin.m_PinTag[3]) do
			InformationTooltip:AddLine( name )
		end
	end,
	tooltip = InformationTooltip
}

Last edited by Keesi : 04/30/14 at 07:40 PM.
  Reply With Quote
05/05/14, 07:08 AM   #2
LilBudyWizer
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
One way is to hook the function. LibAddonMenu uses Prehook defined by the api. Writing your own hook is pretty simple, you just use a closure. A closure is a function that returns a function and has local variables used by that returned function. A simple example is:

Lua Code:
  1. function GetPrint(text)
  2.     local text = text
  3.     return function () print(text) end
  4. end
  5.  
  6. PrintHello = GetPrint("Hello")
  7. PrintHello()

GetPrint returns a function that prints whatever text you passed to GetPrint. The actual parameter will be gone when that returned function executes, but the local will still be there. So hooking a function is simply:

Lua Code:
  1. function Hook(funcname, before, after)
  2.     local origfunc = _G[funcname]
  3.     local before = before
  4.     local after = after
  5.     return function ( ... )
  6.         before( ... )
  7.         local parms = {origfunc( ... )}
  8.         after( ... )
  9.         return unpack(parms)
  10. end
  11.  
  12. function mybefore( ... )
  13.     print("hello")
  14. end
  15.  
  16. function myafter( ... )
  17.     print("world")
  18. end
  19.  
  20. SomeFunc = Hook("SomeFunc", mybefore, myafter)

There's a lot of possible variations on that depending upon what, exactly, you're wanting to do. As an example you could use before to modify parms in which case you would pass it's return value as the parameters to the original function. Similarly after could modify results from the original function. So:

Lua Code:
  1. return after(origfunc(before(...)))

You could also skip calling the original when it's called with particular parameters. The main caveat is be sure the hook can handle being called while the hook is executing. The function you hook may call itself as well as your code directly or indirectly calling it.
  Reply With Quote
05/05/14, 10:24 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
You're making this way too complicated. And you're creating extra, unnecessary functions each time you call GetPrint, etc.
  Reply With Quote
05/06/14, 04:34 AM   #4
LilBudyWizer
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
Too complicated versus, um, nothing? He asked the question a week ago. I don't know the answer to his specific question, but I do know if you need to do something when a function executes you can hook it. Or do you mean it's too complicated of a way to hook a function. Perhaps the qualifications for being a programmer include the ability to read minds, but it's one I lack and, as such, I don't find guess what you're thinking all that helpful.
  Reply With Quote
05/06/14, 05:18 AM   #5
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
The easiest way how to add an icon to the InformationTooltip is:

Lua Code:
  1. local texture = "EsoUI/Art/Icons/lore_book4_detail4_color5.dds"
  2. local width = 24 --pixels
  3. local height = 24 --pixels
  4. local fontname = "ZoFontHeader"
  5. local r, g, b = ZO_TOOLTIP_DEFAULT_COLOR:UnpackRGB()
  6.  
  7. InformationTooltip:AddLine(zo_iconFormat(texture, width, height), fontname, r, g, b)
  8.  
  9. -- :AddLine( text, fontname, r, g, b ), only required argument is text.
or directly:
Lua Code:
  1. InformationTooltip:AddLine("|t24:24:EsoUI/Art/Icons/lore_book4_detail4_color5.dds|t")
The only issue is with position. Do you really need it in top left corner?
  Reply With Quote
05/06/14, 05:34 AM   #6
LilBudyWizer
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 32
I haven't really started playing with controls, but I assume the specific answer is you use SetHandler for events related to a control as opposed to system wide events though the event manager. I would assume control:SetHandler("OnShow", myfunc) is the same as using OnShow in the xml definition of the control.
  Reply With Quote
05/06/14, 06:38 AM   #7
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Keesi View Post
My question is how can I either detect when the InformationTooltip has closed (is there an event I'm missing)
You can hook ZO_Tooltip_OnCleared(tooltipControl) function to clear your modifications to the tooltip.

Originally Posted by Keesi View Post
...or is there some way that I can have it only work for my set of pins?
This will not be necessary - tooltip control is not destroyed when hidden, it is just cleared. So you really need to clear your modification by hooking the function above.
Lua Code:
  1. local pinType = pin.m_PinType
  2. local pinType = pin:GetPinType()
  3. local pinType, pinTag = pin:GetPinTypeAndTag()
  4. --use just one from above
  5.  
  6. if pinType == _G["myCustomPin"] then
  7.  --code
  8. end

Last edited by Garkin : 05/06/14 at 06:43 AM.
  Reply With Quote
05/16/14, 04:20 PM   #8
Keesi
Premium Member
Premium Member
Join Date: Apr 2014
Posts: 2
Thanks guys, I'll give that a shot this weekend. My Addon attempt is coming along nicely and this is an added touch that I wanted in there.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » InformationTooltip Icon... go away


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