Thread Tools Display Modes
05-24-17, 09:59 AM   #1
Eommus
An Aku'mai Servant
Join Date: Apr 2017
Posts: 34
Displaying item tooltip to the right of profession window.

Hi,

I am building a simple addon that will display the tooltip of the output item of a recipe to the right top of the profession window, when that recipe is clicked in the profession window recipes list. The tooltip will be sticky, I mean when the recipe is clicked, the tooltip will be displayed and stay there until the profession window is closed. Please see below image:

http://imgur.com/xY8t682

I was able to get the output item ID on recipe click, display the (empty) frame on recipe click (I tested it with a simple button frame) and hide the frame with "profession window close" using the following:

Lua Code:
  1. local f = CreateFrame("?", "tooltip", UIParent, "?")
  2. f:Hide()
  3.  
  4. hooksecurefunc(TradeSkillFrame.RecipeList, "OnRecipeButtonClicked", function(self, ...)
  5.     local itemId = C_TradeSkillUI.GetRecipeItemLink(TradeSkillFrame.RecipeList.selectedRecipeID):match("item:(%d+):")
  6.     if itemId ~= nil then -- some enchanting recipes show recipe spell instead of item
  7.         f:Show()
  8.     end
  9. end)
  10.  
  11. TradeSkillFrame:HookScript("OnHide", function()
  12.     f:Hide()
  13. end)

I just need to actually create the frame to display the item tooltip as described above. I don't know what frame type and template I should use (tooltip? simpleHTML?), also I don't know how to populate the frame via item info.

Thanks for any tips and ideas.
  Reply With Quote
05-24-17, 10:20 AM   #2
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Lua Code:
  1. local tooltip = CreateFrame('GameTooltip', nil, UIParent, 'GameTooltipTemplate')
Documentation (although outdated):
http://wowprogramming.com/docs/widgets/GameTooltip

Try:
Lua Code:
  1. tooltip:SetHyperlink(link)
Or:
Lua Code:
  1. tooltip:SetItemByID(itemID)

You also have to set the owner of the tooltip to get it to anchor and display correctly.
Lua Code:
  1. tooltip:SetOwner(self, 'ANCHOR_RIGHT')
__________________

Last edited by MunkDev : 05-24-17 at 10:26 AM.
  Reply With Quote
05-24-17, 11:16 AM   #3
Eommus
An Aku'mai Servant
Join Date: Apr 2017
Posts: 34
@MunkDev Thank you, I feel I am on the right track. I now have:

Lua Code:
  1. local f = CreateFrame("GameTooltip", "tooltip", UIParent, "GameTooltipTemplate")
  2. f:SetOwner(self, "ANCHOR_RIGHT")
  3. f:Hide()
  4.  
  5. hooksecurefunc(TradeSkillFrame.RecipeList, "OnRecipeButtonClicked", function(self, ...)
  6.     local itemId = C_TradeSkillUI.GetRecipeItemLink(TradeSkillFrame.RecipeList.selectedRecipeID):match("item:(%d+):")
  7.     if itemId ~= nil then -- some enchanting recipes show recipe spell instead of item
  8.         f:SetItemByID(itemId)
  9.         f:Show()
  10.     end
  11. end)
  12.  
  13. TradeSkillFrame:HookScript("OnHide", function()
  14.     f:Hide()
  15. end)

Which doesn't display anything at all. Not sure which part I am doing wrong.
  Reply With Quote
05-24-17, 11:51 AM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
That self on the second line is nil. You need to set the owner as TradeSkillFrame.
  Reply With Quote
05-24-17, 01:42 PM   #5
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
I also suggest not naming your tooltip just "tooltip". It doesn't imply where it's coming from if you ever intend to release the addon you're working on.
__________________
  Reply With Quote
05-24-17, 04:08 PM   #6
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Original thread for reference

http://www.mmo-champion.com/threads/...dow-is-clicked
  Reply With Quote
