Quantcast
WoWInterface - View Single Post - how is better to write ...
View Single Post
03-30-20, 08:07 AM   #9
gmarco
A Frostmaul Preserver
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 290
Originally Posted by myrroddin View Post
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:
  1. local ADDON, namespace = ...
  2. local L = namespace.L
  3.  
  4. -- code
  5.  
  6. local LibQTip = LibStub('LibQTip-1.0')
  7. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  8.  
  9. local dataobj = ldb:NewDataObject(ADDON, {
  10.     type = "data source",
  11.     icon = "Interface\\Addons\\"..ADDON.."\\icon.tga",
  12.     text = "-"
  13. })
  14.  
  15. local frame = CreateFrame("Frame")
  16.  
  17. local function OnRelease(self)
  18.      -- code
  19. end  
  20.  
  21. local function Button_OnClick(row, arg, button)
  22.      -- code
  23. end
  24.  
  25. local function anchor_OnEnter(self)
  26.  
  27.     arg = {}
  28.  
  29.     if self.tooltip then
  30.         LibQTip:Release(self.tooltip)
  31.         self.tooltip = nil  
  32.     end
  33.     local row,col
  34.     local tooltip = LibQTip:Acquire(ADDON.."tip", 6,"LEFT","LEFT","LEFT","LEFT","RIGHT","RIGHT")
  35.     self.tooltip = tooltip
  36.     tooltip:SmartAnchorTo(self)
  37.     tooltip:EnableMouse(true)
  38.     tooltip.OnRelease = OnRelease
  39.     tooltip.OnLeave = OnLeave
  40.     tooltip:SetAutoHideDelay(.1, self)
  41.  
  42.     row,col = tooltip:AddLine("")
  43.     row,col = tooltip:AddLine("")
  44.  
  45.     if #deaths > 0 then
  46.  
  47.         row,col = tooltip:AddLine()
  48.         tooltip:SetCell(row,1,L["Deaths Reports"],"CENTER",6)
  49.         tooltip:SetColumnTextColor(1,1,1,0)
  50.         row,col = tooltip:AddLine("")
  51.  
  52.     -- code
  53.  
  54.     row,col = tooltip:Show()
  55. end
  56.  
  57. function dataobj.OnEnter(self)
  58.     anchor_OnEnter(self)
  59. end
  60.  
  61. function dataobj.OnLeave(self)
  62.     -- Null operation: Some LDB displays get cranky if this method is missing.
  63. end
  64.  
  65. function dataobj.OnClick(self, button)
  66.    -- code
  67. end
  68.  
  69. --code
  70. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  71. frame:SetScript("OnEvent", function(self, event, ...)
  72.    
  73.     if event == "ZONE_CHANGED_NEW_AREA" or event == "PLAYER_ENTERING_WORLD" then   
  74.         -- code
  75.     end
  76.    
  77.     if event == "COMBAT_LOG_EVENT_UNFILTERED" then
  78.                -- code
  79.     end
  80. end)


Thanks so much for your inputs !
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote