View Single Post
03-22-24, 03:05 PM   #3
Codger
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2021
Posts: 30
Updated example frame with LibDBIcon minimap button

This is a simple example of an addon with a frame and minimap button(using LibDBIcon-1.0).
The Addon has been renamed to "MyAddonFrameExample" to incorporate some necesssary changes noted in the forum thread above by Fizzelmizz (Thank you!!)
The addon consists of three files and a Libs directory containing the four required libraries.
The three files are located in the "MyAddonFrameExample" directory and are:
  • MyAddonFrameExample.toc
  • core.lua
  • embeds.xml
Four libraries are required and must be installed into the Libs directory contained in the MyAddonFrameExample directory. The required libraries are(in order of dependency):
embeds.xml
  • LibStub
  • CallbackHandler-1.0
  • LibDataBroker-1.1
  • LibDBIcon-1.0

Here is the MyAddonFrameExample.toc file:
Lua Code:
  1. ## Title: MyAddonFrameExample
  2. ## Interface: 100206
  3. ## Version: 1.0
  4. ## Author:
  5. ## Notes: A simple WoW addon with a minimap button derived from LibDB-Icon
  6. embeds.xml
  7. core.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\LibStub\LibStub.lua"/>
  3.     <Include file="Libs\CallbackHandler-1.0\CallbackHandler-1.0.xml"/>
  4.     <Script file="Libs\LibDataBroker-1.1\LibDataBroker-1.1.lua"/>    
  5.     <Script file="Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua"/>  
  6. </Ui>

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

Last edited by Codger : 03-22-24 at 03:08 PM.
  Reply With Quote