05-24-17, 10:45 PM   #7
Eommus
An Aku'mai Servant
Join Date: Apr 2017
Posts: 34
Thank you all for the tips. I was able to finish it just the way I wanted and also published it, in case others might need the same thing. It will definitely save me a lot of time and mouse moving in the long term, while crafting.

https://mods.curse.com/addons/wow/26...n-item-tooltip

Originally Posted by MunkDev View Post
I also suggest not naming your tooltip just "tooltip". It doesn't imply where it's coming from if you ever intend to release the addon you're working on.
Thanks, I changed it. But, to understand it better, can you elaborate why "it doesn't imply where it's coming from" is important? Is it related to debugging while many addons are installed?
  Reply With Quote
05-25-17, 04:49 AM   #8
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
It is good Lua practice to give global variables unique names. In WoW, the same goes for frame names of any kind. For example, if I were to create a frame, register some events, and then open the addon EventTracker, I will see that frame's name listed under the events. I believe Blizzard's included etrace also shows some frame names if they cause too much CPU off an event.

Even if no one ever finds your frame in any debug situation, frame names are global and someone else may have used "tooltip" as well. Something as simple as "TradeSkillItemTooltip" will do.
  Reply With Quote
05-25-17, 05:48 AM   #9
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
In an environment where people run all kinds of combinations of addons together that may range from robustly designed to pure garbage, it's always wise to scope and name your own code properly so it doesn't conflict with anything else.

I can give you a concrete example of this. In one of my addons, I'm using a hook on CreateFrame to scan and cache frames that have specific names to add compatibility for other mods. I received a bug report that indicated that my code was trying to compare the "name" parameter of CreateFrame with a number. Now, normally you would either omit the name parameter altogether and therefore it would be nil, or you would provide a string name. Some other addon was just sending a simple number as the frame name, causing my code to break.

In this case, it was bad practice to just give the frame a number as its name, since all frame names are stored as globals and it also doesn't say anything about which addon it belongs to. Let's say someone wanted to expand on your concept by adding additional details to the tooltip if your addon is running simultaneously, (such as a genuine all-purpose tooltip addon). How would they find your custom tooltip?
__________________
  Reply With Quote
05-25-17, 08:37 AM   #10
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
It's undocumented but you can just use GameTooltip.SetRecipeResultItem, instead of getting the Item Id for in GameTooltip.SetItemByID
Lua Code:
  1. function TradeSkillDetailsMixin:OnResultMouseEnter(resultButton)
  2.     if self.selectedRecipeID then
  3.         GameTooltip:SetOwner(resultButton, "ANCHOR_RIGHT");
  4.         GameTooltip:SetRecipeResultItem(self.selectedRecipeID);
  5.         CursorUpdate(resultButton);
  6.     end
  7.    
  8.     resultButton.UpdateTooltip = resultButton.UpdateTooltip or function(owner) self:OnResultMouseEnter(owner); end;
  9. end

This can be shortened to this
Lua Code:
  1. TradeSkillFrame:HookScript("OnHide", function()
  2.     f:Hide()
  3. end)
Lua Code:
  1. TradeSkillFrame:HookScript("OnHide", f.Hide)

Haven't tested your addon, but is the OnHide hook actually needed if you can just parent your tooltip to the TradeSkillFrame?
Code:
local f = CreateFrame("GameTooltip", "ProfessionItemtooltip", TradeSkillFrame, "GameTooltipTemplate")
  Reply With Quote
05-25-17, 08:38 AM   #11
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by Kanegasi View Post
Even if no one ever finds your frame in any debug situation, frame names are global and someone else may have used "tooltip" as well. Something as simple as "TradeSkillItemTooltip" will do.
Originally Posted by MunkDev View Post
In an environment where people run all kinds of combinations of addons together that may range from robustly designed to pure garbage, it's always wise to scope and name your own code properly so it doesn't conflict with anything else.

The horror... https://www.townlong-yak.com/globe/wut/#q:tooltip
  Reply With Quote
05-25-17, 09:26 AM   #12
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Originally Posted by Ketho View Post
Oh my god. This is powerful. How long has this addon code search tool been around?

Edit: I searched for underscore. Appalling.

