Changing the text displayed when choosing a Social Policy based upon the Policy?

JFD

Kathigitarkh
Joined
Oct 19, 2010
Messages
9,132
Location
The Kingdom of New Zealand
I'm looking to change the "Are you sure you want to adopt this Social Policy?" text more dynamically, based upon the Social Policy in question, but don't understand how this might be done. I've browsed a couple of Whoward's UI Tutorials for guidance, but failed to find much use in this regard, and I'd appreciate some advice, if any can be given. Basically, I'm looking for how to change the string which handles this text in the SocialPolicyPopup.xml based upon what policy is being chosen; although this might be more advanced than I'm capable.

Thanks for any help.
 
In SocialPolicyPopup.xml change the bolded line to include ID="PolicyConfirmText":

Code:
<Box Color="Black.200" Size="Full.Full" ID="PolicyConfirm" Hidden="1" ConsumeMouseOver="1" ConsumeMouseButton="1">
	<Grid Size="500,310" Anchor="C,C" Offset="0,0" Padding="0,20" Style="Grid9DetailFive140" Hidden="0">
		<!-- Side treatments -->
		<Box Style="MenuLeftSideTreatment"/>
		<Box Style="MenuRightSideTreatment"/>
		<Image Anchor="C,T" AnchorSide="I.O" Offset="0,-14" Size="256,64" Texture="Top512IconTrim.dds">
			<Image Anchor="C,C" Offset="0,-6" Size="80,80" Texture="NotificationFrameBase.dds">
				<AlphaAnim Anchor="C,C" Offset="0,0" Size="80,80" Texture="assets\UI\Art\Notification\NotificationGenericGlow.dds" Pause="0" Cycle="Bounce" Speed="1" AlphaStart="1" AlphaEnd=".5"/>
			</Image>
		</Image>
		[b]<Label Anchor="C,T" ID="PolicyConfirmText" Offset="0,74" WrapWidth="440" String="TXT_KEY_CONFIRM_POLICY" Font="TwCenMT22" ColorSet="Beige_Black_Alpha" FontStyle="Shadow"/>[/b]
		<Stack Anchor="C,B" Offset="0,80" Padding="24" StackGrowth="Bottom" ID="ButtonStack">
			<!-- Yes Button  -->
			<GridButton Style="BaseButton" ID="Yes" Size="400,42" Anchor="C,T" Offset="0,0" Hidden="0">
				<Label Anchor="C,C" Offset="0,0" String="TXT_KEY_YES_BUTTON" ColorSet="Beige_Black" Font="TwCenMT24" FontStyle="Shadow"/>
			</GridButton>
			<!-- No Button  -->
			<GridButton Style="BaseButton" ID="No" Size="400,42" Anchor="C,T" Offset="0,0" Hidden="0">
				<Label Anchor="C,C" Offset="0,0" String="TXT_KEY_NO_BUTTON" ColorSet="Beige_Black" Font="TwCenMT24" FontStyle="Shadow"/>
			</GridButton>
		</Stack>
	</Grid>
</Box>

In SocialPolicyPopup.lua in function PolicySelected( policyIndex )

Code:
	-- Can adopt Policy right now - don't try this if we're going to unblock the Policy instead
    if (bCanAdoptPolicy and not bPolicyBlocked) then
		m_gPolicyID = policyIndex;
		m_gAdoptingPolicy = true;

		-- Added by Putmalk
		local strPolicyName = "[COLOR_POSITIVE_TEXT]" .. Locale.ConvertTextKey(GameInfo.Policies[policyIndex].Description) .. "[ENDCOLOR]";
		Controls.PolicyConfirmText:SetText("TXT_KEY_CONFIRM_POLICY", strPolicyName);
		-- End Putmalk        

		Controls.PolicyConfirm:SetHide(false);
		Controls.BGBlock:SetHide(true);
    end

Then perform an update on the TXT_KEY_CONFIRM_POLICY tag

Code:
<Update>
	<Where Tag="TXT_KEY_CONFIRM_POLICY"/>
	<Set Text="Are you sure you want to adopt {1_String}?"/>
</Update>

Report back on how it goes.

Remember to set VFS=true for both SocialPolicyPopup lua and xml
 
Ah, thank you. I had trouble with the text until I added it like this:

Spoiler :
Code:
local strPolicyName = "[COLOR_POSITIVE_TEXT]" .. Locale.ConvertTextKey(GameInfo.Policies[policyIndex].Description) .. "[ENDCOLOR]";
local DefaultText = Locale.ConvertTextKey("TXT_KEY_CONFIRM_POLICY", strPolicyName);
			Controls.PolicyConfirmText:SetText(DefaultText);

