Changeset View
Standalone View
binaries/data/mods/public/gui/reference/structree/StructreePage.js
- This file was added.
/** | |||||
* This class represents the Structure Tree GUI page. | |||||
* | |||||
* Further methods are described within draw.js | |||||
*/ | |||||
class StructreePage extends ReferencePage | |||||
{ | |||||
constructor(data) | |||||
{ | |||||
super(); | |||||
this.structureBoxes = []; | |||||
this.trainerBoxes = []; | |||||
this.guiElems = { | |||||
elexis: guiObjects or guiElements | |||||
"civEmblem": Engine.GetGUIObjectByName("civEmblem"), | |||||
"civName": Engine.GetGUIObjectByName("civName"), | |||||
"civHistory": Engine.GetGUIObjectByName("civHistory"), | |||||
"structures": Engine.GetGUIObjectByName("structures"), | |||||
"trainers": Engine.GetGUIObjectByName("trainers"), | |||||
"display_tree": Engine.GetGUIObjectByName("display_tree"), | |||||
"display_trainers": Engine.GetGUIObjectByName("display_trainers"), | |||||
"phase": [], | |||||
}; | |||||
let civList = Object.keys(this.civData).map(civ => ({ | |||||
"name": this.civData[civ].Name, | |||||
"code": civ, | |||||
})).sort(sortNameIgnoreCase); | |||||
if (!civList.length) | |||||
{ | |||||
this.closePage(); | |||||
return; | |||||
} | |||||
let civSelection = Engine.GetGUIObjectByName("civSelection"); | |||||
civSelection.list = civList.map(c => c.name); | |||||
civSelection.list_data = civList.map(c => c.code); | |||||
civSelection.onSelectionChange = () => this.selectCiv(civSelection.list_data[civSelection.selected]); | |||||
Done Inline ActionsI did not check if the the anonymous function () => this.selectCiv(civSelection.list_data[civSelection.selected]); is faster than bind this.selectCiv.bind(this);, either way I suppose its negligible considering how often the function is called (once per click). elexis: I did not check if the the anonymous function `() => this.selectCiv(civSelection.list_data… | |||||
let switchToCivInfoButton = Engine.GetGUIObjectByName("civinfo"); | |||||
switchToCivInfoButton.onPress = this.switchToCivInfoPage.bind(this); | |||||
switchToCivInfoButton.tooltip = colorizeHotkey(translate("%(hotkey)s: Switch to History."), "civinfo"); | |||||
let closeButton = Engine.GetGUIObjectByName("close"); | |||||
closeButton.onPress = this.closePage.bind(this); | |||||
closeButton.tooltip = colorizeHotkey(translate("%(hotkey)s: Close Structure Tree."), "cancel"); | |||||
} | |||||
Done Inline Actions(In many classes one can find foo.prototype.FooTooltip = translate("%(hotkey)s: Close Structure Tree.") and foo.prototype.FooHotkey = "cancel". It can alllow mods to change the strings, furthers separation of data and code, in few cases the hotkey is reused, otherwise its not so important to spend the time splitting that and may be ignored) Hotkeys can change in the future (and for mods I guess), then the tooltip should also become updated (in the hypothetical future then). elexis: (In many classes one can find `foo.prototype.FooTooltip = translate("%(hotkey)s: Close… | |||||
switchToCivInfoPage() | |||||
{ | |||||
Engine.PopGuiPage({ "civ": this.activeCiv, "nextPage": "page_civinfo.xml" }); | |||||
} | |||||
closePage() | |||||
{ | |||||
Engine.PopGuiPage({ "civ": this.activeCiv, "page": "page_structree.xml" }); | |||||
} | |||||
selectCiv(civCode) | |||||
{ | |||||
this.setActiveCiv(civCode); | |||||
// Set basic state (positioning of elements mainly), but only once | |||||
if (!this.structureBoxes.length) | |||||
this.predraw(); | |||||
// Draw the structree | |||||
this.draw(); | |||||
this.drawPhaseIcons(); | |||||
} | |||||
} |
guiObjects or guiElements