Civilopedia UI

Inightshade

Chieftain
Joined
Sep 29, 2014
Messages
33
Location
Renis
Alright!

So how much of the Civilopedia UI is not changeable?


Right now I am working on sorting my promotions into the pedia, and am attempting to figure out how to change the static list of promotions.PediaTypes in the pedia.


I can sort properly now.
Code:
--table for promotion pedia types ~JFCM
local promotionCategories = {};

--Fill pedia types ~JFCM
local iJFCM = -1;
local iTotalPedia = #promotionCategories;
print("JFCM -|- Civilopedia called to fill promotionTypes array.");
for row in GameInfo.UnitPromotions() do
	local skip = false;
	iTotalPedia = #promotionCategories+1;
	for array = 0, iTotalPedia do
		print("check: ",promotionCategories[array],"VS: ",row.PediaType);
		if promotionCategories[array] == row.PediaType then
			skip = true;
		end
	end
	if not skip then
		iJFCM = iJFCM+1;
		promotionCategories[iJFCM] = {};
		promotionCategories[iJFCM][0] = row.PediaType;
		promotionCategories[iJFCM][1] = 1;
		print("JFCM -|- Civilopedia promotion type: ",row.PediaType);
	end
end

...

CivilopediaCategory[CategoryPromotions].PopulateList = function()
	-- add the instances of the promotion entries
	sortedList[CategoryPromotions] = {};
	print("Function called: CategoryPromotions.");
	
	arrayMax = #promotionCategories;
	-- Clean the array from last call;
	for row = 0, arrayMax do
		promotionCategories[row][1] = 1;
		sortedList[CategoryPromotions][row] = {};
	end
	print("Cleaned arrays.");
 
-- For each promotion... Ug. No.
--How about one for, to sort them all? ~JFCM
	for thisPromotion in GameInfo.UnitPromotions() do
		local skip = true;
		for row = 0, arrayMax do
			if skip and thisPromotion.PediaType == promotionCategories[row][0] then
				skip = false;
				local tableID = promotionCategories[row][1];
			
				-- add an article to the list (localized name, unit tag, etc.)
				local article = {};
				local name = Locale.ConvertTextKey( thisPromotion.PediaEntry )
				article.entryName = name;
				article.entryID = thisPromotion.ID;
				article.entryCategory = CategoryPromotions;

				sortedList[CategoryPromotions][row][tableID] = article;
				promotionCategories[row][1] = tableID + 1;
			
				-- index by various keys
				searchableList[Locale.ToLower(name)] = article;
				searchableTextKeyList[thisPromotion.Description] = article;
				categorizedList[(CategoryPromotions * absurdlyLargeNumTopicsInCategory) + thisPromotion.ID] = article;
			end
		end
	end
	
	print("Sort lists.");
	-- sort this list alphabetically by localized name
	for section = 1,8,1 do
		table.sort(sortedList[CategoryPromotions][section], Alphabetically);
	end		
end

and it, kinda? sorts them correctly?
But the drop down lists are still "Melee promos" "Ranged promo" ect. (And I have different names for my PediaTypes!)

I'm a little in over my head when it comes to the UI code, but I would imagine somewhere it defines the lists. And if I can do that, I can get everything sorted correctly.

p.s.
fraxises original code:
Spoiler :
Code:
CivilopediaCategory[CategoryPromotions].PopulateList = function()
	-- add the instances of the promotion entries
	sortedList[CategoryPromotions] = {};
	
	sortedList[CategoryPromotions][1] = {}; 
	local tableid = 1;
	
	-- for each promotion
	for thisPromotion in GameInfo.UnitPromotions() do
		if thisPromotion.PediaType == "PEDIA_MELEE" then
			-- add an article to the list (localized name, unit tag, etc.)
			local article = {};
			local name = Locale.ConvertTextKey( thisPromotion.PediaEntry )
			article.entryName = name;
			article.entryID = thisPromotion.ID;
			article.entryCategory = CategoryPromotions;

			sortedList[CategoryPromotions][1][tableid] = article;
			tableid = tableid + 1;
			
			-- index by various keys
			searchableList[Locale.ToLower(name)] = article;
			searchableTextKeyList[thisPromotion.Description] = article;
			categorizedList[(CategoryPromotions * absurdlyLargeNumTopicsInCategory) + thisPromotion.ID] = article;
		end
	end
	
	sortedList[CategoryPromotions][2] = {}; 
	local tableid = 1;
	for thisPromotion in GameInfo.UnitPromotions() do
		if thisPromotion.PediaType == "PEDIA_RANGED" then
			-- add an article to the list (localized name, unit tag, etc.)
			local article = {};
			local name = Locale.ConvertTextKey( thisPromotion.PediaEntry )
			article.entryName = name;
			article.entryID = thisPromotion.ID;
			article.entryCategory = CategoryPromotions;

			sortedList[CategoryPromotions][2][tableid] = article;
			tableid = tableid + 1;
			
			-- index by various keys
			searchableList[Locale.ToLower(name)] = article;
			searchableTextKeyList[thisPromotion.Description] = article;
			categorizedList[(CategoryPromotions * absurdlyLargeNumTopicsInCategory) + thisPromotion.ID] = article;
		end
	end
	
	sortedList[CategoryPromotions][3] = {}; 
	local tableid = 1;
	for thisPromotion in GameInfo.UnitPromotions() do
		if thisPromotion.PediaType == "PEDIA_NAVAL" then
			-- add an article to the list (localized name, unit tag, etc.)
			local article = {};
			local name = Locale.ConvertTextKey( thisPromotion.PediaEntry )
			article.entryName = name;
			article.entryID = thisPromotion.ID;
			article.entryCategory = CategoryPromotions;

			sortedList[CategoryPromotions][3][tableid] = article;
			tableid = tableid + 1;
			
			-- index by various keys
			searchableList[Locale.ToLower(name)] = article;
			searchableTextKeyList[thisPromotion.Description] = article;
			categorizedList[(CategoryPromotions * absurdlyLargeNumTopicsInCategory) + thisPromotion.ID] = article;
		end
	end
		
	sortedList[CategoryPromotions][4] = {}; 
	local tableid = 1;
	for thisPromotion in GameInfo.UnitPromotions() do
		if thisPromotion.PediaType == "PEDIA_HEAL" then
			-- add an article to the list (localized name, unit tag, etc.)
			local article = {};
			local name = Locale.ConvertTextKey( thisPromotion.PediaEntry )
			article.entryName = name;
			article.entryID = thisPromotion.ID;
			article.entryCategory = CategoryPromotions;

			sortedList[CategoryPromotions][4][tableid] = article;
			tableid = tableid + 1;
			
			-- index by various keys
			searchableList[Locale.ToLower(name)] = article;
			searchableTextKeyList[thisPromotion.Description] = article;
			categorizedList[(CategoryPromotions * absurdlyLargeNumTopicsInCategory) + thisPromotion.ID] = article;
		end
	end
	
	sortedList[CategoryPromotions][5] = {}; 
	local tableid = 1;
	for thisPromotion in GameInfo.UnitPromotions() do
		if thisPromotion.PediaType == "PEDIA_SCOUTING" then
			-- add an article to the list (localized name, unit tag, etc.)
			local article = {};
			local name = Locale.ConvertTextKey( thisPromotion.PediaEntry )
			article.entryName = name;
			article.entryID = thisPromotion.ID;
			article.entryCategory = CategoryPromotions;

			sortedList[CategoryPromotions][5][tableid] = article;
			tableid = tableid + 1;
			
			-- index by various keys
			searchableList[Locale.ToLower(name)] = article;
			searchableTextKeyList[thisPromotion.Description] = article;
			categorizedList[(CategoryPromotions * absurdlyLargeNumTopicsInCategory) + thisPromotion.ID] = article;
		end
	end
	
	sortedList[CategoryPromotions][6] = {}; 
	local tableid = 1;
	for thisPromotion in GameInfo.UnitPromotions() do
		if thisPromotion.PediaType == "PEDIA_AIR" then
			-- add an article to the list (localized name, unit tag, etc.)
			local article = {};
			local name = Locale.ConvertTextKey( thisPromotion.PediaEntry )
			article.entryName = name;
			article.entryID = thisPromotion.ID;
			article.entryCategory = CategoryPromotions;

			sortedList[CategoryPromotions][6][tableid] = article;
			tableid = tableid + 1;
			
			-- index by various keys
			searchableList[Locale.ToLower(name)] = article;
			searchableTextKeyList[thisPromotion.Description] = article;
			categorizedList[(CategoryPromotions * absurdlyLargeNumTopicsInCategory) + thisPromotion.ID] = article;
		end
	end

	sortedList[CategoryPromotions][7] = {}; 
	local tableid = 1;
	for thisPromotion in GameInfo.UnitPromotions() do
		if thisPromotion.PediaType == "PEDIA_SHARED" then
			-- add an article to the list (localized name, unit tag, etc.)
			local article = {};
			local name = Locale.ConvertTextKey( thisPromotion.PediaEntry )
			article.entryName = name;
			article.entryID = thisPromotion.ID;
			article.entryCategory = CategoryPromotions;

			sortedList[CategoryPromotions][7][tableid] = article;
			tableid = tableid + 1;
			
			-- index by various keys
			searchableList[Locale.ToLower(name)] = article;
			searchableTextKeyList[thisPromotion.Description] = article;
			categorizedList[(CategoryPromotions * absurdlyLargeNumTopicsInCategory) + thisPromotion.ID] = article;
		end
	end
	
	sortedList[CategoryPromotions][8] = {}; 
	local tableid = 1;
	for thisPromotion in GameInfo.UnitPromotions() do
		if thisPromotion.PediaType == "PEDIA_ATTRIBUTES" then
			-- add an article to the list (localized name, unit tag, etc.)
			local article = {};
			local name = Locale.ConvertTextKey( thisPromotion.PediaEntry )
			article.entryName = name;
			article.entryID = thisPromotion.ID;
			article.entryCategory = CategoryPromotions;

			sortedList[CategoryPromotions][8][tableid] = article;
			tableid = tableid + 1;
			
			-- index by various keys
			searchableList[Locale.ToLower(name)] = article;
			searchableTextKeyList[thisPromotion.Description] = article;
			categorizedList[(CategoryPromotions * absurdlyLargeNumTopicsInCategory) + thisPromotion.ID] = article;
		end
	end
	-- sort this list alphabetically by localized name
	for section = 1,8,1 do
		table.sort(sortedList[CategoryPromotions][section], Alphabetically);
	end		
end
p.s.s.
Screene
 
See CivilopediaCategory[CategoryPromotions].SelectHeading and CivilopediaCategory[CategoryPromotions].DisplayList

specifically the usage of TXT_KEY_PROMOTIONS_SECTION_
 
Kool! So now to figure out how to make this dynamic and based on the promotions PediaTypes table... Hrm.
I might do a flat list (to start with) and use an 'other' catch all section...


For anyone looking, this works perfectly.

= string.sub(tostring(row.PediaType), 7, 7) .. string.lower(string.sub(tostring(row.PediaType), 8)) .. " Promotions";

I can assume (kinda) that every unitPromotions(pPromotion).PediaType will start with PEDIA_ (hence the 7 and 8's)
and from there can make a title. If you require special titles you can use this also:
Code:
if "PEDIA_MECHANICAL" == row.PediaType then
			promotionCategories[iJFCM][2] = "Vehicle Promotions";
		elseif "PEDIA_ATTRIBUTES" == row.PediaType then
			promotionCategories[iJFCM][2] = "Inherent Promotions";
		else
			promotionCategories[iJFCM][2] = string.sub(tostring(row.PediaType), 6, 6) .. string.lower(string.sub(tostring(row.PediaType), 7)) .. " Promotions";
		end
which precedes that.

From here we can change:
Code:
for section = 1, [COLOR="Red"]8[/COLOR], 1 do	
		-- add a section header
		local thisHeaderInstance = g_ListHeadingManager:GetInstance();
		if thisHeaderInstance then
			sortOrder = sortOrder + 1;
			if sortedList[CategoryPromotions][section].headingOpen then
				[COLOR="red"]local textString = "TXT_KEY_PROMOTIONS_SECTION_"..tostring( section );[/COLOR]
				local localizedLabel = "[ICON_MINUS] "..Locale.ConvertTextKey( textString );
				thisHeaderInstance.ListHeadingLabel:SetText( localizedLabel );
			else
				[COLOR="red"]local textString = "TXT_KEY_PROMOTIONS_SECTION_"..tostring( section );[/COLOR]
				local localizedLabel = "[ICON_PLUS] "..Locale.ConvertTextKey( textString );
				thisHeaderInstance.ListHeadingLabel:SetText( localizedLabel );
			end
			thisHeaderInstance.ListHeadingButton:SetVoids( section, 0 );
			thisHeaderInstance.ListHeadingButton:RegisterCallback( Mouse.eLClick, CivilopediaCategory[CategoryPromotions].SelectHeading );
			otherSortedList[tostring( thisHeaderInstance.ListHeadingButton )] = sortOrder;
		end

to this:
Code:
for section = 1, [COLOR="DarkGreen"]iMax[/COLOR], 1 do	
		-- add a section header
		local thisHeaderInstance = g_ListHeadingManager:GetInstance();
		if thisHeaderInstance then
			sortOrder = sortOrder + 1;
			if sortedList[CategoryPromotions][section].headingOpen then
				[COLOR="rgb(0, 100, 0)"]local textString = promotionCategories[section][2];[/COLOR]
				local localizedLabel = "[ICON_MINUS] "..Locale.ConvertTextKey( textString );
				thisHeaderInstance.ListHeadingLabel:SetText( localizedLabel );
			else
				[COLOR="rgb(0, 100, 0)"]local textString = promotionCategories[section][2];[/COLOR]
				local localizedLabel = "[ICON_PLUS] "..Locale.ConvertTextKey( textString );
				thisHeaderInstance.ListHeadingLabel:SetText( localizedLabel );
			end
			thisHeaderInstance.ListHeadingButton:SetVoids( section, 0 );
			thisHeaderInstance.ListHeadingButton:RegisterCallback( Mouse.eLClick, CivilopediaCategory[CategoryPromotions].SelectHeading );
			otherSortedList[tostring( thisHeaderInstance.ListHeadingButton )] = sortOrder;
		end

and we are rather close to done. A few minor changes (the for loop cap of 8 to #arraySize and the previous change to CivilopediaCategory[CategoryPromotions].PopulateList = function() )

Works as expected! This ought to work for any Civilopedia entry. (In an intrinsic functioning sort of way)
 
Back
Top Bottom