Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/reference/structree/structree.js
/** | /** | ||||
* Array of structure template names when given a civ and a phase name. | * Array of structure template names when given a civ and a phase name. | ||||
*/ | */ | ||||
var g_BuildList = {}; | var g_BuildList = {}; | ||||
/** | /** | ||||
* Array of template names that can be trained from a unit, given a civ and unit template name. | * Array of template names that can be trained from a unit, given a civ and unit template name. | ||||
*/ | */ | ||||
var g_TrainList = {}; | var g_TrainList = {}; | ||||
/** | /** | ||||
* Callback function name on closing gui via Engine.PopGuiPage(). | |||||
*/ | |||||
var g_Callback = ""; | |||||
/** | |||||
* Initialize the page | * Initialize the page | ||||
* | * | ||||
* @param {object} data - Parameters passed from the code that calls this page into existence. | * @param {object} data - Parameters passed from the code that calls this page into existence. | ||||
*/ | */ | ||||
function init(data = {}) | function init(data = {}) | ||||
{ | { | ||||
if (data.callback) | |||||
g_Callback = data.callback; | |||||
let civList = Object.keys(g_CivData).map(civ => ({ | let civList = Object.keys(g_CivData).map(civ => ({ | ||||
"name": g_CivData[civ].Name, | "name": g_CivData[civ].Name, | ||||
"code": civ, | "code": civ, | ||||
})).sort(sortNameIgnoreCase); | })).sort(sortNameIgnoreCase); | ||||
if (!civList.length) | if (!civList.length) | ||||
{ | throw new Error("No civs available!"); | ||||
closePage(); | |||||
return; | |||||
} | |||||
g_ParsedData = { | g_ParsedData = { | ||||
"units": {}, | "units": {}, | ||||
"structures": {}, | "structures": {}, | ||||
"techs": {}, | "techs": {}, | ||||
"phases": {} | "phases": {} | ||||
}; | }; | ||||
let civSelection = Engine.GetGUIObjectByName("civSelection"); | let civSelection = Engine.GetGUIObjectByName("civSelection"); | ||||
civSelection.list = civList.map(c => c.name); | civSelection.list = civList.map(c => c.name); | ||||
civSelection.list_data = civList.map(c => c.code); | civSelection.list_data = civList.map(c => c.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("civinfo").tooltip = colorizeHotkey(translate("%(hotkey)s: Switch to History."), "civinfo"); | Engine.GetGUIObjectByName("civinfo").tooltip = colorizeHotkey(translate("%(hotkey)s: Switch to History."), "civinfo"); | ||||
Engine.GetGUIObjectByName("close").tooltip = colorizeHotkey(translate("%(hotkey)s: Close Structure Tree."), "cancel"); | Engine.GetGUIObjectByName("close").tooltip = colorizeHotkey(translate("%(hotkey)s: Close Structure Tree."), "cancel"); | ||||
} | } | ||||
function switchToCivInfoPage() | function switchToCivInfoPage() | ||||
{ | { | ||||
Engine.PopGuiPage(); | Engine.PopGuiPage({ | ||||
Engine.PushGuiPage("page_civinfo.xml", { "civ": g_SelectedCiv, "callback": g_Callback }); | "civ": g_SelectedCiv, | ||||
"nextPage": "page_civinfo.xml" | |||||
}); | |||||
} | } | ||||
function close() | function closePage() | ||||
{ | { | ||||
if (g_Callback) | Engine.PopGuiPage({ | ||||
Engine.PopGuiPageCB({ "civ": g_SelectedCiv, "page": "page_structree.xml" }); | "civ": g_SelectedCiv, | ||||
else | "lastPage": "page_structree.xml" | ||||
Engine.PopGuiPage(); | }); | ||||
} | } | ||||
/** | /** | ||||
* @param {string} civCode | * @param {string} civCode | ||||
*/ | */ | ||||
function selectCiv(civCode) | function selectCiv(civCode) | ||||
{ | { | ||||
if (civCode === g_SelectedCiv || !g_CivData[civCode]) | if (civCode === g_SelectedCiv || !g_CivData[civCode]) | ||||
▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator