Thread Tools Display Modes
01-14-15, 04:46 PM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Minimap Button Tooltip

Hey guys,

Having issues with getting my tooltip for my addon's minimap button to appear. Here's the code I have right now:

Lua Code:
  1. MMBtn.Tip = CreateFrame("GameToolTip");
  2.  
  3. MMBtn:SetScript("OnEnter",function(self)
  4.     MMBtn.Tip:SetOwner(self,"ANCHOR_CURSOR");
  5.  
  6.     MMBtn.Tip.LeftText = MMBtn.Tip:CreateFontString(nil, nil,nil);
  7.     MMBtn.Tip.LeftText:SetPoint("TOP",0,-12);
  8.     MMBtn.Tip.LeftText:SetFont("Fonts\\FRIZQT__.TTF", 11);
  9.     MMBtn.Tip.LeftText:SetTextColor(1,1,1,1);
  10.     MMBtn.Tip.LeftText:SetJustifyH("LEFT");
  11.     MMBtn.Tip.LeftText:SetText("<AddOn Name >");
  12.  
  13.     MMBtn.Tip.RightText = MMBtn.Tip:CreateFontString(nil, nil,nil);
  14.     MMBtn.Tip.RightText:SetPoint("TOP",0,-12);
  15.     MMBtn.Tip.RightText:SetFont("Fonts\\FRIZQT__.TTF", 11);
  16.     MMBtn.Tip.RightText:SetTextColor(1,1,1,1);
  17.     MMBtn.Tip.RightText:SetJustifyH("LEFT");
  18.     MMBtn.Tip.RightText:SetText("<AddOn Summary >");
  19.  
  20.     MMBtn.Tip:AddFontStrings(MMBtn.Tip.LeftText,MMBtn.Tip.RightText);
  21.  
  22.     MMBtn.Tip:Show()
  23. end);
  24.  
  25. MMBtn:SetScript("OnLeave",function(self)
  26.     MMBtn.Tip:Hide();
  27. end);

Nothing appears when I hover over the minimap button. Any thoughts?
  Reply With Quote
01-14-15, 05:14 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
#1 - I'd strongly recommend not creating your own minimap button from scratch. Instead, create a "launcher" object with LibDataBroker-1.1:
Code:
MyAddonLauncher = LibStub("LibDataBroker-1.1"):NewDataObject("MyAddonName", {
     type = "launcher",
     icon = "Interface\\AddOns\\MyAddon\\Icon",
     OnTooltipShow = function(tooltip)
          tooltip:SetText("<Addon Name>")
          tooltip:AddLine("<Addon Summary>", 1, 1, 1)
          tooltip:Show()
     end,
     OnClick = function(_, button)
         -- your OnClick stuff here
     end
end })
... and then use LibDBIcon-1.0 to create the minimap button for it:
Code:
LibStub("LibDBIcon-1.0"):Register("MyAddon", MyAddonLauncher, MyAddonLauncherDB)
This way, you don't have to do any work yourself to make it work with all minimap shapes (eg. square minimaps) and users can easily turn it off in favor of showing the icon on their DataBroker bar (eg. Bazooka, ChocolateBar, etc.) and you don't have to manage the tooltip yourself either.

#2 - If you really want to do it yourself, make sure you include an option to hide it (personally I would simply not use an addon that forcibly created a minimap button, especially one that did not work with my square minmap).

#3 - As for your actual problem, you have several. First, you're creating new font strings every time the tooltip is displayed, instead of creating them once and reusing them. Second, you are not using the GameTooltip (note the "t" in "tip" is not capitalized) correctly -- you don't place the font strings yourself, you just register them with the tooltip. Third, unless you have some specific need to manage your own tooltip, just inherit from the "GameTooltip" template (yes, it has the same name as the "GameTooltip" object type, and yes, it's a different thing) so it will automatically add any font strings that are needed to display the text you set to it:

