UI Tutorial discussion thread

Here is snippet.

defines file contains following global table declaration:

Code:
----------------------------------------------------------------------------------------------------------------------------
-- Global Data Tables
----------------------------------------------------------------------------------------------------------------------------

g_GlobalSupplyCounters = {

--	Counter is current total amount
--	Output is per turn output from required buildings
--	Cap is the total capacity/limit
--	Penalty is any production or loss penatly applied on current turn (i.e. lack of resource, weather)
--	Bonus is any freebies/bonuses applied on current turn (i.e. lend lease)
--	Healed is the number of personnel healed and returned back into pool

-- Structure: [PlayerID] = {}

}

main lua file executes the following process (this is based on R.E.D WWII mod):
Code:
-- functions to call after game initialization (DoM screen button "Begin your journey" appears)
function OnGameInit ()
	local savedData = Modding.OpenSaveData()
	local iValue = savedData.GetValue("EF_FinalInitDone")
	if (iValue ~= 1) then
		Dprint ("Game is initialized, calling OnGameInit() for new game ...")

		LoadAllTable() -- before any change on tables...
		CreateTerritoryMap()	
		SetInitialCityBuilds()
[B][COLOR="Red"]		InitializeSupplySystem()[/COLOR][/B]
		InitExistingUnitSupplyData()
		Events.SerialEventUnitCreated.Add( InitNewUnitSupplyData )
		Events.SerialEventCityCaptured.Add( VictoryCheck )
		Events.SerialEventCityCaptured.Add( HandleCityCapture )
		GameEvents.UnitSetXY.Add( UnitCaptureTile )

		savedData.SetValue("EF_FinalInitDone", 1)
	else
		Dprint ("Game is initialized, calling OnGameInit() for loaded game ...")
	end
end

Which in turn fires the InitializeSupplySystem function.
Code:
function InitializeSupplySystem()
	Dprint("Initalizing supply system counters...")
	for playerID = 0, GameDefines.MAX_CIV_PLAYERS - 1 do
	local player = Players[playerID]
		if ( player:IsAlive() ) and (player:IsMinorCiv() == false) then	
			Dprint(" - Supply system initialized for player: ".. player:GetName())
			g_GlobalSupplyCounters[playerID] = {}

			-- Test counters - reset once testing is complete

			g_GlobalSupplyCounters[playerID].Counter_FG	= 2500
			g_GlobalSupplyCounters[playerID].Counter_V = 2500
			g_GlobalSupplyCounters[playerID].Counter_R = 2500
			g_GlobalSupplyCounters[playerID].Counter_LT = 2500
			g_GlobalSupplyCounters[playerID].Counter_LSP = 2500
			g_GlobalSupplyCounters[playerID].Counter_LSP2 = 2500
			g_GlobalSupplyCounters[playerID].Counter_LTD = 2500
			g_GlobalSupplyCounters[playerID].Counter_MT = 2500
			g_GlobalSupplyCounters[playerID].Counter_MT2 = 2500
			g_GlobalSupplyCounters[playerID].Counter_MSP = 2500
			g_GlobalSupplyCounters[playerID].Counter_MTD = 2500
			g_GlobalSupplyCounters[playerID].Counter_HT = 2500
			g_GlobalSupplyCounters[playerID].Counter_HSP = 2500
			g_GlobalSupplyCounters[playerID].Counter_HTD = 2500
			g_GlobalSupplyCounters[playerID].Counter_F = 2500
			g_GlobalSupplyCounters[playerID].Counter_JF = 2500
			g_GlobalSupplyCounters[playerID].Counter_GA = 2500
			g_GlobalSupplyCounters[playerID].Counter_FB = 2500
			g_GlobalSupplyCounters[playerID].Counter_MB = 2500
               end
       end
end
 
Nothing obvious from that, so you're down to using print() to ascertain exactly what is wht - the first thing to determine is what is nil -- is it g_GlobalSupplyCounters or g_GlobalSupplyCounters[playerID]
 
I tried sprinkling a few more print statements and it is indeed stopping on the first line on any entry that tries to use the global table. I know for a fact that the global table works fine as this is the core of my supply model I have been testing for the last few months.

