Creating a Minimap Button

79 Night Elf Rogue
980
Can anyone walk me through a code that will allow me to give an addon a Icon around the Minimap?

I don't fully understand LDBIcon and I don't want to have to use a license of any kind other than the generic I made the addon thing.

Anyone know a simple way to load a icon?
Reply Quote
90 Draenei Shaman
9660
Can anyone walk me through a code that will allow me to give an addon a Icon around the Minimap?

I don't fully understand LDBIcon and I don't want to have to use a license of any kind other than the generic I made the addon thing.

Anyone know a simple way to load a icon?


LibDBIcon-1.0 is released under the GPLv2. The only restriction to your addon is that it is available under a free-use and/or open source license. Since we can't charge for addons, you are free to use whatever license you care to.

Using LibDBIcon is VERY simple. LibDBIcon works with existing LibDatabroker objects (http://www.wowace.com/addons/libdatabroker-1-1/):
LibStub("LibDBIcon-1.0"):Register("YourAddonLDBObjectName", yourAddonLDBObject, savedVarStorageTable);

If you are using AceDB, you can register callbacks to "OnProfileChanged", "OnProfileCopied" and "OnProfileReset" to update the storage place:
LibStub("LibDBIcon-1.0"):Refresh("YourAddonLDBObjectName", newSavedVarStorageTable)

Using LibDatabroker and LibDBIcon allows you to target both Minimap icons and LDB-compatible displays (Titan Panel, FuBar (I think?), etc) without making modules for each display addon.
Reply Quote
85 Human Warrior
4790
Well then I need more info maybe a better code sample. Their documentation does not really help me at all.

I just want it to show a text on the button. I also had a issue with the image displaying but I don't mind that just yet.
Reply Quote
90 Draenei Shaman
9660
Here is a simple stub that shows one way to use LibDatabroker and LibDBIcon. It uses AceDB-3.0 as the saved variable table handler. You can use any method to handle saved variables you want. Although, you should properly update the LibDBIcon storage table as is done in the "updateDB" function. You can specify any valid file you wish as the icon by changing the "icon" field in the "ldbObject" table.

LibDBIcon works with both "data source" and "launcher" LibDatabroker object types.

LibDatabroker and LibDBIcon integrate nicely with addons based on the Ace3 libraries (http://www.wowace.com/addons/ace3/).

local db; -- File-global handle to the Database
local defaults = {
profile = {
LDBIconStorage = {}, -- LibDBIcon storage
},
};

local ldbObject = {
type = "launcher",
icon = "Interface\\ICONS\\spell_nature_bloodlust",
--This is the icon used. Any .blp or .tga file is a valid icon.
--This path is ALWAYS relative to the World of Warcraft
--root (ie, "C:\Program Files\World of Warcraft" for
--Windows and "/Applications/World of Warcraft" for Mac)
label = "AddonName",
OnClick = function(self, button)
-- Add a click handler here
end,
OnTooltipShow = function(tooltip)
tooltip:AddLine("Example text");
--Add text here. The first line is ALWAYS a "header" type.
--It will appear slightly larger than subsequent lines of text
end,
};

function updateDB(self, event, database)
db = database.profile;
LibStub("LibDBIcon-1.0"):Refresh("AddonLDBObjectName", db.LDBIconStorage);
end

local vars = LibStub("AceDB-3.0"):New("AddonSavedVarStorage", defaults);
vars:RegisterCallback("OnProfileChanged", updateDB);
vars:RegisterCallback("OnProfileCopied", updateDB);
vars:RegisterCallback("OnProfileReset", updateDB);
db = vars.profile;

LibStub("LibDataBroker-1.1"):NewDataObject("AddonLDBObjectName", ldbObject);
LibStub("LibDBIcon-1.0"):Register("AddonLDBObjectName", ldbObject, db.LDBIconStorage);


Reference links:
Ace3 project site: http://www.wowace.com/addons/ace3/
LibDatabroker project site: https://github.com/tekkub/libdatabroker-1-1
LibDatabroker data specifications: https://github.com/tekkub/libdatabroker-1-1/wiki/data-specifications
LibDBIcon project site: http://www.wowace.com/addons/libdbicon-1-0/
Reply Quote
85 Human Warrior
4790
Is there a easy way to make a dropdown menu while I have you?

I was hoping to use the XML code if you can. I can define functions in the lua code but this way I can place it where it needs to be.
Reply Quote
90 Draenei Shaman
9660
Sadly, dropdown menus aren't quite as easy. The tutorials on wowwiki and wowpedia should still be accurate though.

http://www.wowpedia.org/Using_UIDropDownMenu

There is an "EasyMenu" function but I'm not familiar with it.

http://www.wowpedia.org/API_EasyMenu
Reply Quote
85 Human Warrior
4790
Thanks for the help.
Reply Quote
85 Blood Elf Paladin
4535
first off i want to apologize for bumping this thread, i know how people can rage of that.

but ive been trying to get a working mini map icon using this method for quite a few hours now, and im getting so flustered i want to throw up.

i keep getting this lua error

Message: ...listerings_buff_tracker\Blisterings_buff_Tracker.lua:29: Cannot find a library instance of "LibDBIcon-1.0.lua".
Time: 11/05/11 21:45:12
Count: 1
Stack: [C]: in function `error'
Interface\AddOns\Ace3\LibStub\LibStub.lua:23: in function `LibStub'
...listerings_buff_tracker\Blisterings_buff_Tracker.lua:29: in main chunk

Locals: (*temporary) = "Cannot find a library instance of "LibDBIcon-1.0.lua"."

ive looked at alot of other addons that use libs and they have them listed in the toc file, im not exactly sure how to do this as i see some doing something like

libs\LibDataBroker-1.1.lua
and others doing
#@no-lib-strip@
libs\LibStub\LibStub.lua
libs\CallbackHandler-1.0\CallbackHandler-1.0.xml
#@end-no-lib-strip@


and in the lua file im not sure if its pointing to the correct path or what, or if it gets the path from the toc file. when i downloaded the libs from wow ace there were libs with in the libs and all this crazy stuff

the code trying to use is directly from
http://www.wowace.com/addons/libdbicon-1-0/pages/main/

and what i have is


local icon = LibStub("LibDBIcon-1.0.lua")
icon:Register("MyLDB", myLDB, savedVarTable)
icon:Hide("MyLDB")
icon:Show("MyLDB")
local addon = LibStub("AceAddon-3.0"):NewAddon("Bunnies", "AceConsole-3.0")
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,
})
local icon = LibStub("LibDBIcon-1.0.lua")

