Quantcast
How to add a Minimap Button ? - WoWInterface
Thread Tools Display Modes
08-28-16, 10:46 AM   #1
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
Question How to add a Minimap Button ?

Hi Everyone!
I have now searched around 3 Hours to get this running. and found only an old example which is not working from DRshow

I like to know how to add a Simple Minimap Icon, when i click on it that it opens my Interface.
If anybody has a simple code that can help me further. i would be thankfull.

Greets
  Reply With Quote
08-28-16, 11:23 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 818
Perhaps this lib can help you
https://www.wowace.com/addons/libdbicon-1-0/
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-28-16, 01:24 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Anyone writing a new addon should just create a DataBroker launcher, and optionally use LibDBIcon to give users without an actual DataBroker display a minimap icon.

Rolling your own just means that it's probably full of interoperability fails like (a) not supporting square (or other non-circular) minimaps, and (b) annoying everyone who does use a DataBroker display and expects addon launcher icons to show up there instead of being stuck as ugly warts on the minimap.
__________________
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
08-28-16, 03:05 PM   #4
VincentSDSH
Non-Canadian Luzer!
 
VincentSDSH's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 350
Originally Posted by Phanx View Post
Anyone writing a new addon should just create a DataBroker launcher, and optionally use LibDBIcon to give users without an actual DataBroker display a minimap icon.
Absolutely this.

It's the simplest method for the author and the best flexibility for the user.
__________________
AddonsExecutive Assistant User Configurable To-Do ListLegible Mail Choose the Font for Your Mail
  Reply With Quote
08-28-16, 03:49 PM   #5
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
Smile

Happy,that I got so fast answeres, I ll try out it fast.
Nice to have you here around.
  Reply With Quote
08-29-16, 04:05 AM   #6
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
I'm sad that Leatrix, who postetd the code, deleted his entry herre.
Lua Code:
  1. -- Create minimap button
  2.  
  3. local minibtn = CreateFrame("Button", nil, Minimap)
  4. minibtn:SetFrameLevel(8)
  5. minibtn:SetSize(32,32)
  6. minibtn:SetMovable(true)
  7.  
  8. -- minibtn:SetNormalTexture("Interface/AddOns/AutoSell/Leatrix_Plus_Up.blp")
  9. -- minibtn:SetPushedTexture("Interface/AddOns/AutoSell/Leatrix_Plus_Up.blp")
  10. -- minibtn:SetHighlightTexture("Interface/AddOns/AutoSell/Leatrix_Plus_Up.blp")
  11.  
  12. minibtn:SetNormalTexture("Interface/COMMON/Indicator-Yellow.png")
  13. minibtn:SetPushedTexture("Interface/COMMON/Indicator-Yellow.png")
  14. minibtn:SetHighlightTexture("Interface/COMMON/Indicator-Yellow.png")
  15.  
  16.  
  17. local myIconPos = 0
  18.  
  19. -- Control movement
  20. local function UpdateMapBtn()
  21.     local Xpoa, Ypoa = GetCursorPosition()
  22.     local Xmin, Ymin = Minimap:GetLeft(), Minimap:GetBottom()
  23.     Xpoa = Xmin - Xpoa / Minimap:GetEffectiveScale() + 70
  24.     Ypoa = Ypoa / Minimap:GetEffectiveScale() - Ymin - 70
  25.     myIconPos = math.deg(math.atan2(Ypoa, Xpoa))
  26.     minibtn:ClearAllPoints()
  27.     minibtn:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 52 - (80 * cos(myIconPos)), (80 * sin(myIconPos)) - 52)
  28. end
  29.  
  30. minibtn:RegisterForDrag("LeftButton")
  31. minibtn:SetScript("OnDragStart", function()
  32.     minibtn:StartMoving()
  33.     minibtn:SetScript("OnUpdate", UpdateMapBtn)
  34. end)
  35.  
  36. minibtn:SetScript("OnDragStop", function()
  37.     minibtn:StopMovingOrSizing();
  38.     minibtn:SetScript("OnUpdate", nil)
  39.     UpdateMapBtn();
  40. end)
  41.  
  42. -- Set position
  43. minibtn:ClearAllPoints();
  44. minibtn:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 52 - (80 * cos(myIconPos)),(80 * sin(myIconPos)) - 52)
  45.  
  46. -- Control clicks
  47. minibtn:SetScript("OnClick", function()
  48.     print("You clicked me!")
  49. end)

