View Single Post
05/12/14, 11:36 AM   #4
Harven
 
Harven's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 135
Hey, there is a mechanism for this kind of situations. It's called control pool. You take a control from the pool and when it's no longer needed you just put it back to the pool. Here is an example:

Lua Code:
  1. --first you have to have some parent control
  2. local parentControl = WINDOW_MANAGER:CreateTopLevelWindow("MyParentControl")
  3. --[[
  4. here you create the control pool.
  5. - the first argument is a control template which must be defined in XML file
  6. - the second argument is your parent control
  7. - the third argument is just some name you like
  8. --]]
  9. local myControlPool = ZO_ControlPool:New("MyLabelControlTemplate", parentControl, "SomeName")
  10.  
  11. --then when you want to get a control from the pool you just call:
  12. local myControl, controlKey = myControlPool:AcquireObject()
  13. --controlKey is a key that allows you to put the control back to the pool
  14.  
  15. --you can then do whatever you like with the control, for example attach it to your parent control:
  16. myControl:SetAnchor(CENTER, parentControl, CENTER)
  17.  
  18. --when you no longer need the control, just call"
  19. myControlPool:ReleaseObject(controlKey)
  20. --the control will be hidden automatically, then you can just forget about this control
  21. myControl = nil
  22. controlKey = nil

Here an example XML to define you control template:

Code:
<GuiXml>
	<Controls>
                <!-- It's important to set "virtual" attribute to "true" -->
		<Label name="MyLabelControlTemplate" font="ZoFontGame" virtual="true" />
	</Controls>
</GuiXml>
  Reply With Quote