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