S3rgeus
Emperor
I'm trying to set a progress bar's color from Lua, and having a surprising amount of difficulty. The SetColor function on other UI controls (like labels) expects a table containing the RGBA values (with fields x,y,z,w) and an integer. This works fine, but the progress bar appears to be different. In XML it has an FGColor and a BGColor (so it makes sense that there's something else to call aside from SetColor) but I can't find out what is. (I only need to set the FGColor, if that particularly matters.)
Here's the code I'm working with:
The code all works except for the color. (Setting the color just does nothing and it carries on.) The values color values reported in the print statement are correct (1,0,0,1 for red and 0,0,1,1 for blue with the DB data I'm using right now).
Conceptually, what I'm doing is building up a UI screen that's populated by a series of progress bars which represent 'influence' as a percentage of several competing factions.
Here's the code I'm working with:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by ModBuddy on 3/2/2014 7:31:22 PM -->
<Context ColorSet="Beige_Black" Font="TwCenMT20" FontStyle="Shadow">
<Box Style="BGBlock" ID="BGBlock" />
<Instance Name="AjahInfluence">
<Stack ID="AjahStack" Anchor="C,B" Size="20,200" StackGrowth="Top" Padding="0,12">
<Label ID="AjahLabel" Anchor="C,B" String="TXT_KEY_WHITE_TOWER_BLUE_AJAH" />
<Label ID="AjahPercent" Anchor="C,B" />
<Bar ID="InfluenceBar" Anchor="C,B" Size="10,150" Direction="Up" FGColor="Culture,255" />
</Stack>
</Instance>
<Grid Size="990,650" Anchor="C,C" Offset="0,20" Style="Grid9DetailFive140" ConsumeMouse="1" ID="BGLastBattle">
<!-- Upper Treatment -->
<Image Anchor="C,T" AnchorSide="I.O" Offset="0,-27" Size="256,64" Texture="Top512IconTrim.dds" >
<Image Anchor="C,C" Offset="0,-10" Size="80,80" Texture="NotificationFrameBase.dds" >
<Image ID="CivIconBG" Size="80.80" Anchor="C,C" Offset="0,0" TextureOffset="141,0" Texture="CivIconBGSizes.dds" />
<Image ID="CivIconShadow" Size="64.64" Anchor="C,C" Offset="1,1" Texture="CivSymbolAtlas64.dds" Color="Black.128"/>
<Image ID="CivIcon" Size="64,64" Offset="0,0" Anchor="C,C" Texture="CivSymbolsColor512.dds" />
</Image>
</Image>
<!-- Side treatments -->
<Box Style="MenuLeftSideTreatment"/>
<Box Style="MenuRightSideTreatment"/>
<Stack ID="InfluenceStack" Anchor="C,T" Size="972,572" StackGrowth="Right" Padding="50,0" />
<!-- Description box -->
<Grid Anchor="C,B" ID="WhiteTowerStatusMessageContainer" Offset="0,100" Size="840,90" Padding="0" Style="Grid9FrameBlack" Hidden="0" >
<Label ID="WhiteTowerStatusLabel" String="TXT_KEY_WHITE_TOWER_STATUS" WrapWidth="800" LeadingOffset="-4" Anchor="C,C" Offset="0,15" Font="TwCenMT20" ColorSet="Beige_Black_Alpha" />
</Grid>
<!-- Choice buttons -->
<Box Anchor="C,B" AnchorSide="I.I" Offset="0,54" Size="910,56" Color="255,255,255,0" >
<!-- Bottom Buttons -->
<Stack Anchor="C,B" Offset="0,0" Padding="10" StackGrowth="Right">
<GridButton Size="275,36" ID="OkButton" Style="BaseButton" String="TXT_KEY_OKAY" />
</Stack>
</Box>
</Grid>
</Context>
Code:
... other display/event code up here ...
function OnDisplay()
local pPlayer = Players[m_CityStateId]
Controls.InfluenceStack:DestroyAllChildren()
for pAjah in GameInfo.Ajahs() do
print("Processing Ajah " .. pAjah.ID)
if (pPlayer:IsAjahPermitted(pAjah.ID)) then
local instance = {}
local sAjahName = Locale.ConvertTextKey(pAjah.Description)
local iAjahPercent = pPlayer:GetAjahInfluencePercent(pAjah.ID)
local sAjahPercent = iAjahPercent .. "%"
local colorInfo = GameInfo.Colors[pAjah.Color]
local ajahColor = { x = colorInfo.Red, y = colorInfo.Green, z = colorInfo.Blue, w = colorInfo.Alpha }
print ("Found color " .. colorInfo.Type .. " R:" .. colorInfo.Red .. " G:" .. colorInfo.Green .. " B:" .. colorInfo.Blue .. " A:" .. colorInfo.Alpha)
ContextPtr:BuildInstanceForControl("AjahInfluence", instance, Controls.InfluenceStack);
instance.AjahLabel:SetText(sAjahName)
instance.AjahPercent:SetText(sAjahPercent)
instance.InfluenceBar:SetPercent(iAjahPercent / 100)
instance.InfluenceBar:SetColor(ajahColor)
instance.AjahStack:SetToolTipString(Locale.ConvertTextKey(pAjah.Help))
end
end
Controls.InfluenceStack:CalculateSize()
end
The code all works except for the color. (Setting the color just does nothing and it carries on.) The values color values reported in the print statement are correct (1,0,0,1 for red and 0,0,1,1 for blue with the DB data I'm using right now).
Conceptually, what I'm doing is building up a UI screen that's populated by a series of progress bars which represent 'influence' as a percentage of several competing factions.