Code:
MMBtn.Tip = CreateFrame("GameTooltip", "MMBtnTooltip", nil, "GameTooltip")
MMBtn:SetScript("OnEnter",function(self)
    MMBtn.Tip:SetOwner(self,"ANCHOR_CURSOR")
    MMBtn.Tip:AddDoubleLine("<AddOn Name >", "<AddOn Summary >")
    MMBtn.Tip:Show()
end)
...or, as seems more likely, if you want those on two separate lines, instead of on the left and right at the same level:
Code:
MMBtn.Tip = CreateFrame("GameTooltip", "MMBtnTooltip", nil, "GameTooltip")
MMBtn:SetScript("OnEnter",function(self)
    MMBtn.Tip:SetOwner(self,"ANCHOR_CURSOR")
    MMBtn.Tip:AddLine("<AddOn Name >")
    MMBtn.Tip:AddLine("<AddOn Summary >")
    MMBtn.Tip:Show()
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-14-15, 05:26 PM   #3
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Interesting, I'll definitely give the #1 approach a shot, thanks! I'll post back with the results [or questions]
  Reply With Quote
01-14-15, 05:40 PM   #4
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Wow, what a difference! Worked and worked well, thanks again! I'm definitely going to have to read up on libraries and such.

That having been said, is there anyway I can modify the minimap button texture/icon? It's too small and doesn't fit in the minimap button border correctly.
  Reply With Quote
01-14-15, 05:55 PM   #5
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by Sweetsour View Post
Wow, what a difference! Worked and worked well, thanks again! I'm definitely going to have to read up on libraries and such.

That having been said, is there anyway I can modify the minimap button texture/icon? It's too small and doesn't fit in the minimap button border correctly.
You'll need to show us the code that's creating the button and setting the texture.
  Reply With Quote
01-14-15, 05:57 PM   #6
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Choonstertwo View Post
You'll need to show us the code that's creating the button and setting the texture.
Oh right, lol

Lua Code:
  1. WBiLauncher = WBi.ldb:NewDataObject(addonName, {
  2.     type = "launcher",
  3.     icon = "Interface\\Buttons\\UI-GroupLoot-Coin-Up",
  4.     OnTooltipShow = function(tooltip)
  5.         tooltip:SetText("WoW Bets")
  6.         tooltip:Show()
  7.     end,
  8.     OnClick = function(_, button)
  9.         if(addon.MainFrame:IsShown()) then
  10.             addon.MainFrame:Hide();
  11.         else
  12.             addon.MainFrame:Show();
  13.         end
  14.     end
  15. })

So I'm just not sure how to access or change the texture/icon with this block of code.
  Reply With Quote
01-14-15, 06:07 PM   #7
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I don't understand why LibDBIcon exists. There should just be a Broker display addon that uses minimap buttons instead.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
01-14-15, 06:08 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The problem with that texture is simply that the filled-in region doesn't cover the whole texture:
https://github.com/Gethe/wow-ui-text...ot-Coin-Up.PNG

I'd recommend finding some other gold texture and using that. Fortunately there are lots to choose from:
https://github.com/Gethe/wow-ui-text...sc_Coin_01.PNG
https://github.com/Gethe/wow-ui-text...sc_Coin_02.PNG
https://github.com/Gethe/wow-ui-text...sc_Coin_17.PNG

Or you can go on Wowhead and find an item/spell/whatever with an icon you like, and click on the icon; the name you get in a little popup replaces the "INV_Misc_Coin_17" part in the URLs above, all of which can be used in-game with "Interface\\Icons\\Name_of_the_Icon".
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-14-15, 06:13 PM   #9
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Phanx View Post
The problem with that texture is simply that the filled-in region doesn't cover the whole texture:
https://github.com/Gethe/wow-ui-text...ot-Coin-Up.PNG

I'd recommend finding some other gold texture and using that. Fortunately there are lots to choose from:
https://github.com/Gethe/wow-ui-text...sc_Coin_01.PNG
https://github.com/Gethe/wow-ui-text...sc_Coin_02.PNG
https://github.com/Gethe/wow-ui-text...sc_Coin_17.PNG

Or you can go on Wowhead and find an item/spell/whatever with an icon you like, and click on the icon; the name you get in a little popup replaces the "INV_Misc_Coin_17" part in the URLs above, all of which can be used in-game with "Interface\\Icons\\Name_of_the_Icon".
Perfect, just what I was looking for; thanks again! All done
  Reply With Quote
01-14-15, 06:14 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Why create a new tooltip object for your minimap button instead of just using the regular GameTooltip?

Lua Code:
  1. MMBtn.Tip:SetScript("OnEnter", function(self)
  2.      GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  3.      GameTooltip:AddDoubleLine("<AddOn Name >", "<AddOn Summary >")
  4.      GameTooltip:Show()
  5. end)
  6.  
  7. MMBtn.Tip:SetScript("OnLeave", function() GameTooltip:Hide() end)
__________________
"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
01-14-15, 06:18 PM   #11
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Seerah View Post
Why create a new tooltip object for your minimap button instead of just using the regular GameTooltip?

Lua Code:
  1. MMBtn.Tip:SetScript("OnEnter", function(self)
  2.      GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  3.      GameTooltip:AddDoubleLine("<AddOn Name >", "<AddOn Summary >")
  4.      GameTooltip:Show()
  5. end)
  6.  
  7. MMBtn.Tip:SetScript("OnLeave", function() GameTooltip:Hide() end)
Very good to know, thanks for the tip!
  Reply With Quote
01-14-15, 06:21 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Lombra View Post
I don't understand why LibDBIcon exists. There should just be a Broker display addon that uses minimap buttons instead.
There is -- Barrel, which I now maintain because it's useful when testing on PTRs and such where I don't want my full UI -- but someone somewhere couldn't let go of the "this addon comes with a minimap button" mentality and created an embeddable library for it. I agree that most addons should not embed/use LibDBIcon, but for large standalone addons -- especially ones that had a minimap button before DataBroker came along -- it's often expected that they'll have a minimap button (a really surprising number of people do not use a Broker display or even know that such a system exists) so it's not a problem as long as they provide an option to disable it.

For example, Grid embeds LibDBIcon, but my Broker_* addons do not, since it's expected that if you're installing a Broker plugin you have a Broker display, and many of my other addons will create a Broker object if LDB is available, but don't even embed LDB, let alone LDBIcon.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-14-15, 06:43 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Sweetsour View Post
Very good to know, thanks for the tip!
If you're using the OnTooltipShow method with LibDataBroker you don't need to worry about which tooltip is being used at all; you just take the tooltip passed to your function and add stuff to it. It's probably the standard GameTooltip (named object, not object type) but it might not be.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-14-15, 07:06 PM   #14
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Phanx View Post
If you're using the OnTooltipShow method with LibDataBroker you don't need to worry about which tooltip is being used at all; you just take the tooltip passed to your function and add stuff to it. It's probably the standard GameTooltip (named object, not object type) but it might not be.
Fair enough

Also, I noticed I was getting the following error if my addon was the only addon enable:

Message: ...<AddOn Name>\Libs\LibDataBroker-1.1\LibDataBroker-1.1.lua:2: LibDataBroker-1.1 requires LibStub

Any ideas on why this is happening?

TOC
Lua Code:
  1. ## Interface: 60000
  2. ## Title: <AddOn Name>
  3. ## Notes: Allows two players to whisper bids to each other
  4. ## Author: Sweetsour
  5. ## Version: b1.1.6
  6. ## SavedVariables: WBi_SavedVar
  7.  
  8. Libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
  9. Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua
  10.  
  11. WBi_Core.lua
  12. WBi_Frames_Main.lua


First part of WBi_Core.lua
Lua Code:
  1. local WBi = {};
  2.  
  3. WBi.ldb = LibStub:GetLibrary("LibDataBroker-1.1");
  4. WBi.ldbIcon = LibStub:GetLibrary("LibDBIcon-1.0");
  5.  
  6. local function initAddon() -- Called from "ADDON_LOADED" event
  7.     WBiLauncher = WBi.ldb:NewDataObject(name, {
  8.         type = "launcher",
  9.         icon = "Interface\\ICONS\\INV_Misc_Coin_01",
  10.         OnTooltipShow = function(tooltip)
  11.             tooltip:SetText("<Addon Name>")
  12.             tooltip:Show()
  13.         end,
  14.         OnClick = function(_, button)
  15.             if(addon.MainFrame:IsShown()) then
  16.                 addon.MainFrame:Hide();
  17.             else
  18.                 addon.MainFrame:Show();
  19.             end
  20.         end
  21.     })
  22.  
  23.     WBi.ldbIcon:Register(name, WBiLauncher, WBiLauncherDB)
  24. end

Last edited by Sweetsour : 01-14-15 at 07:09 PM.
  Reply With Quote
01-14-15, 07:31 PM   #15
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by Sweetsour View Post
LibDataBroker-1.1 requires LibStub

........

Code:
Libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua

WBi_Core.lua
WBi_Frames_Main.lua
Do you see LibStub listed in your TOC?
__________________
"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
01-14-15, 07:31 PM   #16
sticklord
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 57
You also need to add the library Libstub
  Reply With Quote
01-14-15, 07:41 PM   #17
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Originally Posted by Seerah View Post
Do you see LibStub listed in your TOC?
Heyyy, derp! Haha, thanks! :P
  Reply With Quote
01-14-15, 08:07 PM   #18
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Most libraries use LibStub to handle versioning -- this way, if the user has 10 addons installed that all include a copy of the same library, once the loading process finishes, there's only one copy of the newest version of the library loaded, and all 10 addons are using it.

LibDataBroker also uses the CallbackHandler-1.0 library, which is commonly used to handle "callbacks", which are bascially custom events. The game can fire a "UNIT_HEALTH" update to notify addons that someone's health changed, but addons can't fire real events, so they have to create their own notification system, and it's just easiest to use one that already exists instead of everyone reinventing the wheel for their own project.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-14-15, 08:12 PM   #19
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Makes sense!
  Reply With Quote
01-15-15, 03:11 PM   #20
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Hello again!

Referencing this code block of code again;

Lua Code:
  1. MyAddonLauncher = LibStub("LibDataBroker-1.1"):NewDataObject("MyAddonName", {
  2.      type = "launcher",
  3.      icon = "Interface\\AddOns\\MyAddon\\Icon",
  4.      OnTooltipShow = function(tooltip)
  5.           tooltip:SetText("<Addon Name>")
  6.           tooltip:AddLine("<Addon Summary>", 1, 1, 1)
  7.           tooltip:Show()
  8.      end,
  9.      OnClick = function(_, button)
  10.          -- your OnClick stuff here
  11.      end
  12. end })

Is there a way I can access the element (the minimap button) to have the ability to set its point using :SetPoint() (outside of this code)?

Last edited by Sweetsour : 01-15-15 at 03:15 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Minimap Button Tooltip

Thread Tools
Display Modes

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