Otherwise, it worked perfectly as intended:

Spoiler :
1dD3uy7.jpg


That said, I actually meant I wanted to insert different text depending upon which policy you adopted (e.g. if you adopt Stratocracy it says one thing, whilst adopting Elite Training it says another). I managed to achieve this* myself by checking if the policy selected is Stratocracy first, so I still am grateful for your help. But I wonder if there's any advice you can give me in regards to what I actually want to achieve.

*
Spoiler :
oVlc1XI.jpg

(I will play around with Text size and such at a later point)
 
Ah, thank you. I had trouble with the text until I added it like this:

Spoiler :
Code:
local strPolicyName = "[COLOR_POSITIVE_TEXT]" .. Locale.ConvertTextKey(GameInfo.Policies[policyIndex].Description) .. "[ENDCOLOR]";
local DefaultText = Locale.ConvertTextKey("TXT_KEY_CONFIRM_POLICY", strPolicyName);
			Controls.PolicyConfirmText:SetText(DefaultText);

Otherwise, it worked perfectly as intended:

Spoiler :
1dD3uy7.jpg


That said, I actually meant I wanted to insert different text depending upon which policy you adopted (e.g. if you adopt Stratocracy it says one thing, whilst adopting Elite Training it says another). I managed to achieve this* myself by checking if the policy selected is Stratocracy first, so I still am grateful for your help. But I wonder if there's any advice you can give me in regards to what I actually want to achieve.

*
Spoiler :
oVlc1XI.jpg

(I will play around with Text size and such at a later point)

Sorry about the text thing, I didn't test the code.

That said, I actually meant I wanted to insert different text depending upon which policy you adopted (e.g. if you adopt Stratocracy it says one thing, whilst adopting Elite Training it says another). I managed to achieve this* myself by checking if the policy selected is Stratocracy first, so I still am grateful for your help. But I wonder if there's any advice you can give me in regards to what I actually want to achieve.

Can add a new column to the Policies table and then assign it to point to a TXT_KEY_whatever.

Then just do

strText = Locale.ConvertTextKey(GameInfo.Policies[policyID].ConfirmText) or something, assuming you called the column ConfirmText
 
Can add a new column to the Policies table and then assign it to point to a TXT_KEY_whatever.

Then just do

strText = Locale.ConvertTextKey(GameInfo.Policies[policyID].ConfirmText) or something, assuming you called the column ConfirmText

With this in an SQL file:

Spoiler :
Code:
ALTER TABLE Policies ADD COLUMN 'ConfirmText' TEXT DEFAULT NULL;

and this in the SocialPoliciesPopup.lua file:

Spoiler :
Code:
-- Added by Putmalk
		local strText = Locale.ConvertTextKey(GameInfo.Policies[policyID].ConfirmText)
		Controls.PolicyConfirmText:SetText(strText);
		-- End Putmalk

and this in a test Policy:

Spoiler :
<ConfirmText>TXT_KEY_CONFIRM_POLICY_MIGHT_STRATOCRACY</ConfirmText>(I'm not sure why that space appears, but it's not how I wrote it)


it returns the error:

SocialPolicyPopup.lua:135: bad argument #2 to '?' (Key must be of type 'number' or 'string'.)
 
Sorry, I found the problem; it should have been:

Code:
-- Added by Putmalk
		local strText = Locale.ConvertTextKey(GameInfo.Policies[[B]m_gPolicyID[/B]].ConfirmText)
		Controls.PolicyConfirmText:SetText(strText);
		-- End Putmalk

Thank you. I'm grateful that it worked; this saves me a lot of work and drives in the immersion that I was hoping for.
 
Yup. No problem. Glad it worked.

Seeing as the last month I've had to write my own interface popup and change a ton of old firaxis interface stuff (unitpanel, worldview, etc.) I'm pretty good at interface stuff now. So don't hesitate to ask if you need more help.
 
Well, I'm trying to figure out the best way to give particular titles to particular civs with particular policies; i.e. Suleiman adopts Monarchy, they get Sultan, but if Catherine adopts Monarchy, they get Tsaritsa, and if Elizabeth adopts Monarchy they get Queen, etc. I can do this - and have done this* - by just checking if the policy is Y and a civ is X before applying the title, but this makes for a very long insertion into the lua files which need this and perhaps you know of a better way.