I modified it to use an if statement that replaces the global table with a zeros if its null and the code worked....kind of! The labeling/text box formatting went haywire...but I won't focus on that until I figure this issues!

It would probably help if I got any idea of load order and precedence with how Civ 5 loads LUA files and UI files. Do you have any observations on load order?
 
The vanilla files are loaded first (toppanel.lua for example), to prevent unwanted early call to variable that are not initialized, maybe you can use a test for g_GlobalSupplyCounters before applying the new text.

like

Code:
function UpdateProdData()

	local playerID = Game.GetActivePlayer()

	if playerID >= 0 [COLOR="Red"]and g_GlobalSupplyCounters[/COLOR]  then
		local strPers_Text = string.format("%i",0)
		local strFG_Text = string.format("%i",g_GlobalSupplyCounters[playerID].Counter_FG)
		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
 
I finally solved the issue, but I don't know how (which I hate)!

I took the easy way out and copied Gedemon's approach in the TopPanel.lua used in his R.E.D WWII mod. I should not complain, but its easy to copy/paste without any thought versus doing it the hard way yourself and learning something!
 
Parts 1, 4, 5 and 6 have received minor updates (latest versions can be downloaded from the ModHub)

The "Animating the UI" tutorial is now Part 7 of this tutorial.

The old Part 7 (Misc) is now Part 8 and has been updated with additional information (ColorN, ColorSet, AnchorSide, Full, and a few minor other changes)
 
I got another question:

I am trying to edit the InfoCorner xml in order to remove the TopLeft001.dds image.

No matter what I do (comment out or set hidden to 1) the image keeps appearing. How do I remove the image?

Note: I also edited the TechPanel and TechPanelSmall just incase but it made no difference.
 
Filename spelt correctly in the mod?
VFS set to true?
No other mod (eg UI - Map Pins)that is also loading a version of the file?
 
I thought VFS does not need to be true for XML files...only LUA? (Will try this and see)

As for spelling...I have imported the file into ModBuddy as an override. I either comment it out or set hidden to true!

EDIT: My mod is stand alone so no conflict with other mods.
 
As you're overriding an existing xml file you will need VFS true
 
Thanks for the previous assistance. You were indeed correct.

Another question:

How do I get a <stack> of <text> fields to auto pad when strings get longer than the default "string" tag description provided?

My counter quantities vary in size which is causing overlapping or too much space between text fields
 
How do I get a <stack> of <text> fields to auto pad when strings get longer than the default "string" tag description provided

IIRC same way you do with a stack that contains dynamic (instance) elements

Code:
  Controls.CSStack:CalculateSize()
  Controls.CSStack:ReprocessAnchoring()
 
New Question: How do I call popup screens?

I have been flicking through the various tuts can't figure out how to actually code a control to open a popup screen on left click.

I want to click on one of the TopPanel text fields and open up a new popup screen I am coding called IndustryOverview.xml.

I noticed in all the tuts, the test screens appear on loading the mod.
 
Cheers. Looks exactly like what I am trying to achieve.
 
I've added an Errata post to the Reference thread - post any errors here and I'll update it as necessary (not too worried about spelling mistakes, more about factual ones!)

Thanks to WW2 for the first one.
 
I downloaded the first tutorial and it works just fine.

However, when I try to create even the first dialog mod, then "hello world" is not appearing. Actually, that seems to be a general problem: while I can create mods which change, e.g., text, or manipulate an existing mod, as soon as I try to create a mod from scratch (with mod buddy) that actually changes something in the UI, then nothing happens ( I can access the mod in the game but the supposed change is never visible). I attach my first attempt. I suppose there is some option/configuration issue I am missing, but I do not get it fixed.

Thanks for any help in advance.
 

Attachments

I attach my first attempt. I suppose there is some option/configuration issue I am missing, but I do not get it fixed.

Thanks for any help in advance.

This

Code:
<?xml version="1.0" encoding="utf-8" ?>
<Context>
  <Label Anchor="C,C" String="Hello World!"/>
</Context>

lives in the UI/Dialog.xml context and not the XML/DialogText.xml GameData update file
 
Back
Top Bottom