1
0
forked from mirrors/0ad
Files
0ad/binaries/data/mods/public/gui/reference/structree/Boxes/TrainerBox.js
T
s0600204 b2842e8021 Rewrite Structure Tree and Template Viewer to use OOP principles
Commenters: elexis, Stan, Angen
Refs.: #5387
Differential Revision: https://code.wildfiregames.com/D2734
This was SVN commit r23808.
2020-07-07 19:11:36 +00:00

43 lines
1.2 KiB
JavaScript

/**
* This code wraps the gui representing "trainer units" (a unit that can train other units) within the structree.
*
* An instance of this class is created for each child of the gui element named "trainers".
*/
class TrainerBox extends EntityBox
{
constructor(page, trainerIdx)
{
super(page);
this.gui = Engine.GetGUIObjectByName("trainer[" + trainerIdx + "]");
this.ProductionRows = new ProductionRowManager(this.page, "trainer[" + trainerIdx + "]_productionRows", false);
let rowHeight = ProductionIcon.Size().rowHeight;
let size = this.gui.size;
// Adjust height to accommodate production row
size.bottom += rowHeight;
// We make the assumuption that all trainer boxes have the same height
let boxHeight = this.VMargin / 2 + (size.bottom - size.top + this.VMargin) * trainerIdx;
size.top += boxHeight;
size.bottom += boxHeight;
// Make the box adjust automatically to column width
size.rright = 100;
size.right = -size.left;
this.gui.size = size;
}
draw(templateName, civCode)
{
super.draw(templateName, civCode);
this.ProductionRows.draw(this.template, civCode);
// Return the box width
return Math.max(this.MinWidth, this.captionWidth(), this.ProductionRows.width);
}
}