UiToolbarBuilding
The UiToolbarBuilding class represents a single building button in the toolbar. It supports click-to-place and drag-to-place interactions, shows a tooltip with the building's name, description, cost, and built/limit count.
UiToolbarBuilding private
Extends UiComponent.
Properties
| Name | Type | Description |
|---|---|---|
ui | Ui | Current Ui instance. Inherited from UiComponent. |
componentElem | HTMLElement | The .hud-toolbar-building anchor element with data-building and draggable="true". |
buildingId | string | The building type ID. |
tooltip | UiTooltip | The tooltip instance for this button. |
Methods
constructor()
function constructor(ui: Ui, buildingId: string): voidCreates the building button, attaches a UiTooltip, binds mousedown, mouseup, dragstart, drag, and dragend listeners, and registers for buildingsUpdate and buildingSchemaUpdate events.
update()
function update(): voidSets the data-key attribute from the schema and toggles is-disabled based on the schema's disabled flag.
onTooltipCreate()
function onTooltipCreate(): stringReturns the tooltip HTML containing the building name, "Tier 1 Building" subtitle, built/limit count (highlighted red if at limit), description, and resource costs via Util.createResourceCostString().
onMouseDown()
function onMouseDown(event: MouseEvent): voidStops event propagation.
onMouseUp()
function onMouseUp(event: MouseEvent): voidStops event propagation. Emits startPlacingBuilding if not disabled.
onDragStart()
function onDragStart(event: DragEvent): voidSets a blank drag image, emits startPlacingBuilding, and hides the tooltip.
onDrag()
function onDrag(event: DragEvent): voidForwards drag events to inputManager as mouseMoved for live placement preview updates.
onDragEnd()
function onDragEnd(event: DragEvent): voidPrevents default and emits placeBuilding.
onBuildingsUpdate()
function onBuildingsUpdate(): voidCalls update().
onBuildingSchemaUpdate()
function onBuildingSchemaUpdate(): voidCalls update().