Differential D2734 Diff 12364 binaries/data/mods/public/gui/reference/structree/Sections/Tree/TreeSection.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/reference/structree/Sections/Tree/TreeSection.js
- This file was added.
class TreeSection | |||||
{ | |||||
constructor(page) | |||||
{ | |||||
this.page = page; | |||||
this.TreeSection = Engine.GetGUIObjectByName("treeSection"); | |||||
this.Structures = Engine.GetGUIObjectByName("structures"); | |||||
this.PhaseIdents = new PhaseIdentManager(this.page); | |||||
this.rightMargin = this.TreeSection.size.right; | |||||
this.structureBoxes = []; | |||||
for (let boxIdx in this.Structures.children) | |||||
this.structureBoxes.push(new StructureBox(this.page, boxIdx)); | |||||
page.TrainerSection.registerWidthChangedHandler(this.onTrainerSectionWidthChange.bind(this)); | |||||
} | |||||
draw(structures, civCode) | |||||
{ | |||||
if (structures.size > this.structureBoxes.length) | |||||
error("\"" + this.activeCiv + "\" has more structures than can be supported by the current GUI layout"); | |||||
// Draw structures | |||||
let phaseList = this.page.TemplateParser.phaseList; | |||||
let count = Math.min(structures.size, this.structureBoxes.length); | |||||
let runningWidths = Array(phaseList.length).fill(0); | |||||
let structureIterator = structures.keys(); | |||||
for (let idx = 0; idx < count; ++idx) | |||||
this.structureBoxes[idx].draw(structureIterator.next().value, civCode, runningWidths); | |||||
hideRemaining(this.Structures.name, count); | |||||
// Position phase idents | |||||
this.PhaseIdents.draw(phaseList, civCode, runningWidths, this.Structures.size.left); | |||||
} | |||||
drawPhaseIcon(phaseIcon, phaseIndex, civCode) | |||||
{ | |||||
let phaseName = this.page.TemplateParser.phaseList[phaseIndex]; | |||||
let prodPhaseTemplate = this.page.TemplateParser.getTechnology(phaseName + "_" + civCode, civCode) || this.page.TemplateParser.getTechnology(phaseName, civCode); | |||||
phaseIcon.sprite = "stretched:" + this.page.IconPath + prodPhaseTemplate.icon; | |||||
phaseIcon.tooltip = getEntityNamesFormatted(prodPhaseTemplate); | |||||
}; | |||||
onTrainerSectionWidthChange(trainerSectionWidth, trainerSectionVisible) | |||||
{ | |||||
let size = this.TreeSection.size; | |||||
size.right = this.rightMargin; | |||||
if (trainerSectionVisible) | |||||
size.right -= trainerSectionWidth + this.page.SectionGap; | |||||
this.TreeSection.size = size; | |||||
elexis: `this.SectionGap`? `this.page.SectionGap`?
Accessing `StructreePage.prototype` can often be… | |||||
Done Inline ActionsReferencePage does not inherit from StructreePage. It's the other way round. However, this should now be handled more to your satisfaction. s0600204: `ReferencePage` does not inherit from `StructreePage`. It's the other way round.
However, this… | |||||
} | |||||
/** | |||||
* Calculate row position offset (accounting for different number of prod rows per phase). | |||||
* | |||||
* This is a static method as it is also used from within the StructureBox and PhaseIdent classes. | |||||
* | |||||
* @param {number} idx | |||||
* @return {number} | |||||
*/ | |||||
static getPositionOffset(idx, TemplateParser) | |||||
{ | |||||
let phases = TemplateParser.phaseList.length; | |||||
let rowHeight = ProductionIcon.Size().rowHeight; | |||||
let size = EntityBox.IconAndCaptionHeight() * idx; // text, image and offset | |||||
size += EntityBox.prototype.VMargin * (idx + 1); // Margin above StructureBoxes | |||||
size += rowHeight * (phases * idx - (idx - 1) * idx / 2); // phase rows (phase-currphase+1 per row) | |||||
return size; | |||||
}; | |||||
} |
Wildfire Games · Phabricator
this.SectionGap? this.page.SectionGap?
Accessing StructreePage.prototype can often be ugly and deprives ability to access the actual instance to utilize its state and caching. Using something like this.page gains that ability at the cost of allowing for new kinds of unanticipating dependencies. Here this number is used in only one place, so it could be moved to this class' prototype.
However I see more references to ReferencePage.prototype and that class inherits StructreePage, so having a this.page already seems to be the case, just being restricted to static members and losing inheritance by having to distinguish using hardcoding between the two page classes.