UI Tutorial discussion thread

whoward69

DLL Minion
Joined
May 30, 2011
Messages
8,691
Location
Near Portsmouth, UK
This thread is for asking questions about the "[Tutorial] User Interface Components" thread (in the "Modding Tutorials and Reference" sub-forum) - as I'd like to (try and) keep that thread for the answers.
 
Ok, lets get this show on the road.

Your probably going to cover this in your tutorial at some point (assumption!), but is it possible/easy to reference a specific section of a dds file so that you can refer to unique icons. I was hoping to create a atlas type file containing numerous square icons.

I.e. In my mod I want unique square icons (similar to the hard-coded font icons) that represents different equipment and resource types and the current font icons does not allow additions.
 
but is it possible/easy to reference a specific section of a dds file so that you can refer to unique icons. I was hoping to create a atlas type file containing numerous square icons.

I.e. In my mod I want unique square icons (similar to the hard-coded font icons) that represents different equipment and resource types and the current font icons does not allow additions.

You can, the TextureOffset="dX, dY" attribute of the <Image> element, but why not just create an icon atlas (they don't have to be round) and use the provided IconSupport:IconHookup() code to get the required part into the image? There are icon sizes at 16, 24, 32, 45, 48, 64, 80, 128, 214 and 256 - the font icons are 24 BTW

HTH

W
 
So I got around to playing with the icon hookup as you suggested and it was not as painful as I thought it would be.

Here is the initial results. I need to resize the grid and the labels in between the icons are just placeholders for now.



Question - Is there a way to get the nice looking ring around the icons like normal unit/building icons? I gather there must be a tag you need to include to make this happen? I am using size 32 icons.
 
The "rings" (aka frames) are achieve by placing an image element (for the icon) within an image element (for the ring) - there is no tag that just makes it happen!

Unfortunately, there is no standard 32x32 frame, so you'd need to make one (probably by scaling the 64x64 version)

Code:
<Image Texture="NotificationIconsInfoFrame.dds" Size="64,64" ID="Frame64">
  <Image Anchor="C,C" Size="64,64" ID="Icon64"/>
</Image>
 
I can try resizing, but the dds is encrypted (all distorted when viewed)?
 
The other option is to use the game to do the scaling, create an Image for the 64x64 frame around the icon, and then resize it

instance.Frame64x64:SetSizeVal(32,32)
 
Part 7 - Miscellanea has been added - no example code, just a PDF that wraps up some loose ends.
 
whoward69,
I just wanted to say that these tutorials are amazing, and I want to thank you for this and your many efforts in raising the bar for the average CiV modder.
 
Call for help!

I have finalised my screen and it all works fine. However, when I go to link the text fields to values I keep getting a runtime error.

Here is the LUA code:
Code:
include ("IconSupport")
include ("EF_Defines_SupplySystem")
include ("EF_SupplySystem_Main")

IconHookup(9, 32, "EF_PROD_ICONS", Controls.FG_Icon)
IconHookup(3, 32, "EF_PROD_ICONS", Controls.V_Icon)
IconHookup(8, 32, "EF_PROD_ICONS", Controls.R_Icon)
IconHookup(0, 32, "EF_PROD_ICONS", Controls.LT_Icon)
IconHookup(1, 32, "EF_PROD_ICONS", Controls.MT_Icon)
IconHookup(2, 32, "EF_PROD_ICONS", Controls.HT_Icon)
IconHookup(4, 32, "EF_PROD_ICONS", Controls.LSP_Icon)
IconHookup(5, 32, "EF_PROD_ICONS", Controls.MSP_Icon)
IconHookup(6, 32, "EF_PROD_ICONS", Controls.HSP_Icon)
IconHookup(7, 32, "EF_PROD_ICONS", Controls.TD_Icon)
IconHookup(10, 32, "EF_PROD_ICONS", Controls.F_Icon)
IconHookup(11, 32, "EF_PROD_ICONS", Controls.GA_Icon)
IconHookup(12, 32, "EF_PROD_ICONS", Controls.FB_Icon)
IconHookup(13, 32, "EF_PROD_ICONS", Controls.MB_Icon)
IconHookup(14, 32, "EF_PROD_ICONS", Controls.Per_Icon)

function UpdateProdData()

	local playerID = Game.GetActivePlayer()

	if playerID >= 0 then
		local strPers_Text = string.format("%i",0)
		[B][COLOR="Red"]local strFG_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_FG)[/COLOR][/B]
		local strV_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_V)
		local strR_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_R)
		local strLT_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_LT)
		local strMT_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_MT)
		local strHT_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_HT)
		local strLSP_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_LSP)
		local strMSP_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_MSP)
		local strHSP_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_HSP)
		local strMTD_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_MTD)
		local strF_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_F)
		local strGA_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_GA)
		local strFB_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_FB)
		local strMB_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_MB)

		Controls.Pers_Text:SetText(strPers_Text)
		Controls.FG_Text:SetText(strFG_Text)
		Controls.V_Text:SetText(strV_Text)
		Controls.R_Text:SetText(strR_Text)
		Controls.LT_Text:SetText(strLT_Text)
		Controls.MT_Text:SetText(strMT_Text)
		Controls.HT_Text:SetText(strHT_Text)
		Controls.LSP_Text:SetText(strLSP_Text)
		Controls.MSP_Text:SetText(strMSP_Text)
		Controls.HSP_Text:SetText(strHSP_Text)
		Controls.MTD_Label:SetText(strMTD_Text)
		Controls.F_Text:SetText(strF_Text)
		Controls.GA_Text:SetText(strGA_Text)
		Controls.FB_Text:SetText(strFB_Text)
		Controls.MB_Text:SetText(strMB_Text)
	end
end


function OnProdPanelDirty()
	UpdateProdData();
end

-- Register Events
Events.SerialEventGameDataDirty.Add(OnProdPanelDirty);
Events.SerialEventTurnTimerDirty.Add(OnProdPanelDirty);
Events.SerialEventCityInfoDirty.Add(OnProdPanelDirty);

-- Update data at initialization
UpdateProdData();
--DoInitTooltips();

Pretty straight forward in that I am trying to read back a value for playerID index in global table GlobalSupplyCounters. The table is defined in EF_Defines_SupplySystem which I have included.

Here is the error message I keep getting at position 28 which is the local strFG_Text entry.

Code:
Runtime Error: [string "C:\Users\user\Documents\My Games\Sid Meier'..."]:28: attempt to index field '?' (a nil value)
 Runtime Error: [string "C:\Users\user\Documents\My Games\Sid Meier'..."]:28: attempt to index field '?' (a nil value)

I know it is the global table causing issues but cant figure out why it cant reference it. All other areas use the exact same table reference without any problems and the table does have data in it for the player I am trying to index!

Is there something I need to do when referencing global tables apart from providing an 'includes' statement? I tried to use a plain print statement to see the value in Firetuner and got the exact same error message....thus it is the whole table reference it does not like.
 
What does a

Code:
g_GlobalSupplyCounters[playerID].Counter_FG = [I]something[/I]

and are you 110% sure it's getting called before UpdateProdData() in file scope at the end of your file?

Best bet is to scatter some print("At xyz") statements at the beginning and end of your UpdateProdData() method and the one that does the assignments to confirm they really are happening in the order you expect
 
It seems the table gets populated after the UI lua executes on first turn.

However, should it not pick up populated table on second turn?
 
Without seeing the code that assigns to g_GlobalSupplyCounters[playerID].Counter_FG, impossible to tell
 
Top Bottom