0ad/binaries/data/mods/public/gui/reference/structree/Boxes/StructureBox.js
Vantha fd847c2a23
Refactor GUI object resizing JS code passages
It is possible to modify sizes by setting the properties directly.
(Without having to create a copy of it)
This allows to shorten those passages quite a bit without any functional change.
2025-06-17 12:57:37 -05:00

35 lines
1.3 KiB
JavaScript

/**
* This code wraps the gui representing buildable structures within the structree.
*
* An instance of this class is created for each child of the gui element named "structures".
*/
class StructureBox extends EntityBox
{
constructor(page, structureIdx)
{
super(page);
this.gui = Engine.GetGUIObjectByName("structure[" + structureIdx + "]");
this.ProductionRows = new ProductionRowManager(this.page, "structure[" + structureIdx + "]_productionRows", true);
}
draw(templateName, civCode, runningWidths)
{
super.draw(templateName, civCode);
this.phaseIdx = this.page.TemplateParser.phaseList.indexOf(this.template.phase);
// Draw the production rows
this.ProductionRows.draw(this.template, civCode, this.phaseIdx);
const boxWidth = Math.max(this.MinWidth, this.captionWidth(), this.ProductionRows.width);
// Set position of the Structure Box
Object.assign(this.gui.size, {
"left": this.HMargin + runningWidths[this.phaseIdx], "top": TreeSection.getPositionOffset(this.phaseIdx, this.page.TemplateParser),
"right": this.HMargin + runningWidths[this.phaseIdx] + boxWidth, "bottom": TreeSection.getPositionOffset(this.phaseIdx + 1, this.page.TemplateParser) - this.VMargin
});
// Update new right-side-edge dimension
runningWidths[this.phaseIdx] += boxWidth + this.HMargin / 2;
}
}