function addon:OnInitialize()
-- Obviously you'll need a ## SavedVariables: BunniesDB line in your TOC, duh!
self.db = LibStub("AceDB-3.0"):New("BunniesDB", {
profile = {
minimap = {
hide = false,
},
},
})
icon:Register("Bunnies!", bunnyLDB, self.db.profile.minimap)
self:RegisterChatCommand("bunnies", "CommandTheBunnies")
end

function addon:CommandTheBunnies()
self.db.profile.minimap.hide = not self.db.profile.minimap.hide
if self.db.profile.minimap.hide then
icon:Hide("Bunnies!")
else
icon:Show("Bunnies!")
end
end


any help with this will be extremely appreciated as im at the point were im going to start throwing anything with in arms reach of my desk as i bask my face into my keyboard
Reply Quote
Your AddOn's TOC (or an XML loaded by the TOC) needs to load LibStub, CallbackHandler, LibDataBroker and LibDBIcon in this order; otherwise the libraries won't be able to function properly.

Let's say you dumped the LibDBIcon-1.0 folder extracted from the download straight into the Libs folder in your AddOn's root directory (where your TOC is). The download comes with all the libraries required by LibDBIcon, so there's no need to download them separately.

Your TOC would look like this:## Interface: 40200
## Title: Bunnies
## Author: Me!
## Version: 1.0

# Everything above here just tells the game about your AddOn.
# Everything below here deals with the actual loading of the AddOn's files.

Libs\LibDBIcon-1.0\libs\LibStub\LibStub.lua
Libs\LibDBIcon-1.0\libs\CallbackHandler-1.0\CallbackHandler-1.0.lua
Libs\LibDBIcon-1.0\libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
# We've now loaded the three libraries LibDBIcon depends on, so we can load LibDBIcon itself
Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua

# We've now loaded LibDBIcon. We can load more libraries (e.g. Ace) if needed, or we can load the AddOn itself

bunnies.lua


#@no-lib-strip@ is just a tag used by the Curse repositories to package your AddOn without its libraries. The game itself does nothing with it.
Edited by Choonster on 11/5/2011 7:40 PM PDT
Reply Quote
85 Blood Elf Paladin
4535
ok so i feel like a noob, and i hate feeling likea noob. i understand what your saying but now i have another lua error wich i dont understand why cuz that lib should be loaded now


Message: ...listerings_buff_tracker\Blisterings_buff_Tracker.lua:33: Cannot find a library instance of "LibDBIcon-1.0.lua".
Time: 11/06/11 00:06:33
Count: 2
Stack: [C]: in function `error'
..._tracker\Libs\LibDBIcon-1.0\libs\LibStub\LibStub.lua:23: in function `LibStub'
...listerings_buff_tracker\Blisterings_buff_Tracker.lua:33: in main chunk

Locals: (*temporary) = "Cannot find a library instance of "LibDBIcon-1.0.lua"."





