UiBuildingOverlay
The UiBuildingOverlay class renders a tooltip overlay on top of a selected building, showing its tier, health bar, stats (current vs. next tier), and action buttons for upgrading, selling, depositing, and collecting. It supports an "Upgrade All" mode and attaches a RangeIndicatorModel for buildings with range stats or for the Gold Stash build radius.
UiBuildingOverlay private
Extends UiComponent.
Properties
| Name | Type | Description |
|---|---|---|
ui | Ui | Current Ui instance. Inherited from UiComponent. |
componentElem | HTMLElement | The root #hud-building-overlay DOM element. Inherited from UiComponent. |
shouldUpgradeAll | boolean | Whether the overlay operates in "Upgrade All" mode. Defaults to false. |
maxStashDistance | number | Maximum grid-cell distance from the Gold Stash that buildings can be placed. Defaults to 18. |
buildingUid | number \| null | The UID of the currently watched building, or null. |
buildingId | string \| null | The type identifier of the currently watched building. |
buildingTier | number \| null | The current tier of the watched building. |
rangeIndicator | RangeIndicatorModel \| undefined | The range indicator rendered on the ground layer, if applicable. |
tierElem | HTMLElement | The .hud-building-tier span showing the current tier number. |
healthBarElem | HTMLElement | The .hud-tooltip-health-bar span representing the health bar fill. |
statsElem | HTMLElement | The .hud-building-stats container for current/next stat values. |
actionsElem | HTMLElement | The .hud-building-actions container for action buttons. |
depositElem | HTMLElement | The .hud-building-deposit button (Harvester-only). |
dualBtnElem | HTMLElement | The .hud-building-dual-btn wrapper for deposit/collect (Harvester-only). |
collectElem | HTMLElement | The .hud-building-collect button (Harvester-only). |
upgradeElem | HTMLElement | The .hud-building-upgrade button. |
sellElem | HTMLElement | The .hud-building-sell button. |
Methods
constructor()
function constructor(ui: Ui): voidInitializes the overlay, binds mousedown/mouseup event propagation stoppers, registers a renderer tick callback, and listens for cameraUpdate, buildingsUpdate, and buildingSchemaUpdate events.
isActive()
function isActive(): booleanReturns true if the overlay is currently watching a building.
getBuildingUid()
function getBuildingUid(): number | nullReturns the UID of the currently watched building.
getShouldUpgradeAll()
function getShouldUpgradeAll(): booleanReturns whether the "Upgrade All" mode is enabled.
setShouldUpgradeAll()
function setShouldUpgradeAll(shouldUpgradeAll: boolean): voidSets the "Upgrade All" mode and triggers an update().
update()
function update(): voidRecalculates and re-renders the overlay content: positions the overlay relative to the building's screen coordinates, computes health percentage, determines current/next tier stats using a stat map (health, damage, range, gps, harvest, harvestCapacity), computes upgrade costs and sell refunds via Util.createResourceCostString() / Util.createResourceRefundString(), toggles action button states, and updates the range indicator position.
startWatching()
function startWatching(buildingUid: number): voidBegins watching a building by UID. Populates the overlay HTML with the building name, tier, health bar, stats, and action buttons. Creates a RangeIndicatorModel if the building is a Gold Stash (rectangular) or has rangeTiers (circular). Calls show() and update().
stopWatching()
function stopWatching(): voidStops watching the current building. Removes the range indicator from the ground layer, clears the overlay HTML, resets internal state, and calls hide().
depositIntoBuilding()
function depositIntoBuilding(): voidSends an AddDepositToHarvester RPC for the watched Harvester building. In "Upgrade All" mode, iterates all buildings of the same type and sends the RPC for each.
collectFromBuilding()
function collectFromBuilding(): voidSends a CollectHarvester RPC for the watched building.
upgradeBuilding()
function upgradeBuilding(): voidSends an UpgradeBuilding RPC. In "Upgrade All" mode, iterates all buildings of the same type and tier and sends the RPC for each.
sellBuilding()
function sellBuilding(): voidSends a DeleteBuilding RPC for the watched building. Returns early without action if the building is a Gold Stash.
getGoldStashTier()
function getGoldStashTier(): numberScans the player's buildings to find the Gold Stash and returns its tier. Defaults to 1 if no Gold Stash is found.
Event Handlers
onMouseDown()
function onMouseDown(event: MouseEvent): voidStops event propagation to prevent clicks from reaching the game world.
onMouseUp()
function onMouseUp(event: MouseEvent): voidStops event propagation to prevent clicks from reaching the game world.
onTick()
function onTick(): voidRenderer tick callback. Updates the health bar percentage and Harvester deposit button disabled state each frame. Calls stopWatching() if the entity no longer exists.
onCameraUpdate()
function onCameraUpdate(): voidHandles the cameraUpdate event. Calls update().
onBuildingsUpdate()
function onBuildingsUpdate(): voidHandles the buildingsUpdate event. Calls update().
onBuildingSchemaUpdate()
function onBuildingSchemaUpdate(): voidHandles the buildingSchemaUpdate event. Calls update().