Last edited by Kanegasi : 05-25-17 at 09:32 AM.
  Reply With Quote
05-25-17, 10:28 AM   #13
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by Ketho View Post
/bookmarks
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
05-26-17, 01:08 AM   #14
Eommus
An Aku'mai Servant
Join Date: Apr 2017
Posts: 34
Originally Posted by Kanegasi View Post
frame names are global and someone else may have used "tooltip" as well.
Originally Posted by MunkDev View Post
it's always wise to scope and name your own code properly so it doesn't conflict with anything else.
Thanks, that's enough to know.

Originally Posted by Ketho View Post
Lua Code:
  1. function TradeSkillDetailsMixin:OnResultMouseEnter(resultButton)
  2.     if self.selectedRecipeID then
  3.         GameTooltip:SetOwner(resultButton, "ANCHOR_RIGHT");
  4.         GameTooltip:SetRecipeResultItem(self.selectedRecipeID);
  5.         CursorUpdate(resultButton);
  6.     end
  7.    
  8.     resultButton.UpdateTooltip = resultButton.UpdateTooltip or function(owner) self:OnResultMouseEnter(owner); end;
  9. end
I didn't quite understand what the above code does. If it is possible, could you explain what each line does? I like using code I understand, so that I can modify it when needed.

Originally Posted by Ketho View Post
Haven't tested your addon, but is the OnHide hook actually needed if you can just parent your tooltip to the TradeSkillFrame?
Code:
local f = CreateFrame("GameTooltip", "ProfessionItemtooltip", TradeSkillFrame, "GameTooltipTemplate")
Thanks, changed the parent and removed the OnHide hook. Works fine.
  Reply With Quote
05-26-17, 06:44 AM   #15
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by Eommus View Post
I didn't quite understand what the above code does. If it is possible, could you explain what each line does? I like using code I understand, so that I can modify it when needed.

It's the reference code from the Blizzard FrameXML. If you clicked the "GameTooltip.SetRecipeResultItem" link in my previous post you would have known that...
https://github.com/Gethe/wow-ui-sour...tails.lua#L376

Originally Posted by Kanegasi View Post
How long has this addon code search tool been around?

No idea, but I saw Foxlit post it in #wowuidev sometimes
http://infobot.rikers.org/%23wowuidev/20160617.html.gz

Last edited by Ketho : 05-26-17 at 06:53 AM.
  Reply With Quote
05-26-17, 07:52 AM   #16
Eommus
An Aku'mai Servant
Join Date: Apr 2017
Posts: 34
Originally Posted by Ketho View Post
It's the reference code from the Blizzard FrameXML. If you clicked the "GameTooltip.SetRecipeResultItem" link in my previous post you would have known that...
https://github.com/Gethe/wow-ui-sour...tails.lua#L376
I had clicked that link and studied that and other files of Blizzard earlier. But as a newbie, it is hard for me to figure out what a code block does by looking at it. For example, I didn't understand what resultButton is, when OnResultMouseEnter is fired, what CursorUpdate does etc. Anyway, thanks for all the tips.

I believe I am done with this addon at this time.
  Reply With Quote
05-26-17, 08:40 AM   #17
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by Eommus View Post
But as a newbie, it is hard for me to figure out what a code block does by looking at it. For example, I didn't understand what resultButton is, when OnResultMouseEnter is fired, what CursorUpdate does etc. Anyway, thanks for all the tips.
Even as a seasoned developer, you don't always intuitively know how something works just by looking at an isolated piece of code. The important part is to know how to figure out how it works. If you have the source code downloaded, make sure you're using an editor that allows you to search for code in multiple files. You can usually figure out how something works by tracing the function calls either backwards or forwards depending on where you start.

In this case, it would have been a good idea to find out where the TradeSkillDetailsMixin is used and from where the function OnResultMouseEnter is called. That would have given you an answer what the variable resultButton actually is.

If you know how to track the function calls, you can easily find out how anything in the Lua implementation of the UI works.
__________________

Last edited by MunkDev : 05-26-17 at 08:43 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Displaying item tooltip to the right of profession window.


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