View Single Post
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