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); | ||||
/** | |||||
* Font tags of the Name, History and Description. | |||||
*/ | |||||
var g_NameHistoryDescriptionTextTags = { | |||||
"name": { "font": "sans-bold-14" } | |||||
}; | |||||
elexis: colour -> color rP16438
Default locale is en-US for both strings and code comments.
Armour… | |||||
var g_SelectedCiv = ""; | var g_SelectedCiv = ""; | ||||
/** | /** | ||||
* Initialize the dropdown containing all the available civs. | * Initialize the dropdown containing all the available civs. | ||||
*/ | */ | ||||
function init(data = {}) | function init(data = {}) | ||||
{ | { | ||||
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 = data.civ ? civSelection.list_data.indexOf(data.civ) : 0; | civSelection.selected = data.civ ? civSelection.list_data.indexOf(data.civ) : 0; | ||||
Engine.GetGUIObjectByName("structreeButton").tooltip = colorizeHotkey(translate("%(hotkey)s: Switch to Structure Tree."), "structree"); | Engine.GetGUIObjectByName("structreeButton").tooltip = colorizeHotkey(translate("%(hotkey)s: Switch to Structure Tree."), "structree"); | ||||
Engine.GetGUIObjectByName("close").tooltip = colorizeHotkey(translate("%(hotkey)s: Close History."), "cancel"); | Engine.GetGUIObjectByName("close").tooltip = colorizeHotkey(translate("%(hotkey)s: Close History."), "cancel"); | ||||
} | } | ||||
/** | /** | ||||
* 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 setStringTags(str[0], { "font": "sans-bold-" + (size + 6) }) + setStringTags(str.substring(1), { "font": "sans-bold-" + size }); | ||||
} | } | ||||
Done Inline ActionsThis smells like it could be updated too. I suppose theres also a better term for bigFirstLetter https://en.wikipedia.org/wiki/Initial
elexis: This smells like it could be updated too.
Notice that we only have very few distinct fonts, at… | |||||
Done Inline ActionsI guess thats OT :P elexis: I guess thats OT :P | |||||
Done Inline ActionsThe Initial is off-topic you mean? Freagarach: The Initial is off-topic you mean? | |||||
Done Inline ActionsOT=offtopic yes not only initial / drop cap, but also not computing fontsize when that is currently not supported. I guess that might be supported eventually, at least I heard two people wanting to work on that. elexis: OT=offtopic yes
not only initial / drop cap, but also not computing fontsize when that is… | |||||
/** | /** | ||||
* Set heading font - bold and mixed caps | * Set heading font - bold and mixed caps | ||||
* | * | ||||
* @param string {string} | * @param string {string} | ||||
* @param size {number} - Font size | * @param size {number} - Font size | ||||
* @returns {string} | * @returns {string} | ||||
*/ | */ | ||||
function heading(string, size) | function heading(string, size) | ||||
{ | { | ||||
var textArray = string.split(" "); | var textArray = string.split(" "); | ||||
for (let i in textArray) | for (let i in textArray) | ||||
{ | { | ||||
var word = textArray[i]; | var word = textArray[i]; | ||||
var wordCaps = word.toUpperCase(); | var wordCaps = word.toUpperCase(); | ||||
// Check if word is capitalized, if so assume it needs a big first letter | // 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 | // Check if toLowerCase changes the character to avoid false positives from special signs | ||||
if (word.length && word[0].toLowerCase() != word[0]) | if (word.length && word[0].toLowerCase() != word[0]) | ||||
textArray[i] = bigFirstLetter(wordCaps, size); | textArray[i] = bigFirstLetter(wordCaps, size); | ||||
else | else | ||||
textArray[i] = '[font="sans-bold-' + size + '"]' + wordCaps + '[/font]'; // TODO: Would not be necessary if we could do nested tags | textArray[i] = setStringTags(wordCaps, { "font": "sans-bold-" + size }); // TODO: Would not be necessary if we could do nested tags | ||||
Done Inline Actions(same) elexis: (same) | |||||
} | } | ||||
return textArray.join(" "); | return textArray.join(" "); | ||||
} | } | ||||
/** | /** | ||||
* Prepends a backslash to all quotation marks. | * Prepends a backslash to all quotation marks. | ||||
* @param str {string} | * @param str {string} | ||||
Show All 9 Lines | |||||
* | * | ||||
* @param obj {Object} | * @param obj {Object} | ||||
* @returns {string} | * @returns {string} | ||||
*/ | */ | ||||
function subHeading(obj) | function subHeading(obj) | ||||
{ | { | ||||
if (!obj.Name) | if (!obj.Name) | ||||
return ""; | return ""; | ||||
let string = '[font="sans-bold-14"]' + obj.Name + '[/font] '; | let string = setStringTags(obj.Name, g_NameHistoryDescriptionTextTags.name); | ||||
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"]'; | ||||
Not Done Inline ActionsThis line shows us that setStringTags is missing some things. CGUIString.h: enum TagType { TAG_B, TAG_I, TAG_FONT, TAG_SIZE, TAG_COLOR, TAG_IMGLEFT, TAG_IMGRIGHT, TAG_ICON, TAG_INVALID }; elexis: This line shows us that setStringTags is missing some things.
And makes me wonder whether it… | |||||
if (obj.Description) | if (obj.Description) | ||||
string += '\n ' + obj.Description; | string += '\n ' + obj.Description; | ||||
// Translation: insert an itemization symbol for each entry. | // Translation: insert an itemization symbol for each entry. | ||||
return sprintf(translate("• %(string)s"), { "string": string }) + "\n"; | return sprintf(translate("• %(string)s"), { "string": string }) + "\n"; | ||||
Done Inline Actions(white was useless and removed (because the prior text didnt set white but intended to use the same color for all items) in r22876) elexis: (`white` was useless and removed (because the prior text didnt set white but intended to use… | |||||
Done Inline ActionsGlobals are frowned upon. Rightfully so. However I don't mind these tags to become global to avoid repeated JS object construction in general, to have modders change the value easily without replacing the function, and to keep it globally consistent. Unless there comes evidence to the contrary, the UI components become prototypes, so then the tags will become prototype members too instead of globals, and thus cleaned again. elexis: Globals are frowned upon. Rightfully so. However I don't mind these tags to become global to… | |||||
} | } | ||||
function switchToStrucTreePage() | function switchToStrucTreePage() | ||||
{ | { | ||||
Engine.PopGuiPage({ "civ": g_SelectedCiv, "nextPage": "page_structree.xml" }); | Engine.PopGuiPage({ "civ": g_SelectedCiv, "nextPage": "page_structree.xml" }); | ||||
} | } | ||||
function closePage() | function closePage() | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |
colour -> color rP16438
Default locale is en-US for both strings and code comments.
Armour->Armor was always planned hence.
"color" seems to be the wrong name if the value is a tag that can contain font and color.
Using an object to encompass all tags (like tooltips.js) actually seems nicer than the stray globals that we find in other GUI pages, so agree on that.
You had asked to make that const, the philosophy was mostly that everything should be var so that modders can change it, unless there is a good reason to have it const. The civs object is const and recursively frozen in order to enforce that no function accidentally and unintentionally modifies the civ data (that may be questioned as a use case for mods actually).
So ack on this being var.