Dynamically adding and removing frames?
Hello! I'm new to creating addons and playing around with my first one. The bulk of my addon is a queue'ing system where players will be added to a queue and then a frame with their name / location / spot in queue will show up. As more people queue, more frames are added dynamically under the other frames.
I am wondering what the best way to approach this is? Ideally it would be an array of frames than are added one after another and then removed from the first spot onward. I know you cant "remove" a frame, so thats another thing I have to tackle.
Anyway, would appreciate any steering or ideas on how should I approach this.
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:
To "deactivate" active frame:
To answer a question that shows up a lot here, frames cannot be "removed" from memory. They stay persistent throughout an entire session. The best you can do is recycle frames by use of "Frame Pools".
Here's a simpler way and keeping a separate table just for active frames in a frame pool is unnecessary if you're already keeping track of them in other parts of your code.
Note: You should create a different pool for each frame template you wish to use in order to keep them from getting mixed up.
If you're feeling adventurous, you might want to take a look at Blizzard's implementation of frame and object pools in SharedXML\Pools.lua.
You'll want to pay attention to CreateFramePool() for a singilar frame pool and CreatePoolCollection() to manage different templates.
|All times are GMT -6. The time now is 10:52 AM.|
vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI