0ad/binaries/data/mods/public/gui/civinfo/civinfo.js
leper 82b08db6ec Remove grouping from civ info screen. Only show playable civs. Refs #2619.
Does not use loadCivData(true) as the civ info screen can also be opened
from the
gamesetup screen and both use g_CivData.

This was SVN commit r16415.
2015-03-15 04:15:59 +00:00

141 lines
4.1 KiB
JavaScript

var g_CivData = {};
function init(settings)
{
initCivNameList();
}
// Initialize the dropdown containing all the available civs
function initCivNameList()
{
// Cache map data
g_CivData = loadCivData();
var civList = [
{ "name": civ.Name, "code": civ.Code }
for each (civ in g_CivData)
if (civ.SelectableInGameSetup !== false)
];
// Alphabetically sort the list, ignoring case
civList.sort(sortNameIgnoreCase);
// Indent sub-factions
var civListNames = [ civ.name for each (civ in civList) ];
var civListCodes = [ civ.code for each (civ in civList) ];
// Set civ control
var civSelection = Engine.GetGUIObjectByName("civSelection");
civSelection.list = civListNames;
civSelection.list_data = civListCodes;
civSelection.selected = 0;
}
// Function to make first char of string big
function bigFirstLetter(str, size)
{
return '[font="sans-bold-'+(size+6)+'"]' + str[0] + '[/font]' + '[font="sans-bold-'+size+'"]' + str.substring(1) + '[/font]';
}
// Heading font - bold and mixed caps
function heading(string, size)
{
var textArray = string.split(" ");
for(var i = 0; i < textArray.length; ++i)
{
var word = textArray[i];
var wordCaps = word.toUpperCase();
// Check if word is capitalized, if so assume it needs a big first letter
// Check if toLowerCase changes the character to avoid false positives from special signs
if (word.length && word[0].toLowerCase() != word[0])
textArray[i] = bigFirstLetter(wordCaps, size);
else
textArray[i] = '[font="sans-bold-'+size+'"]' + wordCaps + '[/font]'; // TODO: Would not be necessary if we could do nested tags
}
return textArray.join(" ");
}
function escapeChars(str)
{
return str.replace(/"/g, "\\\"");
};
function subHeading(obj)
{
if (!obj.Name)
return "";
let string = '[color="white"][font="sans-bold-14"]' + obj.Name + '[/font] ';
if (obj.History)
string += '[icon="iconInfo" tooltip="' + escapeChars(obj.History) + '" tooltip_style="civInfoTooltip"]';
if (obj.Description)
string += '\n ' + obj.Description;
string += '\n[/color]';
return string;
}
// Called when user selects civ from dropdown
function selectCiv(code)
{
var civInfo = g_CivData[code];
if(!civInfo)
error(sprintf("Error loading civ data for \"%(code)s\"", { code: code }));
// Update civ gameplay display
Engine.GetGUIObjectByName("civGameplayHeading").caption = heading(sprintf(translate("%(civilization)s Gameplay"), { civilization: civInfo.Name }), 16);
// Bonuses
var bonusCaption = heading(translatePlural("Civilization Bonus", "Civilization Bonuses", civInfo.CivBonuses.length), 12) + '\n';
for(var i = 0; i < civInfo.CivBonuses.length; ++i)
bonusCaption += subHeading(civInfo.CivBonuses[i]);
bonusCaption += heading(translatePlural("Team Bonus", "Team Bonuses", civInfo.TeamBonuses.length), 12) + '\n';
for(var i = 0; i < civInfo.TeamBonuses.length; ++i)
bonusCaption += subHeading(civInfo.TeamBonuses[i]);
Engine.GetGUIObjectByName("civBonuses").caption = bonusCaption;
// Special techs / buildings
var techCaption = heading(translate("Special Technologies"), 12) + '\n';
for(var i = 0; i < civInfo.Factions.length; ++i)
{
var faction = civInfo.Factions[i];
for(var j = 0; j < faction.Technologies.length; ++j)
techCaption += subHeading(faction.Technologies[j]);
}
techCaption += heading(translatePlural("Special Building", "Special Buildings", civInfo.Structures.length), 12) + '\n';
for(var i = 0; i < civInfo.Structures.length; ++i)
techCaption += subHeading(civInfo.Structures[i]);
Engine.GetGUIObjectByName("civTechs").caption = techCaption;
// Heroes
var heroCaption = heading(translate("Heroes"), 12) + '\n';
for(var i = 0; i < civInfo.Factions.length; ++i)
{
var faction = civInfo.Factions[i];
for(var j = 0; j < faction.Heroes.length; ++j)
heroCaption += subHeading(faction.Heroes[j]);
heroCaption += '\n';
}
Engine.GetGUIObjectByName("civHeroes").caption = heroCaption;
// Update civ history display
Engine.GetGUIObjectByName("civHistoryHeading").caption = heading(sprintf(translate("History of the %(civilization)s"), { civilization: civInfo.Name }), 16);
Engine.GetGUIObjectByName("civHistoryText").caption = civInfo.History;
}