Go to Page... |
|
Thread Tools | Display Modes |
|
07/11/16, 11:38 AM | #1 | |
Join Date: Jul 2016
Posts: 5
|
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:
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:
I have considered creating one list for each element I may need to access, so I could have Lua Code:
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. |
|
07/11/16, 11:52 AM | #2 | |
Join Date: Jul 2016
Posts: 15
|
I'm not gonna answer your question, but if i understand you'll have as many top level controls as group members with this.
You want to have only one toplevelcontrol to control the visibility of the whole group, then simple controls for groups as children of this one, and others simple controls (or labels directly) for members as great-children, so you can control the visibility of each level. But don't multiply the toplevel controls or you'll have a hell making options later. |
|
07/11/16, 12:23 PM | #3 | ||
Join Date: Jul 2016
Posts: 5
|
Code:
Addon, PlayerFrame, TargetFrame, PartyFrame = [ UnitFrame, UnitFrame, UnitFrame, UnitFrame ] RaidFrame = [ UnitFrame, ... ] I develop a lot in Java, and to give an analogy (if it makes any sense to you) what I am trying to do is create View for each group member, and then create a Controller for managing all these views. It's called the "DRY" principle: "Don't repeat yourself". It's the same thing for each group member, so I should have only one piece of logic and markup for it. |
||
07/11/16, 12:42 PM | #4 | ||
Join Date: Jul 2016
Posts: 15
|
then make your virtual be only "Control" and set your toplevelcontrol as parent when your generate them. later work on your controls as you see fit. But TopLevelControls have specific functions and rules attached to them, and you don't want them on all of your controls. I usually create everything in lua, but there are many examples of xml in other addons to understand how names are created. The name you determine in lua is a variable you can check in your code, but for the UI what matter is the named control. You can get it back with a local mycontrolvariable = GetControl("TopLevelNameChildNameLabelNAme") for example. in your example : local mylabel = GetControl("UnitFrameName") mylabel:SetText("Bob") Edit : sorry, i didn't re-read your first post before writing, it would be instead local mylabel = GetControl("TargetName") since UnitFrame is the name of the Template. sry again. and you can use a suffix to the name when generating your controls in a loop : CreateControlFromVirtual(name, parent, templateName, optionalNameSuffix) that can be helpful. edit: Controls dont need to all have a size and place etc, they can be virtual containers for the sake of having properties inherited by a group of children. I mean CT_CONTROL controls... Last edited by Haho : 07/11/16 at 02:00 PM. |
||
07/11/16, 12:50 PM | #5 | ||
Join Date: Jul 2016
Posts: 5
|
|
||
07/11/16, 02:08 PM | #6 | |
|
Also, it has a fair amount of OOP, which might be a more comfortable style if you're coming from Java. http://git.esoui.com/?a=tree&p=CyrHUD |
|
07/11/16, 12:04 PM | #7 |
Welcome to ESOUI and addon development!
If you haven't already read the Getting Started guide, I suggest you take a look to find out where you can find "documentation" and useful info about the API. For something like group unit frames you should create the controls once when you need them and keep a table where you associate a unitTag to the frame control. Lua Code:
Whenever you react to some change to a group member you would then just call GetUnitFrame and pass the unitTag of the affected player. One thing you should keep in mind when creating controls is that for every control you create, a global variable is generated implicitly. Meaning you should not call a control "Target" or "UnitFrame", but instead "MyUnitFrameAddonTarget" and "MyUnitFrameAddonUnitFrameTemplate" to avoid name collisions. |
|
07/11/16, 12:25 PM | #8 | ||
Join Date: Jul 2016
Posts: 5
|
|
||
07/11/16, 12:56 PM | #9 | |
Join Date: Jul 2016
Posts: 15
|
lol no, toplevelcontrol is the one attached to the Guiroot directly. Think of it like your own paper sheet to decorate. Then inside, make your controls groups like you intended to at first.
So yes you have to have one (or you don't if your controls are children of an existing control, but i doubt it in your case) But one is enough for the xml question, i dont get it... are you making one xml file/control? you can write everything in the same xml file. the virtual one will be separated from the "nesting"... i'm not a fan of xml anyway, as i said look into any addon with a UI and a xml and you should see how it works. Or someone else would be more precise on this. so basically : toplevel will be defined, and you'll have after that your virtual definition for the controls you'll be creating dynamically. And they'll have toplevel as parent instead of Guiroot. Last edited by Haho : 07/11/16 at 01:03 PM. |
|
07/11/16, 01:14 PM | #10 | ||
Join Date: Jul 2016
Posts: 5
|
I was wondering whether I could do Code:
<GuiXml> <Controls> <Control name="MyAddonUnitFrame" virtual="true"> <Controls> <Label name="$(parent)Name" text="bob" /> </Controls> </Control> </Controls> </GuiXml> <!-- another file --> <GuiXml> <Controls> <TopLevelControl> <Controls> <MyAddonUnitFrame name="AddonGroup1" /> <MyAddonUnitFrame name="AddonGroup2" /> <MyAddonUnitFrame name="AddonGroup3" /> </Controls> </TopLevelControl> </Controls> </GuiXml> Last edited by tgolsson : 07/11/16 at 01:17 PM. |
||
07/11/16, 01:19 PM | #11 | ||
Join Date: Jul 2016
Posts: 15
|
i'd say more like : Code:
<GuiXml> <Controls> <TopLevelControl name="MyAddon"> </TopLevelControl> <!-- same file --> <Control name="MyAddonUnitFrame" virtual="true"> <Controls> <Label name="$(parent)Name" text="bob" /> </Controls> </Control> </Controls> </GuiXml> Last edited by Haho : 07/11/16 at 01:22 PM. |
||
07/11/16, 02:21 PM | #12 | |
Join Date: Jul 2016
Posts: 15
|
for the part where you edited to have more groups in your example : no, not in the xml
once your template is done as a virtual in your xml, you have to use lua to generate your different group controls as you did in your first post : Code:
for i = 1, numberOfGroups do -- avoid 0 index in lua btw Controls[i] = CreateControlFromVirtual("Target", TopLevelName, TemplateName, "Suffix".. i ) GetControl("TargetSuffix".. i .. "Name"):SetText(Bob[i]) end Last edited by Haho : 07/11/16 at 03:48 PM. |
|
ESOUI » Developer Discussions » Lua/XML Help » Resolve name for descendant of instantiated virtual control? |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|