Thread: ZO_ObjectPool
View Single Post
03/01/14, 10:30 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
I'm using it in a buff addon I'm currently working on. Here's a (very) trimmed down version.

Lua Code:
  1. local pool
  2.  
  3. local function CreateBuff(pool)
  4.      --create a new control frame
  5.      local buff = ZO_ObjectPool_CreateControl("MyBuffTemplate", pool, parentFrame)
  6.      --do other stuff with buff object
  7.  
  8.      --return it for use
  9.      return buff
  10. end
  11.  
  12. local function RemoveBuff(control)
  13.      --do stuff when you don't need a frame anymore
  14.      control:SetHidden(true)
  15. end
  16.  
  17. local function UpdateBuffs()
  18.      local myBuff
  19.      for i = 1, GetNumBuffs("player") do
  20.           --if a control with this id # doesn't exist yet, create it, otherwise just return the one we have
  21.           myBuff = pool:AcquireObject(i)
  22.           --do more stuff with myBuff
  23.      end
  24. end
  25.  
  26. local function Initialize()
  27.      --create a new pool to get my controls from
  28.      pool = ZO_ObjectPool:New(CreateBuff, RemoveBuff)
  29.      EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_EFFECT_CHANGED, UpdateBuffs)
  30. end
  31.  
  32. EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_ADD_ON_LOADED, function(event, addon)
  33.      if addon == "MyAddon" then
  34.           Initialize()
  35.      end
  36. end)
  Reply With Quote