Originally Posted by myrroddin
I'd suggest creating the LDB object in PLAYER_LOGIN because you only need to do that once. You could do in the main chunk of your addon code but that would force you to look up the object to see if it exists, and if so, get its value, and if not, create it. That's doing more CPU work than necessary.
|
I see what you mean ... the problem is for my way of writing that usually I create the frames in the last part of the code of the addon and if I put the create of LDB object there I was unable to build all the others part of the dataobj .
Usually I write in similar way:
Lua Code:
local ADDON, namespace = ...
local L = namespace.L
-- code
local LibQTip = LibStub('LibQTip-1.0')
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local dataobj = ldb:NewDataObject(ADDON, {
type = "data source",
icon = "Interface\\Addons\\"..ADDON.."\\icon.tga",
text = "-"
})
local frame = CreateFrame("Frame")
local function OnRelease(self)
-- code
end
local function Button_OnClick(row, arg, button)
-- code
end
local function anchor_OnEnter(self)
arg = {}
if self.tooltip then
LibQTip:Release(self.tooltip)
self.tooltip = nil
end
local row,col
local tooltip = LibQTip:Acquire(ADDON.."tip", 6,"LEFT","LEFT","LEFT","LEFT","RIGHT","RIGHT")
self.tooltip = tooltip
tooltip:SmartAnchorTo(self)
tooltip:EnableMouse(true)
tooltip.OnRelease = OnRelease
tooltip.OnLeave = OnLeave
tooltip:SetAutoHideDelay(.1, self)
row,col = tooltip:AddLine("")
row,col = tooltip:AddLine("")
if #deaths > 0 then
row,col = tooltip:AddLine()
tooltip:SetCell(row,1,L["Deaths Reports"],"CENTER",6)
tooltip:SetColumnTextColor(1,1,1,0)
row,col = tooltip:AddLine("")
-- code
row,col = tooltip:Show()
end
function dataobj.OnEnter(self)
anchor_OnEnter(self)
end
function dataobj.OnLeave(self)
-- Null operation: Some LDB displays get cranky if this method is missing.
end
function dataobj.OnClick(self, button)
-- code
end
--code
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function(self, event, ...)
if event == "ZONE_CHANGED_NEW_AREA" or event == "PLAYER_ENTERING_WORLD" then
-- code
end
if event == "COMBAT_LOG_EVENT_UNFILTERED" then
-- code
end
end)
Thanks so much for your inputs !