Quantcast
WoWInterface - View Single Post - Dynamically adding and removing frames?
View Single Post
06-30-20, 01:25 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,292
At it's simplest, you have a table of "active" frames. As they become no-longer "active" you move the frame to a "pool" table of inactive frames (delete the frame reference from the active table and add it to the inactive table).

If you need a new frame and the pool is empty, you create a new frame and add it to the active table otherwise take one from the pool table(delete the frame reference from the inactive table and add it to the active table).

This becomes more involved if you want to have frame types for different purposes and how far you want to abstract the pool concept but the general idea is the same.

To add a new active frame:
Lua Code:
  1. local frame
  2. if #MyInactiveFrameTable > 0 then -- 1 or more frames in the inactive table
  3.       frame = MyInactiveFrameTable[1] -- grab the 1st one
  4.       tremove(MyInactiveFrameTable, 1) -- and remove it from the table
  5. else -- otherwise
  6.       -- create a new frame
  7.       frame = CreateFream(...)
  8.        -- add frame elements
  9. end
  10. tinsert(MyActiveFrameTable, frame)  -- add the frame to the active table
  11. -- update "frame" with new information to display

To "deactivate" active frame:
Lua Code:
  1. tinsert(MyInactiveFrameTable, MyActiveFrameTable[1])
  2. tremove(MyActiveFrameTable, 1)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-30-20 at 03:01 AM.
  Reply With Quote