ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Should be simple - seems it's not (for me anyway) (https://www.esoui.com/forums/showthread.php?t=7938)

Dueydoodah 07/17/18 02:13 PM

Should be simple - seems it's not (for me anyway)
 
I am having trouble understanding the interactions between xml and lua. I have a control:

Code:

<GuiXml>
  <Controls>
    <TopLevelControl name="WhichSetIndicator" mouseEnabled="true" movable="true" clampedToScreen="true">
      <Dimensions x="250" y="25" />
      <Anchor point="BOTTOM" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-20" />
 
    <OnMoveStop>
          WhichSet.OnIndicatorMoveStop()
    </OnMoveStop>

      <Controls>
        <Label name="$(parent)Label" width="250" height="25" font="ZoFontWinH1" inheritAlpha="true" color="FF0000"
            wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="Main Weapon Set!">
          <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" />
        </Label>
      </Controls>
    </TopLevelControl>
  </Controls>
</GuiXml>

I would like to change the 'text' element during a keypress event which I already have working. I just can't find the correct way to change the text. I would imagine I could do something like this:

Code:

function WhichSet.OnActionBarChange(event, actionbar)
        if WhichSet.whichActionBar ~= GetActiveWeaponPairInfo() then
                WhichSet.whichActionBar = GetActiveWeaponPairInfo()
        end

        if WhichSet.whichActionBar == 1 then
                WhichSetAddonIndicator:SetText("Main weapon set!")
        else
                WhichSetAddonIndicator:text("Secondary weapon set!")
        end

end

As you might have guessed, the red lines do not work. Can someone help?

Rhyono 07/17/18 02:56 PM

Shouldn't you be writing to the label? Which would be WhichSetIndicatorLabel:SetText("test")

Dolgubon 07/17/18 06:57 PM

Rhyono is correct: You should use WhichSetAddonIndicatorLabel.
If you look at the XML, you have name="WhichSetIndicator". So the game makes a TopLevelControl called WhichSetIndicator. WhichSetIndicator is then added to the global table, allowing you to call it using WhichSetIndicator in Lua code. Next, you have name="$(parent)Label". This tells the game to take the name of the parent (WhichSetIndicator:GetName()) and append Label to it (WhichSetIndicator:GetName().."Label") and make that the name of the Label. So then you can call it as WhichSetIndicatorLabel in Lua code. You can also do WhichSetIndicator:GetNamedChild("Label") which might be more readable. I'd also suggest zgoo (specifically, when you have it, do /zgoo WhichSetIndicator) which could help you in the future if you run into problems with UI design.

Dueydoodah 07/18/18 10:54 AM

Thank you so much for the insight. This should help a lot. I am new to this and have not yet read much LUA reference material. I was relying on previous programming experience in other languages. I guess I had better do my homework. Again, Thank you.


All times are GMT -6. The time now is 12:45 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI