Adding element to popup

Iceco

Warlord
Joined
Oct 27, 2010
Messages
188
For my Not Another City States Mod I am adding an image to the Greeting- and DiploPopups of city-states.
I got it working the easy way, by simply replacing those lua and xml files:
Spoiler :
RenamedCSesLarge.png

Now I'm trying to do it the proper way, that is with ContextPtr, without overwriting the core files, but it's not working.

Code:
<?xml version="1.0" encoding="utf-8"?>
<Context Font="TwCenMT20" ColorSet="Beige_Black_Alpha" FontStyle="Shadow" >
	<Image ID="TitleCSIcon" Anchor="C,T" AnchorSide="I.O"  Offset="0,-11" Texture="Assets/UI/Art/Controls/CityStatePopupTop100.dds" Size="86.86" Hidden="1"/>
</Context>
Code:
[COLOR="Green"]-------------------------------------------------
-- Changes to City State Diplo Popup
-------------------------------------------------[/COLOR]
[COLOR="Teal"]local[/COLOR] g_iMinorCivID = -1;
[COLOR="teal"]local [/COLOR]g_iMinorCivTeamID = -1;
[COLOR="teal"]local [/COLOR]m_PopupInfo = nil;

[COLOR="Green"]-------------------------------------------------
-- On Popup
-------------------------------------------------[/COLOR]
[COLOR="Blue"]function [/COLOR]OnEventReceived( popupInfo )
	
	[COLOR="Teal"]if[/COLOR]( popupInfo.Type ~= ButtonPopupTypes.BUTTONPOPUP_CITY_STATE_DIPLO ) [COLOR="teal"]then[/COLOR]
		[COLOR="teal"]return[/COLOR];
	[COLOR="teal"]end[/COLOR]
	
	m_PopupInfo = popupInfo;	
	
    [COLOR="teal"]local[/COLOR] iPlayer = popupInfo.Data1;
    [COLOR="teal"]local [/COLOR]pPlayer = Players[iPlayer];
	[COLOR="teal"]local [/COLOR]iTeam = pPlayer:GetTeam();
	[COLOR="teal"]local [/COLOR]pTeam = Teams[iTeam];
    
    g_iMinorCivID = iPlayer;
    g_iMinorCivTeamID = iTeam;
	
	[COLOR="teal"]local [/COLOR]bForcePeace = false;
	
	ShowCSIcon()
[COLOR="teal"]end[/COLOR]
Events.SerialEventGameMessagePopup.Add( OnEventReceived );

[COLOR="Blue"]function [/COLOR]OnGameDataDirty()
	[COLOR="Teal"]if [/COLOR](ContextPtr:LookUpControl("/InGame/CityStateDiploPopup"):IsHidden()) [COLOR="teal"]then[/COLOR]
		[COLOR="teal"]return[/COLOR]
	[COLOR="teal"]end	[/COLOR]
	ShowCSIcon()
[COLOR="teal"]end[/COLOR]
Events.SerialEventGameDataDirty.Add(OnGameDataDirty)

[COLOR="Green"]-------------------------------------------------
-- On Display
-------------------------------------------------[/COLOR]
[COLOR="Blue"]function [/COLOR]ShowCSIcon()
	Controls.TitleCSIcon:ChangeParent(ContextPtr:LookUpControl("/InGame/CityStateDiploPopup"))
	ContextPtr:LookUpControl("/InGame/CityStateDiploPopup"):ReprocessAnchoring()
	
	[COLOR="Green"]-- The below code is copied over from the 'easy' version and works in that one[/COLOR]
	[COLOR="Teal"]local[/COLOR] sMinorCivType = [COLOR="Red"]pPlayer[/COLOR]:GetMinorCivType();
	[COLOR="teal"]local [/COLOR]trait = GameInfo.MinorCivilizations[sMinorCivType].MinorCivTrait;
	[COLOR="teal"]local [/COLOR]CSIcon = nil;
	[COLOR="teal"]if [/COLOR](sMinorCivType ~= nil) [COLOR="teal"]then[/COLOR]
		[COLOR="teal"]local [/COLOR]realMinorCivType = GameInfo.MinorCivilizations[sMinorCivType].Type
		[COLOR="teal"]if [/COLOR]realMinorCivType ~= nil [COLOR="teal"]then[/COLOR]
			[COLOR="teal"]local [/COLOR]condition = "MinorCivType = '" .. realMinorCivType .. "'"
			[COLOR="teal"]for [/COLOR]row in GameInfo.MinorCivIcons_Iceco(condition) [COLOR="teal"]do[/COLOR]
				CSIcon = row.CSIcon;
			[COLOR="teal"]end[/COLOR]
		[COLOR="teal"]end[/COLOR]
	[COLOR="teal"]end[/COLOR]
	[COLOR="teal"]if [/COLOR]CSIcon ~= nil [COLOR="teal"]then[/COLOR]
		Controls.TitleCSIcon:SetHide(false);
		Controls.TitleCSIcon:SetTexture(CSIcon);
	[COLOR="teal"]else[/COLOR]
		Controls.TitleCSIcon:SetHide(true);
	[COLOR="teal"]end[/COLOR]
[COLOR="teal"]end[/COLOR]
The files are imported into the VFS and the lua is added as InGameUIAddin.
I assume the problem lies with the first few lines of the ShowCSIcon() function. I tried some different things, but nothing worked.
(The 'CSIcon' is just the round flag icon.)
The code is based on the original DiploPopup file, Onni's tutorial and Gedemon's Mercenary mod.

Any help would be appreciated.
 
Ok, got it working. I deleted a bit too much and the pPlayer marked in red didn't have a value any more. Solved now.

I do have another problem now. I don't know how to get the image align properly. I can change the Offset values until it's in the right place, but that doesn't work for different resolutions/window sizes.
I guess I'm doing it in absolute position in the window, instead of relative to the other elements.
 
I had some alignement problem at first with the Mercenary mod, sorry I can't remember right now what was wrong and how I fixed it, I'll have a look at my code this WE to see if I can help.
 
I do have another problem now. I don't know how to get the image align properly. I can change the Offset values until it's in the right place, but that doesn't work for different resolutions/window sizes.
Why complicate the already valid code when you simply have to edit the DDS file itself?
If you're talking about these "Flag" icons that must fit perfectly into the citystatepopuptop1(_2_3)00.dds. All it takes is *ONE* pixel, at times. I've learned to not trust custom templates even when picked from psd, as proven in Z-UI.
:)
 
XML framework has conventions for relative coordinates such as C,B,T,L,R(etc) but if the resizing of any elements can't be "Centered" in the allocated area, you're bound to offset the intended location within the self-contained space of the popup itself.
Think of it as a single virtual pixel always static surrounded by displayed content(BOX or Images) but still anchored *to* a location.

I'd recommend getting XML-Marker to examine such principles from within the files. It's more obvious once you perceive theses values in more than just sizing of frames.
 
I'll see if making a flag with the same dimensions as the top fixes it. Though if I understand it right, if this is the problem, it wouldn't have aligned correctly when I was simply overwriting the file either, which wasn't the case as far as I remember.
 
Not exactly.
What you'd possibly need is an extra component that "Overlays" the default citystatepopuptop section (that have each a symbol of Maritime, Cultural or Militaristic *INCLUDED & DESIGNED* into the files).

Judging from the snapshot above, you were able to create the Norway version.

For displaying reasons, there are three specific categories while you are trying to consider each as individual. If that's the case then, you'd want to pass a parameter that triggers activation of individual overlays for each CS. With some principles used in CS_Leaders (which you have already) as i recall.
 
Iceco, as it's seems to be the same size as the vanilla one, have you tried to just directly replace the texture using contextptr ?

something like that (you won't need the xml file) :

Code:
-------------------------------------------------
-- On Display
-------------------------------------------------
function ShowCSIcon()
	
	-- The below code is copied over from the 'easy' version and works in that one
	local sMinorCivType = pPlayer:GetMinorCivType();
	local trait = GameInfo.MinorCivilizations[sMinorCivType].MinorCivTrait;
	local CSIcon = nil;
	if (sMinorCivType ~= nil) then
		local realMinorCivType = GameInfo.MinorCivilizations[sMinorCivType].Type
		if realMinorCivType ~= nil then
			local condition = "MinorCivType = '" .. realMinorCivType .. "'"
			for row in GameInfo.MinorCivIcons_Iceco(condition) do
				CSIcon = row.CSIcon;
			end
		end
	end
	if CSIcon ~= nil then
		ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/TitleIcon"):SetTexture(CSIcon);
	end
end
 
@Gedemon
That's not really what I do. I just add an image like this:
Spoiler :
NACSMFlagExample.png
over the existing top.
If all else fails, I might have to go with making complete tops, but that would have its drawbacks:
- The mod's file size will be about 8 times as big as it is now.
- When I eventually add an icon in the top to display their trait, that will not change with possible changes made by others, since it'd be hard-baked in my top.
- It's pretty hard to use the stock resources from the game as they load like this on my pc:
NACSMScramble.png

(That's the top for military city-states. I guess I can puzzle it back together if needed though.)

@Zyxphylon
I think you have the same misunderstanding, or I'm getting it wrong again. I'm already overlaying, but the overlay isn't aligning properly. (Or it aligns relative to the page and I don't know how to make it align relative to the popup.)
 
ok, sorry I didn't see you wanted to do it this way.

for the mercenary mod, I changed the parent to the ButtonStack, something you can't do here as it's relative position from the top can change...

I've also updated my conversion of mihaifx's mod for Ynaemp, but now that I see you objective, it won't help you neither, sorry :/
 
Vanilla Icons (and many more, btw) have Index files for core assets which are used as runtime pre-parsers for any of their corresponding DDS "textures". Technically, the stack space allocation depends on re-construction done through a coded procedure that **accelerates** rendering on the UI.
Sterkhov made a converter for such files with this.

But your problem isn't related to the DDS files, i gather.
More about referencing the **new** assets for the engine to allocate their use within any popups.
Example, the Difficulty levels (1-8) that get in the drop-down selection box during settings.
The individual Icons are pulled off what we call an Atlas. Each versions have a slot that need referencing from both the lua and the xml popup definition_S that includes one section dedicated to; the citystatepopuptop(100_200_300)... as i said earlier.

Since you have THREE categories of CS (pre-defined in the call routines), you'd need three individual atlas to refer the corresponding flags from. One for Maritime, Cultural & Militaristic.
And a supplemental (the overlay mentioned in an earlier post) box created as a relative to (we call that an indented loop) the main CSPopupTOP section but not the entire CS_main popup.

OR... a single one as used by the City-States Leaders mod.
 
Ok, back from a break. Had enough of it for a bit.

I fear I'll have to go with replacing the texture of the TitleIcon. Thank you Zyx for the link to the converter, that will help a lot.
Though before giving up, I have one last idea:

Would it be possible to add a line in the DiploPopup.xml with SQL?
In the style of "WHERE <Image ID="TitleIcon" .../> INSERT line <Image ID="TitleCSIcon" .../>"
 
Back
Top Bottom