Tbh I'm not really familiar with them, I always get lost when I open a xml context file

. Any suggestion from where I should start to learn how it works or Threads that explain that?
Hi Zegangani!
I guess I don't think they're that intimidating... but maybe that's all my years of web programming speaking. I've got ReligionScreen.xml open right now and yeah, the top two lines look pretty obtuse (just ignore those), but after that they're fairly self-explanatory. <Container> defines something that contains other things. <Image> is an image. <Label> is some text. <Stack> and <Grid> represent the most common layouts... Stacks are items displayed in a line (either vertical or horizontal... think: DiplomacyRibbon or TopPanel) and Grids put things in a two-dimensional grid (think: selecting beliefs for your religion).
Attributes (the things inside <>) are similarly pretty easy-to-understand. "size" defines the size of the item. "offset" is used to nudge things relative where it would go without an offset. "anchor" is used to define if something is left-, right-, or center-aligned (also, top- and bottom-). "Hidden" hides things.
You'll pick it up pretty quickly if you just open up ReligionScreen.xml, play with the values, and see how they change the UI. Also open ReligionScreen.lua and you can see the interplay between the two. The lua files usually reference the xml files via the "Name" or 'ID" attributes. When the lua file says:
Code:
local m_ReligionTabsIM:table = InstanceManager:new("ReligionTab", "Button", Controls.TabContainer);
You can go to the context xml file and ctrl-f "ReligionTab" to find what it's refering to.
Code:
<Instance Name="ReligionTab">
<GridButton ID="Button" Size="50,34" Style="TabButton" FontSize="14" TextOffset="0,2">
<Image ID="Icon" Size="22,22" Texture="Religions22" Offset="8,8" />
<GridButton ID="Selection" Offset="-2,0" Size="parent,parent" Style="TabButtonSelected" ConsumeMouseButton="0" ConsumeMouseOver="1" Hidden="1"/>
<Image ID="SelectionIcon" Size="22,22" Texture="Religions22" Offset="8,8" />
</GridButton>
</Instance>
The annoying part of programming with the context xml files is that they are just the starting templates, not the final result. Therefore, you can make changes to the xml file that look like they don't have any effect on the screen. For example, sometimes I'll assign something as Hidden in the context xml file, but it won't be hidden on the screen because in the corresponding lua file it has a SetHide(false) command on the thing I want hidden. But still, whenever a context xml change works, I think it's the way to go.
There are some Notes in GreatWorksOverview_KublaiKhanVietnam_Monopolies.lua that make compatibility with other UI files possible:
Code:
-- This file is being included into the base GreatWorksOverview file using the wildcard include setup in GreatWorksOverview.lua
-- Refer to the bottom of GreatWorksOverview.lua to see how that's happening
-- DO NOT include any GreatWorksOverview files here or it will cause problems
-- include("GreatWorksOverview");
And in GreatWorksOverview.lua:
Code:
-- This wildcard include will include all loaded files beginning with "GreatWorksOverview_"
-- This method replaces the uses of include("GreatWorksOverview") in files that want to override
-- functions from this file. If you're implementing a new "GreatWorksOverview_" file DO NOT include this file.
include("GreatWorksOverview_", true);
I never tested this, so I can't say if this works also with other UI files or it was just included explicitly for that file (hardcoded stuff?). If Yes, then it's the best thing that we got in the January Pack, even better than the Industry/Monopoly Mode

(but we wouldn't have got it if it weren't the Mode).
Oh, I can definitely tell you how those work. I've wrestled with them quite a bit.
The old way Firaxis did a lua file replacement was to have "TechTree.lua" in the base game and then "TechTree_Expansion1.lua" would include it like so:
And then "TechTree_Expansion2.lua" would start with:
Code:
include("TechTree_Expansion1")
The new way is what you copied. If they refactored TechTree with the new way it would go like this. The base file would
end with
Code:
include("TechTree_", true);
And then neither TechTree_Expansion1 nor TechTree_Expansion2 would have an include() for the previous version. That command sets the base file looking for the expansion replacement files automatically.
This is nice for Firaxis because when they make "TechTree_Expansion2" they don't have to check whether they're including TechTree or TechTree_Expansion1. It just works either way. (Because sometimes there isn't an _Expansion1 file.)
Now for modders, this means that if you create a file that starts with "GreatWorksOverview_" (e.g. GreatWorksOverview_Zegangani.lua) and ImportFiles it with your mod, it will automatically be included after the base file
and any subsequent expansion lua files by Firaxis. And, as the comment says, you
don't include('GreatWorksOverview') in your file. All you have to do is make sure the filename starts the right way.
Unfortunately, this only works when Firaxis ended their lua file with
include("BaseFileName_", true), which isn't often. But when they did, it's a nice option for modders, because if you're overwriting a function in the base file, you don't have to make additional files and modinfo criteria for Expansion1 and Expansion2 just to make sure the subsequent lua files get included.
Also unfortunately, this neat feature doesn't work-around the locally-global variables that I mentioned in previous posts. In that case, I still have to replace the whole lua file to make that tiny change.
Kind regards,
DB