How to properly use ContextPtr:LookUpControl

Jiska

Warlord
Joined
Apr 23, 2016
Messages
164
So I've added an InGameUIAddin, Iska_Organizations_Main.lua and .xml. In the xml, I have this line:

<Grid Size="987,700" Anchor="C,C" Offset="0,0" Style="Grid9DetailFive140" Hidden="1" ID="MainFrame">

I'm trying to reference this in a separate file, DiploCorner.lua, like this:

ContextPtr:LookUpControl("Iska_Organizations_Main/MainFrame"):SetHide(false)

But firetuner tells me this is nil. I've tried a few variations of this, including an ID in my <context />. How do I do this properly?
 
So long since I've done any of this, but try "/InGame/Iska_Organizations_Main/MainFrame"
 
its definitely not a vfs problem, but a pathing (ie where your context/control ia, and what thay're known as to the system) problem
 
I'm going necro this because I'm still having problems with it, and I'm curious if anyone has ever gotten it to work.

Testing seems to show that:
-You can use it and it works with UI elements that already exist unmodded in the game, ex: ContextPtr:LookUpControl("/InGame/ReligionOverview/ConfirmYes"):SetHide(true) works fine
-But when using it with UI files you've added in yourself, whether or not they're imported into the VFS, any variation of the above, ex. ContextPtr:LookUpControl( "Iska_WaW_Pantheons" ):SetHide(true) or ContextPtr:LookUpControl( "/InGame/Iska_WaW_Pantheons" ):SetHide(true), LookUpControl will return a nil
-Setting the context ID to the same name as its file doesn't help, and isn't done in any of the game ui files
-Obviously the modded context it loaded, or its UI wouldn't actually show up in the game, so as whoward says in the post above, it must be a pathing problem. However, as I say a couple of posts above that, I either have found the right name for the folder to put my mod ui in, or it doesn't matter and there's some other pathing problem.

Anyway, if anyone could help, I'd appreciate it.
 
Trying to figure this one out too - creating enclaved lua contexts ala the creating ui mods tutorial is fine, but it doesn't really seem possible to create universal access to a context; to basically create a secondary InGame (and thus avoid overriding InGame). Replacing InGame and inserting the new LuaContext path ofc works as intended but this isn't the ideal solution.
 
I assume your real question is how to add a button in DiploCorner pulldown (where Demographics etc. are) that will make your UI visible.

Instead using "LookUpControl" you can use LuaEvents:
LuaEvents.JiskaCallToShowUI()

and then in your file add:
LuaEvents.JiskaCallToShowUI.Add(function()
Controls.MainFrame:SetHide(false);
end)

What is more, you don't even have to mess up with DiploCorner for this:
LuaEvents.AdditionalInformationDropdownGatherEntries.Add(function(tab)
if bHuman then
table.insert(tab, {text = "Prophecies", call = function() LuaEvents.LSThebesPropheciesCall(); end});
end
end)
Firaxis is actually calling for any extra entries (gate for modders). The example above adds button named "Prophecies" that will call LuaEvents on click (under bHuman condition).

Back to ContextPtr:LookUpControl. For me it is a tool to mess up with InGame Interface without the need of replacing the files. Basically, if LuaEvents.AdditionalInformationDropdownGatherEntries would not exist I would create a button (based on instance from DiploCorner) in my OWN xml file then use lua ContextPtr:LookUpControl and ChangeParent to put it in the pulldown.
If you have full control over both files (DiploCorner) and (YourNewFile) I don't think ContextPtr:LookUpControl is needed at all.

Going further, to use LookUpControl efficiently we need to know the name of file (or more precisely full path). By using Firaxis Live Tuner (in game) we can select in Lua Console any Interface and then with command:
ContextPtr:GetID() -- get ID of the file.
For CityView.xml the ID is CityView and path is "/InGame/CityView". However some UI has ID different than name and guessing would be hard. For example DiploCurrentDeals has ID "DealsPanel". However, it is still not enough to use ContextPtr:LookUpControl from other file, because this file is actually only included by other file and we have to use:
ContextPtr:LookUpControl("/InGame/DiploOverview/DealsPanel") to get to DiploCurrentDeals (because this file exists only as an include to DiploOverview.xml). This ID can be also found in DiploOverview.xml.
Looking into steam folder we can get a proper "/InGame/","/InGame/WorldView" prefix. But we can also use Firaxis Live Tuner (example: DiploCurrentDeals):
> ContextPtr:GetID()
DealsPanel
> ContextPtr:LookUpControl(".."):GetID()
DiploOverview
> ContextPtr:LookUpControl("../.."):GetID()
InGame
> ContextPtr:LookUpControl("../../.."):GetID()
InGame
So we know that "/InGame/DiploOverview/DealsPanel" is proper full path to reference. Modiki.

Finally, how we access new modded files? By using ContextPtr:GetID() I got nil (because I haven't defined ID of the Context). After defining context ID/FileName/Name and using all above methods I wasn't able to reference file from WorldView, the entire path ("..", "../..") was always returning the same value as GetID().

Anyway, I abandoned LookUpControl at this point. Workaround is simple, I added to my UI file lua code:
LuaEvents.CallAttemptTROControl.Add(function(name) MapModData.TROReturningControl = Controls[name] end)

From WorldView I called:
LuaEvents.CallAttemptTROControl("Title") -- (Title is ID of control i was looking for)

From WorldView I used command:
MapModData.TROReturningControl:SetHide(true) -- I wanted to hide the control and it worked.

CallAttemptTROControl and TROReturningControl are variables of your choice. If you want to use multiple Controls a lot, you can come up with something like that:
LuaEvents.CallAttemptTROControl.Add(function(name) MapModData["TROReturningControl" .. name] = Controls[name] end)
And then referencing MapModData.TROReturningControlTitle / MapModData.TROReturningControlMainFrame.

Shortly, ContextPtr:LookUpControl is great for accessing InGame UI files and LuaContext as described here. For modding purpose you can use LuaEvents and MapModData. Well, to be honest the usage for above solution with MapModData is truely required only for Mod Mods (basically you leave a gate to access Controls in future without the need of updating the mod)?
 
@LastSword Thank you very much for your long and detailed answer! I'm not going to lie, I'd actually already solved my problem using the almost exact methods you describe. I'm curious though: for the longest of time I've been using Modding.OpenSaveData and the get and set functions, rather than MapModData. Does one have an advantage over the other? I recently spent a while rewriting one of my mods because I realizes I was using get and set too liberally.
@JFD Yeah, I discovered the InGame file yesterday, and it looks like the answer to my question. However, you're right, it doesn't look like it can be edited without being replaced. Sucks.

Thanks all!
 
Back
Top Bottom