View Single Post
07/11/16, 11:38 AM   #1
tgolsson
Join Date: Jul 2016
Posts: 5
Question Resolve name for descendant of instantiated virtual control?

Hello,

I am developing a unit frame addon, and am having some struggles with lacking documentation. I have a UnitFrame template which I want to dynamically populate with data, and I can spawn these using CreateControl, as in my example.

Code:
<GuiXml> 
    <TopLevelControl name="UnitFrame" hidden="false" virtual="true">
    <Controls>
        <Label name="$(parent)Name" text="Hello!" />
    </Controls>
</GuiXml>

Lua Code:
  1. Controls[0] = CreateControlFromVirtual("Target", GuiRoot, "UnitFrame")  
  2. TargetName:SetText("Bob")

Now, for the party and raid frames I need to do this for group1...group24, and at that point it becomes quite awkward. What I'd like to do is something like
Lua Code:
  1. Controls[unitTag].Name:SetText("Bob")
, but I can't find any way to do this. Surely this must be doable without using massive if-statements?

I have considered creating one list for each element I may need to access, so I could have
Lua Code:
  1. self.ControlsName = {
  2.     [group1] = Group1Name,
  3.     [group2] = Group2Name,
  4.     -- ...
  5. }
  6.  
  7. self.ControlsHealthBar = {
  8.     [group1] = Group1HealthBar,
  9.     [group2] = Group2HealthBar,
  10.     -- ...
  11. }

But this becomes quite verbose as well. Are there any options I am missing? I know about string evaluation/introspection, but I fear it might hurt performance a lot.
  Reply With Quote