Quantcast How to get programmatic access to a control defined in XML - ESOUI
Thread Tools Display Modes
07/01/17, 02:44 AM   #1
BoarGules
 
BoarGules's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2017
Posts: 27
How to get programmatic access to a control defined in XML

With the friendly help I've received on this forum I've succeeded in putting a scene fragment on the Guild Home screen:

Code:
<GuiXml>
  <Controls>
    <TopLevelControl name="MyFragment" hidden="true">
      <Dimensions x="200" y="200" />
      <Anchor point="BOTTOM" relativeTo="ZO_GuildSharedInfo" relativePoint="BOTTOM" offsetX="120" offsetY="680" />
      <Controls>
        <Label name="$(parent)Label" width="200" height="25" font="ZoFontWinH3" inheritAlpha="true"  color="FFFFFF"
            wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER"  text="some text">
          <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" />
        </Label>
      </Controls>
    </TopLevelControl>
  </Controls>
</GuiXml>
Lua Code:
  1. local fragment = ZO_SimpleSceneFragment:New(MyFragment)
  2. GUILD_HOME_SCENE:AddFragment(fragment)

Now I want to change the text of the label control MyFragmentLabel under program control but I can't work out how to get a reference to it.
  Reply With Quote
07/01/17, 02:59 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,101
That's one of the easier things to do:
Lua Code:
  1. local label
  2. label = MyFragmentLabel
  3. -- or --
  4. label = MyFragment:GetNamedChild("Label")
  5. -- or --
  6. label = GetControl(fragment.control, "Label")
  7. label:SetText("Hello World!")
You named your label control "Label" and it is a child of your "MyFragment" control, so you can just access it via its global variable or relative to the control.
__________________
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
07/01/17, 07:01 AM   #3
BoarGules
 
BoarGules's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2017
Posts: 27
Thanks, it turns out I was doing the right thing but my error was elsewhere. Knowing that what I was doing really ought to work was the fixed point in the reasoning that I needed.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » How to get programmatic access to a control defined in XML

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off