Thread Tools Display Modes
Prev Previous Post   Next Post Next
03-22-24, 11:36 AM   #1
Codger
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2021
Posts: 30
Simple example frame with LibDBIcon minimap button (for review)

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:
  1. ## Title: MyAddon
  2. ## Interface: 100206
  3. ## Version: 1.0
  4. ## Author:
  5. ## Notes: A simple WoW addon with a minimap button
  6. embeds.xml
  7. MyAddon.lua

Here is the embeds.xml file:
Lua Code:
  1. <Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
  2.     <Script file="Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua"/>  
  3. </Ui>

Here is the lua file:
Lua Code:
  1. local LibDBIcon = LibStub("LibDBIcon-1.0")
  2.  
  3. local frame = CreateFrame("Frame", "MyAddonFrame", UIParent, "BackdropTemplate")
  4. frame:SetBackdrop({
  5.       bgFile="Interface\\DialogFrame\\UI-DialogBox-Background",
  6.       edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
  7.       tile=1, tileSize=32, edgeSize=32,
  8.       insets={left=10, right=10, top=10, bottom=10}
  9. })
  10. frame:SetPoint("CENTER")
  11. frame:SetSize(200, 200)
  12. frame:EnableMouse(true)
  13. frame:SetMovable(true)
  14. frame:RegisterForDrag("LeftButton")
  15. frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
  16. frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
  17. frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  18. local fontStr = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  19. fontStr:SetPoint("CENTER")
  20. fontStr:SetText("MyAddonFrame")
  21. frame:Show()
  22.  
  23. -- Create a minimap button
  24. local icon = LibDBIcon:Register("MyAddon", {
  25.     icon = "Interface\\Icons\\Ability_Marksmanship",
  26.     OnClick = function(self, button)
  27.         if button == "LeftButton" then
  28.             if frame:IsShown() then
  29.                 frame:Hide()
  30.             else
  31.                 frame:Show()
  32.             end
  33.         elseif button == "RightButton" then
  34.             print("Right click not configured")
  35.         end
  36.     end,
  37.     OnTooltipShow = function(tooltip)
  38.         tooltip:SetText("MyAddon")
  39.         tooltip:AddLine("Left-click to open / close", 1, 1, 1)
  40.         tooltip:AddLine("Right-click not configured", 1, 1, 1)
  41.     end,
  42. })

Last edited by Codger : 03-22-24 at 11:39 AM.
  Reply With Quote
 

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Simple example frame with LibDBIcon minimap button (for review)


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