*
Spoiler :
Code:
if (CivType == GameInfoTypes["CIVILIZATION_ARABIA"]) then
local strArabianCaliphateTextKey = "TXT_KEY_CALIPHATE_TITLE";
local strArabianCaliphateTitleText = Locale.ConvertTextKey(strArabianCaliphateTextKey, player:GetNameKey(), player:GetCivilizationAdjectiveKey());
	Controls.TitleText:SetText(strArabianCaliphateTitleText);

Perhaps I could use the method inspired by the above and add a column for each title to each civ that had a unique one, but the problem for me there is twofold: I can add a new column through SQL, but not a new table, and then once done I'm not sure how to reference that in the lua.

I have this:

Spoiler :

Code:
local strKingdomTitleText = Locale.ConvertTextKey(GameInfo.Civilizations[CivType].[B]Description[/B], player:GetNameKey(), player:GetCivilizationShortDescriptionKey());
	Controls.TitleText:SetText(strKingdomTitleText);

EDIT: In fact, the error is with this part, - as in I'm trying to reference the new columns here - because it did convert the description of the civ correctly. I shall keep working on it.
 
Well, I managed to get it working and this will make things a lot easier. Thanks Putmalk, without your Social Policy prompt help I wouldn't have been able to figure it at all.
 
As a semi-continuation of this topic, I'm having some trouble editing the DiploList.lua file. I want to show in place of the Civilisation's description the style of their government (but without any ethnic variations for this screen). Frustratingly, however, it never displays the text - only a blank space - once the conditions have been met, no matter how I try and input it. For instance:

Spoiler :

Code:
local strKingdomTextKey = "TXT_KEY_KINGDOM_TITLE";
local strKingdom = Locale.ConvertTextKey("TXT_KEY_KINGDOM_TITLE");
	controlTable.CivName:SetText(strKingdom);


nor:

Spoiler :

Code:
local strRepublic = Locale.ConvertTextKey([B]GameInfo.Civilizations[CivType].RepublicTitleText[/B]);
	controlTable.CivName:SetText(strRepublic );


work at all and only show a blank space (so it's not a simply matter of the TXT_KEY being incorrect) when Tradition/Liberty are adopted. But it'll work fine if I put something like pOtherPlayer:GetLeaderType() in place of the above, bolded text, displaying in place the Civ description the Leader name.

To make the matter more difficult, there's nothing in the logs, which means I have to ask for help once again. So hopefully someone has some advice for me.
 
I highly recommend using print statements before the troublesome code to help you debug.

So just add print(strKingdom); and print(strRepublic) and see what comes up.
 
It doesn't display anything useful, just:

Spoiler :
Code:
[67036.453] DiploList: strRepublic
[67036.453] AdvisorInfoPopup: Closing Advisor Info
[67036.453] Demographics: Dequeuing demographics
[67036.453] Demographics: Dequeuing demographics
[67036.484] DiploList: strRepublic
[67036.671] DiploList: strRepublic
 
Did you type it out print("strRepublic") or print(strRepublic) because they are two very different things.
 
Did you type it out print("strRepublic") or print(strRepublic) because they are two very different things.

I did print(strRepublic) first, but that didn't have anything at all, and then tried the former. But I'll try the latter again. I didn't realise there was an important distinction, so maybe I glossed over it.
 
What does print(strRepublic) do, exactly? There's no reference to it in the log. The only thing of note is: DiploList: nil, but I'll have to see if that's to do with my mod or that's there by default.
 
It prints out the value of the variable, for example if you did print(number) and number was 3 it would print out 3. In this case it prints out the string strRepublic, so you could see what it was being assigned. If nothing is spitting out, then nothing is being tagged, and that is your problem. Print statements are very useful for debugging for this reason (if you do print("strRepublic") then you are literally printing out a string "strRepublic" not the value of the variable strRepublic.

Post the entire section of code.
 
I believe I've just realized what it was from having a look at the localization.log file. I'm pointing the TXT_KEY to the same TXT_KEY that handles the leader titles, which uses these placeholders {1_PlayerName:textkey} and {2_CivName:textkey}, but I'm not converting the leadername or civname in the DiploLists code. I just need to give the DiploLists reference its own TXT_KEY tag without those placeholders and it'll be fine. Thanks for your help; I wouldn't have looked in that file if I had been trying to absentmindedly search for the print function.

EDIT: Yes, that was the problem after all.
 
Back
Top Bottom