This is a simple example of an addon with a frame and minimap button(using LibDBIcon-1.0).
Since I'm fairly new to addon development I thought I would post this to see if there is anything I should do differently.
This will require a Libs directory in the MyAddon directory that contains the LibDBIcon-1.0 library.
This is the .toc file:
Lua Code:
## Title: MyAddon
## Interface: 100206
## Version: 1.0
## Author:
## Notes: A simple WoW addon with a minimap button
embeds.xml
MyAddon.lua
Here is the embeds.xml file:
Lua Code:
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
<Script file="Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua"/>
</Ui>
Here is the lua file:
Lua Code:
local LibDBIcon = LibStub("LibDBIcon-1.0")
local frame = CreateFrame("Frame", "MyAddonFrame", UIParent, "BackdropTemplate")
frame:SetBackdrop({
bgFile="Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
tile=1, tileSize=32, edgeSize=32,
insets={left=10, right=10, top=10, bottom=10}
})
frame:SetPoint("CENTER")
frame:SetSize(200, 200)
frame:EnableMouse(true)
frame:SetMovable(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
local fontStr = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
fontStr:SetPoint("CENTER")
fontStr:SetText("MyAddonFrame")
frame:Show()
-- Create a minimap button
local icon = LibDBIcon:Register("MyAddon", {
icon = "Interface\\Icons\\Ability_Marksmanship",
OnClick = function(self, button)
if button == "LeftButton" then
if frame:IsShown() then
frame:Hide()
else
frame:Show()
end
elseif button == "RightButton" then
print("Right click not configured")
end
end,
OnTooltipShow = function(tooltip)
tooltip:SetText("MyAddon")
tooltip:AddLine("Left-click to open / close", 1, 1, 1)
tooltip:AddLine("Right-click not configured", 1, 1, 1)
end,
})