Fix visibility handling for Tour cards

Panel visibility isn't inhered by the children, so each element in the panel has to have the visibility set directly.
This commit is contained in:
Buhallin 2022-12-14 23:18:58 -08:00
parent 1c3260edf3
commit bdadfdcc9f
No known key found for this signature in database
GPG Key ID: DB3C362823852294

View File

@ -179,19 +179,33 @@ do
return
end
tourCardTemplate.attributes.id = internal.getUiId(CARD_ID, playerColor)
tourCardTemplate.attributes.visibility = playerColor
tourCardTemplate.children[1].attributes.id = internal.getUiId(NARRATOR_ID, playerColor)
tourCardTemplate.children[2].children[1].attributes.id = internal.getUiId(TEXT_ID, playerColor)
tourCardTemplate.children[3].attributes.id = internal.getUiId(NEXT_BUTTON_ID, playerColor)
tourCardTemplate.children[4].attributes.id = internal.getUiId(STOP_BUTTON_ID, playerColor)
tourCardTemplate.children[3].attributes.onClick = self.getGUID().."/nextCard"
tourCardTemplate.children[4].attributes.id = internal.getUiId(STOP_BUTTON_ID, playerColor)
tourCardTemplate.children[4].attributes.onClick = self.getGUID().."/stopTour"
internal.setDeepVisibility(tourCardTemplate, playerColor)
local globalXml = Global.UI.getXmlTable()
table.insert(globalXml, tourCardTemplate)
Global.UI.setXmlTable(globalXml)
end
-- Panels don't cause their children to inherit their visibility value, so this recurses down the
-- XML table to set all children to the same visibility.
---@param xmlUi Table. Lua table describing the XML
---@param playerColor String. String color of the player to make this visible for
internal.setDeepVisibility = function(xmlUi, playerColor)
xmlUi.attributes.visibility = "" .. playerColor
log(xmlUi.attributes.id)
if xmlUi.children ~= nil then
for _, child in ipairs(xmlUi.children) do
internal.setDeepVisibility(child, playerColor)
end
end
end
internal.getUiId = function(baseId, playerColor)
return baseId .. "_" .. playerColor
end