Changeset View
Standalone View
binaries/data/mods/public/gui/civinfo/civinfo.js
/** | /** | ||||
* Display selectable civs only. | * Display selectable civs only. | ||||
*/ | */ | ||||
const g_CivData = loadCivData(true, false); | const g_CivData = loadCivData(true, false); | ||||
/* | |||||
s0600204Unsubmitted Not Done Inline Actionss0600204: /** | |||||
* Callback function on closing gui via Engine.PopGuiPage(). | |||||
*/ | |||||
var g_Callback = ""; | |||||
Not Done Inline ActionsAs in structree.js below, the comment should probably mention that this contains the name, not the actual function. Or rename the variable to g_CallbackName wherever it is used. s0600204: As in `structree.js` below, the comment should probably mention that this contains the name… | |||||
/** | /** | ||||
* Initialize the dropdown containing all the available civs. | * Initialize the dropdown containing all the available civs. | ||||
*/ | */ | ||||
function init(settings) | function init(data = {}) | ||||
Not Done Inline Actions
s0600204: 1) Set a default value (`data = {}`) | |||||
{ | |||||
if (data.callback) | |||||
Not Done Inline Actions
s0600204: 2) `if (data.callback)` | |||||
{ | { | ||||
g_CallbackSet = true; | |||||
g_Callback = data.callback; | |||||
} | |||||
var civList = Object.keys(g_CivData).map(civ => ({ "name": g_CivData[civ].Name, "code": civ })).sort(sortNameIgnoreCase); | var civList = Object.keys(g_CivData).map(civ => ({ "name": g_CivData[civ].Name, "code": civ })).sort(sortNameIgnoreCase); | ||||
var civSelection = Engine.GetGUIObjectByName("civSelection"); | var civSelection = Engine.GetGUIObjectByName("civSelection"); | ||||
civSelection.list = civList.map(civ => civ.name); | civSelection.list = civList.map(civ => civ.name); | ||||
civSelection.list_data = civList.map(civ => civ.code); | civSelection.list_data = civList.map(civ => civ.code); | ||||
civSelection.selected = 0; | civSelection.selected = data.civ ? civSelection.list_data.indexOf(data.civ) : 0; | ||||
Not Done Inline Actions
s0600204: 3) Remove line | |||||
} | } | ||||
Not Done Inline Actions
s0600204: 4) Use `data.civ` instead of `g_SelectedCiv` (`g_SelectedCiv` gets set in `selectCiv()`, which… | |||||
/** | /** | ||||
Not Done Inline ActionsAfaik, the term "page" is not exposed to the user - it's what they're called in code, but the end user doesn't need to know that. ack --type=js -i "\.tooltip.*page" reveals these (and the two later in this patch) are the only JS-set tooltips where "page" is mentioned. ack --type=xml -i "tooltip.*page" reveals only one location where the word "page" is used in a tooltip - and that is inside the phrase "Click to open the 0 A.D. translate page in your browser." and refers to a webpage. My point is, better tooltips would be "Switch to the Structure Tree" and "Close History" respectively. s0600204: Afaik, the term "page" is not exposed to the user - it's what they're called in code, but the… | |||||
* Give the first character a larger font. | * Give the first character a larger font. | ||||
*/ | */ | ||||
function bigFirstLetter(str, size) | function bigFirstLetter(str, size) | ||||
{ | { | ||||
return '[font="sans-bold-' + (size + 6) + '"]' + str[0] + '[/font]' + '[font="sans-bold-' + size + '"]' + str.substring(1) + '[/font]'; | return '[font="sans-bold-' + (size + 6) + '"]' + str[0] + '[/font]' + '[font="sans-bold-' + size + '"]' + str.substring(1) + '[/font]'; | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | function subHeading(obj) | ||||
let string = '[font="sans-bold-14"]' + obj.Name + '[/font] '; | let string = '[font="sans-bold-14"]' + obj.Name + '[/font] '; | ||||
if (obj.History) | if (obj.History) | ||||
string += '[icon="iconInfo" tooltip="' + escapeQuotation(obj.History) + '" tooltip_style="civInfoTooltip"]'; | string += '[icon="iconInfo" tooltip="' + escapeQuotation(obj.History) + '" tooltip_style="civInfoTooltip"]'; | ||||
if (obj.Description) | if (obj.Description) | ||||
string += '\n ' + obj.Description; | string += '\n ' + obj.Description; | ||||
return coloredText(string + "\n", "white"); | return coloredText(string + "\n", "white"); | ||||
} | } | ||||
function switchToStrucTreePage() | |||||
{ | |||||
Engine.PopGuiPage(); | |||||
Engine.PushGuiPage("page_structree.xml", { "civ": g_SelectedCiv, "callback": g_Callback }); | |||||
} | |||||
function close() | |||||
{ | |||||
closePage({ "civ": g_SelectedCiv, "page": "page_civinfo.xml" }); | |||||
} | |||||
/** | /** | ||||
* Updates the GUI after the user selected a civ from dropdown. | * Updates the GUI after the user selected a civ from dropdown. | ||||
* | * | ||||
* @param code {string} | * @param code {string} | ||||
*/ | */ | ||||
function selectCiv(code) | function selectCiv(code) | ||||
{ | { | ||||
var civInfo = g_CivData[code]; | var civInfo = g_CivData[code]; | ||||
g_SelectedCiv = code; | |||||
if(!civInfo) | if(!civInfo) | ||||
error(sprintf("Error loading civ data for \"%(code)s\"", { "code": code })); | error(sprintf("Error loading civ data for \"%(code)s\"", { "code": code })); | ||||
// Update civ gameplay display | // Update civ gameplay display | ||||
Engine.GetGUIObjectByName("civGameplayHeading").caption = heading(sprintf(translate("%(civilization)s Gameplay"), { "civilization": civInfo.Name }), 16); | Engine.GetGUIObjectByName("civGameplayHeading").caption = heading(sprintf(translate("%(civilization)s Gameplay"), { "civilization": civInfo.Name }), 16); | ||||
// Bonuses | // Bonuses | ||||
var bonusCaption = heading(translatePlural("Civilization Bonus", "Civilization Bonuses", civInfo.CivBonuses.length), 12) + '\n'; | var bonusCaption = heading(translatePlural("Civilization Bonus", "Civilization Bonuses", civInfo.CivBonuses.length), 12) + '\n'; | ||||
Show All 37 Lines |