I had added this code, but not seen the Minimap button. I think there has to something else. Anybody knows what is wrong or missing ?

I have tried to use an icon in my directory like the Path that is greyd out, and has still no effect.
I believe SetNormalTexture("Interface/COMMON/Indicator-Yellow.png") , that is a real dircectory path you can find under your installed WOW start directory.
EDIT: After I deleted the old ADDON similar to this i got it to work, but the Button is smaller than normal with no border like the other.


Alternative I try the solution of Rilgamon though there I will will dependenced to the upgrades of the code.
I bind the code into my script.

Lua Code:
  1. local addon = LibStub("AceAddon-3.0"):NewAddon("Bunnies", "AceConsole-3.0")
  2. local bunnyLDB = LibStub("LibDataBroker-1.1"):NewDataObject("Bunnies!", {
  3.     type = "data source",
  4.     text = "Bunnies!",
  5.     icon = "Interface\\Icons\\INV_Chest_Cloth_17",
  6.     OnClick = function() print("BUNNIES ARE TAKING OVER THE WORLD") end,
  7. })
  8. local icon = LibStub("LibDBIcon-1.0")
  9.  
  10. function addon:OnInitialize()
  11.     -- Obviously you'll need a ## SavedVariables: BunniesDB line in your TOC, duh!
  12.     self.db = LibStub("AceDB-3.0"):New("BunniesDB", {
  13.         profile = {
  14.             minimap = {
  15.                 hide = false,
  16.             },
  17.         },
  18.     })
  19.     icon:Register("Bunnies!", bunnyLDB, self.db.profile.minimap)
  20.     self:RegisterChatCommand("bunnies", "CommandTheBunnies")
  21. end
  22.  
  23. function addon:CommandTheBunnies()
  24.     self.db.profile.minimap.hide = not self.db.profile.minimap.hide
  25.     if self.db.profile.minimap.hide then
  26.         icon:Hide("Bunnies!")
  27.     else
  28.         icon:Show("Bunnies!")
  29.     end
  30. end

What else do i need to do to get this working ?
1. I see this line
SavedVariables: BunniesDB line in your TOC, and did that
2. icon = "Interface\\Icons\\INV_Chest_Cloth_17",
do I have to change something to get work this ? and how would i be able to use own Icons
3. what else is to do ?

EDIT: I got it to work, it was simpler than i thought. But how can i Implement own Icons ? (Point 2)

Last edited by FreeXerxes : 08-29-16 at 04:21 AM.
  Reply With Quote
08-29-16, 06:05 AM   #7
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Use LibDBIcon, as two other people already told you. Rolling your own these days really isn't the best thing to do, even if you're experienced; far too many people expect things to behave as LibDBIcon does.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
08-29-16, 07:45 AM   #8
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
lol your signature is funny,Torhal

Yes. My Decision is defenetly now to use LibDBIcon. And it works perfect
But:
I'd like to know, how i can change the icon to own ones and if there is a list of the icons i can use with
Code:
icon = "Interface\\Icons\\INV_Chest_Cloth_17"
  Reply With Quote
08-29-16, 05:01 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by FreeXerxes View Post
I'd like to know, how i can change the icon to own ones
All LDBIcon does is show your DataBroker object on a minimap button -- the button's icon shows whatever your DataBroker object specifies as its icon. If you want a different icon, just specify something else here:

Code:
local bunnyLDB = LibStub("LibDataBroker-1.1"):NewDataObject("Bunnies!", {
    type = "data source",
    text = "Bunnies!",
    icon = "Interface\\Icons\\INV_Chest_Cloth_17",
    OnClick = function() print("BUNNIES ARE TAKING OVER THE WORLD") end,
})
You can also change it later in your code:

Code:
bunnyLDB.icon = "Path\\To\\Your\\Icon\\Here"
The icons available in the game are mostly those used by spells, items, achievements, etc. Just pick one you like and then use the appropriate API (eg. GetSpellInfo for spells) or Wowhead to find out what its name is.
__________________
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
08-29-16, 08:50 PM   #10
FreeXerxes
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 10
Thanks. Thats it.
Got my questions fully answered here.
Thread can be closed now.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to add a Minimap Button ?

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