UI: Manipulating Instance elements?

sp00n

Prince
Joined
Jan 4, 2007
Messages
371
I've asked the question here already, but opening a new thread is probably better.
I'm trying to manipulate (e.g. change the text) of a child element of an already existing Instance. The element even has an ID, but I cannot access it with the ContextPtr:LookUpControl() command.
I've shortened the code from the EspionageChooser files, which I'm trying to modify:

EspionageChooser.lua:
Code:
local m_MissionStackIM:table = InstanceManager:new("MissionInstance", "MissionButton", Controls.MissionStack);


function AddOffensiveOperation(operation:table, result:table, targetCityPlot:table)
    local missionInstance:table = m_MissionStackIM:GetInstance();
    local iconString:string = "[Icon_" .. districtInfo.DistrictType .. "]";
    
    -- This I'm trying to manipulate
    missionInstance.MissionDistrictIcon:SetText(iconString);
end


EspionageChooser.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<Context xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="..\..\..\..\..\CivTech\Libs\ForgeUI\ForgeUI_Assets\Controls.xsd">
    [...]
    <Instance Name="MissionInstance">
        <GridButton ID="MissionButton" Size="parent,70" Offset="0,0" Anchor="C,T" AutoSize="Vertical">
            <GridData Texture="DestinationChooser_Button" StateOffsetIncrement="0,76" SliceCorner="14,14" SliceSize="19,44" SliceTextureSize="48,76" NoStateChange="0"/>

            <Grid ID="SelectorBrace" Anchor="C,C" Size="parent,90" AutoSize="Vertical" AutoSizePadding="6,3" Texture="Controls_SelectorBrace" SliceCorner="29,29" SliceSize="2,2" SliceTextureSize="64,64" Color="255,255,255,0">

                <!-- This I can select with LookUpControl() -->
                <Stack ID="MissionStack" StackGrowth="Down" Offset="70,7">
                    <Label ID="MissionName" Size="180,20" Style="FontNormal16"/>
                    <Label ID="MissionDetails" Style="FontNormal12" WrapWidth="192"/>
                    <Container Size="192,18"/>
                </Stack>

                <Stack ID="MissionStatsStack" Anchor="R,B" Offset="8,5" StackGrowth="Right" StackPadding="4">
                    <Grid AutoSize="1" AutoSizePadding="-4,0" Texture="Controls_ItemContainer" SliceCorner="8,8" SliceTextureSize="16,16">
                        <Stack Offset="-2,0" StackGrowth="Right" StackPadding="-3">
                            <Label ID="MissionDistrictIcon" Offset="3,4" Style="FontNormal14" String="[Icon_DISTRICT_CITYCENTER]"/>
                        </Stack>
                    </Grid>
                </Stack>
            </Grid>
        </GridButton>
    </Instance>
</Context>


In my Lua mod file this works:
local EspionageChooser1 = ContextPtr:LookUpControl("/InGame/EspionageChooser/MissionStack");

But this doesn't:
local EspionageChooser2 = ContextPtr:LookUpControl("/InGame/EspionageChooser/MissionDistrictIcon");
(And neither does "MissionStatsStack".)

I can however iterate through the child elements of the MissionStack elements via :GetChildren(), until I finally arrive at the MissionDistrictIcon element (6 levels deep, so 6 for loops...):

Code:
local EspionageChooser1 = ContextPtr:LookUpControl("/InGame/EspionageChooser/MissionStack");

for i, entry1 in ipairs(EspionageChooser1:GetChildren()) do
    [...4 more for loops...]
                        for n, entry6 in ipairs(entry5:GetChildren()) do
                            if ( entry6:GetID() == "MissionDistrictIcon" ) then
                                print("Element MissionDistrictIcon found");
                            end
                        end
end

But even then I cannot set the "text" (icon) of this element with :SetText(). I can however apply the :SetHide() method.

Is there a "correct" way to manipulate child elements of Instances? Or a proper way to traverse the child elements without having to resurt to ugly chained for loops?
I guess I'm too spoiled by SimpleXML or jQuery's DOM traversing...
 
Back
Top Bottom