here is my toc file



## Author: Blistering - Nathrezim
## Interface: 40200
## Notes: Reports names to chat of players that do not have buffs.
## Title: |cFFFF00FFBlisterings buff tracker|r
## Version: 1.2b
## SavedVariables: BBT_chat_DEFAULTS, BTT_tracking_DEFAULTS



Libs\LibDBIcon-1.0\libs\LibStub\LibStub.lua
Libs\LibDBIcon-1.0\libs\CallbackHandler-1.0\CallbackHandler-1.0.lua
Libs\LibDBIcon-1.0\libs\LibDataBroker-1.1\LibDataBroker-1.1.lua
# We've now loaded the three libraries LibDBIcon depends on, so we can load LibDBIcon itself
Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua

Blisterings_buff_Tracker.xml
Blisterings_buff_Tracker.lua
Reply Quote
85 Blood Elf Paladin
4535
does it mater if the addon is entirely in ace? or can it be a basic lua addon with ace stuff like this. im not sure if that makes any sense lol.
Reply Quote
11/05/2011 09:13 PMPosted by Drawkward
does it mater if the addon is entirely in ace? or can it be a basic lua addon with ace stuff like this. im not sure if that makes any sense lol.
How much of the AddOn is written around Ace has no bearing on this error.

Do you actually have all the files in the places your TOC is looking for them? because it seems that it isn't loading LibDBIcon.
Reply Quote
85 Blood Elf Paladin
4535
the only part of the addon that so far is written in ace ( unsuccessfully, wich is the reason for the post here) is the mini map icon. All the files appear to be in the correct places,

but the thing is when i look at the lua error the stack trace says



Stack: [C]: in function `error'
Interface\AddOns\Ace3\LibStub\LibStub.lua:23: in function `LibStub'



does that mean its looking in the Ace3 addon folder i have installed as a seperate addon and ignoring the paths in the toc??


and that code that i posted above in my first post from http://www.wowace.com/addons/libdbicon-1-0/pages/main/ is all the bit of "ace" code i have in my addon , the rest if just basic wow lua. but those 30 lines of code are completely disabling my addon. with out it, my addon runs fine,
Edited by Drawkward on 11/5/2011 9:59 PM PDT
Reply Quote
11/05/2011 09:58 PMPosted by Drawkward
does that mean its looking in the Ace3 addon folder i have installed as a seperate addon and ignoring the paths in the toc??
That just means that Ace3 loaded LibStub before your AddOn did. Not every user of your AddOn will have Ace3 installed as a stand-alone, so you need to tell your AddOn to load every library it requires to function.

and that code that i posted above in my first post from http://www.wowace.com/addons/libdbicon-1-0/pages/main/ is all the bit of "ace" code i have in my addon , the rest if just basic wow lua. but those 30 lines of code are completely disabling my addon. with out it, my addon runs fine,
I just figured out what your problem is. You're telling LibStub to look for a library called "LibDBIcon-1.0.lua" instead of "LibDBIcon-1.0". LibStub works with library names, not file names.

i.e. instead of this:local icon = LibStub("LibDBIcon-1.0.lua")

You should write this:local icon = LibStub("LibDBIcon-1.0")
Edited by Choonster on 11/5/2011 10:13 PM PDT
Reply Quote
85 Blood Elf Paladin
4535
Ok, making progress now. but still not working lol. now i get this

