Thread Tools Display Modes
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
03-22-24, 11:56 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
LibDBIcon has dependancies on LibStub and LibCallBackHandler. Those should both be included in your addon (lib folder) and .toc (or other .XML include file eg. embeds.xml) in case the user doesn't have another addon that does include them (libs aren't automatically included or loaded).

Frame names are also added to the global table and should also be unique "CodgerAddonFrame" instead of "MyAddonFrame". If it has a name (and is unique) you can use it in your show/hide code

Lua Code:
  1. OnClick = function(self, button)
  2.         if button == "LeftButton" then
  3.             CodgerAddonFrame:SetShown(not CodgerAddonFrame:IsShown()) -- toggle show/hide
  4.         elseif button == "RightButton" then
  5.             print("Right click not configured")
  6.         end
  7.     end,

Edit: Missed the "MyAddon" in:
Code:
local icon = LibDBIcon:Register("MyAddon", {
It should also be unique (like the name of your addon folder).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-22-24 at 12:23 PM.
  Reply With Quote
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
03-22-24, 03:23 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
That actual code isn't using LibDataBroker-1.1 but I'm guessing it's all meant to come together with the previous code (or other).

As a frame that shows/hides using the minimap button, it works as is.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
03-22-24, 03:45 PM   #5
Codger
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2021
Posts: 30
Lib dependency

Ok. I'm still trying to figure this stuff out. Thanks again for your thoughtful and instructional replies.
The reason I thought I needed it was an entry in the Libs\LibDBIcom-1.0\embeds.xml file

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
  2.  
  3. <Script file="LibStub\LibStub.lua"/>
  4. <Script file="CallbackHandler-1.0\CallbackHandler-1.0.lua"/>
  5. <Script file="LibDataBroker-1.1\LibDataBroker-1.1.lua"/>
  6.  
  7. </Ui>
After looking at the embeds file I was thinking maybe I should have included a link to the Libs\LibDBIcom-1.0\embeds.xml
rather than the Libs\LibDBIcom-1.0\LibDBIcon-1.0.lua file in my addon embeds.xml file as it appears to have the
libraries and dependencies in the LibDBIcon xml file.

However when I tried to do that the LibDBIcon xml file contained a split line which generated an error.
I didn't want to change my local LibDBIcon library as others who use this example may not have a
working version of the library to depend on and the example would fail so I included all four of the libraries
in my addon embeds.xml file.
  Reply With Quote
03-22-24, 04:10 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
You have two (for want of a better term) "primary" libraries (although your posted code only uses LibDBIcon)
  • LibDBIcon -- Creates manages the minimap button
  • LibDataBroker -- Helps creating plugins for addons like TitanPanel.

Both of these use (depend on) LibStub (a library for managing library versioning) and LibCallBackHandler (for handling callbacks).

If your included a libraries depend on another library (or more) then the "sub-libraries" also need to be included in your addon and listed in the .toc (or via an xml file that does this).

Other addons may also use/include the same libraries (and sub-libraries). The loading of these is managed via LibStub.
Code:
    <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
     
    <Script file="LibStub\LibStub.lua"/>
    <Script file="CallbackHandler-1.0\CallbackHandler-1.0.lua"/>
     <Script file="Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua"/>
    </Ui>
Only include LibDataBroker-1.1 if you are actually using it (maybe you are, it just wasn't it the code you posted).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-22-24 at 04:15 PM.
  Reply With Quote
03-22-24, 04:20 PM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Codger, if you want to have a look at a relatively simple addon that uses the libdatabroker part of the library you can grab a copy of my AltILevel addon I created 10 years ago. It was still working as of the start of dragonflight. But with some of the minimap having changes this patch ( Tracking frame name changed .. again ) I might have to test it out again rofl.


https://www.wowinterface.com/downloa...AltILevel.html
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
03-22-24, 07:10 PM   #8
Codger
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2021
Posts: 30
Xinfo doesn't seem to be creating a menu?

I loaded the Xinfo addon but I'm not seeing a menu come up?
  Reply With Quote
03-22-24, 07:32 PM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Originally Posted by Codger View Post
I loaded the Xinfo addon but I'm not seeing a menu come up?
It doesn't come up on the minimap button. My addon uses the LibDataBroker part to place a button display on things like titanpanel, chocolatebar type of addons. The addon page explains that.

But, on clicking that button, it should start generating a list of your characters as you log them in. Like in the screenshots on the addon page.

Edit:
Just double checked in case it had bugged out and it still works as expected.

An addon like chocolatebar ( only one available when I tested at the start of dragonflight ) is needed, and you need to select to show text or show label as I have no icon for the addon. After that mousing over, left clicking or right clicking will show a variety of windows/menus.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 03-22-24 at 07:39 PM.
  Reply With Quote
03-24-24, 11:06 PM   #10
Codger
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2021
Posts: 30
New version using LibDataBroker

This fixes an issue affecting coordination with other addons.
I noticed that although the icon was being shown on the mini-map, addons that combined mini-map buttons would not display this addons icon. This version fixes that problem by adding libdatabroker to handle communication between this addon and others that may need to coordinate with it; including as examples; leatrix plus and titan panel.

This addon is using the four libraries: CallbackHandler-1.0, LibDataBroker-1.1, LibDBIcon-1.0 and LibStub.

Here is the MyAddonFrameExample.toc file:
Lua Code:
  1. ## Title: MyAddonFrameExample
  2. ## Interface: 100206
  3. ## Version: 2.0
  4. ## Author: Codger
  5. ## Notes: A simple WoW addon with a minimap button derived from LibDB-Icon
  6. ## OptionalDeps: LibDBIcon-1.0, LibDataBroker-1.1.lua
  7. ## IconTexture: Interface\\Icons\\inv_gizmo_bronzeframework_01
  8.  
  9. embeds.xml
  10. 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 addon = LibStub("AceAddon-3.0"):NewAddon("MyAddonFrameExample")  
  2. local MyAddonFrameExampleLDB = LibStub("LibDataBroker-1.1"):NewDataObject("MyAddonFrameExample", {  
  3.     type = "data source",  
  4.     text = "MyAddonFrameExample!",  
  5.     icon = "Interface\\Icons\\inv_gizmo_bronzeframework_01",  
  6.     OnClick = function(self, button)
  7.         if button == "LeftButton" then
  8.             MyAddonFrameExample:SetShown(not MyAddonFrameExample:IsShown()) -- toggle show/hide
  9.         elseif button == "RightButton" then
  10.             ReloadUI()
  11.         end
  12.     end,
  13.     OnTooltipShow = function(tooltip)
  14.         tooltip:SetText("MyAddonFrameExample")
  15.         tooltip:AddLine("Left-click to open / close", 1, 1, 1)
  16.         tooltip:AddLine("Right-click to Reload Ui", 1, 1, 1)
  17.     end,
  18. })  
  19. local icon = LibStub("LibDBIcon-1.0")  
  20.  
  21. function addon:OnInitialize()
  22.     -- Assuming you have a ## SavedVariables: BunniesDB line in your TOC
  23.     self.db = LibStub("AceDB-3.0"):New("BunniesDB", {
  24.         profile = {
  25.             minimap = {
  26.                 hide = false,
  27.             },
  28.         },
  29.     })
  30.     icon:Register("MyAddonFrameExample", MyAddonFrameExampleLDB, self.db.profile.minimap)
  31. end
  32.  
  33. --Frame names are global and must be unique: 'MyAddonFrameExample'
  34. local frame = CreateFrame("Frame", "MyAddonFrameExample", UIParent, "BackdropTemplate")
  35. frame:SetBackdrop({
  36.       bgFile="Interface\\DialogFrame\\UI-DialogBox-Background",
  37.       edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
  38.       tile=1, tileSize=32, edgeSize=32,
  39.       insets={left=10, right=10, top=10, bottom=10}
  40. })
  41. frame:SetPoint("CENTER")
  42. frame:SetSize(200, 200)
  43. frame:EnableMouse(true)
  44. frame:SetMovable(true)
  45. frame:RegisterForDrag("LeftButton")
  46. frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
  47. frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
  48. frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  49. local fontStr = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  50. fontStr:SetPoint("CENTER")
  51. fontStr:SetText("MyAddonFrameExample")
  52. frame:Show()
  Reply With Quote
03-31-24, 08:16 PM   #11
Codger
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2021
Posts: 30
New version. Added a missing library (AceDB).

So I must have been lucky enough in my previous testing to have had another addon installed that loaded AceDB-3.0. A new Wow install due to a computer crash revealed the bug due to the missing library. I also added a saved variable for the database and renamed it from BunniesDB to MyAddonFrameExampleDB and included it in the .toc file.

This addon is using the five libraries: CallbackHandler-1.0, LibDataBroker-1.1, AceDB-3.0, LibDBIcon-1.0 and LibStub.

Here is the MyAddonFrameExample.toc file:
Lua Code:
  1. ## Title: MyAddonFrameExample
  2. ## Interface: 100206
  3. ## Version: 2.0
  4. ## Author: Codger
  5. ## Notes: A simple WoW addon with a minimap button derived from LibDB-Icon
  6. ## OptionalDeps: LibDBIcon-1.0, LibDataBroker-1.1.lua
  7. ## IconTexture: Interface\\Icons\\inv_gizmo_bronzeframework_01
  8. ## SavedVariables: MyAddonFrameExampleDB
  9.  
  10. embeds.xml
  11. core.lua

Here is the embeds.xml file with the added library. The order of the libraries is important/:
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.     <Include file="Libs\AceDB-3.0\AceDB-3.0.xml"/>
  5.     <Script file="Libs\LibDataBroker-1.1\LibDataBroker-1.1.lua"/>    
  6.     <Script file="Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua"/>  
  7. </Ui>

And the core.lua file:
Lua Code:
  1. local addon = LibStub("AceAddon-3.0"):NewAddon("MyAddonFrameExample")  
  2. local MyAddonFrameExampleLDB = LibStub("LibDataBroker-1.1"):NewDataObject("MyAddonFrameExample", {  
  3.     type = "data source",  
  4.     text = "MyAddonFrameExample!",  
  5.     icon = "Interface\\Icons\\inv_gizmo_bronzeframework_01",  
  6.     OnClick = function(self, button)
  7.         if button == "LeftButton" then
  8.             MyAddonFrameExample:SetShown(not MyAddonFrameExample:IsShown()) -- toggle show/hide
  9.         elseif button == "RightButton" then
  10.             ReloadUI()
  11.         end
  12.     end,
  13.     OnTooltipShow = function(tooltip)
  14.         tooltip:SetText("MyAddonFrameExample")
  15.         tooltip:AddLine("Left-click to open / close", 1, 1, 1)
  16.         tooltip:AddLine("Right-click to Reload Ui", 1, 1, 1)
  17.     end,
  18. })  
  19. local icon = LibStub("LibDBIcon-1.0")  
  20.  
  21. function addon:OnInitialize()
  22.     self.db = LibStub("AceDB-3.0"):New("MyAddonFrameExampleDB", {
  23.         profile = {
  24.             minimap = {
  25.                 hide = false,
  26.             },
  27.         },
  28.     })
  29.     icon:Register("MyAddonFrameExample", MyAddonFrameExampleLDB, self.db.profile.minimap)
  30. end
  31.  
  32. --Frame names are global and must be unique: 'MyAddonFrameExample'
  33. local frame = CreateFrame("Frame", "MyAddonFrameExample", UIParent, "BackdropTemplate")
  34. frame:SetBackdrop({
  35.       bgFile="Interface\\DialogFrame\\UI-DialogBox-Background",
  36.       edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border",
  37.       tile=1, tileSize=32, edgeSize=32,
  38.       insets={left=10, right=10, top=10, bottom=10}
  39. })
  40. frame:SetPoint("CENTER")
  41. frame:SetSize(200, 200)
  42. frame:EnableMouse(true)
  43. frame:SetMovable(true)
  44. frame:RegisterForDrag("LeftButton")
  45. frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
  46. frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
  47. frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  48. local fontStr = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  49. fontStr:SetPoint("CENTER")
  50. fontStr:SetText("MyAddonFrameExample")
  51. frame:Show()
  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