Message: ...r\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:224: attempt to index local 'object' (a nil value)
Time: 11/06/11 01:10:56
Count: 2
Stack: ...r\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:224: in function `Register'
...listerings_buff_tracker\Blisterings_buff_Tracker.lua:32: in main chunk

Locals: self = <table> {
notCreated = <table> {
}
Register = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:223
IsRegistered = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:243
Refresh = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:246
Show = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:237
EnableLibrary = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:259
loggedIn = false
objects = <table> {
}
Hide = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:233
callbackRegistered = true
DisableLibrary = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:275
IconCallback = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:48
}
name = "MyLDB"
object = nil
db = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index local 'object' (a nil value)"
lib = <table> {
notCreated = <table> {
}
Register = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:223
IsRegistered = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:243
Refresh = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:246
Show = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:237
EnableLibrary = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:259
loggedIn = false
objects = <table> {
}
Hide = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:233
callbackRegistered = true
DisableLibrary = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:275
IconCallback = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:48
}
createButton = <function> defined @Interface\AddOns\Blisterings_buff_tracker\Libs\LibDBIcon-1.0\LibDBIcon-1.0\LibDBIcon-1.0.lua:154



and by the way , thank you for all this help i cant even begin to explain how much i apreciate this
Edited by Drawkward on 11/5/2011 10:14 PM PDT
Reply Quote
85 Blood Elf Paladin
4535
line 32 of my addon in the stack trace is

icon:Register("MyLDB", myLDB, savedVarTable)



i originaly started coding in Vb.net going lua, so this entire ace framework thing is just throwing me through loops since i can barely find any documentation for what i want to do.

im not sure what the savedVarTable is sapose to refer to. i could post the rest of my addon but its already around 900 some lines
Edited by Drawkward on 11/5/2011 10:20 PM PDT
Reply Quote
You're trying to register an LDB object with LDBIcon before you actually create the object. The first few lines of your Lua file can be removed completely, they're just API usage examples.

Your Lua file should look like this:local addon = LibStub("AceAddon-3.0"):NewAddon("Bunnies", "AceConsole-3.0")
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,
})
local icon = LibStub("LibDBIcon-1.0.lua")

function addon:OnInitialize()
-- Obviously you'll need a ## SavedVariables: BunniesDB line in your TOC, duh!
self.db = LibStub("AceDB-3.0"):New("BunniesDB", {
profile = {
minimap = {
hide = false,
},
},
})
icon:Register("Bunnies!", bunnyLDB, self.db.profile.minimap)
self:RegisterChatCommand("bunnies", "CommandTheBunnies")
end

function addon:CommandTheBunnies()
self.db.profile.minimap.hide = not self.db.profile.minimap.hide
if self.db.profile.minimap.hide then
icon:Hide("Bunnies!")
else
icon:Show("Bunnies!")
end
end
Edited by Choonster on 11/5/2011 10:23 PM PDT
Reply Quote
85 Blood Elf Paladin
4535
OK.... finaly lol


after adding

Libs\AceDB-3.0\AceDB-3.0.lua
Libs\AceConsole-3.0\AceConsole-3.0.lua
Libs\AceAddon-3.0\AceAddon-3.0.lua



to my toc file, i started with AceAddon-3.0 , then console then db..... completely backwards lol but its working. the minimap button is there i added my code to the onclick and it works, but now every time i reload my ui i get


Message: ...listerings_buff_tracker\Blisterings_buff_Tracker.lua:29: Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon 'Bunnies' already exists.
Time: 11/06/11 01:43:04
Count: 1
Stack: [C]: ?
...ings_buff_tracker\Libs\AceAddon-3.0\AceAddon-3.0.lua:140: in function `NewAddon'
...listerings_buff_tracker\Blisterings_buff_Tracker.lua:29: in main chunk

Locals: (*temporary) = "Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon 'Bunnies' already exists."




is there a way that i could check to see if 'Bunnies' exists before trying to create it? or should i put all this code into some event handler or something
Reply Quote
It looks like you're trying to create the Bunnies AddOn twice. Make sure you're not somehow loading a duplicate of your AddOn and aren't calling :NewAddon("Bunnies") more than once in your AddOn.
Reply Quote
85 Blood Elf Paladin
4535
lol well im not trying to, im pretty much using your code example'



local addon = LibStub("AceAddon-3.0"):NewAddon("Bunnies", "AceConsole-3.0")
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")
inLockdown = InCombatLockdown();
if(inLockdown)then
print("Cannot Hide in Combat");
else
if(BBFframe1:IsShown()) then
BBFframe1:Hide();
else
BBFframe1:Show();
end
end


end,
})
local icon = LibStub("LibDBIcon-1.0")

function addon:OnInitialize()
-- Obviously you'll need a ## SavedVariables: BunniesDB line in your TOC, duh!
self.db = LibStub("AceDB-3.0"):New("BunniesDB", {
profile = {
minimap = {
hide = false,
},
},
})
icon:Register("Bunnies!", bunnyLDB, self.db.profile.minimap)
self:RegisterChatCommand("bunnies", "CommandTheBunnies")
end

function addon:CommandTheBunnies()
self.db.profile.minimap.hide = not self.db.profile.minimap.hide
if self.db.profile.minimap.hide then
icon:Hide("Bunnies!")
else
icon:Show("Bunnies!")
end
end


i tried wrapping it all in



local frame = CreateFrame("FRAME"); -- Need a frame to respond to events
frame:RegisterEvent("ADDON_LOADED"); -- Fired when saved variables are loaded
function frame:OnEvent(event, arg1)
if event == "ADDON_LOADED" then



end;
end;




but thats yet another thing i cant seem to get to work correctly, any time i used it, it fails to load the code with in the function
Reply Quote

Please report any Code of Conduct violations, including:

Threats of violence. We take these seriously and will alert the proper authorities.

Posts containing personal information about other players. This includes physical addresses, e-mail addresses, phone numbers, and inappropriate photos and/or videos.

Harassing or discriminatory language. This will not be tolerated.

Forums Code of Conduct

Report Post # written by

Reason
Explain (256 characters max)
Submit Cancel

Reported!

[Close]